void pie_ActivateShader(SHADER_MODE shaderMode, iIMDShape* shape, PIELIGHT teamcolour, PIELIGHT colour) { int maskpage = shape->tcmaskpage; int normalpage = shape->normalpage; GLfloat colour4f[4]; if (shaderMode != currentShaderMode) { GLint locTex0, locTex1, locTex2; glUseProgram(shaderProgram[shaderMode]); locTex0 = glGetUniformLocation(shaderProgram[shaderMode], "Texture0"); locTex1 = glGetUniformLocation(shaderProgram[shaderMode], "Texture1"); locTex2 = glGetUniformLocation(shaderProgram[shaderMode], "Texture2"); locTeam = glGetUniformLocation(shaderProgram[shaderMode], "teamcolour"); locStretch = glGetUniformLocation(shaderProgram[shaderMode], "stretch"); locTCMask = glGetUniformLocation(shaderProgram[shaderMode], "tcmask"); locNormalMap = glGetUniformLocation(shaderProgram[shaderMode], "normalmap"); locFog = glGetUniformLocation(shaderProgram[shaderMode], "fogEnabled"); locEcm = glGetUniformLocation(shaderProgram[shaderMode], "ecmEffect"); locTime = glGetUniformLocation(shaderProgram[shaderMode], "graphicsCycle"); // These never change glUniform1i(locTex0, 0); glUniform1i(locTex1, 1); glUniform1i(locTex2, 2); currentShaderMode = shaderMode; } glColor4ubv(colour.vector); pie_SetTexturePage(shape->texpage); pal_PIELIGHTtoRGBA4f(&colour4f[0], teamcolour); glUniform4fv(locTeam, 1, &colour4f[0]); glUniform1f(locStretch, shaderStretch); glUniform1i(locTCMask, maskpage != iV_TEX_INVALID); glUniform1i(locNormalMap, normalpage != iV_TEX_INVALID); glUniform1i(locFog, rendStates.fog); glUniform1f(locTime, timeState); glUniform1i(locEcm, ecmState); if (maskpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[maskpage].id); } if (normalpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[normalpage].id); } glActiveTexture(GL_TEXTURE0); #ifdef _DEBUG glErrors(); #endif }
void pie_ActivateFallback(SHADER_MODE, iIMDShape* shape, PIELIGHT teamcolour, PIELIGHT colour) { if (shape->tcmaskpage == iV_TEX_INVALID) { return; } //Set the environment colour with tcmask GLfloat tc_env_colour[4]; pal_PIELIGHTtoRGBA4f(&tc_env_colour[0], teamcolour); // TU0 glActiveTexture(GL_TEXTURE0); pie_SetTexturePage(shape->texpage); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, tc_env_colour); // TU0 RGB glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); // TU0 Alpha glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); // TU1 glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[shape->tcmaskpage].id); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); // TU1 RGB glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE0); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); // TU1 Alpha glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); if (GLEW_ARB_imaging || GLEW_EXT_blend_color) { glEnable(GL_BLEND); glBlendFunc(GL_CONSTANT_COLOR, GL_ZERO); glBlendColor(colour.byte.r / 255.0, colour.byte.g / 255.0, colour.byte.b / 255.0, colour.byte.a / 255.0); } glActiveTexture(GL_TEXTURE0); }
void pie_ActivateShader(SHADER_MODE shaderMode, PIELIGHT teamcolour, int maskpage, int normalpage) { GLfloat colour4f[4]; if (shaderMode != currentShaderMode) { GLint locTex0, locTex1, locTex2; glUseProgram(shaderProgram[shaderMode]); locTex0 = glGetUniformLocation(shaderProgram[shaderMode], "Texture0"); locTex1 = glGetUniformLocation(shaderProgram[shaderMode], "Texture1"); locTex2 = glGetUniformLocation(shaderProgram[shaderMode], "Texture2"); locTeam = glGetUniformLocation(shaderProgram[shaderMode], "teamcolour"); locStretch = glGetUniformLocation(shaderProgram[shaderMode], "stretch"); locTCMask = glGetUniformLocation(shaderProgram[shaderMode], "tcmask"); locNormalMap = glGetUniformLocation(shaderProgram[shaderMode], "normalmap"); locFog = glGetUniformLocation(shaderProgram[shaderMode], "fogEnabled"); // These never change glUniform1i(locTex0, 0); glUniform1i(locTex1, 1); glUniform1i(locTex2, 2); currentShaderMode = shaderMode; } pal_PIELIGHTtoRGBA4f(&colour4f[0], teamcolour); glUniform4fv(locTeam, 1, &colour4f[0]); glUniform1f(locStretch, shaderStretch); glUniform1i(locTCMask, maskpage != iV_TEX_INVALID); glUniform1i(locNormalMap, normalpage != iV_TEX_INVALID); glUniform1i(locFog, rendStates.fog); if (maskpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE1); pie_SetTexturePage(maskpage); } if (normalpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE2); pie_SetTexturePage(normalpage); } glActiveTexture(GL_TEXTURE0); #ifdef _DEBUG glErrors(); #endif }
void pie_ActivateShader_TCMask(PIELIGHT teamcolour, int maskpage) { GLfloat colour4f[4]; pie_SetShader(SHADER_COMPONENT); pal_PIELIGHTtoRGBA4f(&colour4f[0], teamcolour); glUniform4fv(locTeam, 1, &colour4f[0]); glUniform1f(locStretch, shaderStretch); glUniform1i(locTCMask, maskpage != iV_TEX_INVALID); glUniform1i(locFog, rendStates.fog); if (maskpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE1); pie_SetTexturePage(maskpage); } glActiveTexture(GL_TEXTURE0); #ifdef _DEBUG glErrors(); #endif }
static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT teamcolour, WZ_DECL_UNUSED PIELIGHT specular, int pieFlag, int pieFlagData) { iIMDPoly *pPolys; bool light = lighting; pie_SetAlphaTest(true); /* Set fog status */ if (!(pieFlag & pie_FORCE_FOG) && (pieFlag & pie_ADDITIVE || pieFlag & pie_TRANSLUCENT || pieFlag & pie_BUTTON)) { pie_SetFogStatus(false); } else { pie_SetFogStatus(true); } /* Set tranlucency */ if (pieFlag & pie_ADDITIVE) { pie_SetRendMode(REND_ADDITIVE); colour.byte.a = (UBYTE)pieFlagData; light = false; } else if (pieFlag & pie_TRANSLUCENT) { pie_SetRendMode(REND_ALPHA); colour.byte.a = (UBYTE)pieFlagData; light = false; } else { if (pieFlag & pie_BUTTON) { pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON); } pie_SetRendMode(REND_OPAQUE); } if (light) { const float ambient[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; const float diffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; const float specular[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; const float shininess = 10; glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); } if (pieFlag & pie_HEIGHT_SCALED) // construct { glScalef(1.0f, (float)pieFlagData / (float)pie_RAISE_SCALE, 1.0f); } if (pieFlag & pie_RAISE) // collapse { glTranslatef(1.0f, (-shape->max.y * (pie_RAISE_SCALE - pieFlagData)) / pie_RAISE_SCALE, 1.0f); } glColor4ubv(colour.vector); // Only need to set once for entire model pie_SetTexturePage(shape->texpage); // Activate TCMask if needed if (shape->flags & iV_IMD_TCMASK && rendStates.rendMode == REND_OPAQUE) { #ifdef _DEBUG glErrors(); #endif if (pie_GetShadersStatus()) { pie_ActivateShader_TCMask(teamcolour, shape->tcmaskpage); } else { //Set the environment colour with tcmask GLfloat tc_env_colour[4]; pal_PIELIGHTtoRGBA4f(&tc_env_colour[0], teamcolour); // TU0 glActiveTexture(GL_TEXTURE0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, tc_env_colour); // TU0 RGB glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); // TU0 Alpha glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); // TU1 glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[shape->tcmaskpage].id); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); // TU1 RGB glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE0); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA); // TU1 Alpha glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_PREVIOUS); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA); // This is why we are doing in opaque mode. glEnable(GL_BLEND); glBlendFunc(GL_CONSTANT_COLOR, GL_ZERO); glBlendColor(colour.byte.r / 255.0, colour.byte.g / 255.0, colour.byte.b / 255.0, colour.byte.a / 255.0); } #ifdef _DEBUG glErrors(); #endif } for (pPolys = shape->polys; pPolys < shape->polys + shape->npolys; pPolys++) { Vector2f texCoords[pie_MAX_VERTICES_PER_POLYGON]; Vector3f vertexCoords[pie_MAX_VERTICES_PER_POLYGON]; unsigned int n; VERTEXID *index; for (n = 0, index = pPolys->pindex; n < pPolys->npnts; n++, index++) { vertexCoords[n].x = shape->points[*index].x; vertexCoords[n].y = shape->points[*index].y; vertexCoords[n].z = shape->points[*index].z; texCoords[n].x = pPolys->texCoord[n].x; texCoords[n].y = pPolys->texCoord[n].y; } polyCount++; // Run TextureAnimation (exluding the new teamcoloured models) if (frame && pPolys->flags & iV_IMD_TEXANIM && !(shape->flags & iV_IMD_TCMASK)) { frame %= shape->numFrames; if (frame > 0) { const int framesPerLine = OLD_TEXTURE_SIZE_FIX / (pPolys->texAnim.x * OLD_TEXTURE_SIZE_FIX); const int uFrame = (frame % framesPerLine) * (pPolys->texAnim.x * OLD_TEXTURE_SIZE_FIX); const int vFrame = (frame / framesPerLine) * (pPolys->texAnim.y * OLD_TEXTURE_SIZE_FIX); for (n = 0; n < pPolys->npnts; n++) { texCoords[n].x += uFrame / OLD_TEXTURE_SIZE_FIX; texCoords[n].y += vFrame / OLD_TEXTURE_SIZE_FIX; } } } glBegin(GL_TRIANGLE_FAN); if (light) { glNormal3fv((GLfloat*)&pPolys->normal); } for (n = 0; n < pPolys->npnts; n++) { glTexCoord2fv((GLfloat*)&texCoords[n]); if (shape->flags & iV_IMD_TCMASK && rendStates.rendMode == REND_OPAQUE && !pie_GetShadersStatus()) { glMultiTexCoord2fv(GL_TEXTURE1, (GLfloat*)&texCoords[n]); } glVertex3fv((GLfloat*)&vertexCoords[n]); } glEnd(); } // Deactivate TCMask if it was previously enabled if (shape->flags & iV_IMD_TCMASK && rendStates.rendMode == REND_OPAQUE) { if (pie_GetShadersStatus()) { pie_DeactivateShader(); } else { glDisable(GL_BLEND); glActiveTexture(GL_TEXTURE1); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } } if (pieFlag & pie_BUTTON) { pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON); } if (light) { glDisable(GL_LIGHTING); glDisable(GL_NORMALIZE); } }
void pie_ActivateShader(int shaderMode, const iIMDShape *shape, PIELIGHT teamcolour, PIELIGHT colour) { int maskpage = shape->tcmaskpage; int normalpage = shape->normalpage; int specularpage = shape->specularpage; GLfloat colour4f[4]; SHADER_PROGRAM program = shaderProgram[shaderMode]; if (shaderMode != currentShaderMode) { glUseProgram(program.program); // These do not change during our drawing pass glUniform1i(program.locFog, rendStates.fog); glUniform1f(program.locTime, timeState); currentShaderMode = shaderMode; } glColor4ubv(colour.vector); pie_SetTexturePage(shape->texpage); pal_PIELIGHTtoRGBA4f(&colour4f[0], teamcolour); glUniform4fv(program.locTeam, 1, &colour4f[0]); glUniform1i(program.locTCMask, maskpage != iV_TEX_INVALID); if (program.locStretch >= 0) { glUniform1f(program.locStretch, shaderStretch); } if (program.locNormalMap >= 0) { glUniform1i(program.locNormalMap, normalpage != iV_TEX_INVALID); } if (program.locSpecularMap >= 0) { glUniform1i(program.locSpecularMap, specularpage != iV_TEX_INVALID); } if (program.locEcm >= 0) { glUniform1i(program.locEcm, ecmState); } if (maskpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, pie_Texture(maskpage)); } if (normalpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, pie_Texture(normalpage)); } if (specularpage != iV_TEX_INVALID) { glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, pie_Texture(specularpage)); } glActiveTexture(GL_TEXTURE0); #ifdef _DEBUG glErrors(); #endif }