1// Modified from chromium/src/webkit/glue/gl_bindings_skia_cmd_buffer.cc 2 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 5// found in the LICENSE file. 6 7#include "gl/GrGLExtensions.h" 8#include "gl/GrGLInterface.h" 9 10#ifndef GL_GLEXT_PROTOTYPES 11#define GL_GLEXT_PROTOTYPES 12#endif 13 14#include <GLES2/gl2.h> 15#include <GLES2/gl2ext.h> 16 17#include <EGL/egl.h> 18 19const GrGLInterface* GrGLCreateNativeInterface() { 20 static SkAutoTUnref<GrGLInterface> glInterface; 21 if (!glInterface.get()) { 22 GrGLExtensions extensions; 23 if (!extensions.init(kES2_GrGLBinding, glGetString, NULL, glGetIntegerv)) { 24 return NULL; 25 } 26 GrGLInterface* interface = new GrGLInterface; 27 glInterface.reset(interface); 28 interface->fBindingsExported = kES2_GrGLBinding; 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 interface->fGetUniformLocation = glGetUniformLocation; 77 interface->fLineWidth = glLineWidth; 78 interface->fLinkProgram = glLinkProgram; 79 interface->fPixelStorei = glPixelStorei; 80 interface->fReadPixels = glReadPixels; 81 interface->fScissor = glScissor; 82#if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE 83 interface->fShaderSource = (GrGLShaderSourceProc) glShaderSource; 84#else 85 interface->fShaderSource = glShaderSource; 86#endif 87 interface->fStencilFunc = glStencilFunc; 88 interface->fStencilFuncSeparate = glStencilFuncSeparate; 89 interface->fStencilMask = glStencilMask; 90 interface->fStencilMaskSeparate = glStencilMaskSeparate; 91 interface->fStencilOp = glStencilOp; 92 interface->fStencilOpSeparate = glStencilOpSeparate; 93 interface->fTexImage2D = glTexImage2D; 94 interface->fTexParameteri = glTexParameteri; 95 interface->fTexParameteriv = glTexParameteriv; 96 interface->fTexSubImage2D = glTexSubImage2D; 97#if GL_ARB_texture_storage 98 interface->fTexStorage2D = glTexStorage2D; 99#elif GL_EXT_texture_storage 100 interface->fTexStorage2D = glTexStorage2DEXT; 101#else 102 interface->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexStorage2DEXT"); 103#endif 104#if GL_EXT_discard_framebuffer 105 interface->fDiscardFramebuffer = glDiscardFramebufferEXT; 106#endif 107 interface->fUniform1f = glUniform1f; 108 interface->fUniform1i = glUniform1i; 109 interface->fUniform1fv = glUniform1fv; 110 interface->fUniform1iv = glUniform1iv; 111 interface->fUniform2f = glUniform2f; 112 interface->fUniform2i = glUniform2i; 113 interface->fUniform2fv = glUniform2fv; 114 interface->fUniform2iv = glUniform2iv; 115 interface->fUniform3f = glUniform3f; 116 interface->fUniform3i = glUniform3i; 117 interface->fUniform3fv = glUniform3fv; 118 interface->fUniform3iv = glUniform3iv; 119 interface->fUniform4f = glUniform4f; 120 interface->fUniform4i = glUniform4i; 121 interface->fUniform4fv = glUniform4fv; 122 interface->fUniform4iv = glUniform4iv; 123 interface->fUniformMatrix2fv = glUniformMatrix2fv; 124 interface->fUniformMatrix3fv = glUniformMatrix3fv; 125 interface->fUniformMatrix4fv = glUniformMatrix4fv; 126 interface->fUseProgram = glUseProgram; 127 interface->fVertexAttrib4fv = glVertexAttrib4fv; 128 interface->fVertexAttribPointer = glVertexAttribPointer; 129 interface->fViewport = glViewport; 130 interface->fBindFramebuffer = glBindFramebuffer; 131 interface->fBindRenderbuffer = glBindRenderbuffer; 132 interface->fCheckFramebufferStatus = glCheckFramebufferStatus; 133 interface->fDeleteFramebuffers = glDeleteFramebuffers; 134 interface->fDeleteRenderbuffers = glDeleteRenderbuffers; 135 interface->fFramebufferRenderbuffer = glFramebufferRenderbuffer; 136 interface->fFramebufferTexture2D = glFramebufferTexture2D; 137 if (extensions.has("GL_EXT_multisampled_render_to_texture")) { 138#if GL_EXT_multisampled_render_to_texture 139 interface->fFramebufferTexture2DMultisample = glFramebufferTexture2DMultisampleEXT; 140 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleEXT; 141#else 142 interface->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DMultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"); 143 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleEXT"); 144#endif 145 } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) { 146#if GL_IMG_multisampled_render_to_texture 147 interface->fFramebufferTexture2DMultisample = glFramebufferTexture2DMultisampleIMG; 148 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleIMG; 149#else 150 interface->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DMultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleIMG"); 151 interface->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleIMG"); 152#endif 153 } 154 interface->fGenFramebuffers = glGenFramebuffers; 155 interface->fGenRenderbuffers = glGenRenderbuffers; 156 interface->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv; 157 interface->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv; 158 interface->fRenderbufferStorage = glRenderbufferStorage; 159#if GL_OES_mapbuffer 160 interface->fMapBuffer = glMapBufferOES; 161 interface->fUnmapBuffer = glUnmapBufferOES; 162#else 163 interface->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBufferOES"); 164 interface->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBufferOES"); 165#endif 166 } 167 glInterface.get()->ref(); 168 return glInterface.get(); 169} 170