Fix n00b shader mistake (conditional code in shader) =D

This commit is contained in:
Aaron Culliney 2015-09-27 11:45:37 -07:00
parent d90b523440
commit f627ccef3f
7 changed files with 15 additions and 89 deletions

View File

@ -21,26 +21,7 @@ varying vec2 varTexcoord;
// global alpha value // global alpha value
uniform float aValue; uniform float aValue;
// texture switch uniform sampler2D texture;
uniform int tex2Use;
// Framebuffer
uniform sampler2D framebufferTexture;
// Floating message
uniform sampler2D messageTexture;
// Joystick axis
uniform sampler2D axisTexture;
// Joystick buttons
uniform sampler2D buttonTexture;
// Keyboard
uniform sampler2D kbdTexture;
// HUD Sprouting Menus
uniform sampler2D topMenuTexture;
#if __VERSION__ >= 140 #if __VERSION__ >= 140
#define OUTPUT_TEXTURE(TEX) \ #define OUTPUT_TEXTURE(TEX) \
@ -55,19 +36,6 @@ uniform sampler2D topMenuTexture;
void main(void) void main(void)
{ {
if (tex2Use == 0) { OUTPUT_TEXTURE(texture);
OUTPUT_TEXTURE(framebufferTexture); //OUTPUT_RED(); -- WTF is this failing?
} else if (tex2Use == 1) {
OUTPUT_TEXTURE(messageTexture);
} else if (tex2Use == 2) {
OUTPUT_TEXTURE(axisTexture);
} else if (tex2Use == 3) {
OUTPUT_TEXTURE(buttonTexture);
} else if (tex2Use == 4) {
OUTPUT_TEXTURE(kbdTexture);
} else if (tex2Use == 5) {
OUTPUT_TEXTURE(topMenuTexture);
} else {
//OUTPUT_RED(); -- WTF is this failing?
}
} }

View File

@ -184,7 +184,7 @@ static void alert_render(void) {
messageModel->texDirty = false; messageModel->texDirty = false;
glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, messageModel->texWidth, messageModel->texHeight, /*border*/0, TEX_FORMAT, TEX_TYPE, messageModel->texPixels); glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, messageModel->texWidth, messageModel->texHeight, /*border*/0, TEX_FORMAT, TEX_TYPE, messageModel->texPixels);
} }
glUniform1i(uniformTex2Use, TEXTURE_ID_MESSAGE); glUniform1i(texSamplerLoc, TEXTURE_ID_MESSAGE);
glhud_renderDefault(messageModel); glhud_renderDefault(messageModel);
} }

View File

@ -301,7 +301,7 @@ static void gltouchjoy_render(void) {
glBindBuffer(GL_ARRAY_BUFFER, axes.model->posBufferName); glBindBuffer(GL_ARRAY_BUFFER, axes.model->posBufferName);
glBufferData(GL_ARRAY_BUFFER, axes.model->positionArraySize, axes.model->positions, GL_DYNAMIC_DRAW); glBufferData(GL_ARRAY_BUFFER, axes.model->positionArraySize, axes.model->positions, GL_DYNAMIC_DRAW);
} }
glUniform1i(uniformTex2Use, TEXTURE_ID_TOUCHJOY_AXIS); glUniform1i(texSamplerLoc, TEXTURE_ID_TOUCHJOY_AXIS);
glhud_renderDefault(axes.model); glhud_renderDefault(axes.model);
} }
@ -322,7 +322,7 @@ static void gltouchjoy_render(void) {
glBindBuffer(GL_ARRAY_BUFFER, buttons.model->posBufferName); glBindBuffer(GL_ARRAY_BUFFER, buttons.model->posBufferName);
glBufferData(GL_ARRAY_BUFFER, buttons.model->positionArraySize, buttons.model->positions, GL_DYNAMIC_DRAW); glBufferData(GL_ARRAY_BUFFER, buttons.model->positionArraySize, buttons.model->positions, GL_DYNAMIC_DRAW);
} }
glUniform1i(uniformTex2Use, TEXTURE_ID_TOUCHJOY_BUTTON); glUniform1i(texSamplerLoc, TEXTURE_ID_TOUCHJOY_BUTTON);
glhud_renderDefault(buttons.model); glhud_renderDefault(buttons.model);
} }
} }

