Properly binding shader attributes.

This commit is contained in:
Rinnegatamante
2020-10-18 14:43:45 +02:00
parent 621e1ef445
commit 08876f4ea4
6 changed files with 27 additions and 12 deletions
+7 -1
View File
@@ -22,6 +22,7 @@ extern float *gVertexBuffer;
extern uint16_t *gIndicesPtr;
extern float *gVertexBufferPtr;
uint16_t *gConstIndices;
float *gVertexBufferIm2D;
uint16_t *gIndicesIm2D;
@@ -1409,11 +1410,16 @@ initOpenGL(void)
gVertexBufferPtr = (float*)malloc(0x1800000);
gIndicesPtr = (uint16_t*)malloc(0x600000);
gConstIndices = (uint16_t*)malloc(sizeof(uint16_t) * 512);
gVertexBuffer = gVertexBufferPtr;
gVertexBufferIm2D = gVertexBufferPtr + 0xC00000;
gIndices = gIndicesPtr;
gIndicesIm2D = gIndicesPtr + 0x300000;
for (uint16_t i = 0; i < 512; i++) {
gConstIndices[i] = i;
}
#ifdef RW_GLES2
#include "gl2_shaders/default_vs_gl2.inc"
#include "gl2_shaders/simple_fs_gl2.inc"
@@ -1423,7 +1429,7 @@ initOpenGL(void)
#endif
const char *vs[] = { header_vert_src, default_vert_src, nil };
const char *fs[] = { header_frag_src, simple_frag_src, nil };
defaultShader = Shader::create(vs, fs);
defaultShader = Shader::create(vs, fs, false);
assert(defaultShader);
openIm2D();
+4 -2
View File
@@ -19,6 +19,7 @@ extern float *gVertexBuffer;
extern float *gVertexBufferIm2D;
extern uint16_t *gIndicesIm2D;
extern uint16_t *gIndices;
extern uint16_t *gConstIndices;
namespace rw {
namespace gl3 {
@@ -64,7 +65,7 @@ openIm2D(void)
#endif
const char *vs[] = { header_vert_src, im2d_vert_src, nil };
const char *fs[] = { header_frag_src, simple_frag_src, nil };
im2dShader = Shader::create(vs, fs);
im2dShader = Shader::create(vs, fs, true);
assert(im2dShader);
}
@@ -105,6 +106,7 @@ im2DRenderPrimitive(PrimitiveType primType, void *vertices, int32 numVertices)
memcpy_neon(gVertexBufferIm2D, vertices, numVertices*sizeof(Im2DVertex));
vglVertexPointerMapped(gVertexBufferIm2D);
vglIndexPointerMapped(gConstIndices);
gVertexBufferIm2D += numVertices*(sizeof(Im2DVertex)/sizeof(float));
xform[0] = 2.0f/cam->frameBuffer->width;
@@ -188,7 +190,7 @@ openIm3D(void)
#endif
const char *vs[] = { header_vert_src, im3d_vert_src, nil };
const char *fs[] = { header_frag_src, simple_frag_src, nil };
im3dShader = Shader::create(vs, fs);
im3dShader = Shader::create(vs, fs, false);
assert(im3dShader);
}
+1 -1
View File
@@ -174,7 +174,7 @@ matfxOpen(void *o, int32, int32)
#endif
const char *vs[] = { header_vert_src, matfx_env_vert_src, nil };
const char *fs[] = { header_frag_src, matfx_env_frag_src, nil };
envShader = Shader::create(vs, fs);
envShader = Shader::create(vs, fs, false);
assert(envShader);
return o;
+12 -5
View File
@@ -136,7 +136,7 @@ compileshader(GLenum type, const char **src, GLuint *shader)
}
static int
linkprogram(GLint vs, GLint fs, GLuint *program)
linkprogram(GLint vs, GLint fs, GLuint *program, bool is_2d)
{
GLint prog, success;
GLint len;
@@ -154,6 +154,15 @@ linkprogram(GLint vs, GLint fs, GLuint *program)
glBindAttribLocation(prog, ATTRIB_INDICES, "in_indices");
#endif
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_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);
glAttachShader(prog, vs);
glAttachShader(prog, fs);
glLinkProgram(prog);
@@ -163,7 +172,7 @@ linkprogram(GLint vs, GLint fs, GLuint *program)
}
Shader*
Shader::create(const char **vsrc, const char **fsrc)
Shader::create(const char **vsrc, const char **fsrc, bool is_2d)
{
GLuint vs, fs, program;
int i;
@@ -179,14 +188,12 @@ Shader::create(const char **vsrc, const char **fsrc)
return nil;
}
fail = linkprogram(vs, fs, &program);
fail = linkprogram(vs, fs, &program, is_2d);
if(fail){
glDeleteShader(fs);
glDeleteShader(vs);
return nil;
}
glDeleteProgram(vs);
glDeleteProgram(fs);
Shader *sh = rwNewT(Shader, 1, MEMDUR_EVENT | ID_DRIVER); // or global?
+1 -1
View File
@@ -289,7 +289,7 @@ skinOpen(void *o, int32, int32)
#endif
const char *vs[] = { header_vert_src, skin_vert_src, nil };
const char *fs[] = { header_frag_src, simple_frag_src, nil };
skinShader = Shader::create(vs, fs);
skinShader = Shader::create(vs, fs, false);
assert(skinShader);
return o;
+1 -1
View File
@@ -31,7 +31,7 @@ struct Shader
// same number of elements as UniformRegistry::numUniforms
GLint *uniformLocations;
static Shader *create(const char **vsrc, const char **fsrc);
static Shader *create(const char **vsrc, const char **fsrc, bool is_2d);
// static Shader *fromFiles(const char *vs, const char *fs);
// static Shader *fromStrings(const char *vsrc, const char *fsrc);
void use(void);