1 2 /* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 #include "gl/GrGLInterface.h" 11 12 #import <OpenGLES/ES2/gl.h> 13 #import <OpenGLES/ES2/glext.h> 14 GrGLCreateNativeInterface()15const GrGLInterface* GrGLCreateNativeInterface() { 16 static SkAutoTUnref<GrGLInterface> glInterface; 17 if (!glInterface.get()) { 18 GrGLInterface* interface = SkNEW(GrGLInterface); 19 glInterface.reset(interface); 20 21 interface->fActiveTexture = glActiveTexture; 22 interface->fAttachShader = glAttachShader; 23 interface->fBindAttribLocation = glBindAttribLocation; 24 interface->fBindBuffer = glBindBuffer; 25 interface->fBindTexture = glBindTexture; 26 interface->fBlendColor = glBlendColor; 27 interface->fBlendFunc = glBlendFunc; 28 interface->fBufferData = (GrGLBufferDataProc)glBufferData; 29 interface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData; 30 interface->fClear = glClear; 31 interface->fClearColor = glClearColor; 32 interface->fClearStencil = glClearStencil; 33 interface->fColorMask = glColorMask; 34 interface->fCompileShader = glCompileShader; 35 interface->fCompressedTexImage2D = glCompressedTexImage2D; 36 interface->fCreateProgram = glCreateProgram; 37 interface->fCreateShader = glCreateShader; 38 interface->fCullFace = glCullFace; 39 interface->fDeleteBuffers = glDeleteBuffers; 40 interface->fDeleteProgram = glDeleteProgram; 41 interface->fDeleteShader = glDeleteShader; 42 interface->fDeleteTextures = glDeleteTextures; 43 interface->fDepthMask = glDepthMask; 44 interface->fDisable = glDisable; 45 interface->fDisableVertexAttribArray = glDisableVertexAttribArray; 46 interface->fDrawArrays = glDrawArrays; 47 interface->fDrawBuffer = NULL; 48 interface->fDrawBuffers = NULL; 49 interface->fDrawElements = glDrawElements; 50 interface->fEnable = glEnable; 51 interface->fEnableVertexAttribArray = glEnableVertexAttribArray; 52 interface->fFinish = glFinish; 53 interface->fFlush = glFlush; 54 interface->fFrontFace = glFrontFace; 55 interface->fGenBuffers = glGenBuffers; 56 interface->fGetBufferParameteriv = glGetBufferParameteriv; 57 interface->fGetError = glGetError; 58 interface->fGetIntegerv = glGetIntegerv; 59 interface->fGetProgramInfoLog = glGetProgramInfoLog; 60 interface->fGetProgramiv = glGetProgramiv; 61 interface->fGetShaderInfoLog = glGetShaderInfoLog; 62 interface->fGetShaderiv = glGetShaderiv; 63 interface->fGetString = glGetString; 64 interface->fGenTextures = glGenTextures; 65 interface->fGetUniformLocation = glGetUniformLocation; 66 interface->fLineWidth = glLineWidth; 67 interface->fLinkProgram = glLinkProgram; 68 interface->fPixelStorei = glPixelStorei; 69 interface->fReadBuffer = NULL; 70 interface->fReadPixels = glReadPixels; 71 interface->fScissor = glScissor; 72 interface->fShaderSource = glShaderSource; 73 interface->fStencilFunc = glStencilFunc; 74 interface->fStencilFuncSeparate = glStencilFuncSeparate; 75 interface->fStencilMask = glStencilMask; 76 interface->fStencilMaskSeparate = glStencilMaskSeparate; 77 interface->fStencilOp = glStencilOp; 78 interface->fStencilOpSeparate = glStencilOpSeparate; 79 // mac uses GLenum for internalFormat param (non-standard) 80 // amounts to int vs. uint. 81 interface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D; 82 #if GL_ARB_texture_storage 83 interface->fTexStorage2D = glTexStorage2D; 84 #elif GL_EXT_texture_storage 85 interface->fTexStorage2D = glTexStorage2DEXT; 86 #endif 87 interface->fTexParameteri = glTexParameteri; 88 interface->fTexParameteriv = glTexParameteriv; 89 interface->fTexSubImage2D = glTexSubImage2D; 90 interface->fUniform1f = glUniform1f; 91 interface->fUniform1i = glUniform1i; 92 interface->fUniform1fv = glUniform1fv; 93 interface->fUniform1iv = glUniform1iv; 94 interface->fUniform2f = glUniform2f; 95 interface->fUniform2i = glUniform2i; 96 interface->fUniform2fv = glUniform2fv; 97 interface->fUniform2iv = glUniform2iv; 98 interface->fUniform3f = glUniform3f; 99 interface->fUniform3i = glUniform3i; 100 interface->fUniform3fv = glUniform3fv; 101 interface->fUniform3iv = glUniform3iv; 102 interface->fUniform4f = glUniform4f; 103 interface->fUniform4i = glUniform4i; 104 interface->fUniform4fv = glUniform4fv; 105 interface->fUniform4iv = glUniform4iv; 106 interface->fUniform4fv = glUniform4fv; 107 interface->fUniformMatrix2fv = glUniformMatrix2fv; 108 interface->fUniformMatrix3fv = glUniformMatrix3fv; 109 interface->fUniformMatrix4fv = glUniformMatrix4fv; 110 interface->fUseProgram = glUseProgram; 111 interface->fVertexAttrib4fv = glVertexAttrib4fv; 112 interface->fVertexAttribPointer = glVertexAttribPointer; 113 interface->fViewport = glViewport; 114 interface->fGenFramebuffers = glGenFramebuffers; 115 interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv; 116 interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv; 117 interface->fBindFramebuffer = glBindFramebuffer; 118 interface->fFramebufferTexture2D = glFramebufferTexture2D; 119 interface->fCheckFramebufferStatus = glCheckFramebufferStatus; 120 interface->fDeleteFramebuffers = glDeleteFramebuffers; 121 interface->fRenderbufferStorage = glRenderbufferStorage; 122 interface->fGenRenderbuffers = glGenRenderbuffers; 123 interface->fDeleteRenderbuffers = glDeleteRenderbuffers; 124 interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer; 125 interface->fBindRenderbuffer = glBindRenderbuffer; 126 127 #if GL_OES_mapbuffer 128 interface->fMapBuffer = glMapBufferOES; 129 interface->fUnmapBuffer = glUnmapBufferOES; 130 #endif 131 132 #if GL_APPLE_framebuffer_multisample 133 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE; 134 interface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE; 135 #endif 136 interface->fBindFragDataLocationIndexed = NULL; 137 138 interface->fBindingsExported = kES2_GrGLBinding; 139 } 140 glInterface.get()->ref(); 141 return glInterface.get(); 142 } 143