#include #include #include #include #include "../rwbase.h" #include "../rwerror.h" #include "../rwplg.h" #include "../rwrender.h" #include "../rwengine.h" #include "../rwpipeline.h" #include "../rwobjects.h" #ifdef RW_OPENGL #include "rwgl3.h" #include "rwgl3shader.h" #include "rwgl3impl.h" namespace rw { namespace gl3 { extern "C" int draw; extern "C" int render; void drawInst_simple(InstanceDataHeader *header, InstanceData *inst) { draw++; flushCache(); glDrawElements(header->primType, inst->numIndex, GL_UNSIGNED_SHORT, ((uint8*) header->indexBuffer) + inst->offset); } void drawInst(InstanceDataHeader *header, InstanceData *inst) { drawInst_simple(header, inst); } void setAttribPointers(AttribDesc *attribDescs, int32 numAttribs) { AttribDesc *a; for(a = attribDescs; a != &attribDescs[numAttribs]; a++){ glEnableVertexAttribArray(a->index); glVertexAttribPointer(a->index, a->size, a->type, a->normalized, a->stride, (void*)(uint64)a->offset); } } void disableAttribPointers(AttribDesc *attribDescs, int32 numAttribs) { AttribDesc *a; for(a = attribDescs; a != &attribDescs[numAttribs]; a++) glDisableVertexAttribArray(a->index); } void setupVertexInput(InstanceDataHeader *header) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, header->vbo); setAttribPointers(header->attribDesc, header->numAttribs); } void teardownVertexInput(InstanceDataHeader *header) { disableAttribPointers(header->attribDesc, header->numAttribs); } int32 lightingCB(Atomic *atomic) { WorldLights lightData; if(atomic->geometry->flags & rw::Geometry::LIGHT){ ((World*)engine->currentWorld)->enumerateLights(atomic, &lightData); return setLights(&lightData); }else{ memset(&lightData, 0, sizeof(lightData)); return setLights(&lightData); } } void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) { render++; Material *m; uint32 flags = atomic->geometry->flags; setWorldMatrix(atomic->getFrame()->getLTM()); lightingCB(atomic); setupVertexInput(header); InstanceData *inst = header->inst; int32 n = header->numMeshes; if(getAlphaTest()) defaultShader->use(); else defaultShader_noAT->use(); while(n--){ m = inst->material; setMaterial(flags, m->color, m->surfaceProps); setTexture(0, m->texture); rw::SetRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF); drawInst(header, inst); inst++; } teardownVertexInput(header); } } } #endif