Skip to content

Commit

Permalink
Remove the GLFunction template.
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen committed Feb 28, 2022
1 parent fc9c22c commit b02fd53
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 169 deletions.
2 changes: 1 addition & 1 deletion src/rendering/utils/GLRestorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GLRestorer::GLRestorer(const tgfx::GLFunctions* gl) : gl(gl) {
gl->getIntegerv(GL_TEXTURE_BINDING_2D, &textureID);
gl->getIntegerv(GL_ARRAY_BUFFER_BINDING, &arrayBuffer);
gl->getIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &elementArrayBuffer);
if (gl->bindVertexArray) {
if (gl->bindVertexArray != nullptr) {
gl->getIntegerv(GL_VERTEX_ARRAY_BINDING, &vertexArray);
}
gl->bindBuffer(GL_ARRAY_BUFFER, 0);
Expand Down
295 changes: 127 additions & 168 deletions tgfx/include/gpu/opengl/GLFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,47 +216,6 @@ using GLVertexAttribPointer = void GL_FUNCTION_TYPE(unsigned indx, int size, uns
using GLViewport = void GL_FUNCTION_TYPE(int x, int y, int width, int height);
using GLWaitSync = void GL_FUNCTION_TYPE(void* sync, unsigned flags, uint64_t timeout);

// This is a lighter-weight std::function, trying to reduce code size and compile time by only
// supporting the exact use cases we require.
template <typename T>
class GLFunction;

template <typename R, typename... Args>
class GLFunction<R GL_FUNCTION_TYPE(Args...)> {
public:
GLFunction() = default;

GLFunction(std::nullptr_t) {
}

template <typename Closure>
GLFunction(Closure closure) : GLFunction() {
static_assert(sizeof(Closure) <= sizeof(buffer), "buffer is too small");
memcpy(buffer, &closure, sizeof(closure));
call = [](const void* buf, Args... args) {
auto closure = reinterpret_cast<const Closure*>(buf);
return (*closure)(std::forward<Args>(args)...);
};
}

R operator()(Args... args) const {
return call(buffer, std::forward<Args>(args)...);
}

explicit operator bool() const {
return call != nullptr;
}

void reset() {
call = nullptr;
}

private:
using Call = R(const void* buf, Args...);
Call* call = nullptr;
size_t buffer[4] = {};
};

class Context;

/**
Expand All @@ -269,133 +228,133 @@ class GLFunctions {
*/
static const GLFunctions* Get(const Context* context);

GLFunction<GLActiveTexture> activeTexture = nullptr;
GLFunction<GLAttachShader> attachShader = nullptr;
GLFunction<GLBindAttribLocation> bindAttribLocation = nullptr;
GLFunction<GLBindBuffer> bindBuffer = nullptr;
GLFunction<GLBindFramebuffer> bindFramebuffer = nullptr;
GLFunction<GLBindRenderbuffer> bindRenderbuffer = nullptr;
GLFunction<GLBindTexture> bindTexture = nullptr;
GLFunction<GLBindVertexArray> bindVertexArray = nullptr;
GLFunction<GLBlendColor> blendColor = nullptr;
GLFunction<GLBlendEquation> blendEquation = nullptr;
GLFunction<GLBlendEquationSeparate> blendEquationSeparate = nullptr;
GLFunction<GLBlendFunc> blendFunc = nullptr;
GLFunction<GLBlendFuncSeparate> blendFuncSeparate = nullptr;
GLFunction<GLBufferData> bufferData = nullptr;
GLFunction<GLBufferSubData> bufferSubData = nullptr;
GLFunction<GLCheckFramebufferStatus> checkFramebufferStatus = nullptr;
GLFunction<GLClear> clear = nullptr;
GLFunction<GLClearColor> clearColor = nullptr;
GLFunction<GLClearStencil> clearStencil = nullptr;
GLFunction<GLColorMask> colorMask = nullptr;
GLFunction<GLCompileShader> compileShader = nullptr;
GLFunction<GLCompressedTexImage2D> compressedTexImage2D = nullptr;
GLFunction<GLCompressedTexSubImage2D> compressedTexSubImage2D = nullptr;
GLFunction<GLCopyTexSubImage2D> copyTexSubImage2D = nullptr;
GLFunction<GLCreateProgram> createProgram = nullptr;
GLFunction<GLCreateShader> createShader = nullptr;
GLFunction<GLCullFace> cullFace = nullptr;
GLFunction<GLDeleteBuffers> deleteBuffers = nullptr;
GLFunction<GLDeleteFramebuffers> deleteFramebuffers = nullptr;
GLFunction<GLDeleteProgram> deleteProgram = nullptr;
GLFunction<GLDeleteRenderbuffers> deleteRenderbuffers = nullptr;
GLFunction<GLDeleteShader> deleteShader = nullptr;
GLFunction<GLDeleteSync> deleteSync = nullptr;
GLFunction<GLDeleteTextures> deleteTextures = nullptr;
GLFunction<GLDeleteVertexArrays> deleteVertexArrays = nullptr;
GLFunction<GLDepthMask> depthMask = nullptr;
GLFunction<GLDisable> disable = nullptr;
GLFunction<GLDisableVertexAttribArray> disableVertexAttribArray = nullptr;
GLFunction<GLDrawArrays> drawArrays = nullptr;
GLFunction<GLDrawElements> drawElements = nullptr;
GLFunction<GLEnable> enable = nullptr;
GLFunction<GLIsEnabled> isEnabled = nullptr;
GLFunction<GLEnableVertexAttribArray> enableVertexAttribArray = nullptr;
GLFunction<GLFenceSync> fenceSync = nullptr;
GLFunction<GLFinish> finish = nullptr;
GLFunction<GLFlush> flush = nullptr;
GLFunction<GLFramebufferRenderbuffer> framebufferRenderbuffer = nullptr;
GLFunction<GLFramebufferTexture2D> framebufferTexture2D = nullptr;
GLFunction<GLFramebufferTexture2DMultisample> framebufferTexture2DMultisample = nullptr;
GLFunction<GLFrontFace> frontFace = nullptr;
GLFunction<GLGenBuffers> genBuffers = nullptr;
GLFunction<GLGenFramebuffers> genFramebuffers = nullptr;
GLFunction<GLGenerateMipmap> generateMipmap = nullptr;
GLFunction<GLGenRenderbuffers> genRenderbuffers = nullptr;
GLFunction<GLGenTextures> genTextures = nullptr;
GLFunction<GLGenVertexArrays> genVertexArrays = nullptr;
GLFunction<GLGetBufferParameteriv> getBufferParameteriv = nullptr;
GLFunction<GLGetError> getError = nullptr;
GLFunction<GLGetFramebufferAttachmentParameteriv> getFramebufferAttachmentParameteriv = nullptr;
GLFunction<GLGetIntegerv> getIntegerv = nullptr;
GLFunction<GLGetInternalformativ> getInternalformativ = nullptr;
GLFunction<GLGetBooleanv> getBooleanv = nullptr;
GLFunction<GLGetProgramInfoLog> getProgramInfoLog = nullptr;
GLFunction<GLGetProgramiv> getProgramiv = nullptr;
GLFunction<GLGetRenderbufferParameteriv> getRenderbufferParameteriv = nullptr;
GLFunction<GLGetShaderInfoLog> getShaderInfoLog = nullptr;
GLFunction<GLGetShaderiv> getShaderiv = nullptr;
GLFunction<GLGetShaderPrecisionFormat> getShaderPrecisionFormat = nullptr;
GLFunction<GLGetString> getString = nullptr;
GLFunction<GLGetStringi> getStringi = nullptr;
GLFunction<GLGetVertexAttribiv> getVertexAttribiv = nullptr;
GLFunction<GLGetVertexAttribPointerv> getVertexAttribPointerv = nullptr;
GLFunction<GLGetAttribLocation> getAttribLocation = nullptr;
GLFunction<GLGetUniformLocation> getUniformLocation = nullptr;
GLFunction<GLIsTexture> isTexture = nullptr;
GLFunction<GLLineWidth> lineWidth = nullptr;
GLFunction<GLLinkProgram> linkProgram = nullptr;
GLFunction<GLPixelStorei> pixelStorei = nullptr;
GLFunction<GLReadPixels> readPixels = nullptr;
GLFunction<GLRenderbufferStorage> renderbufferStorage = nullptr;
GLFunction<GLRenderbufferStorageMultisample> renderbufferStorageMultisample = nullptr;
GLFunction<GLRenderbufferStorageMultisampleAPPLE> renderbufferStorageMultisampleAPPLE = nullptr;
GLFunction<GLRenderbufferStorageMultisampleEXT> renderbufferStorageMultisampleEXT = nullptr;
GLFunction<GLResolveMultisampleFramebuffer> resolveMultisampleFramebuffer = nullptr;
GLFunction<GLBlitFramebuffer> blitFramebuffer = nullptr;
GLFunction<GLScissor> scissor = nullptr;
GLFunction<GLShaderSource> shaderSource = nullptr;
GLFunction<GLStencilFunc> stencilFunc = nullptr;
GLFunction<GLStencilFuncSeparate> stencilFuncSeparate = nullptr;
GLFunction<GLStencilMask> stencilMask = nullptr;
GLFunction<GLStencilMaskSeparate> stencilMaskSeparate = nullptr;
GLFunction<GLStencilOp> stencilOp = nullptr;
GLFunction<GLStencilOpSeparate> stencilOpSeparate = nullptr;
GLFunction<GLTexImage2D> texImage2D = nullptr;
GLFunction<GLTexParameterf> texParameterf = nullptr;
GLFunction<GLTexParameterfv> texParameterfv = nullptr;
GLFunction<GLTexParameteri> texParameteri = nullptr;
GLFunction<GLTexParameteriv> texParameteriv = nullptr;
GLFunction<GLTexSubImage2D> texSubImage2D = nullptr;
GLFunction<GLTextureBarrier> textureBarrier = nullptr;
GLFunction<GLUniform1f> uniform1f = nullptr;
GLFunction<GLUniform1i> uniform1i = nullptr;
GLFunction<GLUniform1fv> uniform1fv = nullptr;
GLFunction<GLUniform1iv> uniform1iv = nullptr;
GLFunction<GLUniform2f> uniform2f = nullptr;
GLFunction<GLUniform2i> uniform2i = nullptr;
GLFunction<GLUniform2fv> uniform2fv = nullptr;
GLFunction<GLUniform2iv> uniform2iv = nullptr;
GLFunction<GLUniform3f> uniform3f = nullptr;
GLFunction<GLUniform3i> uniform3i = nullptr;
GLFunction<GLUniform3fv> uniform3fv = nullptr;
GLFunction<GLUniform3iv> uniform3iv = nullptr;
GLFunction<GLUniform4f> uniform4f = nullptr;
GLFunction<GLUniform4i> uniform4i = nullptr;
GLFunction<GLUniform4fv> uniform4fv = nullptr;
GLFunction<GLUniform4iv> uniform4iv = nullptr;
GLFunction<GLUniformMatrix2fv> uniformMatrix2fv = nullptr;
GLFunction<GLUniformMatrix3fv> uniformMatrix3fv = nullptr;
GLFunction<GLUniformMatrix4fv> uniformMatrix4fv = nullptr;
GLFunction<GLUseProgram> useProgram = nullptr;
GLFunction<GLVertexAttrib1f> vertexAttrib1f = nullptr;
GLFunction<GLVertexAttrib2fv> vertexAttrib2fv = nullptr;
GLFunction<GLVertexAttrib3fv> vertexAttrib3fv = nullptr;
GLFunction<GLVertexAttrib4fv> vertexAttrib4fv = nullptr;
GLFunction<GLVertexAttribPointer> vertexAttribPointer = nullptr;
GLFunction<GLViewport> viewport = nullptr;
GLFunction<GLWaitSync> waitSync = nullptr;
GLActiveTexture* activeTexture = nullptr;
GLAttachShader* attachShader = nullptr;
GLBindAttribLocation* bindAttribLocation = nullptr;
GLBindBuffer* bindBuffer = nullptr;
GLBindFramebuffer* bindFramebuffer = nullptr;
GLBindRenderbuffer* bindRenderbuffer = nullptr;
GLBindTexture* bindTexture = nullptr;
GLBindVertexArray* bindVertexArray = nullptr;
GLBlendColor* blendColor = nullptr;
GLBlendEquation* blendEquation = nullptr;
GLBlendEquationSeparate* blendEquationSeparate = nullptr;
GLBlendFunc* blendFunc = nullptr;
GLBlendFuncSeparate* blendFuncSeparate = nullptr;
GLBufferData* bufferData = nullptr;
GLBufferSubData* bufferSubData = nullptr;
GLCheckFramebufferStatus* checkFramebufferStatus = nullptr;
GLClear* clear = nullptr;
GLClearColor* clearColor = nullptr;
GLClearStencil* clearStencil = nullptr;
GLColorMask* colorMask = nullptr;
GLCompileShader* compileShader = nullptr;
GLCompressedTexImage2D* compressedTexImage2D = nullptr;
GLCompressedTexSubImage2D* compressedTexSubImage2D = nullptr;
GLCopyTexSubImage2D* copyTexSubImage2D = nullptr;
GLCreateProgram* createProgram = nullptr;
GLCreateShader* createShader = nullptr;
GLCullFace* cullFace = nullptr;
GLDeleteBuffers* deleteBuffers = nullptr;
GLDeleteFramebuffers* deleteFramebuffers = nullptr;
GLDeleteProgram* deleteProgram = nullptr;
GLDeleteRenderbuffers* deleteRenderbuffers = nullptr;
GLDeleteShader* deleteShader = nullptr;
GLDeleteSync* deleteSync = nullptr;
GLDeleteTextures* deleteTextures = nullptr;
GLDeleteVertexArrays* deleteVertexArrays = nullptr;
GLDepthMask* depthMask = nullptr;
GLDisable* disable = nullptr;
GLDisableVertexAttribArray* disableVertexAttribArray = nullptr;
GLDrawArrays* drawArrays = nullptr;
GLDrawElements* drawElements = nullptr;
GLEnable* enable = nullptr;
GLIsEnabled* isEnabled = nullptr;
GLEnableVertexAttribArray* enableVertexAttribArray = nullptr;
GLFenceSync* fenceSync = nullptr;
GLFinish* finish = nullptr;
GLFlush* flush = nullptr;
GLFramebufferRenderbuffer* framebufferRenderbuffer = nullptr;
GLFramebufferTexture2D* framebufferTexture2D = nullptr;
GLFramebufferTexture2DMultisample* framebufferTexture2DMultisample = nullptr;
GLFrontFace* frontFace = nullptr;
GLGenBuffers* genBuffers = nullptr;
GLGenFramebuffers* genFramebuffers = nullptr;
GLGenerateMipmap* generateMipmap = nullptr;
GLGenRenderbuffers* genRenderbuffers = nullptr;
GLGenTextures* genTextures = nullptr;
GLGenVertexArrays* genVertexArrays = nullptr;
GLGetBufferParameteriv* getBufferParameteriv = nullptr;
GLGetError* getError = nullptr;
GLGetFramebufferAttachmentParameteriv* getFramebufferAttachmentParameteriv = nullptr;
GLGetIntegerv* getIntegerv = nullptr;
GLGetInternalformativ* getInternalformativ = nullptr;
GLGetBooleanv* getBooleanv = nullptr;
GLGetProgramInfoLog* getProgramInfoLog = nullptr;
GLGetProgramiv* getProgramiv = nullptr;
GLGetRenderbufferParameteriv* getRenderbufferParameteriv = nullptr;
GLGetShaderInfoLog* getShaderInfoLog = nullptr;
GLGetShaderiv* getShaderiv = nullptr;
GLGetShaderPrecisionFormat* getShaderPrecisionFormat = nullptr;
GLGetString* getString = nullptr;
GLGetStringi* getStringi = nullptr;
GLGetVertexAttribiv* getVertexAttribiv = nullptr;
GLGetVertexAttribPointerv* getVertexAttribPointerv = nullptr;
GLGetAttribLocation* getAttribLocation = nullptr;
GLGetUniformLocation* getUniformLocation = nullptr;
GLIsTexture* isTexture = nullptr;
GLLineWidth* lineWidth = nullptr;
GLLinkProgram* linkProgram = nullptr;
GLPixelStorei* pixelStorei = nullptr;
GLReadPixels* readPixels = nullptr;
GLRenderbufferStorage* renderbufferStorage = nullptr;
GLRenderbufferStorageMultisample* renderbufferStorageMultisample = nullptr;
GLRenderbufferStorageMultisampleAPPLE* renderbufferStorageMultisampleAPPLE = nullptr;
GLRenderbufferStorageMultisampleEXT* renderbufferStorageMultisampleEXT = nullptr;
GLResolveMultisampleFramebuffer* resolveMultisampleFramebuffer = nullptr;
GLBlitFramebuffer* blitFramebuffer = nullptr;
GLScissor* scissor = nullptr;
GLShaderSource* shaderSource = nullptr;
GLStencilFunc* stencilFunc = nullptr;
GLStencilFuncSeparate* stencilFuncSeparate = nullptr;
GLStencilMask* stencilMask = nullptr;
GLStencilMaskSeparate* stencilMaskSeparate = nullptr;
GLStencilOp* stencilOp = nullptr;
GLStencilOpSeparate* stencilOpSeparate = nullptr;
GLTexImage2D* texImage2D = nullptr;
GLTexParameterf* texParameterf = nullptr;
GLTexParameterfv* texParameterfv = nullptr;
GLTexParameteri* texParameteri = nullptr;
GLTexParameteriv* texParameteriv = nullptr;
GLTexSubImage2D* texSubImage2D = nullptr;
GLTextureBarrier* textureBarrier = nullptr;
GLUniform1f* uniform1f = nullptr;
GLUniform1i* uniform1i = nullptr;
GLUniform1fv* uniform1fv = nullptr;
GLUniform1iv* uniform1iv = nullptr;
GLUniform2f* uniform2f = nullptr;
GLUniform2i* uniform2i = nullptr;
GLUniform2fv* uniform2fv = nullptr;
GLUniform2iv* uniform2iv = nullptr;
GLUniform3f* uniform3f = nullptr;
GLUniform3i* uniform3i = nullptr;
GLUniform3fv* uniform3fv = nullptr;
GLUniform3iv* uniform3iv = nullptr;
GLUniform4f* uniform4f = nullptr;
GLUniform4i* uniform4i = nullptr;
GLUniform4fv* uniform4fv = nullptr;
GLUniform4iv* uniform4iv = nullptr;
GLUniformMatrix2fv* uniformMatrix2fv = nullptr;
GLUniformMatrix3fv* uniformMatrix3fv = nullptr;
GLUniformMatrix4fv* uniformMatrix4fv = nullptr;
GLUseProgram* useProgram = nullptr;
GLVertexAttrib1f* vertexAttrib1f = nullptr;
GLVertexAttrib2fv* vertexAttrib2fv = nullptr;
GLVertexAttrib3fv* vertexAttrib3fv = nullptr;
GLVertexAttrib4fv* vertexAttrib4fv = nullptr;
GLVertexAttribPointer* vertexAttribPointer = nullptr;
GLViewport* viewport = nullptr;
GLWaitSync* waitSync = nullptr;
};

} // namespace tgfx

0 comments on commit b02fd53

Please sign in to comment.