void COGL::DisableClientStates (int bTexCoord, int bColor, int bNormals, int nTMU) { if (nTMU >= GL_TEXTURE0) SelectTMU (nTMU, true); if (bNormals) DisableClientState (GL_NORMAL_ARRAY); if (bTexCoord) DisableClientState (GL_TEXTURE_COORD_ARRAY); if (bColor) DisableClientState (GL_COLOR_ARRAY); DisableClientState (GL_VERTEX_ARRAY); }
void GrGpuGLFixed::resetContext() { INHERITED::resetContext(); GR_GL(Disable(GR_GL_TEXTURE_2D)); for (int s = 0; s < kNumStages; ++s) { setTextureUnit(s); GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_TEXTURE_ENV_MODE, GR_GL_COMBINE)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_RGB, GR_GL_MODULATE)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_RGB, GR_GL_TEXTURE0+s)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_RGB, GR_GL_PREVIOUS)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_RGB, GR_GL_SRC_COLOR)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_ALPHA, GR_GL_MODULATE)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_ALPHA, GR_GL_TEXTURE0+s)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND0_ALPHA, GR_GL_SRC_ALPHA)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_ALPHA, GR_GL_PREVIOUS)); GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_ALPHA, GR_GL_SRC_ALPHA)); // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending // upon whether we have a (premultiplied) RGBA texture or just an ALPHA // texture, e.g.: //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR); fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1; } fHWGeometryState.fVertexLayout = 0; fHWGeometryState.fVertexOffset = ~0; GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY)); GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY)); GR_GL(ShadeModel(GR_GL_FLAT)); GR_GL(DisableClientState(GR_GL_COLOR_ARRAY)); GR_GL(PointSize(1.f)); GrGLClearErr(); fTextVerts = false; fBaseVertex = 0xffffffff; }
int COGL::EnableClientStates (int bTexCoord, int bColor, int bNormals, int nTMU) { if (nTMU >= GL_TEXTURE0) SelectTMU (nTMU, true); if (!bNormals) DisableClientState (GL_NORMAL_ARRAY); else if (!EnableClientState (GL_NORMAL_ARRAY, -1)) { DisableClientStates (0, 0, 0, -1); return 0; } if (!bTexCoord) DisableClientState (GL_TEXTURE_COORD_ARRAY); else if (!EnableClientState (GL_TEXTURE_COORD_ARRAY, -1)) { DisableClientStates (0, 0, 0, -1); return 0; } if (!bColor) DisableClientState (GL_COLOR_ARRAY); else if (!EnableClientState (GL_COLOR_ARRAY, -1)) { DisableClientStates (bTexCoord, 0, 0, -1); return 0; } return EnableClientState (GL_VERTEX_ARRAY, -1); }
int COGL::EnableClientState (GLuint nState, int nTMU) { if (nTMU >= GL_TEXTURE0) SelectTMU (nTMU, true); glEnableClientState (nState); #if DBG_OGL memset (&m_states.clientBuffers [m_states.nTMU [0]][nState - GL_VERTEX_ARRAY], 0, sizeof (m_states.clientBuffers [m_states.nTMU [0]][nState - GL_VERTEX_ARRAY])); #endif if (!glGetError ()) { m_states.clientStates [m_states.nTMU [0]][nState - GL_VERTEX_ARRAY] = 1; return 1; } DisableClientState (nState, -1); return glGetError () == 0; }
void GrGpuGLFixed::setupGeometry(int* startVertex, int* startIndex, int vertexCount, int indexCount) { int newColorOffset; int newTexCoordOffsets[kNumStages]; GrGLsizei newStride = VertexSizeAndOffsetsByStage(fGeometrySrc.fVertexLayout, newTexCoordOffsets, &newColorOffset); int oldColorOffset; int oldTexCoordOffsets[kNumStages]; GrGLsizei oldStride = VertexSizeAndOffsetsByStage(fHWGeometryState.fVertexLayout, oldTexCoordOffsets, &oldColorOffset); bool indexed = NULL != startIndex; int extraVertexOffset; int extraIndexOffset; setBuffers(indexed, &extraVertexOffset, &extraIndexOffset); GrGLenum scalarType; if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) { scalarType = GrGLTextType; } else { scalarType = GrGLType; } size_t vertexOffset = (*startVertex + extraVertexOffset) * newStride; *startVertex = 0; if (indexed) { *startIndex += extraIndexOffset; } // all the Pointers must be set if any of these are true bool allOffsetsChange = fHWGeometryState.fArrayPtrsDirty || vertexOffset != fHWGeometryState.fVertexOffset || newStride != oldStride; // position and tex coord offsets change if above conditions are true // or the type changed based on text vs nontext type coords. bool posAndTexChange = allOffsetsChange || ((GrGLTextType != GrGLType) && (kTextFormat_VertexLayoutBit & (fHWGeometryState.fVertexLayout ^ fGeometrySrc.fVertexLayout))); if (posAndTexChange) { GR_GL(VertexPointer(2, scalarType, newStride, (GrGLvoid*)vertexOffset)); fHWGeometryState.fVertexOffset = vertexOffset; } for (int s = 0; s < kNumStages; ++s) { // need to enable array if tex coord offset is 0 // (using positions as coords) if (newTexCoordOffsets[s] >= 0) { GrGLvoid* texCoordOffset = (GrGLvoid*)(vertexOffset + newTexCoordOffsets[s]); if (oldTexCoordOffsets[s] < 0) { GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s)); GR_GL(EnableClientState(GR_GL_TEXTURE_COORD_ARRAY)); GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset)); } else if (posAndTexChange || newTexCoordOffsets[s] != oldTexCoordOffsets[s]) { GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s)); GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordOffset)); } } else if (oldTexCoordOffsets[s] >= 0) { GR_GL(ClientActiveTexture(GR_GL_TEXTURE0+s)); GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY)); } } if (newColorOffset > 0) { GrGLvoid* colorOffset = (GrGLvoid*)(vertexOffset + newColorOffset); if (oldColorOffset <= 0) { GR_GL(EnableClientState(GR_GL_COLOR_ARRAY)); GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset)); } else if (allOffsetsChange || newColorOffset != oldColorOffset) { GR_GL(ColorPointer(4, GR_GL_UNSIGNED_BYTE, newStride, colorOffset)); } } else if (oldColorOffset > 0) { GR_GL(DisableClientState(GR_GL_COLOR_ARRAY)); } fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout; fHWGeometryState.fArrayPtrsDirty = false; }
void cRendererGLES2::SetShader( cShaderProgram * Shader ) { if ( NULL == Shader ) { Shader = mShaders[ EEGLES2_SHADER_BASE ]; } if ( mCurShader == Shader ) { return; } DisableClientState( GL_VERTEX_ARRAY ); DisableClientState( GL_TEXTURE_COORD_ARRAY ); DisableClientState( GL_COLOR_ARRAY ); mShaderPrev = mCurShader; mCurShader = Shader; CheckLocalShader(); mProjectionMatrix_id = mCurShader->UniformLocation( "dgl_ProjectionMatrix" ); mModelViewMatrix_id = mCurShader->UniformLocation( "dgl_ModelViewMatrix" ); mTexActiveLoc = mCurShader->UniformLocation( "dgl_TexActive" ); mClippingEnabledLoc = mCurShader->UniformLocation( "dgl_ClippingEnabled" ); mCurActiveTex = 0; Uint32 i; for ( i = 0; i < EEGL_ARRAY_STATES_COUNT; i++ ) { mAttribsLoc[ i ] = mCurShader->AttributeLocation( EEGLES2_STATES_NAME[ i ] ); } for ( i = 0; i < EE_MAX_PLANES; i++ ) { if ( -1 != mClippingEnabledLoc ) { mPlanes[ i ] = mCurShader->UniformLocation( EEGLES2_PLANES_NAMENABLED_NAME[ i ] ); } else { mPlanes[ i ] = -1; } } for ( i = 0; i < EE_MAX_TEXTURE_UNITS; i++ ) { mTextureUnits[ i ] = mCurShader->AttributeLocation( EEGLES2_TEXTUREUNIT_NAMES[ i ] ); } glUseProgram( mCurShader->Handler() ); if ( -1 != mAttribsLoc[ EEGL_VERTEX_ARRAY ] ) EnableClientState( GL_VERTEX_ARRAY ); if ( -1 != mAttribsLoc[ EEGL_COLOR_ARRAY ] ) EnableClientState( GL_COLOR_ARRAY ); if ( -1 != mTextureUnits[ mCurActiveTex ] ) EnableClientState( GL_TEXTURE_COORD_ARRAY ); GLenum CM = mCurrentMode; MatrixMode( GL_PROJECTION ); UpdateMatrix(); MatrixMode( GL_MODELVIEW ); UpdateMatrix(); MatrixMode( CM ); if ( -1 != mTexActiveLoc ) { mCurShader->SetUniform( mTexActiveLoc, mTexActive ); } if ( -1 != mClippingEnabledLoc ) { mCurShader->SetUniform( mClippingEnabledLoc, 0 ); } for ( i = 0; i < EE_MAX_PLANES; i++ ) { if ( -1 != mPlanes[ i ] ) { mCurShader->SetUniform( EEGLES2_PLANES_ENABLED_NAME[ i ], 0 ); } } }