-
-
-extern Opengles1DrawableImage in "C" `{struct mnit_opengles_DrawableTexture*`}
- super DrawableImage
- new ( w, h: Int ) is extern `{
- struct mnit_opengles_DrawableTexture *image =
- malloc( sizeof(struct mnit_opengles_DrawableTexture) );
-
- #ifdef a
- const EGLint attribs[] = {
- EGL_WIDTH, w,
- EGL_HEIGHT, h,
- EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA,
- EGL_TEXTURE_TARGET, EGL_TEXTURE_2D,
- EGL_NONE
- };
-
- image->surface = eglCreatePbufferSurface( andronit.display,
- andronit.config,
- attribs );
- if ( eglGetError() )
- LOGW( "eglCreatePbuffer error" );
-
- image->width = w;
- image->height = h;
- image->center_x = w/2;
- image->center_y = h/2;
- eglMakeCurrent( andronit.display,
- surface,
- surface,
- andronit.context );
-
- #else
- /* texture */
- glGenTextures(1, &image->super.texture);
- glBindTexture(GL_TEXTURE_2D, image->super.texture);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- /* glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // automatic mipmap generation included in OpenGL v1.4c */
- glBindTexture(GL_TEXTURE_2D, 0);
-
- /* fbo */
- glGenFramebuffersOES( 1, &image->fbo );
- glBindFramebufferOES( GL_FRAMEBUFFER_OES, image->fbo );
- glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES,
- GL_COLOR_ATTACHMENT0_OES,
- GL_TEXTURE_2D,
- image->super.texture,
- 0 );
-
- /* depth */
- glGenRenderbuffersOES(1, &image->depth);
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, image->depth);
- glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES,
- w, h);
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, 0);
- glFramebufferRenderbufferOES( GL_FRAMEBUFFER_OES,
- GL_DEPTH_ATTACHMENT_OES,
- GL_RENDERBUFFER_OES,
- image->depth );
-
- /* tex framebuffer */
- glGenRenderbuffersOES(1, &image->color);
- glBindRenderbufferOES(GL_RENDERBUFFER_OES, image->color);
- glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, w, h);
- glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, image->color );
-
- if ( glCheckFramebufferStatusOES( GL_FRAMEBUFFER_OES ) != GL_FRAMEBUFFER_COMPLETE_OES )
- {
- LOGW( "framebuffer not set" );
- if ( glCheckFramebufferStatusOES( GL_FRAMEBUFFER_OES ) == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_OES )
- LOGW( "framebuffer not set a" );
- else if ( glCheckFramebufferStatusOES( GL_FRAMEBUFFER_OES ) == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_OES )
- LOGW( "framebuffer not set b" );
- else if ( glCheckFramebufferStatusOES( GL_FRAMEBUFFER_OES ) == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES )
- LOGW( "framebuffer not set c" );
- else if ( glCheckFramebufferStatusOES( GL_FRAMEBUFFER_OES ) == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_OES )
- LOGW( "framebuffer not set d" );
- }
-
- image->super.width = w;
- image->super.height = h;
- image->super.center_x = w/2;
- image->super.center_y = h/2;
- image->super.scale = 1.0f;
- image->super.blended = 0;
-
- #endif
-
- if (glGetError() != GL_NO_ERROR) LOGW( "gl error");
-
- return image;
- `}
-
-# fun image: I is extern `{
-# struct mnit_opengles_Texture *image;
-# const uint_least32_t *pixels;
-# pixels = malloc( sizeof(uint_least32_t)*recv->width*recv->height );
-# glReadPixels( 0, 0, recv->width, recv->height,
-# GL_RGBA, GL_UNSIGNED_BYTE, pixels );
-# image = mnit_opengles_load_image( pixels, recv->width, recv->height );
-# return image;
-
- fun set_as_target is extern `{
- LOGI( "sat %i", recv->fbo );
- glBindFramebufferOES(GL_FRAMEBUFFER_OES, recv->fbo);
- /*glBindRenderbufferOES(GL_FRAMEBUFFER_OES, recv->color);*/
- if (glGetError() != GL_NO_ERROR) LOGW( "gl error 0");
- /*glGetIntegerv(GL_FRAMEBUFFER_BINDING_OES,&recv->fbo);
- //if (glGetError() != GL_NO_ERROR) LOGW( "gl error a");*/
- glViewport(0, 0, recv->super.width, recv->super.height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrthof(0.0f, recv->super.width, recv->super.height, 0.0f, 0.0f, 1.0f);
- glMatrixMode(GL_MODELVIEW);
- glFrontFace( GL_CW );
-
- glClearColor( 0.0f, 1.0f, 1.0f, 1.0f );
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- `}
-
- fun unset_as_target is extern `{
- glFlush();
- /*glBindTexture(GL_TEXTURE_2D, recv->super.texture);
- glGenerateMipmapOES(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);*/
- glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
- if (glGetError() != GL_NO_ERROR) LOGW( "gl error");
- `}
-end
-