diff --git a/ARCHITECTURE.MD b/ARCHITECTURE.MD index c23d39e..dad04fa 100644 --- a/ARCHITECTURE.MD +++ b/ARCHITECTURE.MD @@ -87,7 +87,7 @@ but because librw is supposed to be able to convert between all sorts of platform specific files, the code for that has to be available no matter the render platform used. -The common interface for all device-indepenent +The common interface for all device-independent platform code is the `Driver` struct. The `Engine` struct has an array with one for each platform. diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index a3783c9..df7cb34 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -127,13 +127,7 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header) setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); -#ifdef RW_GL_USE_VAOS - glBindVertexArray(header->vao); -#else - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); - glBindBuffer(GL_ARRAY_BUFFER, header->vbo); - setAttribPointers(header->attribDesc, header->numAttribs); -#endif + setupVertexInput(header); lastEnvFrame = nil; @@ -155,9 +149,7 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header) } inst++; } -#ifndef RW_GL_USE_VAOS - disableAttribPointers(header->attribDesc, header->numAttribs); -#endif + teardownVertexInput(header); } ObjPipeline* diff --git a/src/gl/gl3render.cpp b/src/gl/gl3render.cpp index cf96f7f..fadbb45 100644 --- a/src/gl/gl3render.cpp +++ b/src/gl/gl3render.cpp @@ -90,6 +90,26 @@ disableAttribPointers(AttribDesc *attribDescs, int32 numAttribs) glDisableVertexAttribArray(a->index); } +void +setupVertexInput(InstanceDataHeader *header) +{ +#ifdef RW_GL_USE_VAOS + glBindVertexArray(header->vao); +#else + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); + glBindBuffer(GL_ARRAY_BUFFER, header->vbo); + setAttribPointers(header->attribDesc, header->numAttribs); +#endif +} + +void +teardownVertexInput(InstanceDataHeader *header) +{ +#ifndef RW_GL_USE_VAOS + disableAttribPointers(header->attribDesc, header->numAttribs); +#endif +} + int32 lightingCB(Atomic *atomic) { @@ -115,8 +135,6 @@ lightingCB(Atomic *atomic) } } -#define U(i) currentShader->uniformLocations[i] - void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) { @@ -126,13 +144,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); -#ifdef RW_GL_USE_VAOS - glBindVertexArray(header->vao); -#else - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); - glBindBuffer(GL_ARRAY_BUFFER, header->vbo); - setAttribPointers(header->attribDesc, header->numAttribs); -#endif + setupVertexInput(header); InstanceData *inst = header->inst; int32 n = header->numMeshes; @@ -151,9 +163,7 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) drawInst(header, inst); inst++; } -#ifndef RW_GL_USE_VAOS - disableAttribPointers(header->attribDesc, header->numAttribs); -#endif + teardownVertexInput(header); } diff --git a/src/gl/gl3skin.cpp b/src/gl/gl3skin.cpp index 396fe88..d97498a 100644 --- a/src/gl/gl3skin.cpp +++ b/src/gl/gl3skin.cpp @@ -259,13 +259,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); -#ifdef RW_GL_USE_VAOS - glBindVertexArray(header->vao); -#else - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo); - glBindBuffer(GL_ARRAY_BUFFER, header->vbo); - setAttribPointers(header->attribDesc, header->numAttribs); -#endif + setupVertexInput(header); InstanceData *inst = header->inst; int32 n = header->numMeshes; @@ -286,9 +280,7 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) drawInst(header, inst); inst++; } -#ifndef RW_GL_USE_VAOS - disableAttribPointers(header->attribDesc, header->numAttribs); -#endif + teardownVertexInput(header); } static void* diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index bfd6118..ca732bd 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -150,6 +150,8 @@ struct Im2DVertex void setAttribPointers(AttribDesc *attribDescs, int32 numAttribs); void disableAttribPointers(AttribDesc *attribDescs, int32 numAttribs); +void setupVertexInput(InstanceDataHeader *header); +void teardownVertexInput(InstanceDataHeader *header); // Render state