diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index db7c610..de7e07c 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -17,12 +17,8 @@ #define PLUGIN_ID 0 -extern uint16_t *gIndices; -extern float *gVertexBuffer; -extern uint16_t *gIndicesPtr; uint16_t *gIndicesIm2DPtr; uint16_t *gIndicesIm3DPtr; -extern float *gVertexBufferPtr; float *gVertexBufferIm2DPtr; float *gVertexBufferIm3DPtr; @@ -1162,10 +1158,8 @@ showRaster(Raster *raster, uint32 flags) vglWaitVblankStart(GL_FALSE); vglStopRendering(); vglStartRendering(); - gVertexBuffer = gVertexBufferPtr; gVertexBufferIm2D = gVertexBufferIm2DPtr; gVertexBufferIm3D = gVertexBufferIm3DPtr; - gIndices = gIndicesPtr; gIndicesIm2D = gIndicesIm2DPtr; gIndicesIm3D = gIndicesIm3DPtr; #endif @@ -1417,23 +1411,19 @@ initOpenGL(void) resetRenderState(); - gVertexBufferPtr = (float*)malloc(0x1800000); gVertexBufferIm2DPtr = (float*)malloc(0x500000); - gVertexBufferIm3DPtr = (float*)malloc(0x500000); - gIndicesPtr = (uint16_t*)malloc(0x600000); + gVertexBufferIm3DPtr = (float*)malloc(0x1800000); gIndicesIm2DPtr = (uint16_t*)malloc(0x600000); - gIndicesIm3DPtr = (uint16_t*)malloc(0x600000); + gIndicesIm3DPtr = (uint16_t*)malloc(0x1800000); - gConstIndices = (uint16_t*)malloc(sizeof(uint16_t) * 512); + gConstIndices = (uint16_t*)malloc(sizeof(uint16_t) * 0xFFFF); - gVertexBuffer = gVertexBufferPtr; gVertexBufferIm2D = gVertexBufferIm2DPtr; gVertexBufferIm3D = gVertexBufferIm3DPtr; - gIndices = gIndicesPtr; gIndicesIm2D = gIndicesIm2DPtr; gIndicesIm3D = gIndicesIm3DPtr; - for (uint16_t i = 0; i < 512; i++) { + for (uint16_t i = 0; i < 0xFFFF; i++) { gConstIndices[i] = i; } diff --git a/src/gl/gl3immed.cpp b/src/gl/gl3immed.cpp index b0cb76a..829796b 100644 --- a/src/gl/gl3immed.cpp +++ b/src/gl/gl3immed.cpp @@ -103,11 +103,6 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices) GLfloat xform[4]; Camera *cam; cam = (Camera*)engine->currentCamera; - - memcpy_neon(gVertexBufferIm2D, vertices, numVertices*sizeof(Im2DVertex)); - vglVertexAttribPointerMapped(0, gVertexBufferIm2D); - vglIndexPointerMapped(gConstIndices); - gVertexBufferIm2D += numVertices*(sizeof(Im2DVertex)/sizeof(float)); xform[0] = 2.0f/cam->frameBuffer->width; xform[1] = -2.0f/cam->frameBuffer->height; @@ -122,6 +117,11 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices) flushCache(); glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform); + memcpy_neon(gVertexBufferIm2D, vertices, numVertices*sizeof(Im2DVertex)); + vglVertexAttribPointerMapped(0, gVertexBufferIm2D); + vglIndexPointerMapped(gConstIndices); + gVertexBufferIm2D += numVertices*(sizeof(Im2DVertex)/sizeof(float)); + vglDrawObjects(primTypeMap[primType], numVertices, GL_FALSE); } @@ -135,14 +135,6 @@ im2DRenderIndexedPrimitive(PrimitiveType primType, Camera *cam; cam = (Camera*)engine->currentCamera; - memcpy_neon(gIndicesIm2D, indices, numIndices * 2); - vglIndexPointerMapped(gIndicesIm2D); - gIndicesIm2D += numIndices; - - memcpy_neon(gVertexBufferIm2D, vertices, numVertices*sizeof(Im2DVertex)); - vglVertexAttribPointerMapped(0, gVertexBufferIm2D); - gVertexBufferIm2D += numVertices*(sizeof(Im2DVertex)/sizeof(float)); - xform[0] = 2.0f/cam->frameBuffer->width; xform[1] = -2.0f/cam->frameBuffer->height; xform[2] = -1.0f; @@ -155,6 +147,14 @@ im2DRenderIndexedPrimitive(PrimitiveType primType, flushCache(); glUniform4fv(currentShader->uniformLocations[u_xform], 1, xform); + + memcpy_neon(gIndicesIm2D, indices, numIndices * 2); + vglIndexPointerMapped(gIndicesIm2D); + gIndicesIm2D += numIndices; + + memcpy_neon(gVertexBufferIm2D, vertices, numVertices*sizeof(Im2DVertex)); + vglVertexAttribPointerMapped(0, gVertexBufferIm2D); + gVertexBufferIm2D += numVertices*(sizeof(Im2DVertex)/sizeof(float)); vglDrawObjects(primTypeMap[primType], numIndices, GL_FALSE); } @@ -205,7 +205,7 @@ void im3DTransform(void *vertices, int32 numVertices, Matrix *world, uint32 flags) { if(world == nil){ - Matrix ident; + static Matrix ident; ident.setIdentity(); world = &ident; } @@ -236,13 +236,12 @@ im3DRenderPrimitive(PrimitiveType primType) void im3DRenderIndexedPrimitive(PrimitiveType primType, void *indices, int32 numIndices) { + flushCache(); memcpy_neon(gIndicesIm3D, indices, numIndices * 2); vglIndexPointerMapped(gIndicesIm3D); vglVertexAttribPointerMapped(0, gVertexBufferIm3D); gVertexBufferIm3D += num3DVertices*(sizeof(Im3DVertex)/sizeof(float)); gIndicesIm3D += numIndices; - - flushCache(); vglDrawObjects(primTypeMap[primType], numIndices, GL_FALSE); } diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index 94d2478..cfc82fe 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -33,17 +33,18 @@ static int32 u_colorClamp; void matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst) { - Material *m; - m = inst->material; + Material *m = inst->material; defaultShader->use(); + + rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); + + flushCache(); setMaterial(m->color, m->surfaceProps); setTexture(0, m->texture); - rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); - drawInst(header, inst); } @@ -89,6 +90,11 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) } envShader->use(); + + rw::SetRenderState(VERTEXALPHA, 1); + rw::SetRenderState(SRCBLEND, BLENDONE); + + flushCache(); setTexture(0, m->texture); setTexture(1, env->tex); @@ -109,9 +115,6 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst, MatFX::Env *env) else glUniform4fv(U(u_colorClamp), 1, one); - rw::SetRenderState(VERTEXALPHA, 1); - rw::SetRenderState(SRCBLEND, BLENDONE); - drawInst(header, inst); rw::SetRenderState(SRCBLEND, BLENDSRCALPHA); diff --git a/src/gl/gl3pipe.cpp b/src/gl/gl3pipe.cpp index 80b75b2..13919cd 100644 --- a/src/gl/gl3pipe.cpp +++ b/src/gl/gl3pipe.cpp @@ -12,9 +12,6 @@ #include "rwgl3.h" #include "rwgl3shader.h" -extern float *gVertexBuffer; -extern uint16_t *gIndices; - namespace rw { namespace gl3 { diff --git a/src/gl/gl3render.cpp b/src/gl/gl3render.cpp index e8716bb..cb4e54e 100644 --- a/src/gl/gl3render.cpp +++ b/src/gl/gl3render.cpp @@ -15,11 +15,6 @@ #include "rwgl3impl.h" -extern uint16_t *gIndices; -extern float *gVertexBuffer; -extern uint16_t *gIndicesPtr; -extern float *gVertexBufferPtr; - namespace rw { namespace gl3 { @@ -28,13 +23,8 @@ namespace gl3 { void drawInst_simple(InstanceDataHeader *header, InstanceData *inst) { - flushCache(); - memcpy_neon(gIndices, (uint8_t*)header->indexBuffer + inst->offset, inst->numIndex * 2); - vglIndexPointerMapped(gIndices); - gIndices += inst->numIndex; - memcpy_neon(gVertexBuffer, (uint8_t*)header->vertexBuffer, inst->numVertices * header->attribDesc[0].stride); - vglVertexAttribPointerMapped(0, gVertexBuffer); - gVertexBuffer += (inst->numVertices * header->attribDesc[0].stride) / sizeof(float); + vglIndexPointerMapped(header->indexBuffer + inst->offset); + vglVertexAttribPointerMapped(0, header->vertexBuffer); vglDrawObjects(header->primType, inst->numIndex, GL_FALSE); } @@ -140,12 +130,14 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) while(n--){ m = inst->material; + rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); + + flushCache(); + setMaterial(m->color, m->surfaceProps); setTexture(0, m->texture); - rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); - drawInst(header, inst); inst++; } diff --git a/src/gl/gl3shader.cpp b/src/gl/gl3shader.cpp index 7eb88fb..5cce9d8 100644 --- a/src/gl/gl3shader.cpp +++ b/src/gl/gl3shader.cpp @@ -149,12 +149,12 @@ linkprogram(GLint vs, GLint fs, GLuint *program, bool is_2d) int stride = 0; int pos_size = is_2d ? 4 : 3; - stride += vglBindPackedAttribLocation(prog, "in_pos" , pos_size, GL_FLOAT, stride, stride + sizeof(float) * pos_size) * (sizeof(float) * pos_size); - stride += vglBindPackedAttribLocation(prog, "in_normal" , 3, GL_FLOAT, stride, stride + sizeof(float) * 3) * (sizeof(float) * 3); + stride += vglBindPackedAttribLocation(prog, "in_pos" , pos_size, GL_FLOAT, stride, stride + sizeof(float) * pos_size) * (sizeof(float) * pos_size); + stride += vglBindPackedAttribLocation(prog, "in_normal" , 3, GL_FLOAT, stride, stride + sizeof(float) * 3) * (sizeof(float) * 3); stride += vglBindPackedAttribLocation(prog, "in_color" , 4, GL_UNSIGNED_BYTE, stride, stride + 4) * 4; - stride += vglBindPackedAttribLocation(prog, "in_tex0" , 2, GL_FLOAT, stride, stride + sizeof(float) * 2) * (sizeof(float) * 2); - stride += vglBindPackedAttribLocation(prog, "in_weights", 4, GL_FLOAT, stride, stride + sizeof(float) * 4) * (sizeof(float) * 4); - vglBindPackedAttribLocation(prog, "in_indices", 4, GL_UNSIGNED_BYTE, stride, stride + 4); + stride += vglBindPackedAttribLocation(prog, "in_tex0" , 2, GL_FLOAT, stride, stride + sizeof(float) * 2) * (sizeof(float) * 2); + stride += vglBindPackedAttribLocation(prog, "in_weights", 4, GL_FLOAT, stride, stride + sizeof(float) * 4) * (sizeof(float) * 4); + vglBindPackedAttribLocation(prog, "in_indices", 4, GL_UNSIGNED_BYTE, stride, stride + 4); glLinkProgram(prog); diff --git a/src/gl/gl3skin.cpp b/src/gl/gl3skin.cpp index fda79ef..134cb76 100644 --- a/src/gl/gl3skin.cpp +++ b/src/gl/gl3skin.cpp @@ -254,17 +254,21 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) skinShader->use(); - uploadSkinMatrices(atomic); + while(n--){ m = inst->material; + + rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); + + flushCache(); setMaterial(m->color, m->surfaceProps); setTexture(0, m->texture); - - rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); - + + uploadSkinMatrices(atomic); + drawInst(header, inst); inst++; } diff --git a/src/gl/wdgl.cpp b/src/gl/wdgl.cpp index 1f56815..43ae467 100644 --- a/src/gl/wdgl.cpp +++ b/src/gl/wdgl.cpp @@ -28,11 +28,6 @@ #define PLUGIN_ID 2 -uint16_t *gIndices; -float *gVertexBuffer; -uint16_t *gIndicesPtr; -float *gVertexBufferPtr; - namespace rw { namespace wdgl {