mirror of
https://github.com/aap/librw.git
synced 2024-11-25 13:15:43 +00:00
Fixed OpenGL instancing.
This commit is contained in:
parent
0d6216554c
commit
fb78a7a7b9
12
src/ogl.cpp
12
src/ogl.cpp
@ -107,7 +107,7 @@ GetSizeNativeData(void *object, int32, int32)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
packattrib(uint8 *dst, float32 *src, AttribDesc *a)
|
packattrib(uint8 *dst, float32 *src, AttribDesc *a, float32 scale=1.0f)
|
||||||
{
|
{
|
||||||
int8 *i8dst;
|
int8 *i8dst;
|
||||||
uint16 *u16dst;
|
uint16 *u16dst;
|
||||||
@ -123,7 +123,7 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a)
|
|||||||
i8dst = (int8*)dst;
|
i8dst = (int8*)dst;
|
||||||
for(int i = 0; i < a->size; i++){
|
for(int i = 0; i < a->size; i++){
|
||||||
if(!a->normalized)
|
if(!a->normalized)
|
||||||
i8dst[i] = src[i];
|
i8dst[i] = src[i]*scale;
|
||||||
else if(src[i] > 0.0f)
|
else if(src[i] > 0.0f)
|
||||||
i8dst[i] = src[i]*127.0f;
|
i8dst[i] = src[i]*127.0f;
|
||||||
else
|
else
|
||||||
@ -134,7 +134,7 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a)
|
|||||||
case 2: // ubyte
|
case 2: // ubyte
|
||||||
for(int i = 0; i < a->size; i++){
|
for(int i = 0; i < a->size; i++){
|
||||||
if(!a->normalized)
|
if(!a->normalized)
|
||||||
dst[i] = src[i];
|
dst[i] = src[i]*scale;
|
||||||
else
|
else
|
||||||
dst[i] = src[i]*255.0f;
|
dst[i] = src[i]*255.0f;
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a)
|
|||||||
i16dst = (int16*)dst;
|
i16dst = (int16*)dst;
|
||||||
for(int i = 0; i < a->size; i++){
|
for(int i = 0; i < a->size; i++){
|
||||||
if(!a->normalized)
|
if(!a->normalized)
|
||||||
i16dst[i] = src[i];
|
i16dst[i] = src[i]*scale;
|
||||||
else if(src[i] > 0.0f)
|
else if(src[i] > 0.0f)
|
||||||
i16dst[i] = src[i]*32767.0f;
|
i16dst[i] = src[i]*32767.0f;
|
||||||
else
|
else
|
||||||
@ -156,7 +156,7 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a)
|
|||||||
u16dst = (uint16*)dst;
|
u16dst = (uint16*)dst;
|
||||||
for(int i = 0; i < a->size; i++){
|
for(int i = 0; i < a->size; i++){
|
||||||
if(!a->normalized)
|
if(!a->normalized)
|
||||||
u16dst[i] = src[i];
|
u16dst[i] = src[i]*scale;
|
||||||
else
|
else
|
||||||
u16dst[i] = src[i]*65535.0f;
|
u16dst[i] = src[i]*65535.0f;
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ Instance(Atomic *atomic)
|
|||||||
p = header->data + a->offset;
|
p = header->data + a->offset;
|
||||||
float32 *texcoord = geo->texCoords[0];
|
float32 *texcoord = geo->texCoords[0];
|
||||||
for(int32 i = 0; i < geo->numVertices; i++){
|
for(int32 i = 0; i < geo->numVertices; i++){
|
||||||
packattrib(p, texcoord, a);
|
packattrib(p, texcoord, a, 512.0f);
|
||||||
texcoord += 2;
|
texcoord += 2;
|
||||||
p += a->stride;
|
p += a->stride;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ renderAtomic(Rw::Atomic *atomic)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(program, "worldMat"),
|
glUniformMatrix4fv(glGetUniformLocation(program, "worldMat"),
|
||||||
1, GL_FALSE, frm->ltm);
|
1, GL_FALSE, frm->ltm);
|
||||||
|
|
||||||
glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f);
|
glVertexAttrib4f(3, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if(inst->vbo == 0 && inst->ibo == 0)
|
if(inst->vbo == 0 && inst->ibo == 0)
|
||||||
Gl::UploadGeo(geo);
|
Gl::UploadGeo(geo);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, inst->vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, inst->vbo);
|
||||||
@ -41,6 +41,14 @@ renderAtomic(Rw::Atomic *atomic)
|
|||||||
uint64 offset = 0;
|
uint64 offset = 0;
|
||||||
for(uint32 i = 0; i < meshHeader->numMeshes; i++){
|
for(uint32 i = 0; i < meshHeader->numMeshes; i++){
|
||||||
Mesh *mesh = &meshHeader->mesh[i];
|
Mesh *mesh = &meshHeader->mesh[i];
|
||||||
|
float color[4];
|
||||||
|
uint8 *col = mesh->material->color;
|
||||||
|
color[0] = col[0] / 255.0f;
|
||||||
|
color[1] = col[1] / 255.0f;
|
||||||
|
color[2] = col[2] / 255.0f;
|
||||||
|
color[3] = col[3] / 255.0f;
|
||||||
|
glUniform4fv(glGetUniformLocation(program, "matColor"),
|
||||||
|
1, color);
|
||||||
Texture *tex = mesh->material->texture;
|
Texture *tex = mesh->material->texture;
|
||||||
if(tex){
|
if(tex){
|
||||||
Rw::Gl::Raster *raster = (Rw::Gl::Raster*)tex->raster;
|
Rw::Gl::Raster *raster = (Rw::Gl::Raster*)tex->raster;
|
||||||
@ -98,12 +106,17 @@ init(void)
|
|||||||
{
|
{
|
||||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
glAlphaFunc(GL_GEQUAL, 0.5f);
|
||||||
const char *shadersrc =
|
const char *shadersrc =
|
||||||
"#version 120\n"
|
"#version 120\n"
|
||||||
"#ifdef VERTEX\n"
|
"#ifdef VERTEX\n"
|
||||||
"uniform mat4 projMat;"
|
"uniform mat4 projMat;"
|
||||||
"uniform mat4 viewMat;"
|
"uniform mat4 viewMat;"
|
||||||
"uniform mat4 worldMat;"
|
"uniform mat4 worldMat;"
|
||||||
|
"uniform vec4 matColor;"
|
||||||
"attribute vec3 in_vertex;"
|
"attribute vec3 in_vertex;"
|
||||||
"attribute vec2 in_texCoord;"
|
"attribute vec2 in_texCoord;"
|
||||||
"attribute vec3 in_normal;"
|
"attribute vec3 in_normal;"
|
||||||
@ -111,12 +124,13 @@ init(void)
|
|||||||
"varying vec4 v_color;"
|
"varying vec4 v_color;"
|
||||||
"varying vec2 v_texCoord;"
|
"varying vec2 v_texCoord;"
|
||||||
"vec3 lightdir = vec3(0.5, -0.5, -0.70710);"
|
"vec3 lightdir = vec3(0.5, -0.5, -0.70710);"
|
||||||
|
"vec4 amblight = vec4(20, 20, 20, 0)/255;"
|
||||||
"void main()"
|
"void main()"
|
||||||
"{"
|
"{"
|
||||||
" gl_Position = projMat * viewMat * worldMat * vec4(in_vertex, 1.0);"
|
" gl_Position = projMat * viewMat * worldMat * vec4(in_vertex, 1.0);"
|
||||||
" vec3 n = mat3(worldMat) * in_normal;"
|
" vec3 n = mat3(worldMat) * in_normal;"
|
||||||
" float l = max(0.0, dot(n, -lightdir));"
|
" float l = max(0.0, dot(n, -lightdir));"
|
||||||
" v_color = in_color*l;"
|
" v_color = (in_color+vec4(l,l,l,0)+amblight)*matColor;"
|
||||||
" v_texCoord = in_texCoord;"
|
" v_texCoord = in_texCoord;"
|
||||||
"}\n"
|
"}\n"
|
||||||
"#endif\n"
|
"#endif\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user