/* ================== GL_SelectTexture ================== */ void GL_SelectTexture (int unit){ if (glState.texUnit == unit) return; glState.texUnit = unit; qglActiveTexture(GL_TEXTURE0 + unit); }
/* * R_SelectTexture */ void R_SelectTexture(r_texunit_t *texunit) { if (texunit == r_state.active_texunit) return; r_state.active_texunit = texunit; qglActiveTexture(texunit->texture); qglClientActiveTexture(texunit->texture); }
/* ================== GL_BindMultitexture ================== */ void GL_BindMultitexture (texture_t *texture, int unit){ if (texture->frameUsed != rg.frameCount){ texture->frameUsed = rg.frameCount; rg.pc.textures++; rg.pc.textureBytes += texture->size; } if (glState.texture[unit] == texture) return; glState.texture[unit] = texture; if (glState.texUnit != unit){ glState.texUnit = unit; qglActiveTexture(GL_TEXTURE0 + unit); } qglBindTexture(texture->target, texture->textureId); }
/* ================== GL_SetDefaultState ================== */ void GL_SetDefaultState (){ int i; QGL_LogPrintf("---------- GL_SetDefaultState ----------\n"); // Reset the state manager glState.projectionMatrixIdentity = true; glState.modelviewMatrixIdentity = true; for (i = 0; i < MAX_TEXTURE_UNITS; i++) glState.textureMatrixIdentity[i] = true; for (i = 0; i < MAX_TEXTURE_UNITS; i++) glState.texture[i] = NULL; glState.program = NULL; glState.indexBuffer = NULL; glState.vertexBuffer = NULL; glState.viewportX = 0; glState.viewportY = 0; glState.viewportWidth = glConfig.videoWidth; glState.viewportHeight = glConfig.videoHeight; glState.scissorX = 0; glState.scissorY = 0; glState.scissorWidth = glConfig.videoWidth; glState.scissorHeight = glConfig.videoHeight; glState.depthBoundsMin = 0.0f; glState.depthBoundsMax = 1.0f; glState.texUnit = 0; for (i = 0; i < MAX_TEXTURE_UNITS; i++){ glState.texTarget[i] = 0; glState.texEnv[i] = GL_MODULATE; glState.texGen[i][0] = GL_OBJECT_LINEAR; glState.texGen[i][1] = GL_OBJECT_LINEAR; glState.texGen[i][2] = GL_OBJECT_LINEAR; glState.texGen[i][3] = GL_OBJECT_LINEAR; } glState.cullFace = false; glState.polygonOffsetFill = false; glState.polygonOffsetLine = false; glState.blend = false; glState.alphaTest = false; glState.depthTest = false; glState.stencilTest = false; for (i = 0; i < MAX_TEXTURE_UNITS; i++){ glState.textureGen[i][0] = false; glState.textureGen[i][1] = false; glState.textureGen[i][2] = false; glState.textureGen[i][3] = false; } glState.cullMode = GL_FRONT; glState.polygonMode = GL_FILL; glState.polygonOffsetFactor = 0.0f; glState.polygonOffsetUnits = 0.0f; glState.blendSrc = GL_ONE; glState.blendDst = GL_ZERO; glState.blendMode = GL_FUNC_ADD; glState.alphaFunc = GL_GREATER; glState.alphaFuncRef = 0.0f; glState.depthFunc = GL_LEQUAL; glState.stencilFunc[0] = GL_ALWAYS; glState.stencilFunc[1] = GL_ALWAYS; glState.stencilFuncRef[0] = 0; glState.stencilFuncRef[1] = 0; glState.stencilFuncMask[0] = 255; glState.stencilFuncMask[1] = 255; glState.stencilOpFail[0] = GL_KEEP; glState.stencilOpFail[1] = GL_KEEP; glState.stencilOpZFail[0] = GL_KEEP; glState.stencilOpZFail[1] = GL_KEEP; glState.stencilOpZPass[0] = GL_KEEP; glState.stencilOpZPass[1] = GL_KEEP; glState.depthMin = 0.0f; glState.depthMax = 1.0f; glState.colorMask[0] = GL_TRUE; glState.colorMask[1] = GL_TRUE; glState.colorMask[2] = GL_TRUE; glState.colorMask[3] = GL_TRUE; glState.depthMask = GL_TRUE; glState.stencilMask[0] = 255; glState.stencilMask[1] = 255; // Set default state qglMatrixMode(GL_PROJECTION); qglLoadIdentity(); qglMatrixMode(GL_MODELVIEW); qglLoadIdentity(); for (i = MAX_TEXTURE_UNITS - 1; i >= 0; i--){ if (i >= glConfig.maxTextureImageUnits) continue; if (i >= glConfig.maxTextureUnits){ qglActiveTexture(GL_TEXTURE0 + i); qglBindTexture(GL_TEXTURE_2D, 0); qglBindTexture(GL_TEXTURE_3D, 0); qglBindTexture(GL_TEXTURE_CUBE_MAP, 0); qglBindTexture(GL_TEXTURE_2D_ARRAY, 0); continue; } qglActiveTexture(GL_TEXTURE0 + i); qglMatrixMode(GL_TEXTURE); qglLoadIdentity(); qglDisable(GL_TEXTURE_2D); qglDisable(GL_TEXTURE_3D); qglDisable(GL_TEXTURE_CUBE_MAP); qglDisable(GL_TEXTURE_2D_ARRAY); qglBindTexture(GL_TEXTURE_2D, 0); qglBindTexture(GL_TEXTURE_3D, 0); qglBindTexture(GL_TEXTURE_CUBE_MAP, 0); qglBindTexture(GL_TEXTURE_2D_ARRAY, 0); qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); qglDisable(GL_TEXTURE_GEN_S); qglDisable(GL_TEXTURE_GEN_T); qglDisable(GL_TEXTURE_GEN_R); qglDisable(GL_TEXTURE_GEN_Q); qglTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); qglTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); qglTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); qglTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); } qglDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS); qglUseProgram(0); qglBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); qglBindBuffer(GL_ARRAY_BUFFER, 0); qglViewport(0, 0, glConfig.videoWidth, glConfig.videoHeight); qglEnable(GL_SCISSOR_TEST); qglScissor(0, 0, glConfig.videoWidth, glConfig.videoHeight); qglEnable(GL_DEPTH_BOUNDS_TEST_EXT); qglDepthBoundsEXT(0.0f, 1.0f); qglFrontFace(GL_CCW); qglShadeModel(GL_SMOOTH); qglPolygonMode(GL_FRONT_AND_BACK, GL_FILL); qglDisable(GL_CULL_FACE); qglCullFace(GL_FRONT); qglDisable(GL_POLYGON_OFFSET_FILL); qglDisable(GL_POLYGON_OFFSET_LINE); qglPolygonOffset(0.0f, 0.0f); qglDisable(GL_BLEND); qglBlendFunc(GL_ONE, GL_ZERO); qglBlendEquation(GL_FUNC_ADD); qglDisable(GL_ALPHA_TEST); qglAlphaFunc(GL_GREATER, 0.0f); qglDisable(GL_DEPTH_TEST); qglDepthFunc(GL_LEQUAL); qglDisable(GL_STENCIL_TEST); qglStencilFunc(GL_ALWAYS, 128, 255); qglStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); qglDepthRange(0.0f, 1.0f); qglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); qglDepthMask(GL_TRUE); qglStencilMask(255); qglDisable(GL_DEPTH_CLAMP); qglDisable(GL_CLIP_PLANE0); if (glConfig.multiSamples > 1){ qglDisable(GL_MULTISAMPLE); qglDisable(GL_SAMPLE_ALPHA_TO_COVERAGE); } qglClearColor(0.0f, 0.0f, 0.0f, 1.0f); qglClearDepth(1.0f); qglClearStencil(128); qglEnableClientState(GL_VERTEX_ARRAY); qglDisableVertexAttribArray(GL_ATTRIB_NORMAL); qglDisableVertexAttribArray(GL_ATTRIB_TANGENT1); qglDisableVertexAttribArray(GL_ATTRIB_TANGENT2); qglDisableVertexAttribArray(GL_ATTRIB_TEXCOORD); qglDisableVertexAttribArray(GL_ATTRIB_COLOR); QGL_LogPrintf("--------------------\n"); }
/** * @brief Dumps OpenGL state for debugging - typically every capability set with glEnable(). */ void R_DumpOpenGlState (void) { #define CAPABILITY( X ) {GL_ ## X, # X} /* List taken from here: http://www.khronos.org/opengles/sdk/1.1/docs/man/glIsEnabled.xml */ const struct { GLenum idx; const char * text; } openGLCaps[] = { CAPABILITY(ALPHA_TEST), CAPABILITY(BLEND), CAPABILITY(COLOR_ARRAY), CAPABILITY(COLOR_LOGIC_OP), CAPABILITY(COLOR_MATERIAL), CAPABILITY(CULL_FACE), CAPABILITY(DEPTH_TEST), CAPABILITY(DITHER), CAPABILITY(FOG), CAPABILITY(LIGHTING), CAPABILITY(LINE_SMOOTH), CAPABILITY(MULTISAMPLE), CAPABILITY(NORMAL_ARRAY), CAPABILITY(NORMALIZE), CAPABILITY(POINT_SMOOTH), CAPABILITY(POLYGON_OFFSET_FILL), CAPABILITY(RESCALE_NORMAL), CAPABILITY(SAMPLE_ALPHA_TO_COVERAGE), CAPABILITY(SAMPLE_ALPHA_TO_ONE), CAPABILITY(SAMPLE_COVERAGE), CAPABILITY(SCISSOR_TEST), CAPABILITY(STENCIL_TEST), CAPABILITY(VERTEX_ARRAY) }; #undef CAPABILITY char s[1024] = ""; GLint i; GLint maxTexUnits = 0; GLint activeTexUnit = 0; GLint activeClientTexUnit = 0; GLint activeTexId = 0; GLfloat texEnvMode = 0; const char * texEnvModeStr = "UNKNOWN"; GLfloat color[4]; for (int i = 0; i < lengthof(openGLCaps); i++) { if (glIsEnabled(openGLCaps[i].idx)) { Q_strcat(s, openGLCaps[i].text, sizeof(s)); Q_strcat(s, " ", sizeof(s)); } } glGetFloatv(GL_CURRENT_COLOR, color); Com_Printf("OpenGL enabled caps: %s color %f %f %f %f \n", s, color[0], color[1], color[2], color[3]); glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexUnit); glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &activeClientTexUnit); glGetIntegerv(GL_MAX_TEXTURE_UNITS, &maxTexUnits); for (i = GL_TEXTURE0; i < GL_TEXTURE0 + maxTexUnits; i++) { qglActiveTexture(i); qglClientActiveTexture(i); strcpy(s, ""); if (glIsEnabled (GL_TEXTURE_2D)) strcat(s, "enabled, "); if (glIsEnabled (GL_TEXTURE_COORD_ARRAY)) strcat(s, "with texcoord array, "); if (i == activeTexUnit) strcat(s, "active, "); if (i == activeClientTexUnit) strcat(s, "client active, "); glGetIntegerv(GL_TEXTURE_BINDING_2D, &activeTexId); glGetTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texEnvMode); if (fabs(texEnvMode - GL_ADD) < 0.1f) texEnvModeStr = "ADD"; if (fabs(texEnvMode - GL_MODULATE) < 0.1f) texEnvModeStr = "MODULATE"; if (fabs(texEnvMode - GL_DECAL) < 0.1f) texEnvModeStr = "DECAL"; if (fabs(texEnvMode - GL_BLEND) < 0.1f) texEnvModeStr = "BLEND"; if (fabs(texEnvMode - GL_REPLACE) < 0.1f) texEnvModeStr = "REPLACE"; if (fabs(texEnvMode - GL_COMBINE) < 0.1f) texEnvModeStr = "COMBINE"; Com_Printf("Texunit: %d texID %d %s texEnv mode %s\n", i - GL_TEXTURE0, activeTexId, s, texEnvModeStr); } qglActiveTexture(activeTexUnit); qglClientActiveTexture(activeClientTexUnit); }