• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #define GR_GET_PROC(procType, baseName)             \
21     interface->f ## baseName = (procType) GetProcAddress(ghANGLELib, "gl" #baseName);
22 
GrGLCreateANGLEInterface()23 const GrGLInterface* GrGLCreateANGLEInterface() {
24 
25     static SkAutoTUnref<GrGLInterface> glInterface;
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 
37     if (!glInterface.get()) {
38         GrGLInterface* interface = new GrGLInterface;
39         glInterface.reset(interface);
40         interface->fBindingsExported = kES2_GrGLBinding;
41 
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(GrGLTexParameterivProc,     TexParameteriv);
100         GR_GET_PROC(GrGLTexSubImage2DProc,      TexSubImage2D);
101 #if GL_ARB_texture_storage
102         GR_GET_PROC(GrGLTexStorage2DProc,       TexStorage2D);
103 #elif GL_EXT_texture_storage
104         interface->fTexStorage2D = (GrGLTexStorage2DProc)
105                                             GetProcAddress(ghANGLELib,
106                                             "glTexStorage2DEXT");
107 #endif
108         GR_GET_PROC(GrGLUniform1fProc,          Uniform1f);
109         GR_GET_PROC(GrGLUniform1iProc,          Uniform1i);
110         GR_GET_PROC(GrGLUniform1fvProc,         Uniform1fv);
111         GR_GET_PROC(GrGLUniform1ivProc,         Uniform1iv);
112 
113         GR_GET_PROC(GrGLUniform2fProc,          Uniform2f);
114         GR_GET_PROC(GrGLUniform2iProc,          Uniform2i);
115         GR_GET_PROC(GrGLUniform2fvProc,         Uniform2fv);
116         GR_GET_PROC(GrGLUniform2ivProc,         Uniform2iv);
117 
118         GR_GET_PROC(GrGLUniform3fProc,          Uniform3f);
119         GR_GET_PROC(GrGLUniform3iProc,          Uniform3i);
120         GR_GET_PROC(GrGLUniform3fvProc,         Uniform3fv);
121         GR_GET_PROC(GrGLUniform3ivProc,         Uniform3iv);
122 
123         GR_GET_PROC(GrGLUniform4fProc,          Uniform4f);
124         GR_GET_PROC(GrGLUniform4iProc,          Uniform4i);
125         GR_GET_PROC(GrGLUniform4fvProc,         Uniform4fv);
126         GR_GET_PROC(GrGLUniform4ivProc,         Uniform4iv);
127 
128         GR_GET_PROC(GrGLUniformMatrix2fvProc,   UniformMatrix2fv);
129         GR_GET_PROC(GrGLUniformMatrix3fvProc,   UniformMatrix3fv);
130         GR_GET_PROC(GrGLUniformMatrix4fvProc,   UniformMatrix4fv);
131         GR_GET_PROC(GrGLUseProgramProc,         UseProgram);
132         GR_GET_PROC(GrGLVertexAttrib4fvProc,    VertexAttrib4fv);
133         GR_GET_PROC(GrGLVertexAttribPointerProc, VertexAttribPointer);
134         GR_GET_PROC(GrGLViewportProc,           Viewport);
135         GR_GET_PROC(GrGLBindFramebufferProc,    BindFramebuffer);
136         GR_GET_PROC(GrGLBindRenderbufferProc,   BindRenderbuffer);
137         GR_GET_PROC(GrGLCheckFramebufferStatusProc, CheckFramebufferStatus);
138         GR_GET_PROC(GrGLDeleteFramebuffersProc, DeleteFramebuffers);
139         GR_GET_PROC(GrGLDeleteRenderbuffersProc, DeleteRenderbuffers);
140         GR_GET_PROC(GrGLFramebufferRenderbufferProc, FramebufferRenderbuffer);
141         GR_GET_PROC(GrGLFramebufferTexture2DProc, FramebufferTexture2D);
142         GR_GET_PROC(GrGLGenFramebuffersProc,    GenFramebuffers);
143         GR_GET_PROC(GrGLGenRenderbuffersProc,   GenRenderbuffers);
144         GR_GET_PROC(GrGLGetFramebufferAttachmentParameterivProc,
145                                 GetFramebufferAttachmentParameteriv);
146         GR_GET_PROC(GrGLGetRenderbufferParameterivProc,
147                                 GetRenderbufferParameteriv);
148         GR_GET_PROC(GrGLRenderbufferStorageProc, RenderbufferStorage);
149 
150         interface->fMapBuffer = (PFNGLMAPBUFFEROESPROC) eglGetProcAddress("glMapBufferOES");
151         interface->fUnmapBuffer = (PFNGLUNMAPBUFFEROESPROC) eglGetProcAddress("glUnmapBufferOES");
152     }
153     glInterface.get()->ref();
154     return glInterface.get();
155 }
156