1 #ifndef __EXGL_H__ 2 #define __EXGL_H__ 3 4 #ifdef __ANDROID__ 5 #include <GLES3/gl3.h> 6 #endif 7 #ifdef __APPLE__ 8 #include <OpenGLES/ES3/gl.h> 9 #endif 10 11 #ifdef __cplusplus 12 #include <functional> 13 #else 14 #include <stdbool.h> 15 #endif 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 // Identifies an EXGL context. No EXGL context has the id 0, so that can be 22 // used as a 'null' value. 23 typedef unsigned int EXGLContextId; 24 25 // Identifies an EXGL object. EXGL objects represent virtual mappings to underlying OpenGL objects. 26 // No EXGL object has the id 0, so that can be used as a 'null' value. 27 typedef unsigned int EXGLObjectId; 28 29 EXGLContextId EXGLContextCreate(); 30 31 #ifdef __cplusplus 32 // [JS thread] Create an EXGL context and return its id number. Saves the 33 // JavaScript interface object (has a WebGLRenderingContext-style API) at 34 // `global.__EXGLContexts[id]` in JavaScript. 35 void EXGLContextPrepare(void *runtime, EXGLContextId exglCtxId, std::function<void(void)> flushMethod); 36 #endif // __cplusplus 37 38 // [UI thread] Creates an EXGL context inside Reanimated worklet. 39 void EXGLContextPrepareWorklet(EXGLContextId exglCtxId); 40 41 // [Any thread] Check whether we should redraw the surface 42 bool EXGLContextNeedsRedraw(EXGLContextId exglCtxId); 43 44 // [GL thread] Tell cpp that we finished drawing to the surface 45 void EXGLContextDrawEnded(EXGLContextId exglCtxId); 46 47 // [Any thread] Release the resources for an EXGL context. The same id is never 48 // reused. 49 void EXGLContextDestroy(EXGLContextId exglCtxId); 50 51 // [GL thread] Perform one frame's worth of queued up GL work 52 void EXGLContextFlush(EXGLContextId exglCtxId); 53 54 // [GL thread] Set the default framebuffer (used when binding 0). Allows using 55 // platform-specific extensions on the default framebuffer, such as MSAA. 56 void EXGLContextSetDefaultFramebuffer(EXGLContextId exglCtxId, GLint framebuffer); 57 58 // [Any thread] Create an EXGL object. Initially maps to the OpenGL object zero. 59 EXGLObjectId EXGLContextCreateObject(EXGLContextId exglCtxId); 60 61 // [GL thread] Destroy an EXGL object. 62 void EXGLContextDestroyObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId); 63 64 // [GL thread] Set the underlying OpenGL object an EXGL object maps to. 65 void EXGLContextMapObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId, GLuint glObj); 66 67 // [GL thread] Get the underlying OpenGL object an EXGL object maps to. 68 GLuint EXGLContextGetObject(EXGLContextId exglCtxId, EXGLObjectId exglObjId); 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #endif 75