epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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. |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
tomhudson@google.com | 6c8c34e | 2012-02-14 15:31:03 +0000 | [diff] [blame] | 10 | #include "gl/GrGLInterface.h" |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 11 | |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 12 | #import <OpenGLES/ES2/gl.h> |
| 13 | #import <OpenGLES/ES2/glext.h> |
| 14 | |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 15 | const GrGLInterface* GrGLDefaultInterface() { |
| 16 | static SkAutoTUnref<GrGLInterface> glInterface; |
| 17 | if (!glInterface.get()) { |
| 18 | GrGLInteface* interface = new GrGLInterface; |
| 19 | glInterface.reset(interface); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 20 | |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 21 | interface->fActiveTexture = glActiveTexture; |
| 22 | interface->fAttachShader = glAttachShader; |
| 23 | interface->fBindAttribLocation = glBindAttribLocation; |
| 24 | interface->fBindBuffer = glBindBuffer; |
| 25 | interface->fBindTexture = glBindTexture; |
| 26 | interface->fBlendColor = glBlendColor; |
robertphillips@google.com | e788430 | 2012-04-18 14:39:58 +0000 | [diff] [blame] | 27 | interface->fBlendEquation = glBlendEquation; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 28 | interface->fBlendFunc = glBlendFunc; |
| 29 | interface->fBufferData = (GrGLBufferDataProc)glBufferData; |
| 30 | interface->fBufferSubData = (GrGLBufferSubDataProc)glBufferSubData; |
| 31 | interface->fClear = glClear; |
| 32 | interface->fClearColor = glClearColor; |
| 33 | interface->fClearStencil = glClearStencil; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 34 | interface->fColorMask = glColorMask; |
| 35 | interface->fColorPointer = glColorPointer; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 36 | interface->fCompileShader = glCompileShader; |
| 37 | interface->fCompressedTexImage2D = glCompressedTexImage2D; |
| 38 | interface->fCreateProgram = glCreateProgram; |
| 39 | interface->fCreateShader = glCreateShader; |
| 40 | interface->fCullFace = glCullFace; |
| 41 | interface->fDeleteBuffers = glDeleteBuffers; |
| 42 | interface->fDeleteProgram = glDeleteProgram; |
| 43 | interface->fDeleteShader = glDeleteShader; |
| 44 | interface->fDeleteTextures = glDeleteTextures; |
| 45 | interface->fDepthMask = glDepthMask; |
| 46 | interface->fDisable = glDisable; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 47 | interface->fDisableVertexAttribArray = glDisableVertexAttribArray; |
| 48 | interface->fDrawArrays = glDrawArrays; |
| 49 | interface->fDrawBuffer = NULL; |
| 50 | interface->fDrawBuffers = NULL; |
| 51 | interface->fDrawElements = glDrawElements; |
| 52 | interface->fEnable = glEnable; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 53 | interface->fEnableVertexAttribArray = glEnableVertexAttribArray; |
| 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; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 68 | interface->fPixelStorei = glPixelStorei; |
| 69 | interface->fReadBuffer = NULL; |
| 70 | interface->fReadPixels = glReadPixels; |
| 71 | interface->fScissor = glScissor; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 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; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 79 | // mac uses GLenum for internalFormat param (non-standard) |
| 80 | // amounts to int vs. uint. |
| 81 | interface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 82 | #if GL_ARB_texture_storage |
| 83 | interface->fTexStorage2D = glTexStorage2D; |
| 84 | #elif GL_EXT_texture_storage |
| 85 | interface->fTexStorage2D = glTexStorage2DEXT; |
| 86 | #endif |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 87 | interface->fTexParameteri = glTexParameteri; |
bsalomon@google.com | 4d063de | 2012-05-31 17:59:23 +0000 | [diff] [blame] | 88 | interface->fTexParameteriv = glTexParameteriv; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 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; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 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; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame^] | 126 | |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 127 | #if GL_OES_mapbuffer |
| 128 | interface->fMapBuffer = glMapBufferOES; |
| 129 | interface->fUnmapBuffer = glUnmapBufferOES; |
| 130 | #endif |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame^] | 131 | |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 132 | #if GL_APPLE_framebuffer_multisample |
| 133 | interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE; |
| 134 | interface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE; |
| 135 | #endif |
| 136 | interface->fBindFragDataLocationIndexed = NULL; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame^] | 137 | |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 138 | interface->fBindingsExported = kES2_GrGLBinding; |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 139 | } |
| 140 | glInterface.get()->ref(); |
| 141 | return glInterface.get(); |
| 142 | } |