OLD | NEW |
1 // Modified from chromium/src/webkit/glue/gl_bindings_skia_cmd_buffer.cc | 1 // Modified from chromium/src/webkit/glue/gl_bindings_skia_cmd_buffer.cc |
2 | 2 |
3 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
6 | 6 |
7 #include "gl/GrGLExtensions.h" | 7 #include "gl/GrGLExtensions.h" |
8 #include "gl/GrGLInterface.h" | 8 #include "gl/GrGLInterface.h" |
9 #include "gl/GrGLUtil.h" | 9 #include "gl/GrGLUtil.h" |
10 | 10 |
11 #ifndef GL_GLEXT_PROTOTYPES | 11 #ifndef GL_GLEXT_PROTOTYPES |
12 #define GL_GLEXT_PROTOTYPES | 12 #define GL_GLEXT_PROTOTYPES |
13 #endif | 13 #endif |
14 | 14 |
15 #include <GLES2/gl2.h> | 15 #include <GLES2/gl2.h> |
16 #include <GLES2/gl2ext.h> | 16 #include <GLES2/gl2ext.h> |
17 | 17 |
18 #include <EGL/egl.h> | 18 #include <EGL/egl.h> |
19 | 19 |
| 20 static const GrGLInterface* create_es_interface(GrGLVersion version, |
| 21 const GrGLExtensions& extensions
) { |
| 22 if (version < GR_GL_VER(2,0)) { |
| 23 return NULL; |
| 24 } |
| 25 |
| 26 GrGLInterface* interface = SkNEW(GrGLInterface); |
| 27 interface->fBindingsExported = kES_GrGLBinding; |
| 28 |
| 29 interface->fActiveTexture = glActiveTexture; |
| 30 interface->fAttachShader = glAttachShader; |
| 31 interface->fBindAttribLocation = glBindAttribLocation; |
| 32 interface->fBindBuffer = glBindBuffer; |
| 33 interface->fBindTexture = glBindTexture; |
| 34 interface->fBindVertexArray = glBindVertexArrayOES; |
| 35 interface->fBlendColor = glBlendColor; |
| 36 interface->fBlendFunc = glBlendFunc; |
| 37 interface->fBufferData = glBufferData; |
| 38 interface->fBufferSubData = glBufferSubData; |
| 39 interface->fClear = glClear; |
| 40 interface->fClearColor = glClearColor; |
| 41 interface->fClearStencil = glClearStencil; |
| 42 interface->fColorMask = glColorMask; |
| 43 interface->fCompileShader = glCompileShader; |
| 44 interface->fCompressedTexImage2D = glCompressedTexImage2D; |
| 45 interface->fCopyTexSubImage2D = glCopyTexSubImage2D; |
| 46 interface->fCreateProgram = glCreateProgram; |
| 47 interface->fCreateShader = glCreateShader; |
| 48 interface->fCullFace = glCullFace; |
| 49 interface->fDeleteBuffers = glDeleteBuffers; |
| 50 interface->fDeleteProgram = glDeleteProgram; |
| 51 interface->fDeleteShader = glDeleteShader; |
| 52 interface->fDeleteTextures = glDeleteTextures; |
| 53 interface->fDeleteVertexArrays = glDeleteVertexArraysOES; |
| 54 interface->fDepthMask = glDepthMask; |
| 55 interface->fDisable = glDisable; |
| 56 interface->fDisableVertexAttribArray = glDisableVertexAttribArray; |
| 57 interface->fDrawArrays = glDrawArrays; |
| 58 interface->fDrawElements = glDrawElements; |
| 59 interface->fEnable = glEnable; |
| 60 interface->fEnableVertexAttribArray = glEnableVertexAttribArray; |
| 61 interface->fFinish = glFinish; |
| 62 interface->fFlush = glFlush; |
| 63 interface->fFrontFace = glFrontFace; |
| 64 interface->fGenBuffers = glGenBuffers; |
| 65 interface->fGenerateMipmap = glGenerateMipmap; |
| 66 interface->fGenTextures = glGenTextures; |
| 67 interface->fGenVertexArrays = glGenVertexArraysOES; |
| 68 interface->fGetBufferParameteriv = glGetBufferParameteriv; |
| 69 interface->fGetError = glGetError; |
| 70 interface->fGetIntegerv = glGetIntegerv; |
| 71 interface->fGetProgramInfoLog = glGetProgramInfoLog; |
| 72 interface->fGetProgramiv = glGetProgramiv; |
| 73 interface->fGetShaderInfoLog = glGetShaderInfoLog; |
| 74 interface->fGetShaderiv = glGetShaderiv; |
| 75 interface->fGetString = glGetString; |
| 76 #if GL_ES_VERSION_30 |
| 77 interface->fGetStringi = glGetStringi; |
| 78 #else |
| 79 interface->fGetStringi = (GrGLGetStringiProc) eglGetProcAddress("glGetString
i"); |
| 80 #endif |
| 81 interface->fGetUniformLocation = glGetUniformLocation; |
| 82 interface->fLineWidth = glLineWidth; |
| 83 interface->fLinkProgram = glLinkProgram; |
| 84 interface->fPixelStorei = glPixelStorei; |
| 85 interface->fReadPixels = glReadPixels; |
| 86 interface->fScissor = glScissor; |
| 87 #if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE |
| 88 interface->fShaderSource = (GrGLShaderSourceProc) glShaderSource; |
| 89 #else |
| 90 interface->fShaderSource = glShaderSource; |
| 91 #endif |
| 92 interface->fStencilFunc = glStencilFunc; |
| 93 interface->fStencilFuncSeparate = glStencilFuncSeparate; |
| 94 interface->fStencilMask = glStencilMask; |
| 95 interface->fStencilMaskSeparate = glStencilMaskSeparate; |
| 96 interface->fStencilOp = glStencilOp; |
| 97 interface->fStencilOpSeparate = glStencilOpSeparate; |
| 98 interface->fTexImage2D = glTexImage2D; |
| 99 interface->fTexParameteri = glTexParameteri; |
| 100 interface->fTexParameteriv = glTexParameteriv; |
| 101 interface->fTexSubImage2D = glTexSubImage2D; |
| 102 |
| 103 if (version >= GR_GL_VER(3,0)) { |
| 104 #if GL_ES_VERSION_3_0 |
| 105 interface->fTexStorage2D = glTexStorage2D; |
| 106 #else |
| 107 interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glT
exStorage2D"); |
| 108 #endif |
| 109 } else { |
| 110 #if GL_EXT_texture_storage |
| 111 interface->fTexStorage2D = glTexStorage2DEXT; |
| 112 #else |
| 113 interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glT
exStorage2DEXT"); |
| 114 #endif |
| 115 } |
| 116 |
| 117 #if GL_EXT_discard_framebuffer |
| 118 interface->fDiscardFramebuffer = glDiscardFramebufferEXT; |
| 119 #endif |
| 120 interface->fUniform1f = glUniform1f; |
| 121 interface->fUniform1i = glUniform1i; |
| 122 interface->fUniform1fv = glUniform1fv; |
| 123 interface->fUniform1iv = glUniform1iv; |
| 124 interface->fUniform2f = glUniform2f; |
| 125 interface->fUniform2i = glUniform2i; |
| 126 interface->fUniform2fv = glUniform2fv; |
| 127 interface->fUniform2iv = glUniform2iv; |
| 128 interface->fUniform3f = glUniform3f; |
| 129 interface->fUniform3i = glUniform3i; |
| 130 interface->fUniform3fv = glUniform3fv; |
| 131 interface->fUniform3iv = glUniform3iv; |
| 132 interface->fUniform4f = glUniform4f; |
| 133 interface->fUniform4i = glUniform4i; |
| 134 interface->fUniform4fv = glUniform4fv; |
| 135 interface->fUniform4iv = glUniform4iv; |
| 136 interface->fUniformMatrix2fv = glUniformMatrix2fv; |
| 137 interface->fUniformMatrix3fv = glUniformMatrix3fv; |
| 138 interface->fUniformMatrix4fv = glUniformMatrix4fv; |
| 139 interface->fUseProgram = glUseProgram; |
| 140 interface->fVertexAttrib4fv = glVertexAttrib4fv; |
| 141 interface->fVertexAttribPointer = glVertexAttribPointer; |
| 142 interface->fViewport = glViewport; |
| 143 interface->fBindFramebuffer = glBindFramebuffer; |
| 144 interface->fBindRenderbuffer = glBindRenderbuffer; |
| 145 interface->fCheckFramebufferStatus = glCheckFramebufferStatus; |
| 146 interface->fDeleteFramebuffers = glDeleteFramebuffers; |
| 147 interface->fDeleteRenderbuffers = glDeleteRenderbuffers; |
| 148 interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer; |
| 149 interface->fFramebufferTexture2D = glFramebufferTexture2D; |
| 150 if (extensions.has("GL_EXT_multisampled_render_to_texture")) { |
| 151 #if GL_EXT_multisampled_render_to_texture |
| 152 interface->fFramebufferTexture2DMultisample = glFramebufferTexture2DMult
isampleEXT; |
| 153 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultis
ampleEXT; |
| 154 #else |
| 155 interface->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DM
ultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"); |
| 156 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMul
tisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleEXT"); |
| 157 #endif |
| 158 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) { |
| 159 #if GL_IMG_multisampled_render_to_texture |
| 160 interface->fFramebufferTexture2DMultisample = glFramebufferTexture2DMult
isampleIMG; |
| 161 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultis
ampleIMG; |
| 162 #else |
| 163 interface->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DM
ultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"); |
| 164 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMul
tisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleIMG"); |
| 165 #endif |
| 166 } |
| 167 interface->fGenFramebuffers = glGenFramebuffers; |
| 168 interface->fGenRenderbuffers = glGenRenderbuffers; |
| 169 interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachment
Parameteriv; |
| 170 interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv; |
| 171 interface->fRenderbufferStorage = glRenderbufferStorage; |
| 172 #if GL_OES_mapbuffer |
| 173 interface->fMapBuffer = glMapBufferOES; |
| 174 interface->fUnmapBuffer = glUnmapBufferOES; |
| 175 #else |
| 176 interface->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBufferOE
S"); |
| 177 interface->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBu
fferOES"); |
| 178 #endif |
| 179 |
| 180 return interface; |
| 181 } |
| 182 |
| 183 static const GrGLInterface* create_desktop_interface(GrGLVersion version, |
| 184 const GrGLExtensions& exten
sions) { |
| 185 // Currently this assumes a 4.4 context or later. Supporting lower GL versio
ns would require |
| 186 // getting suffixed versions of pointers for supported extensions. |
| 187 if (version < GR_GL_VER(4,4)) { |
| 188 return NULL; |
| 189 } |
| 190 |
| 191 GrGLInterface* interface = SkNEW(GrGLInterface); |
| 192 interface->fBindingsExported = kDesktop_GrGLBinding; |
| 193 |
| 194 interface->fActiveTexture = (GrGLActiveTextureProc) eglGetProcAddress("glAct
iveTexture"); |
| 195 interface->fAttachShader = (GrGLAttachShaderProc) eglGetProcAddress("glAttac
hShader"); |
| 196 interface->fBeginQuery = (GrGLBeginQueryProc) eglGetProcAddress("glBeginQuer
y"); |
| 197 interface->fBindAttribLocation = (GrGLBindAttribLocationProc) eglGetProcAddr
ess("glBindAttribLocation"); |
| 198 interface->fBindBuffer = (GrGLBindBufferProc) eglGetProcAddress("glBindBuffe
r"); |
| 199 interface->fBindFragDataLocation = (GrGLBindFragDataLocationProc) eglGetProc
Address("glBindFragDataLocation"); |
| 200 interface->fBindFragDataLocationIndexed = (GrGLBindFragDataLocationIndexedPr
oc) eglGetProcAddress("glBindFragDataLocationIndexed"); |
| 201 interface->fBindFramebuffer = (GrGLBindFramebufferProc) eglGetProcAddress("g
lBindFramebuffer"); |
| 202 interface->fBindRenderbuffer = (GrGLBindRenderbufferProc) eglGetProcAddress(
"glBindRenderbuffer"); |
| 203 interface->fBindTexture = (GrGLBindTextureProc) eglGetProcAddress("glBindTex
ture"); |
| 204 interface->fBindVertexArray = (GrGLBindVertexArrayProc) eglGetProcAddress("g
lBindVertexArray"); |
| 205 interface->fBlendColor = (GrGLBlendColorProc) eglGetProcAddress("glBlendColo
r"); |
| 206 interface->fBlendFunc = (GrGLBlendFuncProc) eglGetProcAddress("glBlendFunc")
; |
| 207 interface->fBlitFramebuffer = (GrGLBlitFramebufferProc) eglGetProcAddress("g
lBlitFramebuffer"); |
| 208 interface->fBufferData = (GrGLBufferDataProc) eglGetProcAddress("glBufferDat
a"); |
| 209 interface->fBufferSubData = (GrGLBufferSubDataProc) eglGetProcAddress("glBuf
ferSubData"); |
| 210 interface->fCheckFramebufferStatus = (GrGLCheckFramebufferStatusProc) eglGet
ProcAddress("glCheckFramebufferStatus"); |
| 211 interface->fClear = (GrGLClearProc) eglGetProcAddress("glClear"); |
| 212 interface->fClearColor = (GrGLClearColorProc) eglGetProcAddress("glClearColo
r"); |
| 213 interface->fClearStencil = (GrGLClearStencilProc) eglGetProcAddress("glClear
Stencil"); |
| 214 interface->fClientActiveTexture = (GrGLClientActiveTextureProc) eglGetProcAd
dress("glClientActiveTexture"); |
| 215 interface->fColorMask = (GrGLColorMaskProc) eglGetProcAddress("glColorMask")
; |
| 216 interface->fCompileShader = (GrGLCompileShaderProc) eglGetProcAddress("glCom
pileShader"); |
| 217 interface->fCompressedTexImage2D = (GrGLCompressedTexImage2DProc) eglGetProc
Address("glCompressedTexImage2D"); |
| 218 interface->fCopyTexSubImage2D = (GrGLCopyTexSubImage2DProc) eglGetProcAddres
s("glCopyTexSubImage2D"); |
| 219 interface->fCreateProgram = (GrGLCreateProgramProc) eglGetProcAddress("glCre
ateProgram"); |
| 220 interface->fCreateShader = (GrGLCreateShaderProc) eglGetProcAddress("glCreat
eShader"); |
| 221 interface->fCullFace = (GrGLCullFaceProc) eglGetProcAddress("glCullFace"); |
| 222 interface->fDeleteBuffers = (GrGLDeleteBuffersProc) eglGetProcAddress("glDel
eteBuffers"); |
| 223 interface->fDeleteFramebuffers = (GrGLDeleteFramebuffersProc) eglGetProcAddr
ess("glDeleteFramebuffers"); |
| 224 interface->fDeleteProgram = (GrGLDeleteProgramProc) eglGetProcAddress("glDel
eteProgram"); |
| 225 interface->fDeleteQueries = (GrGLDeleteQueriesProc) eglGetProcAddress("glDel
eteQueries"); |
| 226 interface->fDeleteRenderbuffers = (GrGLDeleteRenderbuffersProc) eglGetProcAd
dress("glDeleteRenderbuffers"); |
| 227 interface->fDeleteShader = (GrGLDeleteShaderProc) eglGetProcAddress("glDelet
eShader"); |
| 228 interface->fDeleteTextures = (GrGLDeleteTexturesProc) eglGetProcAddress("glD
eleteTextures"); |
| 229 interface->fDeleteVertexArrays = (GrGLDeleteVertexArraysProc) eglGetProcAddr
ess("glDeleteVertexArrays"); |
| 230 interface->fDepthMask = (GrGLDepthMaskProc) eglGetProcAddress("glDepthMask")
; |
| 231 interface->fDisable = (GrGLDisableProc) eglGetProcAddress("glDisable"); |
| 232 interface->fDisableClientState = (GrGLDisableClientStateProc) eglGetProcAddr
ess("glDisableClientState"); |
| 233 interface->fDisableVertexAttribArray = (GrGLDisableVertexAttribArrayProc) eg
lGetProcAddress("glDisableVertexAttribArray"); |
| 234 interface->fDrawArrays = (GrGLDrawArraysProc) eglGetProcAddress("glDrawArray
s"); |
| 235 interface->fDrawBuffer = (GrGLDrawBufferProc) eglGetProcAddress("glDrawBuffe
r"); |
| 236 interface->fDrawBuffers = (GrGLDrawBuffersProc) eglGetProcAddress("glDrawBuf
fers"); |
| 237 interface->fDrawElements = (GrGLDrawElementsProc) eglGetProcAddress("glDrawE
lements"); |
| 238 interface->fEnable = (GrGLEnableProc) eglGetProcAddress("glEnable"); |
| 239 interface->fEnableClientState = (GrGLEnableClientStateProc) eglGetProcAddres
s("glEnableClientState"); |
| 240 interface->fEnableVertexAttribArray = (GrGLEnableVertexAttribArrayProc) eglG
etProcAddress("glEnableVertexAttribArray"); |
| 241 interface->fEndQuery = (GrGLEndQueryProc) eglGetProcAddress("glEndQuery"); |
| 242 interface->fFinish = (GrGLFinishProc) eglGetProcAddress("glFinish"); |
| 243 interface->fFlush = (GrGLFlushProc) eglGetProcAddress("glFlush"); |
| 244 interface->fFramebufferRenderbuffer = (GrGLFramebufferRenderbufferProc) eglG
etProcAddress("glFramebufferRenderbuffer"); |
| 245 interface->fFramebufferTexture2D = (GrGLFramebufferTexture2DProc) eglGetProc
Address("glFramebufferTexture2D"); |
| 246 interface->fFrontFace = (GrGLFrontFaceProc) eglGetProcAddress("glFrontFace")
; |
| 247 interface->fGenBuffers = (GrGLGenBuffersProc) eglGetProcAddress("glGenBuffer
s"); |
| 248 interface->fGenFramebuffers = (GrGLGenFramebuffersProc) eglGetProcAddress("g
lGenFramebuffers"); |
| 249 interface->fGenerateMipmap = (GrGLGenerateMipmapProc) eglGetProcAddress("glG
enerateMipmap"); |
| 250 interface->fGenQueries = (GrGLGenQueriesProc) eglGetProcAddress("glGenQuerie
s"); |
| 251 interface->fGenRenderbuffers = (GrGLGenRenderbuffersProc) eglGetProcAddress(
"glGenRenderbuffers"); |
| 252 interface->fGenTextures = (GrGLGenTexturesProc) eglGetProcAddress("glGenText
ures"); |
| 253 interface->fGenVertexArrays = (GrGLGenVertexArraysProc) eglGetProcAddress("g
lGenVertexArrays"); |
| 254 interface->fGetBufferParameteriv = (GrGLGetBufferParameterivProc) eglGetProc
Address("glGetBufferParameteriv"); |
| 255 interface->fGetError = (GrGLGetErrorProc) eglGetProcAddress("glGetError"); |
| 256 interface->fGetFramebufferAttachmentParameteriv = (GrGLGetFramebufferAttachm
entParameterivProc) eglGetProcAddress("glGetFramebufferAttachmentParameteriv"); |
| 257 interface->fGetIntegerv = (GrGLGetIntegervProc) eglGetProcAddress("glGetInte
gerv"); |
| 258 interface->fGetQueryObjecti64v = (GrGLGetQueryObjecti64vProc) eglGetProcAddr
ess("glGetQueryObjecti64v"); |
| 259 interface->fGetQueryObjectiv = (GrGLGetQueryObjectivProc) eglGetProcAddress(
"glGetQueryObjectiv"); |
| 260 interface->fGetQueryObjectui64v = (GrGLGetQueryObjectui64vProc) eglGetProcAd
dress("glGetQueryObjectui64v"); |
| 261 interface->fGetQueryObjectuiv = (GrGLGetQueryObjectuivProc) eglGetProcAddres
s("glGetQueryObjectuiv"); |
| 262 interface->fGetQueryiv = (GrGLGetQueryivProc) eglGetProcAddress("glGetQueryi
v"); |
| 263 interface->fGetProgramInfoLog = (GrGLGetProgramInfoLogProc) eglGetProcAddres
s("glGetProgramInfoLog"); |
| 264 interface->fGetProgramiv = (GrGLGetProgramivProc) eglGetProcAddress("glGetPr
ogramiv"); |
| 265 interface->fGetRenderbufferParameteriv = (GrGLGetRenderbufferParameterivProc
) eglGetProcAddress("glGetRenderbufferParameteriv"); |
| 266 interface->fGetShaderInfoLog = (GrGLGetShaderInfoLogProc) eglGetProcAddress(
"glGetShaderInfoLog"); |
| 267 interface->fGetShaderiv = (GrGLGetShaderivProc) eglGetProcAddress("glGetShad
eriv"); |
| 268 interface->fGetString = (GrGLGetStringProc) eglGetProcAddress("glGetString")
; |
| 269 interface->fGetStringi = (GrGLGetStringiProc) eglGetProcAddress("glGetString
i"); |
| 270 interface->fGetTexLevelParameteriv = (GrGLGetTexLevelParameterivProc) eglGet
ProcAddress("glGetTexLevelParameteriv"); |
| 271 interface->fGetUniformLocation = (GrGLGetUniformLocationProc) eglGetProcAddr
ess("glGetUniformLocation"); |
| 272 interface->fLineWidth = (GrGLLineWidthProc) eglGetProcAddress("glLineWidth")
; |
| 273 interface->fLinkProgram = (GrGLLinkProgramProc) eglGetProcAddress("glLinkPro
gram"); |
| 274 interface->fLoadIdentity = (GrGLLoadIdentityProc) eglGetProcAddress("glLoadI
dentity"); |
| 275 interface->fLoadMatrixf = (GrGLLoadMatrixfProc) eglGetProcAddress("glLoadMat
rixf"); |
| 276 interface->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBuffer")
; |
| 277 interface->fMatrixMode = (GrGLMatrixModeProc) eglGetProcAddress("glMatrixMod
e"); |
| 278 interface->fPixelStorei = (GrGLPixelStoreiProc) eglGetProcAddress("glPixelSt
orei"); |
| 279 interface->fQueryCounter = (GrGLQueryCounterProc) eglGetProcAddress("glQuery
Counter"); |
| 280 interface->fReadBuffer = (GrGLReadBufferProc) eglGetProcAddress("glReadBuffe
r"); |
| 281 interface->fReadPixels = (GrGLReadPixelsProc) eglGetProcAddress("glReadPixel
s"); |
| 282 interface->fRenderbufferStorage = (GrGLRenderbufferStorageProc) eglGetProcAd
dress("glRenderbufferStorage"); |
| 283 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMultisa
mpleProc) eglGetProcAddress("glRenderbufferStorageMultisample"); |
| 284 interface->fRenderbufferStorageMultisampleCoverage = (GrGLRenderbufferStorag
eMultisampleCoverageProc) eglGetProcAddress("glRenderbufferStorageMultisampleCov
erage"); |
| 285 interface->fScissor = (GrGLScissorProc) eglGetProcAddress("glScissor"); |
| 286 interface->fShaderSource = (GrGLShaderSourceProc) eglGetProcAddress("glShade
rSource"); |
| 287 interface->fStencilFunc = (GrGLStencilFuncProc) eglGetProcAddress("glStencil
Func"); |
| 288 interface->fStencilFuncSeparate = (GrGLStencilFuncSeparateProc) eglGetProcAd
dress("glStencilFuncSeparate"); |
| 289 interface->fStencilMask = (GrGLStencilMaskProc) eglGetProcAddress("glStencil
Mask"); |
| 290 interface->fStencilMaskSeparate = (GrGLStencilMaskSeparateProc) eglGetProcAd
dress("glStencilMaskSeparate"); |
| 291 interface->fStencilOp = (GrGLStencilOpProc) eglGetProcAddress("glStencilOp")
; |
| 292 interface->fStencilOpSeparate = (GrGLStencilOpSeparateProc) eglGetProcAddres
s("glStencilOpSeparate"); |
| 293 interface->fTexGenf = (GrGLTexGenfProc) eglGetProcAddress("glTexGenf"); |
| 294 interface->fTexGenfv = (GrGLTexGenfvProc) eglGetProcAddress("glTexGenfv"); |
| 295 interface->fTexGeni = (GrGLTexGeniProc) eglGetProcAddress("glTexGeni"); |
| 296 interface->fTexImage2D = (GrGLTexImage2DProc) eglGetProcAddress("glTexImage2
D"); |
| 297 interface->fTexParameteri = (GrGLTexParameteriProc) eglGetProcAddress("glTex
Parameteri"); |
| 298 interface->fTexParameteriv = (GrGLTexParameterivProc) eglGetProcAddress("glT
exParameteriv"); |
| 299 interface->fTexSubImage2D = (GrGLTexSubImage2DProc) eglGetProcAddress("glTex
SubImage2D"); |
| 300 interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexSt
orage2D"); |
| 301 interface->fUniform1f = (GrGLUniform1fProc) eglGetProcAddress("glUniform1f")
; |
| 302 interface->fUniform1i = (GrGLUniform1iProc) eglGetProcAddress("glUniform1i")
; |
| 303 interface->fUniform1fv = (GrGLUniform1fvProc) eglGetProcAddress("glUniform1f
v"); |
| 304 interface->fUniform1iv = (GrGLUniform1ivProc) eglGetProcAddress("glUniform1i
v"); |
| 305 interface->fUniform2f = (GrGLUniform2fProc) eglGetProcAddress("glUniform2f")
; |
| 306 interface->fUniform2i = (GrGLUniform2iProc) eglGetProcAddress("glUniform2i")
; |
| 307 interface->fUniform2fv = (GrGLUniform2fvProc) eglGetProcAddress("glUniform2f
v"); |
| 308 interface->fUniform2iv = (GrGLUniform2ivProc) eglGetProcAddress("glUniform2i
v"); |
| 309 interface->fUniform3f = (GrGLUniform3fProc) eglGetProcAddress("glUniform3f")
; |
| 310 interface->fUniform3i = (GrGLUniform3iProc) eglGetProcAddress("glUniform3i")
; |
| 311 interface->fUniform3fv = (GrGLUniform3fvProc) eglGetProcAddress("glUniform3f
v"); |
| 312 interface->fUniform3iv = (GrGLUniform3ivProc) eglGetProcAddress("glUniform3i
v"); |
| 313 interface->fUniform4f = (GrGLUniform4fProc) eglGetProcAddress("glUniform4f")
; |
| 314 interface->fUniform4i = (GrGLUniform4iProc) eglGetProcAddress("glUniform4i")
; |
| 315 interface->fUniform4fv = (GrGLUniform4fvProc) eglGetProcAddress("glUniform4f
v"); |
| 316 interface->fUniform4iv = (GrGLUniform4ivProc) eglGetProcAddress("glUniform4i
v"); |
| 317 interface->fUniformMatrix2fv = (GrGLUniformMatrix2fvProc) eglGetProcAddress(
"glUniformMatrix2fv"); |
| 318 interface->fUniformMatrix3fv = (GrGLUniformMatrix3fvProc) eglGetProcAddress(
"glUniformMatrix3fv"); |
| 319 interface->fUniformMatrix4fv = (GrGLUniformMatrix4fvProc) eglGetProcAddress(
"glUniformMatrix4fv"); |
| 320 interface->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBu
ffer"); |
| 321 interface->fUseProgram = (GrGLUseProgramProc) eglGetProcAddress("glUseProgra
m"); |
| 322 interface->fVertexAttrib4fv = (GrGLVertexAttrib4fvProc) eglGetProcAddress("g
lVertexAttrib4fv"); |
| 323 interface->fVertexAttribPointer = (GrGLVertexAttribPointerProc) eglGetProcAd
dress("glVertexAttribPointer"); |
| 324 interface->fVertexPointer = (GrGLVertexPointerProc) eglGetProcAddress("glVer
texPointer"); |
| 325 interface->fViewport = (GrGLViewportProc) eglGetProcAddress("glViewport"); |
| 326 |
| 327 if (extensions.has("GL_NV_path_rendering")) { |
| 328 interface->fPathCommands = (GrGLPathCommandsProc) eglGetProcAddress("glP
athCommandsNV"); |
| 329 interface->fPathCoords = (GrGLPathCoordsProc) eglGetProcAddress("glPathC
oordsNV"); |
| 330 interface->fPathSubCommands = (GrGLPathSubCommandsProc) eglGetProcAddres
s("glPathSubCommandsNV"); |
| 331 interface->fPathSubCoords = (GrGLPathSubCoordsProc) eglGetProcAddress("g
lPathSubCoordsNV"); |
| 332 interface->fPathString = (GrGLPathStringProc) eglGetProcAddress("glPathS
tringNV"); |
| 333 interface->fPathGlyphs = (GrGLPathGlyphsProc) eglGetProcAddress("glPathG
lyphsNV"); |
| 334 interface->fPathGlyphRange = (GrGLPathGlyphRangeProc) eglGetProcAddress(
"glPathGlyphRangeNV"); |
| 335 interface->fWeightPaths = (GrGLWeightPathsProc) eglGetProcAddress("glWei
ghtPathsNV"); |
| 336 interface->fCopyPath = (GrGLCopyPathProc) eglGetProcAddress("glCopyPathN
V"); |
| 337 interface->fInterpolatePaths = (GrGLInterpolatePathsProc) eglGetProcAddr
ess("glInterpolatePathsNV"); |
| 338 interface->fTransformPath = (GrGLTransformPathProc) eglGetProcAddress("g
lTransformPathNV"); |
| 339 interface->fPathParameteriv = (GrGLPathParameterivProc) eglGetProcAddres
s("glPathParameterivNV"); |
| 340 interface->fPathParameteri = (GrGLPathParameteriProc) eglGetProcAddress(
"glPathParameteriNV"); |
| 341 interface->fPathParameterfv = (GrGLPathParameterfvProc) eglGetProcAddres
s("glPathParameterfvNV"); |
| 342 interface->fPathParameterf = (GrGLPathParameterfProc) eglGetProcAddress(
"glPathParameterfNV"); |
| 343 interface->fPathDashArray = (GrGLPathDashArrayProc) eglGetProcAddress("g
lPathDashArrayNV"); |
| 344 interface->fGenPaths = (GrGLGenPathsProc) eglGetProcAddress("glGenPathsN
V"); |
| 345 interface->fDeletePaths = (GrGLDeletePathsProc) eglGetProcAddress("glDel
etePathsNV"); |
| 346 interface->fIsPath = (GrGLIsPathProc) eglGetProcAddress("glIsPathNV"); |
| 347 interface->fPathStencilFunc = (GrGLPathStencilFuncProc) eglGetProcAddres
s("glPathStencilFuncNV"); |
| 348 interface->fPathStencilDepthOffset = (GrGLPathStencilDepthOffsetProc) eg
lGetProcAddress("glPathStencilDepthOffsetNV"); |
| 349 interface->fStencilFillPath = (GrGLStencilFillPathProc) eglGetProcAddres
s("glStencilFillPathNV"); |
| 350 interface->fStencilStrokePath = (GrGLStencilStrokePathProc) eglGetProcAd
dress("glStencilStrokePathNV"); |
| 351 interface->fStencilFillPathInstanced = (GrGLStencilFillPathInstancedProc
) eglGetProcAddress("glStencilFillPathInstancedNV"); |
| 352 interface->fStencilStrokePathInstanced = (GrGLStencilStrokePathInstanced
Proc) eglGetProcAddress("glStencilStrokePathInstancedNV"); |
| 353 interface->fPathCoverDepthFunc = (GrGLPathCoverDepthFuncProc) eglGetProc
Address("glPathCoverDepthFuncNV"); |
| 354 interface->fPathColorGen = (GrGLPathColorGenProc) eglGetProcAddress("glP
athColorGenNV"); |
| 355 interface->fPathTexGen = (GrGLPathTexGenProc) eglGetProcAddress("glPathT
exGenNV"); |
| 356 interface->fPathFogGen = (GrGLPathFogGenProc) eglGetProcAddress("glPathF
ogGenNV"); |
| 357 interface->fCoverFillPath = (GrGLCoverFillPathProc) eglGetProcAddress("g
lCoverFillPathNV"); |
| 358 interface->fCoverStrokePath = (GrGLCoverStrokePathProc) eglGetProcAddres
s("glCoverStrokePathNV"); |
| 359 interface->fCoverFillPathInstanced = (GrGLCoverFillPathInstancedProc) eg
lGetProcAddress("glCoverFillPathInstancedNV"); |
| 360 interface->fCoverStrokePathInstanced = (GrGLCoverStrokePathInstancedProc
) eglGetProcAddress("glCoverStrokePathInstancedNV"); |
| 361 interface->fGetPathParameteriv = (GrGLGetPathParameterivProc) eglGetProc
Address("glGetPathParameterivNV"); |
| 362 interface->fGetPathParameterfv = (GrGLGetPathParameterfvProc) eglGetProc
Address("glGetPathParameterfvNV"); |
| 363 interface->fGetPathCommands = (GrGLGetPathCommandsProc) eglGetProcAddres
s("glGetPathCommandsNV"); |
| 364 interface->fGetPathCoords = (GrGLGetPathCoordsProc) eglGetProcAddress("g
lGetPathCoordsNV"); |
| 365 interface->fGetPathDashArray = (GrGLGetPathDashArrayProc) eglGetProcAddr
ess("glGetPathDashArrayNV"); |
| 366 interface->fGetPathMetrics = (GrGLGetPathMetricsProc) eglGetProcAddress(
"glGetPathMetricsNV"); |
| 367 interface->fGetPathMetricRange = (GrGLGetPathMetricRangeProc) eglGetProc
Address("glGetPathMetricRangeNV"); |
| 368 interface->fGetPathSpacing = (GrGLGetPathSpacingProc) eglGetProcAddress(
"glGetPathSpacingNV"); |
| 369 interface->fGetPathColorGeniv = (GrGLGetPathColorGenivProc) eglGetProcAd
dress("glGetPathColorGenivNV"); |
| 370 interface->fGetPathColorGenfv = (GrGLGetPathColorGenfvProc) eglGetProcAd
dress("glGetPathColorGenfvNV"); |
| 371 interface->fGetPathTexGeniv = (GrGLGetPathTexGenivProc) eglGetProcAddres
s("glGetPathTexGenivNV"); |
| 372 interface->fGetPathTexGenfv = (GrGLGetPathTexGenfvProc) eglGetProcAddres
s("glGetPathTexGenfvNV"); |
| 373 interface->fIsPointInFillPath = (GrGLIsPointInFillPathProc) eglGetProcAd
dress("glIsPointInFillPathNV"); |
| 374 interface->fIsPointInStrokePath = (GrGLIsPointInStrokePathProc) eglGetPr
ocAddress("glIsPointInStrokePathNV"); |
| 375 interface->fGetPathLength = (GrGLGetPathLengthProc) eglGetProcAddress("g
lGetPathLengthNV"); |
| 376 interface->fPointAlongPath = (GrGLPointAlongPathProc) eglGetProcAddress(
"glPointAlongPathNV"); |
| 377 } |
| 378 |
| 379 return interface; |
| 380 } |
| 381 |
20 const GrGLInterface* GrGLCreateNativeInterface() { | 382 const GrGLInterface* GrGLCreateNativeInterface() { |
21 static SkAutoTUnref<GrGLInterface> glInterface; | 383 |
22 if (!glInterface.get()) { | 384 GrGLGetStringiProc getStringi = (GrGLGetStringiProc) eglGetProcAddress("glGe
tStringi"); |
23 GrGLExtensions extensions; | 385 |
24 GrGLGetStringiProc getStringi; | 386 const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION
)); |
25 #if GL_ES_VERSION_3_0 | 387 GrGLVersion version = GrGLGetVersionFromString(verStr); |
26 getStringi = glGetStringi; | 388 GrGLBinding binding = GrGLGetBindingInUseFromString(verStr); |
27 #else | 389 |
28 getStringi = (GrGLGetStringiProc) eglGetProcAddress("glGetStringi"); | 390 GrGLExtensions extensions; |
29 #endif | 391 if (!extensions.init(binding, glGetString, getStringi, glGetIntegerv)) { |
30 | 392 return NULL; |
31 if (!extensions.init(kES_GrGLBinding, glGetString, getStringi, glGetInte
gerv)) { | 393 } |
32 return NULL; | 394 |
33 } | 395 if (kES_GrGLBinding == binding) { |
34 const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VER
SION)); | 396 return create_es_interface(version, extensions); |
35 GrGLVersion version = GrGLGetVersionFromString(verStr); | 397 } else if (kDesktop_GrGLBinding == binding) { |
36 if (version < GR_GL_VER(2,0)) { | 398 return create_desktop_interface(version, extensions); |
37 return NULL; | 399 } else { |
38 } | 400 return NULL; |
39 | 401 } |
40 GrGLInterface* interface = new GrGLInterface; | |
41 glInterface.reset(interface); | |
42 interface->fBindingsExported = kES_GrGLBinding; | |
43 interface->fActiveTexture = glActiveTexture; | |
44 interface->fAttachShader = glAttachShader; | |
45 interface->fBindAttribLocation = glBindAttribLocation; | |
46 interface->fBindBuffer = glBindBuffer; | |
47 interface->fBindTexture = glBindTexture; | |
48 interface->fBindVertexArray = glBindVertexArrayOES; | |
49 interface->fBlendColor = glBlendColor; | |
50 interface->fBlendFunc = glBlendFunc; | |
51 interface->fBufferData = glBufferData; | |
52 interface->fBufferSubData = glBufferSubData; | |
53 interface->fClear = glClear; | |
54 interface->fClearColor = glClearColor; | |
55 interface->fClearStencil = glClearStencil; | |
56 interface->fColorMask = glColorMask; | |
57 interface->fCompileShader = glCompileShader; | |
58 interface->fCompressedTexImage2D = glCompressedTexImage2D; | |
59 interface->fCopyTexSubImage2D = glCopyTexSubImage2D; | |
60 interface->fCreateProgram = glCreateProgram; | |
61 interface->fCreateShader = glCreateShader; | |
62 interface->fCullFace = glCullFace; | |
63 interface->fDeleteBuffers = glDeleteBuffers; | |
64 interface->fDeleteProgram = glDeleteProgram; | |
65 interface->fDeleteShader = glDeleteShader; | |
66 interface->fDeleteTextures = glDeleteTextures; | |
67 interface->fDeleteVertexArrays = glDeleteVertexArraysOES; | |
68 interface->fDepthMask = glDepthMask; | |
69 interface->fDisable = glDisable; | |
70 interface->fDisableVertexAttribArray = glDisableVertexAttribArray; | |
71 interface->fDrawArrays = glDrawArrays; | |
72 interface->fDrawElements = glDrawElements; | |
73 interface->fEnable = glEnable; | |
74 interface->fEnableVertexAttribArray = glEnableVertexAttribArray; | |
75 interface->fFinish = glFinish; | |
76 interface->fFlush = glFlush; | |
77 interface->fFrontFace = glFrontFace; | |
78 interface->fGenBuffers = glGenBuffers; | |
79 interface->fGenerateMipmap = glGenerateMipmap; | |
80 interface->fGenTextures = glGenTextures; | |
81 interface->fGenVertexArrays = glGenVertexArraysOES; | |
82 interface->fGetBufferParameteriv = glGetBufferParameteriv; | |
83 interface->fGetError = glGetError; | |
84 interface->fGetIntegerv = glGetIntegerv; | |
85 interface->fGetProgramInfoLog = glGetProgramInfoLog; | |
86 interface->fGetProgramiv = glGetProgramiv; | |
87 interface->fGetShaderInfoLog = glGetShaderInfoLog; | |
88 interface->fGetShaderiv = glGetShaderiv; | |
89 interface->fGetString = glGetString; | |
90 interface->fGetStringi = getStringi; // located above | |
91 interface->fGetUniformLocation = glGetUniformLocation; | |
92 interface->fLineWidth = glLineWidth; | |
93 interface->fLinkProgram = glLinkProgram; | |
94 interface->fPixelStorei = glPixelStorei; | |
95 interface->fReadPixels = glReadPixels; | |
96 interface->fScissor = glScissor; | |
97 #if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE | |
98 interface->fShaderSource = (GrGLShaderSourceProc) glShaderSource; | |
99 #else | |
100 interface->fShaderSource = glShaderSource; | |
101 #endif | |
102 interface->fStencilFunc = glStencilFunc; | |
103 interface->fStencilFuncSeparate = glStencilFuncSeparate; | |
104 interface->fStencilMask = glStencilMask; | |
105 interface->fStencilMaskSeparate = glStencilMaskSeparate; | |
106 interface->fStencilOp = glStencilOp; | |
107 interface->fStencilOpSeparate = glStencilOpSeparate; | |
108 interface->fTexImage2D = glTexImage2D; | |
109 interface->fTexParameteri = glTexParameteri; | |
110 interface->fTexParameteriv = glTexParameteriv; | |
111 interface->fTexSubImage2D = glTexSubImage2D; | |
112 | |
113 if (version >= GR_GL_VER(3,0)) { | |
114 #if GL_ES_VERSION_3_0 | |
115 interface->fTexStorage2D = glTexStorage2D; | |
116 #else | |
117 interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress(
"glTexStorage2D"); | |
118 #endif | |
119 } else { | |
120 #if GL_EXT_texture_storage | |
121 interface->fTexStorage2D = glTexStorage2DEXT; | |
122 #else | |
123 interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress(
"glTexStorage2DEXT"); | |
124 #endif | |
125 } | |
126 | |
127 #if GL_EXT_discard_framebuffer | |
128 interface->fDiscardFramebuffer = glDiscardFramebufferEXT; | |
129 #endif | |
130 interface->fUniform1f = glUniform1f; | |
131 interface->fUniform1i = glUniform1i; | |
132 interface->fUniform1fv = glUniform1fv; | |
133 interface->fUniform1iv = glUniform1iv; | |
134 interface->fUniform2f = glUniform2f; | |
135 interface->fUniform2i = glUniform2i; | |
136 interface->fUniform2fv = glUniform2fv; | |
137 interface->fUniform2iv = glUniform2iv; | |
138 interface->fUniform3f = glUniform3f; | |
139 interface->fUniform3i = glUniform3i; | |
140 interface->fUniform3fv = glUniform3fv; | |
141 interface->fUniform3iv = glUniform3iv; | |
142 interface->fUniform4f = glUniform4f; | |
143 interface->fUniform4i = glUniform4i; | |
144 interface->fUniform4fv = glUniform4fv; | |
145 interface->fUniform4iv = glUniform4iv; | |
146 interface->fUniformMatrix2fv = glUniformMatrix2fv; | |
147 interface->fUniformMatrix3fv = glUniformMatrix3fv; | |
148 interface->fUniformMatrix4fv = glUniformMatrix4fv; | |
149 interface->fUseProgram = glUseProgram; | |
150 interface->fVertexAttrib4fv = glVertexAttrib4fv; | |
151 interface->fVertexAttribPointer = glVertexAttribPointer; | |
152 interface->fViewport = glViewport; | |
153 interface->fBindFramebuffer = glBindFramebuffer; | |
154 interface->fBindRenderbuffer = glBindRenderbuffer; | |
155 interface->fCheckFramebufferStatus = glCheckFramebufferStatus; | |
156 interface->fDeleteFramebuffers = glDeleteFramebuffers; | |
157 interface->fDeleteRenderbuffers = glDeleteRenderbuffers; | |
158 interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer; | |
159 interface->fFramebufferTexture2D = glFramebufferTexture2D; | |
160 if (extensions.has("GL_EXT_multisampled_render_to_texture")) { | |
161 #if GL_EXT_multisampled_render_to_texture | |
162 interface->fFramebufferTexture2DMultisample = glFramebufferTexture2D
MultisampleEXT; | |
163 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMu
ltisampleEXT; | |
164 #else | |
165 interface->fFramebufferTexture2DMultisample = (GrGLFramebufferTextur
e2DMultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"); | |
166 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorag
eMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleEXT"); | |
167 #endif | |
168 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) { | |
169 #if GL_IMG_multisampled_render_to_texture | |
170 interface->fFramebufferTexture2DMultisample = glFramebufferTexture2D
MultisampleIMG; | |
171 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMu
ltisampleIMG; | |
172 #else | |
173 interface->fFramebufferTexture2DMultisample = (GrGLFramebufferTextur
e2DMultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"); | |
174 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorag
eMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleIMG"); | |
175 #endif | |
176 } | |
177 interface->fGenFramebuffers = glGenFramebuffers; | |
178 interface->fGenRenderbuffers = glGenRenderbuffers; | |
179 interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttach
mentParameteriv; | |
180 interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv; | |
181 interface->fRenderbufferStorage = glRenderbufferStorage; | |
182 #if GL_OES_mapbuffer | |
183 interface->fMapBuffer = glMapBufferOES; | |
184 interface->fUnmapBuffer = glUnmapBufferOES; | |
185 #else | |
186 interface->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBuff
erOES"); | |
187 interface->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnm
apBufferOES"); | |
188 #endif | |
189 } | |
190 glInterface.get()->ref(); | |
191 return glInterface.get(); | |
192 } | 402 } |
OLD | NEW |