View File

@ -531,7 +531,7 @@ static void gltouchkbd_render(void) {
glBindBuffer(GL_ARRAY_BUFFER, kbd.model->posBufferName); glBindBuffer(GL_ARRAY_BUFFER, kbd.model->posBufferName);
glBufferData(GL_ARRAY_BUFFER, kbd.model->positionArraySize, kbd.model->positions, GL_DYNAMIC_DRAW); glBufferData(GL_ARRAY_BUFFER, kbd.model->positionArraySize, kbd.model->positions, GL_DYNAMIC_DRAW);
} }
glUniform1i(uniformTex2Use, TEXTURE_ID_TOUCHKBD); glUniform1i(texSamplerLoc, TEXTURE_ID_TOUCHKBD);
glhud_renderDefault(kbd.model); glhud_renderDefault(kbd.model);
} }
} }

View File

@ -432,7 +432,7 @@ static void gltouchmenu_render(void) {
menu.model->texDirty = false; menu.model->texDirty = false;
glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, menu.model->texWidth, menu.model->texHeight, /*border*/0, TEX_FORMAT, TEX_TYPE, menu.model->texPixels); glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, menu.model->texWidth, menu.model->texHeight, /*border*/0, TEX_FORMAT, TEX_TYPE, menu.model->texPixels);
} }
glUniform1i(uniformTex2Use, TEXTURE_ID_TOUCHMENU); glUniform1i(texSamplerLoc, TEXTURE_ID_TOUCHMENU);
glhud_renderDefault(menu.model); glhud_renderDefault(menu.model);
GL_ERRLOG("gltouchmenu_render"); GL_ERRLOG("gltouchmenu_render");

View File

