robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 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 | #ifndef GL_GLEXT_PROTOTYPES |
| 13 | #define GL_GLEXT_PROTOTYPES |
| 14 | #endif |
| 15 | |
| 16 | #include "GLES2/gl2.h" |
| 17 | #include "GLES2/gl2ext.h" |
| 18 | #include "EGL/egl.h" |
| 19 | |
robertphillips@google.com | d5c8fe6 | 2012-04-02 15:04:16 +0000 | [diff] [blame] | 20 | #define GR_GET_PROC(procType, baseName) \ |
| 21 | interface->f ## baseName = (procType) GetProcAddress(ghANGLELib, "gl" #baseName); |
| 22 | |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 23 | const GrGLInterface* GrGLCreateANGLEInterface() { |
robertphillips@google.com | d5c8fe6 | 2012-04-02 15:04:16 +0000 | [diff] [blame] | 24 | |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 25 | static SkAutoTUnref<GrGLInterface> glInterface; |
robertphillips@google.com | d5c8fe6 | 2012-04-02 15:04:16 +0000 | [diff] [blame] | 26 | static HMODULE ghANGLELib = NULL; |
| 27 | |
| 28 | if (NULL == ghANGLELib) { |
| 29 | // We load the ANGLE library and never let it go |
| 30 | ghANGLELib = LoadLibrary("libGLESv2.dll"); |
| 31 | } |
| 32 | if (NULL == ghANGLELib) { |
| 33 | // We can't setup the interface correctly w/o the DLL |
| 34 | return NULL; |
| 35 | } |
| 36 | |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 37 | if (!glInterface.get()) { |
| 38 | GrGLInterface* interface = new GrGLInterface; |
| 39 | glInterface.reset(interface); |
| 40 | interface->fBindingsExported = kES2_GrGLBinding; |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 41 | |
robertphillips@google.com | d5c8fe6 | 2012-04-02 15:04:16 +0000 | [diff] [blame] | 42 | GR_GET_PROC(GrGLActiveTextureProc, ActiveTexture); |
| 43 | GR_GET_PROC(GrGLAttachShaderProc, AttachShader); |
| 44 | GR_GET_PROC(GrGLBindAttribLocationProc, BindAttribLocation); |
| 45 | GR_GET_PROC(GrGLBindBufferProc, BindBuffer); |
| 46 | GR_GET_PROC(GrGLBindTextureProc, BindTexture); |
| 47 | GR_GET_PROC(GrGLBlendColorProc, BlendColor); |
| 48 | GR_GET_PROC(GrGLBlendFuncProc, BlendFunc); |
| 49 | GR_GET_PROC(GrGLBufferDataProc, BufferData); |
| 50 | GR_GET_PROC(GrGLBufferSubDataProc, BufferSubData); |
| 51 | GR_GET_PROC(GrGLClearProc, Clear); |
| 52 | GR_GET_PROC(GrGLClearColorProc, ClearColor); |
| 53 | GR_GET_PROC(GrGLClearStencilProc, ClearStencil); |
| 54 | GR_GET_PROC(GrGLColorMaskProc, ColorMask); |
| 55 | GR_GET_PROC(GrGLCompileShaderProc, CompileShader); |
| 56 | GR_GET_PROC(GrGLCompressedTexImage2DProc, CompressedTexImage2D); |
| 57 | GR_GET_PROC(GrGLCreateProgramProc, CreateProgram); |
| 58 | GR_GET_PROC(GrGLCreateShaderProc, CreateShader); |
| 59 | GR_GET_PROC(GrGLCullFaceProc, CullFace); |
| 60 | GR_GET_PROC(GrGLDeleteBuffersProc, DeleteBuffers); |
| 61 | GR_GET_PROC(GrGLDeleteProgramProc, DeleteProgram); |
| 62 | GR_GET_PROC(GrGLDeleteShaderProc, DeleteShader); |
| 63 | GR_GET_PROC(GrGLDeleteTexturesProc, DeleteTextures); |
| 64 | GR_GET_PROC(GrGLDepthMaskProc, DepthMask); |
| 65 | GR_GET_PROC(GrGLDisableProc, Disable); |
| 66 | GR_GET_PROC(GrGLDisableVertexAttribArrayProc, DisableVertexAttribArray); |
| 67 | GR_GET_PROC(GrGLDrawArraysProc, DrawArrays); |
| 68 | GR_GET_PROC(GrGLDrawElementsProc, DrawElements); |
| 69 | GR_GET_PROC(GrGLEnableProc, Enable); |
| 70 | GR_GET_PROC(GrGLEnableVertexAttribArrayProc, EnableVertexAttribArray); |
| 71 | GR_GET_PROC(GrGLFinishProc, Finish); |
| 72 | GR_GET_PROC(GrGLFlushProc, Flush); |
| 73 | GR_GET_PROC(GrGLFrontFaceProc, FrontFace); |
| 74 | GR_GET_PROC(GrGLGenBuffersProc, GenBuffers); |
| 75 | GR_GET_PROC(GrGLGenTexturesProc, GenTextures); |
| 76 | GR_GET_PROC(GrGLGetBufferParameterivProc, GetBufferParameteriv); |
| 77 | GR_GET_PROC(GrGLGetErrorProc, GetError); |
| 78 | GR_GET_PROC(GrGLGetIntegervProc, GetIntegerv); |
| 79 | GR_GET_PROC(GrGLGetProgramInfoLogProc, GetProgramInfoLog); |
| 80 | GR_GET_PROC(GrGLGetProgramivProc, GetProgramiv); |
| 81 | GR_GET_PROC(GrGLGetShaderInfoLogProc, GetShaderInfoLog); |
| 82 | GR_GET_PROC(GrGLGetShaderivProc, GetShaderiv); |
| 83 | GR_GET_PROC(GrGLGetStringProc, GetString); |
| 84 | GR_GET_PROC(GrGLGetUniformLocationProc, GetUniformLocation); |
| 85 | GR_GET_PROC(GrGLLineWidthProc, LineWidth); |
| 86 | GR_GET_PROC(GrGLLinkProgramProc, LinkProgram); |
| 87 | GR_GET_PROC(GrGLPixelStoreiProc, PixelStorei); |
| 88 | GR_GET_PROC(GrGLReadPixelsProc, ReadPixels); |
| 89 | GR_GET_PROC(GrGLScissorProc, Scissor); |
| 90 | GR_GET_PROC(GrGLShaderSourceProc, ShaderSource); |
| 91 | GR_GET_PROC(GrGLStencilFuncProc, StencilFunc); |
| 92 | GR_GET_PROC(GrGLStencilFuncSeparateProc, StencilFuncSeparate); |
| 93 | GR_GET_PROC(GrGLStencilMaskProc, StencilMask); |
| 94 | GR_GET_PROC(GrGLStencilMaskSeparateProc, StencilMaskSeparate); |
| 95 | GR_GET_PROC(GrGLStencilOpProc, StencilOp); |
| 96 | GR_GET_PROC(GrGLStencilOpSeparateProc, StencilOpSeparate); |
| 97 | GR_GET_PROC(GrGLTexImage2DProc, TexImage2D); |
| 98 | GR_GET_PROC(GrGLTexParameteriProc, TexParameteri); |
| 99 | GR_GET_PROC(GrGLTexSubImage2DProc, TexSubImage2D); |
| 100 | #if GL_ARB_texture_storage |
| 101 | GR_GET_PROC(GrGLTexStorage2DProc, TexStorage2D); |
| 102 | #elif GL_EXT_texture_storage |
| 103 | interface->fTexStorage2D = (GrGLTexStorage2DProc) |
| 104 | GetProcAddress(ghANGLELib, |
| 105 | "glTexStorage2DEXT"); |
| 106 | #endif |
| 107 | GR_GET_PROC(GrGLUniform1fProc, Uniform1f); |
| 108 | GR_GET_PROC(GrGLUniform1iProc, Uniform1i); |
| 109 | GR_GET_PROC(GrGLUniform1fvProc, Uniform1fv); |
| 110 | GR_GET_PROC(GrGLUniform1ivProc, Uniform1iv); |
| 111 | |
| 112 | GR_GET_PROC(GrGLUniform2fProc, Uniform2f); |
| 113 | GR_GET_PROC(GrGLUniform2iProc, Uniform2i); |
| 114 | GR_GET_PROC(GrGLUniform2fvProc, Uniform2fv); |
| 115 | GR_GET_PROC(GrGLUniform2ivProc, Uniform2iv); |
| 116 | |
| 117 | GR_GET_PROC(GrGLUniform3fProc, Uniform3f); |
| 118 | GR_GET_PROC(GrGLUniform3iProc, Uniform3i); |
| 119 | GR_GET_PROC(GrGLUniform3fvProc, Uniform3fv); |
| 120 | GR_GET_PROC(GrGLUniform3ivProc, Uniform3iv); |
| 121 | |
| 122 | GR_GET_PROC(GrGLUniform4fProc, Uniform4f); |
| 123 | GR_GET_PROC(GrGLUniform4iProc, Uniform4i); |
| 124 | GR_GET_PROC(GrGLUniform4fvProc, Uniform4fv); |
| 125 | GR_GET_PROC(GrGLUniform4ivProc, Uniform4iv); |
| 126 | |
| 127 | GR_GET_PROC(GrGLUniformMatrix2fvProc, UniformMatrix2fv); |
| 128 | GR_GET_PROC(GrGLUniformMatrix3fvProc, UniformMatrix3fv); |
| 129 | GR_GET_PROC(GrGLUniformMatrix4fvProc, UniformMatrix4fv); |
| 130 | GR_GET_PROC(GrGLUseProgramProc, UseProgram); |
| 131 | GR_GET_PROC(GrGLVertexAttrib4fvProc, VertexAttrib4fv); |
| 132 | GR_GET_PROC(GrGLVertexAttribPointerProc, VertexAttribPointer); |
| 133 | GR_GET_PROC(GrGLViewportProc, Viewport); |
| 134 | GR_GET_PROC(GrGLBindFramebufferProc, BindFramebuffer); |
| 135 | GR_GET_PROC(GrGLBindRenderbufferProc, BindRenderbuffer); |
| 136 | GR_GET_PROC(GrGLCheckFramebufferStatusProc, CheckFramebufferStatus); |
| 137 | GR_GET_PROC(GrGLDeleteFramebuffersProc, DeleteFramebuffers); |
| 138 | GR_GET_PROC(GrGLDeleteRenderbuffersProc, DeleteRenderbuffers); |
| 139 | GR_GET_PROC(GrGLFramebufferRenderbufferProc, FramebufferRenderbuffer); |
| 140 | GR_GET_PROC(GrGLFramebufferTexture2DProc, FramebufferTexture2D); |
| 141 | GR_GET_PROC(GrGLGenFramebuffersProc, GenFramebuffers); |
| 142 | GR_GET_PROC(GrGLGenRenderbuffersProc, GenRenderbuffers); |
| 143 | GR_GET_PROC(GrGLGetFramebufferAttachmentParameterivProc, |
| 144 | GetFramebufferAttachmentParameteriv); |
| 145 | GR_GET_PROC(GrGLGetRenderbufferParameterivProc, |
| 146 | GetRenderbufferParameteriv); |
| 147 | GR_GET_PROC(GrGLRenderbufferStorageProc, RenderbufferStorage); |
| 148 | |
| 149 | interface->fMapBuffer = (PFNGLMAPBUFFEROESPROC) eglGetProcAddress("glMapBufferOES"); |
| 150 | interface->fUnmapBuffer = (PFNGLUNMAPBUFFEROESPROC) eglGetProcAddress("glUnmapBufferOES"); |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 151 | } |
| 152 | glInterface.get()->ref(); |
| 153 | return glInterface.get(); |
| 154 | } |