m3g/m3gcore11/src/m3g_rendercontext.c
branchRCL_3
changeset 26 15986eb6c500
parent 11 fed1595b188e
child 163 bbf46f59e123
equal deleted inserted replaced
19:ac96196b945c 26:15986eb6c500
   399  * \param ctx        the rendering context
   399  * \param ctx        the rendering context
   400  */
   400  */
   401 M3G_API M3Gbool m3gGetAlphaWrite(M3GRenderContext ctx)
   401 M3G_API M3Gbool m3gGetAlphaWrite(M3GRenderContext ctx)
   402 {
   402 {
   403 	return ctx->alphaWrite;
   403 	return ctx->alphaWrite;
       
   404 }
       
   405 
       
   406 /*!
       
   407  * \brief Frees all GLES resources allocated by the M3G API 
       
   408  *        (EGL surfaces, contexts and texture objects). 
       
   409  *
       
   410  * \note M3G must not be bound to any target when calling this.
       
   411  *
       
   412  */
       
   413 M3G_API void m3gFreeGLESResources(M3GRenderContext ctx)
       
   414 {
       
   415 #ifdef M3G_ENABLE_GLES_RESOURCE_HANDLING
       
   416 
       
   417     PointerArray image2DObjects;
       
   418     M3Gint i;
       
   419 
       
   420     /* M3G must not be bound to a rendering target at this point. */
       
   421     if (ctx->target.type != SURFACE_NONE) {
       
   422         m3gRaiseError(M3G_INTERFACE(ctx), M3G_INVALID_OPERATION);
       
   423     }
       
   424 
       
   425     /* EGL might not be initialized yet, so do it here just in case. */ 
       
   426     eglInitialize(eglGetDisplay(EGL_DEFAULT_DISPLAY), NULL, NULL);
       
   427     eglMakeCurrent(eglGetDisplay(EGL_DEFAULT_DISPLAY), NULL, NULL, NULL);
       
   428 
       
   429     /* Delete EGL surfaces */
       
   430     for (i = 0; i < M3G_MAX_GL_SURFACES; ++i) {
       
   431         GLSurfaceRecord *surf = &ctx->glSurface[i];
       
   432         if (surf->handle) {
       
   433             m3gDeleteGLSurface(surf->handle);
       
   434         }
       
   435         m3gZero(surf, sizeof(GLSurfaceRecord));
       
   436     }
       
   437     if (ctx->backBuffer.glSurface != NULL) {
       
   438         m3gDeleteGLSurface(ctx->backBuffer.glSurface);
       
   439         m3gZero(&ctx->backBuffer, sizeof(BackBuffer));
       
   440     }
       
   441 
       
   442     /* Delete EGL contexts */
       
   443     for (i = 0; i < M3G_MAX_GL_CONTEXTS; ++i) {
       
   444         GLContextRecord *context = &ctx->glContext[i];
       
   445         if (context->handle) {
       
   446             m3gDeleteGLContext(context->handle);
       
   447         }
       
   448         m3gZero(context, sizeof(GLContextRecord));
       
   449     }
       
   450 
       
   451     /* Delete references to GLES texture objects from all live Image2D objects. 
       
   452        Texture objects themselves have already been destroyed with the last GL context. */
       
   453 
       
   454     m3gInitArray(&image2DObjects);
       
   455     m3gGetObjectsWithClassID(M3G_INTERFACE(ctx), M3G_CLASS_IMAGE, &image2DObjects);
       
   456 
       
   457     i = m3gArraySize(&image2DObjects);
       
   458 
       
   459     while (i > 0) {
       
   460         Image *image = (Image*)m3gGetArrayElement(&image2DObjects, --i);
       
   461 
       
   462         m3gInvalidateImage(image);
       
   463         image->texObject = 0;
       
   464     }
       
   465     m3gDestroyArray(&image2DObjects, M3G_INTERFACE(ctx));
       
   466 #endif
   404 }
   467 }
   405 
   468 
   406 
   469 
   407 /*!
   470 /*!
   408  * \internal
   471  * \internal