@ -32,7 +32,7 @@ static int viewportHeight = SCANHEIGHT*1.5;
static int adjustedHeight = 0; static int adjustedHeight = 0;
#endif #endif
GLint uniformTex2Use = UNINITIALIZED_GL; GLint texSamplerLoc = UNINITIALIZED_GL;
GLint alphaValue = UNINITIALIZED_GL; GLint alphaValue = UNINITIALIZED_GL;
static GLint uniformMVPIdx = UNINITIALIZED_GL; static GLint uniformMVPIdx = UNINITIALIZED_GL;
static GLenum crtElementType = UNINITIALIZED_GL; static GLenum crtElementType = UNINITIALIZED_GL;
@ -436,18 +436,11 @@ static GLuint _build_program(demoSource *vertexSource, demoSource *fragmentSourc
// Setup common program input points // // Setup common program input points //
/////////////////////////////////////// ///////////////////////////////////////
GLint fbSamplerLoc = glGetUniformLocation(prgName, "framebufferTexture"); texSamplerLoc = glGetUniformLocation(prgName, "texture");
if (fbSamplerLoc < 0) { if (texSamplerLoc < 0) {
LOG("OOPS, no framebufferTexture shader : %d", fbSamplerLoc); LOG("OOPS, no framebufferTexture shader : %d", texSamplerLoc);
} else { } else {
glUniform1i(fbSamplerLoc, TEXTURE_ID_FRAMEBUFFER); glUniform1i(texSamplerLoc, TEXTURE_ID_FRAMEBUFFER);
}
GLint messageSamplerLoc = glGetUniformLocation(prgName, "messageTexture");
if (messageSamplerLoc < 0) {
LOG("OOPS, no messageSamplerLoc shader : %d", messageSamplerLoc);
} else {
glUniform1i(messageSamplerLoc, TEXTURE_ID_MESSAGE);
} }
GLint maxTextureUnits = -1; GLint maxTextureUnits = -1;
@ -460,46 +453,11 @@ static GLuint _build_program(demoSource *vertexSource, demoSource *fragmentSourc
LOG("GL_MAX_TEXTURE_IMAGE_UNITS : %d", maxTextureUnits); LOG("GL_MAX_TEXTURE_IMAGE_UNITS : %d", maxTextureUnits);
} }
#if INTERFACE_TOUCH
GLint axisSamplerLoc = glGetUniformLocation(prgName, "axisTexture");
if (axisSamplerLoc < 0) {
LOG("OOPS, no axisSamplerLoc shader : %d", axisSamplerLoc);
} else {
glUniform1i(axisSamplerLoc, TEXTURE_ID_TOUCHJOY_AXIS);
}
GLint buttonSamplerLoc = glGetUniformLocation(prgName, "buttonTexture");
if (buttonSamplerLoc < 0) {
LOG("OOPS, no buttonSamplerLoc shader : %d", buttonSamplerLoc);
} else {
glUniform1i(buttonSamplerLoc, TEXTURE_ID_TOUCHJOY_BUTTON);
}
GLint kbdSamplerLoc = glGetUniformLocation(prgName, "kbdTexture");
if (kbdSamplerLoc < 0) {
LOG("OOPS, no kbdSamplerLoc shader : %d", kbdSamplerLoc);
} else {
glUniform1i(kbdSamplerLoc, TEXTURE_ID_TOUCHKBD);
}
GLint topMenuSamplerLoc = glGetUniformLocation(prgName, "topMenuTexture");
if (topMenuSamplerLoc < 0) {
LOG("OOPS, no topMenuSamplerLoc shader : %d", topMenuSamplerLoc);
} else {
glUniform1i(topMenuSamplerLoc, TEXTURE_ID_TOUCHMENU);
}
#endif
uniformMVPIdx = glGetUniformLocation(prgName, "modelViewProjectionMatrix"); uniformMVPIdx = glGetUniformLocation(prgName, "modelViewProjectionMatrix");
if (uniformMVPIdx < 0) { if (uniformMVPIdx < 0) {
LOG("OOPS, no modelViewProjectionMatrix in shader : %d", uniformMVPIdx); LOG("OOPS, no modelViewProjectionMatrix in shader : %d", uniformMVPIdx);
} }
uniformTex2Use = glGetUniformLocation(prgName, "tex2Use");
if (uniformTex2Use < 0) {
LOG("OOPS, no texture selector in shader : %d", uniformTex2Use);
}
alphaValue = glGetUniformLocation(prgName, "aValue"); alphaValue = glGetUniformLocation(prgName, "aValue");
if (alphaValue < 0) { if (alphaValue < 0) {
LOG("OOPS, no texture selector in shader : %d", alphaValue); LOG("OOPS, no texture selector in shader : %d", alphaValue);
@ -743,7 +701,7 @@ static void gldriver_render(void) {
glActiveTexture(TEXTURE_ACTIVE_FRAMEBUFFER); glActiveTexture(TEXTURE_ACTIVE_FRAMEBUFFER);
glBindTexture(GL_TEXTURE_2D, a2TextureName); glBindTexture(GL_TEXTURE_2D, a2TextureName);
glUniform1i(uniformTex2Use, TEXTURE_ID_FRAMEBUFFER); glUniform1i(texSamplerLoc, TEXTURE_ID_FRAMEBUFFER);
if (wasDirty) { if (wasDirty) {
glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, SCANWIDTH, SCANHEIGHT, /*border*/0, TEX_FORMAT, TEX_TYPE, (GLvoid *)&pixels[0]); glTexImage2D(GL_TEXTURE_2D, /*level*/0, TEX_FORMAT_INTERNAL, SCANWIDTH, SCANHEIGHT, /*border*/0, TEX_FORMAT, TEX_TYPE, (GLvoid *)&pixels[0]);
} }

View File

@ -43,7 +43,7 @@ enum {
TEXTURE_ACTIVE_MAX, TEXTURE_ACTIVE_MAX,
}; };
extern GLint uniformTex2Use; extern GLint texSamplerLoc;
extern GLint alphaValue; extern GLint alphaValue;
#endif #endif