static void InitGL() { OGLEXT(PFNGLCLIENTACTIVETEXTUREPROC, glClientActiveTexture); OGLEXT(PFNGLACTIVETEXTUREPROC, glActiveTexture); OGLEXT(PFNGLDELETEBUFFERSARBPROC, glDeleteBuffers); OGLEXT(PFNGLGENBUFFERSPROC, glGenBuffers); OGLEXT(PFNGLBINDBUFFERPROC, glBindBuffer); OGLEXT(PFNGLBUFFERDATAPROC, glBufferData); OGLEXT(PFNGLATTACHSHADERPROC, glAttachShader); OGLEXT(PFNGLCOMPILESHADERPROC, glCompileShader); OGLEXT(PFNGLCREATEPROGRAMPROC, glCreateProgram); OGLEXT(PFNGLCREATESHADERPROC, glCreateShader); OGLEXT(PFNGLDELETEPROGRAMPROC, glDeleteProgram); OGLEXT(PFNGLDELETESHADERPROC, glDeleteShader); OGLEXT(PFNGLLINKPROGRAMPROC, glLinkProgram); OGLEXT(PFNGLSHADERSOURCEPROC, glShaderSource); OGLEXT(PFNGLUSEPROGRAMPROC, glUseProgram); OGLEXT(PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation); OGLEXT(PFNGLVERTEXATTRIB4FVARBPROC, glVertexAttrib4fvARB); OGLEXT(PFNGLGETATTRIBLOCATIONPROC, glGetAttribLocation); OGLEXT(PFNGLUNIFORMMATRIX4FVARBPROC, glUniformMatrix4fvARB); OGLEXT(PFNGLUNIFORM3FPROC, glUniform3f); OGLEXT(PFNGLUNIFORM1IPROC, glUniform1i); OGLEXT(PFNGLVERTEXATTRIBPOINTERPROC, glVertexAttribPointer); OGLEXT(PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray); OGLEXT(PFNGLDISABLEVERTEXATTRIBARRAYPROC, glDisableVertexAttribArray); OGLEXT(PFNGLGENPROGRAMSARBPROC, glGenProgramsARB); OGLEXT(PFNGLPROGRAMSTRINGARBPROC, glProgramStringARB); OGLEXT(PFNGLBINDPROGRAMARBPROC, glBindProgramARB); OGLEXT(PFNGLDELETEPROGRAMSARBPROC, glDeleteProgramARB); OGLEXT(PFNGLPROGRAMENVPARAMETER4FARBPROC, glProgramEnvParameter4fARB); OGLEXT(PFNGLPROGRAMLOCALPARAMETER4FARBPROC, glProgramLocalParameter4fARB); OGLEXT(PFNGLBINDFRAMEBUFFEREXTPROC, glBindFramebufferEXT); OGLEXT(PFNGLDELETEFRAMEBUFFERSEXTPROC, glDeleteFramebuffersEXT); OGLEXT(PFNGLGENFRAMEBUFFERSEXTPROC, glGenFramebuffersEXT); OGLEXT(PFNGLBINDRENDERBUFFEREXTPROC, glBindRenderbufferEXT); OGLEXT(PFNGLDELETERENDERBUFFERSEXTPROC, glDeleteRenderbuffersEXT); OGLEXT(PFNGLGENRENDERBUFFERSEXTPROC, glGenRenderbuffersEXT); OGLEXT(PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC, glFramebufferRenderbufferEXT); OGLEXT(PFNGLRENDERBUFFERSTORAGEEXTPROC, glRenderbufferStorageEXT); OGLEXT(PFNGLFRAMEBUFFERTEXTURE2DEXTPROC, glFramebufferTexture2DEXT); OGLEXT(PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC, glCheckFramebufferStatusEXT); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClearDepth(1.0f); ClientActiveTexture(GL_TEXTURE0_ARB); glShadeModel(GL_FLAT); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); CullFace(true); AlphaTest(false); DepthTest(false); DepthWrite(false); Blend(false); }
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; }