blob: ae43d982c02d66b7c35404d2e4f78fc08ddd9d2e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
yangsu@google.combd3e3202011-07-13 22:05:00 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.combd3e3202011-07-13 22:05:00 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
tomhudson@google.com6c8c34e2012-02-14 15:31:03 +000010#include "gl/GrGLInterface.h"
yangsu@google.combd3e3202011-07-13 22:05:00 +000011
yangsu@google.combd3e3202011-07-13 22:05:00 +000012#import <OpenGLES/ES2/gl.h>
13#import <OpenGLES/ES2/glext.h>
14
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000015const GrGLInterface* GrGLDefaultInterface() {
16 static SkAutoTUnref<GrGLInterface> glInterface;
17 if (!glInterface.get()) {
18 GrGLInteface* interface = new GrGLInterface;
19 glInterface.reset(interface);
bsalomon@google.com0b77d682011-08-19 13:28:54 +000020
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000021 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.come7884302012-04-18 14:39:58 +000027 interface->fBlendEquation = glBlendEquation;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000028 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.com6fb736f2011-09-16 18:51:57 +000034 interface->fColorMask = glColorMask;
35 interface->fColorPointer = glColorPointer;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000036 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.com6fb736f2011-09-16 18:51:57 +000047 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.com6fb736f2011-09-16 18:51:57 +000053 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.com6fb736f2011-09-16 18:51:57 +000068 interface->fPixelStorei = glPixelStorei;
69 interface->fReadBuffer = NULL;
70 interface->fReadPixels = glReadPixels;
71 interface->fScissor = glScissor;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000072 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.com6fb736f2011-09-16 18:51:57 +000079 // mac uses GLenum for internalFormat param (non-standard)
80 // amounts to int vs. uint.
81 interface->fTexImage2D = (GrGLTexImage2DProc)glTexImage2D;
bsalomon@google.com280e99f2012-01-05 16:17:38 +000082 #if GL_ARB_texture_storage
83 interface->fTexStorage2D = glTexStorage2D;
84 #elif GL_EXT_texture_storage
85 interface->fTexStorage2D = glTexStorage2DEXT;
86 #endif
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000087 interface->fTexParameteri = glTexParameteri;
bsalomon@google.com4d063de2012-05-31 17:59:23 +000088 interface->fTexParameteriv = glTexParameteriv;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000089 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.com6fb736f2011-09-16 18:51:57 +0000113 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.comd6176b02012-08-23 18:14:13 +0000126
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000127 #if GL_OES_mapbuffer
128 interface->fMapBuffer = glMapBufferOES;
129 interface->fUnmapBuffer = glUnmapBufferOES;
130 #endif
rmistry@google.comd6176b02012-08-23 18:14:13 +0000131
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000132 #if GL_APPLE_framebuffer_multisample
133 interface->fRenderbufferStorageMultisample = glRenderbufferStorageMultisampleAPPLE;
134 interface->fResolveMultisampleFramebuffer = glResolveMultisampleFramebufferAPPLE;
135 #endif
136 interface->fBindFragDataLocationIndexed = NULL;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000137
bsalomon@google.com1dcf5062011-11-14 19:29:53 +0000138 interface->fBindingsExported = kES2_GrGLBinding;
bsalomon@google.com6fb736f2011-09-16 18:51:57 +0000139 }
140 glInterface.get()->ref();
141 return glInterface.get();
142}