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
uniform float aValue;
// texture switch
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;
uniform sampler2D texture;
#if __VERSION__ >= 140
#define OUTPUT_TEXTURE(TEX) \
@ -55,19 +36,6 @@ uniform sampler2D topMenuTexture;
void main(void)
{
if (tex2Use == 0) {
OUTPUT_TEXTURE(framebufferTexture);
} 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?
}
OUTPUT_TEXTURE(texture);
//OUTPUT_RED(); -- WTF is this failing?
}

View File

@ -184,7 +184,7 @@ static void alert_render(void) {
messageModel->texDirty = false;
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);
}

View File

@ -301,7 +301,7 @@ static void gltouchjoy_render(void) {
glBindBuffer(GL_ARRAY_BUFFER, axes.model->posBufferName);
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);
}
@ -322,7 +322,7 @@ static void gltouchjoy_render(void) {
glBindBuffer(GL_ARRAY_BUFFER, buttons.model->posBufferName);
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);
}
}

View File

@ -531,7 +531,7 @@ static void gltouchkbd_render(void) {
glBindBuffer(GL_ARRAY_BUFFER, kbd.model->posBufferName);
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);
}
}

View File

@ -432,7 +432,7 @@ static void gltouchmenu_render(void) {
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);
}
glUniform1i(uniformTex2Use, TEXTURE_ID_TOUCHMENU);
glUniform1i(texSamplerLoc, TEXTURE_ID_TOUCHMENU);
glhud_renderDefault(menu.model);
GL_ERRLOG("gltouchmenu_render");

View File

@ -32,7 +32,7 @@ static int viewportHeight = SCANHEIGHT*1.5;
static int adjustedHeight = 0;
#endif
GLint uniformTex2Use = UNINITIALIZED_GL;
GLint texSamplerLoc = UNINITIALIZED_GL;
GLint alphaValue = UNINITIALIZED_GL;
static GLint uniformMVPIdx = UNINITIALIZED_GL;
static GLenum crtElementType = UNINITIALIZED_GL;
@ -436,18 +436,11 @@ static GLuint _build_program(demoSource *vertexSource, demoSource *fragmentSourc
// Setup common program input points //
///////////////////////////////////////
GLint fbSamplerLoc = glGetUniformLocation(prgName, "framebufferTexture");
if (fbSamplerLoc < 0) {
LOG("OOPS, no framebufferTexture shader : %d", fbSamplerLoc);
texSamplerLoc = glGetUniformLocation(prgName, "texture");
if (texSamplerLoc < 0) {
LOG("OOPS, no framebufferTexture shader : %d", texSamplerLoc);
} else {
glUniform1i(fbSamplerLoc, TEXTURE_ID_FRAMEBUFFER);
}
GLint messageSamplerLoc = glGetUniformLocation(prgName, "messageTexture");
if (messageSamplerLoc < 0) {
LOG("OOPS, no messageSamplerLoc shader : %d", messageSamplerLoc);
} else {
glUniform1i(messageSamplerLoc, TEXTURE_ID_MESSAGE);
glUniform1i(texSamplerLoc, TEXTURE_ID_FRAMEBUFFER);
}
GLint maxTextureUnits = -1;
@ -460,46 +453,11 @@ static GLuint _build_program(demoSource *vertexSource, demoSource *fragmentSourc
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");
if (uniformMVPIdx < 0) {
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");
if (alphaValue < 0) {
LOG("OOPS, no texture selector in shader : %d", alphaValue);
@ -743,7 +701,7 @@ static void gldriver_render(void) {
glActiveTexture(TEXTURE_ACTIVE_FRAMEBUFFER);
glBindTexture(GL_TEXTURE_2D, a2TextureName);
glUniform1i(uniformTex2Use, TEXTURE_ID_FRAMEBUFFER);
glUniform1i(texSamplerLoc, TEXTURE_ID_FRAMEBUFFER);
if (wasDirty) {
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,
};
extern GLint uniformTex2Use;
extern GLint texSamplerLoc;
extern GLint alphaValue;
#endif