2016-06-24 15:24:58 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "../rwbase.h"
|
|
|
|
#include "../rwerror.h"
|
|
|
|
#include "../rwplg.h"
|
|
|
|
#include "../rwpipeline.h"
|
|
|
|
#include "../rwobjects.h"
|
|
|
|
#include "../rwengine.h"
|
|
|
|
#ifdef RW_OPENGL
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#include "rwgl3.h"
|
|
|
|
#include "rwgl3shader.h"
|
|
|
|
|
2016-07-05 11:36:43 +02:00
|
|
|
#include "rwgl3impl.h"
|
|
|
|
|
2016-06-24 15:24:58 +02:00
|
|
|
namespace rw {
|
|
|
|
namespace gl3 {
|
|
|
|
|
|
|
|
#define MAX_LIGHTS 8
|
|
|
|
|
|
|
|
void
|
2016-08-21 18:20:27 +02:00
|
|
|
setAttribPointers(AttribDesc *attribDescs, int32 numAttribs)
|
2016-06-24 15:24:58 +02:00
|
|
|
{
|
|
|
|
AttribDesc *a;
|
2016-08-21 18:20:27 +02:00
|
|
|
for(a = attribDescs; a != &attribDescs[numAttribs]; a++){
|
2016-06-24 15:24:58 +02:00
|
|
|
glEnableVertexAttribArray(a->index);
|
|
|
|
glVertexAttribPointer(a->index, a->size, a->type, a->normalized,
|
|
|
|
a->stride, (void*)(uint64)a->offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 18:20:27 +02:00
|
|
|
void
|
|
|
|
disableAttribPointers(AttribDesc *attribDescs, int32 numAttribs)
|
|
|
|
{
|
|
|
|
AttribDesc *a;
|
|
|
|
for(a = attribDescs; a != &attribDescs[numAttribs]; a++)
|
|
|
|
glDisableVertexAttribArray(a->index);
|
|
|
|
}
|
|
|
|
|
2016-06-24 15:24:58 +02:00
|
|
|
void
|
|
|
|
lightingCB(void)
|
|
|
|
{
|
|
|
|
World *world;
|
|
|
|
RGBAf ambLight = (RGBAf){0.0, 0.0, 0.0, 1.0};
|
|
|
|
int n = 0;
|
|
|
|
|
2016-06-25 17:58:52 +02:00
|
|
|
world = (World*)engine->currentWorld;
|
2016-06-24 15:24:58 +02:00
|
|
|
// only unpositioned lights right now
|
|
|
|
FORLIST(lnk, world->directionalLights){
|
|
|
|
Light *l = Light::fromWorld(lnk);
|
|
|
|
if(l->getType() == Light::DIRECTIONAL){
|
|
|
|
if(n >= MAX_LIGHTS)
|
|
|
|
continue;
|
|
|
|
setLight(n++, l);
|
|
|
|
}else if(l->getType() == Light::AMBIENT){
|
|
|
|
ambLight.red += l->color.red;
|
|
|
|
ambLight.green += l->color.green;
|
|
|
|
ambLight.blue += l->color.blue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setNumLights(n);
|
|
|
|
setAmbientLight(&ambLight);
|
|
|
|
}
|
|
|
|
|
2016-07-05 11:36:43 +02:00
|
|
|
#define U(s) currentShader->uniformLocations[findUniform(s)]
|
|
|
|
|
2016-06-27 21:59:35 +02:00
|
|
|
void
|
|
|
|
defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|
|
|
{
|
2016-07-05 11:36:43 +02:00
|
|
|
Material *m;
|
|
|
|
RGBAf col;
|
|
|
|
GLfloat surfProps[4];
|
|
|
|
int id;
|
|
|
|
|
2016-06-27 21:59:35 +02:00
|
|
|
setWorldMatrix(atomic->getFrame()->getLTM());
|
|
|
|
lightingCB();
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, header->vbo);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, header->ibo);
|
2016-08-21 18:20:27 +02:00
|
|
|
setAttribPointers(header->attribDesc, header->numAttribs);
|
2016-06-27 21:59:35 +02:00
|
|
|
|
|
|
|
InstanceData *inst = header->inst;
|
|
|
|
int32 n = header->numMeshes;
|
|
|
|
|
2017-03-16 01:10:01 +01:00
|
|
|
// rw::setRenderState(ALPHATESTFUNC, 1);
|
|
|
|
// rw::setRenderState(ALPHATESTREF, 50);
|
2016-06-27 21:59:35 +02:00
|
|
|
|
2016-06-29 12:53:02 +02:00
|
|
|
simpleShader->use();
|
|
|
|
|
2016-06-27 21:59:35 +02:00
|
|
|
while(n--){
|
|
|
|
m = inst->material;
|
2016-06-24 15:24:58 +02:00
|
|
|
|
|
|
|
convColor(&col, &m->color);
|
|
|
|
glUniform4fv(U("u_matColor"), 1, (GLfloat*)&col);
|
|
|
|
|
|
|
|
surfProps[0] = m->surfaceProps.ambient;
|
|
|
|
surfProps[1] = m->surfaceProps.specular;
|
|
|
|
surfProps[2] = m->surfaceProps.diffuse;
|
|
|
|
surfProps[3] = 0.0f;
|
|
|
|
glUniform4fv(U("u_surfaceProps"), 1, surfProps);
|
|
|
|
|
|
|
|
setTexture(0, m->texture);
|
|
|
|
|
2016-07-05 11:36:43 +02:00
|
|
|
rw::setRenderState(VERTEXALPHA, inst->vertexAlpha || m->color.alpha != 0xFF);
|
2016-06-24 15:24:58 +02:00
|
|
|
|
|
|
|
flushCache();
|
|
|
|
glDrawElements(header->primType, inst->numIndex,
|
|
|
|
GL_UNSIGNED_SHORT, (void*)(uintptr)inst->offset);
|
|
|
|
inst++;
|
|
|
|
}
|
2016-08-21 18:20:27 +02:00
|
|
|
disableAttribPointers(header->attribDesc, header->numAttribs);
|
2016-06-24 15:24:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|