blob: da6491a6d5c0e12c2217bf501cf3535f635e4640 [file] [log] [blame]
bsalomon@google.com74913722011-10-27 20:44:19 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
tomhudson@google.com6bf38b52012-02-14 15:11:59 +00009#include "gl/GrGLInterface.h"
bsalomon@google.com91bcc942012-05-07 17:28:41 +000010#include "GrGLDefines.h"
bsalomon@google.com21cbec42013-01-07 17:23:00 +000011#include "SkTDArray.h"
bsalomon@google.com8f943612013-02-26 14:34:43 +000012#include "GrGLNoOpInterface.h"
13
14// Functions not declared in GrGLBogusInterface.h (not common with the Debug GL interface).
bsalomon@google.com74913722011-10-27 20:44:19 +000015
caryclark@google.comcf6285b2012-06-06 12:09:01 +000016namespace { // added to suppress 'no previous prototype' warning
17
bsalomon@google.com74913722011-10-27 20:44:19 +000018GrGLvoid GR_GL_FUNCTION_TYPE nullGLActiveTexture(GrGLenum texture) {}
19GrGLvoid GR_GL_FUNCTION_TYPE nullGLAttachShader(GrGLuint program, GrGLuint shader) {}
20GrGLvoid GR_GL_FUNCTION_TYPE nullGLBeginQuery(GrGLenum target, GrGLuint id) {}
21GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindAttribLocation(GrGLuint program, GrGLuint index, const char* name) {}
22GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindTexture(GrGLenum target, GrGLuint texture) {}
bsalomon@google.com74913722011-10-27 20:44:19 +000023GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage) {}
bsalomon@google.com74913722011-10-27 20:44:19 +000024GrGLvoid GR_GL_FUNCTION_TYPE nullGLPixelStorei(GrGLenum pname, GrGLint param) {}
bsalomon@google.com74913722011-10-27 20:44:19 +000025GrGLvoid GR_GL_FUNCTION_TYPE nullGLReadPixels(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels) {}
bsalomon@google.com74913722011-10-27 20:44:19 +000026GrGLvoid GR_GL_FUNCTION_TYPE nullGLUseProgram(GrGLuint program) {}
bsalomon@google.com74913722011-10-27 20:44:19 +000027GrGLvoid GR_GL_FUNCTION_TYPE nullGLViewport(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height) {}
28GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindFramebuffer(GrGLenum target, GrGLuint framebuffer) {}
29GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindRenderbuffer(GrGLenum target, GrGLuint renderbuffer) {}
30GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteFramebuffers(GrGLsizei n, const GrGLuint *framebuffers) {}
31GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteRenderbuffers(GrGLsizei n, const GrGLuint *renderbuffers) {}
32GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferRenderbuffer(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer) {}
33GrGLvoid GR_GL_FUNCTION_TYPE nullGLFramebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level) {}
bsalomon@google.com74913722011-10-27 20:44:19 +000034
35GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateProgram() {
36 static int gCurrID = 0;
37 return ++gCurrID;
38}
39
40GrGLuint GR_GL_FUNCTION_TYPE nullGLCreateShader(GrGLenum type) {
41 static int gCurrID = 0;
42 return ++gCurrID;
43}
44
45// same delete used for shaders and programs
46GrGLvoid GR_GL_FUNCTION_TYPE nullGLDelete(GrGLuint program) {
47}
48
bsalomon@google.com74913722011-10-27 20:44:19 +000049
50// In debug builds we do asserts that ensure we agree with GL about when a buffer
51// is mapped.
bsalomon@google.com21cbec42013-01-07 17:23:00 +000052static SkTDArray<GrGLuint> gMappedBuffers;
bsalomon@google.com74913722011-10-27 20:44:19 +000053static GrGLuint gCurrArrayBuffer;
54static GrGLuint gCurrElementArrayBuffer;
55
56GrGLvoid GR_GL_FUNCTION_TYPE nullGLBindBuffer(GrGLenum target, GrGLuint buffer) {
57 switch (target) {
58 case GR_GL_ARRAY_BUFFER:
59 gCurrArrayBuffer = buffer;
60 break;
61 case GR_GL_ELEMENT_ARRAY_BUFFER:
62 gCurrElementArrayBuffer = buffer;
63 break;
64 }
65}
66
67// deleting a bound buffer has the side effect of binding 0
68GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) {
69 for (int i = 0; i < n; ++i) {
70 if (ids[i] == gCurrArrayBuffer) {
71 gCurrArrayBuffer = 0;
72 }
73 if (ids[i] == gCurrElementArrayBuffer) {
74 gCurrElementArrayBuffer = 0;
75 }
76 for (int j = 0; j < gMappedBuffers.count(); ++j) {
77 if (gMappedBuffers[j] == ids[i]) {
78 gMappedBuffers.remove(j);
79 // don't break b/c we didn't check for dupes on insert
80 --j;
81 }
82 }
83 }
84}
85
86GrGLvoid* GR_GL_FUNCTION_TYPE nullGLMapBuffer(GrGLenum target, GrGLenum access) {
87 // We just reserve 32MB of RAM for all locks and hope its big enough
88 static SkAutoMalloc gBufferData(32 * (1 << 20));
89 GrGLuint buf = 0;
90 switch (target) {
91 case GR_GL_ARRAY_BUFFER:
92 buf = gCurrArrayBuffer;
93 break;
94 case GR_GL_ELEMENT_ARRAY_BUFFER:
95 buf = gCurrElementArrayBuffer;
96 break;
97 }
98 if (buf) {
99 *gMappedBuffers.append() = buf;
100 }
101 return gBufferData.get();
102}
103
104GrGLboolean GR_GL_FUNCTION_TYPE nullGLUnmapBuffer(GrGLenum target) {
105 GrGLuint buf = 0;
106 switch (target) {
107 case GR_GL_ARRAY_BUFFER:
108 buf = gCurrArrayBuffer;
109 break;
110 case GR_GL_ELEMENT_ARRAY_BUFFER:
111 buf = gCurrElementArrayBuffer;
112 break;
113 }
114 if (buf) {
115 for (int i = 0; i < gMappedBuffers.count(); ++i) {
116 if (gMappedBuffers[i] == buf) {
117 gMappedBuffers.remove(i);
118 // don't break b/c we didn't check for dupes on insert
119 --i;
120 }
121 }
122 }
123 return GR_GL_TRUE;
124}
125
126GrGLvoid GR_GL_FUNCTION_TYPE nullGLGetBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) {
127 switch (pname) {
128 case GR_GL_BUFFER_MAPPED: {
129 *params = GR_GL_FALSE;
130 GrGLuint buf = 0;
131 switch (target) {
132 case GR_GL_ARRAY_BUFFER:
133 buf = gCurrArrayBuffer;
134 break;
135 case GR_GL_ELEMENT_ARRAY_BUFFER:
136 buf = gCurrElementArrayBuffer;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000137 break;
bsalomon@google.com74913722011-10-27 20:44:19 +0000138 }
139 if (buf) {
140 for (int i = 0; i < gMappedBuffers.count(); ++i) {
141 if (gMappedBuffers[i] == buf) {
142 *params = GR_GL_TRUE;
143 break;
144 }
145 }
146 }
147 break; }
148 default:
149 GrCrash("Unexpected pname to GetBufferParamateriv");
150 break;
151 }
152};
153
caryclark@google.comcf6285b2012-06-06 12:09:01 +0000154} // end anonymous namespace
155
bsalomon@google.com74913722011-10-27 20:44:19 +0000156const GrGLInterface* GrGLCreateNullInterface() {
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000157 // The gl functions are not context-specific so we create one global
bsalomon@google.com74913722011-10-27 20:44:19 +0000158 // interface
159 static SkAutoTUnref<GrGLInterface> glInterface;
160 if (!glInterface.get()) {
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000161 GrGLInterface* interface = SkNEW(GrGLInterface);
bsalomon@google.com74913722011-10-27 20:44:19 +0000162 glInterface.reset(interface);
163 interface->fBindingsExported = kDesktop_GrGLBinding;
164 interface->fActiveTexture = nullGLActiveTexture;
165 interface->fAttachShader = nullGLAttachShader;
166 interface->fBeginQuery = nullGLBeginQuery;
167 interface->fBindAttribLocation = nullGLBindAttribLocation;
168 interface->fBindBuffer = nullGLBindBuffer;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000169 interface->fBindFragDataLocation = noOpGLBindFragDataLocation;
bsalomon@google.com74913722011-10-27 20:44:19 +0000170 interface->fBindTexture = nullGLBindTexture;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000171 interface->fBlendColor = noOpGLBlendColor;
172 interface->fBlendFunc = noOpGLBlendFunc;
bsalomon@google.com74913722011-10-27 20:44:19 +0000173 interface->fBufferData = nullGLBufferData;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000174 interface->fBufferSubData = noOpGLBufferSubData;
175 interface->fClear = noOpGLClear;
176 interface->fClearColor = noOpGLClearColor;
177 interface->fClearStencil = noOpGLClearStencil;
178 interface->fColorMask = noOpGLColorMask;
179 interface->fCompileShader = noOpGLCompileShader;
180 interface->fCompressedTexImage2D = noOpGLCompressedTexImage2D;
bsalomon@google.com74913722011-10-27 20:44:19 +0000181 interface->fCreateProgram = nullGLCreateProgram;
182 interface->fCreateShader = nullGLCreateShader;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000183 interface->fCullFace = noOpGLCullFace;
bsalomon@google.com74913722011-10-27 20:44:19 +0000184 interface->fDeleteBuffers = nullGLDeleteBuffers;
185 interface->fDeleteProgram = nullGLDelete;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000186 interface->fDeleteQueries = noOpGLDeleteIds;
bsalomon@google.com74913722011-10-27 20:44:19 +0000187 interface->fDeleteShader = nullGLDelete;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000188 interface->fDeleteTextures = noOpGLDeleteIds;
189 interface->fDepthMask = noOpGLDepthMask;
190 interface->fDisable = noOpGLDisable;
191 interface->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray;
192 interface->fDrawArrays = noOpGLDrawArrays;
193 interface->fDrawBuffer = noOpGLDrawBuffer;
194 interface->fDrawBuffers = noOpGLDrawBuffers;
195 interface->fDrawElements = noOpGLDrawElements;
196 interface->fEnable = noOpGLEnable;
197 interface->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray;
198 interface->fEndQuery = noOpGLEndQuery;
199 interface->fFinish = noOpGLFinish;
200 interface->fFlush = noOpGLFlush;
201 interface->fFrontFace = noOpGLFrontFace;
202 interface->fGenBuffers = noOpGLGenIds;
203 interface->fGenQueries = noOpGLGenIds;
204 interface->fGenTextures = noOpGLGenIds;
bsalomon@google.com74913722011-10-27 20:44:19 +0000205 interface->fGetBufferParameteriv = nullGLGetBufferParameteriv;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000206 interface->fGetError = noOpGLGetError;
207 interface->fGetIntegerv = noOpGLGetIntegerv;
208 interface->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v;
209 interface->fGetQueryObjectiv = noOpGLGetQueryObjectiv;
210 interface->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v;
211 interface->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv;
212 interface->fGetQueryiv = noOpGLGetQueryiv;
213 interface->fGetProgramInfoLog = noOpGLGetInfoLog;
214 interface->fGetProgramiv = noOpGLGetShaderOrProgramiv;
215 interface->fGetShaderInfoLog = noOpGLGetInfoLog;
216 interface->fGetShaderiv = noOpGLGetShaderOrProgramiv;
217 interface->fGetString = noOpGLGetString;
bsalomon@google.com1744f972013-02-26 21:46:32 +0000218 interface->fGetStringi = noOpGLGetStringi;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000219 interface->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv;
220 interface->fGetUniformLocation = noOpGLGetUniformLocation;
221 interface->fLineWidth = noOpGLLineWidth;
222 interface->fLinkProgram = noOpGLLinkProgram;
bsalomon@google.com74913722011-10-27 20:44:19 +0000223 interface->fPixelStorei = nullGLPixelStorei;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000224 interface->fQueryCounter = noOpGLQueryCounter;
225 interface->fReadBuffer = noOpGLReadBuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000226 interface->fReadPixels = nullGLReadPixels;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000227 interface->fScissor = noOpGLScissor;
228 interface->fShaderSource = noOpGLShaderSource;
229 interface->fStencilFunc = noOpGLStencilFunc;
230 interface->fStencilFuncSeparate = noOpGLStencilFuncSeparate;
231 interface->fStencilMask = noOpGLStencilMask;
232 interface->fStencilMaskSeparate = noOpGLStencilMaskSeparate;
233 interface->fStencilOp = noOpGLStencilOp;
234 interface->fStencilOpSeparate = noOpGLStencilOpSeparate;
235 interface->fTexImage2D = noOpGLTexImage2D;
236 interface->fTexParameteri = noOpGLTexParameteri;
237 interface->fTexParameteriv = noOpGLTexParameteriv;
238 interface->fTexSubImage2D = noOpGLTexSubImage2D;
239 interface->fTexStorage2D = noOpGLTexStorage2D;
240 interface->fUniform1f = noOpGLUniform1f;
241 interface->fUniform1i = noOpGLUniform1i;
242 interface->fUniform1fv = noOpGLUniform1fv;
243 interface->fUniform1iv = noOpGLUniform1iv;
244 interface->fUniform2f = noOpGLUniform2f;
245 interface->fUniform2i = noOpGLUniform2i;
246 interface->fUniform2fv = noOpGLUniform2fv;
247 interface->fUniform2iv = noOpGLUniform2iv;
248 interface->fUniform3f = noOpGLUniform3f;
249 interface->fUniform3i = noOpGLUniform3i;
250 interface->fUniform3fv = noOpGLUniform3fv;
251 interface->fUniform3iv = noOpGLUniform3iv;
252 interface->fUniform4f = noOpGLUniform4f;
253 interface->fUniform4i = noOpGLUniform4i;
254 interface->fUniform4fv = noOpGLUniform4fv;
255 interface->fUniform4iv = noOpGLUniform4iv;
256 interface->fUniformMatrix2fv = noOpGLUniformMatrix2fv;
257 interface->fUniformMatrix3fv = noOpGLUniformMatrix3fv;
258 interface->fUniformMatrix4fv = noOpGLUniformMatrix4fv;
bsalomon@google.com74913722011-10-27 20:44:19 +0000259 interface->fUseProgram = nullGLUseProgram;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000260 interface->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
261 interface->fVertexAttribPointer = noOpGLVertexAttribPointer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000262 interface->fViewport = nullGLViewport;
263 interface->fBindFramebuffer = nullGLBindFramebuffer;
264 interface->fBindRenderbuffer = nullGLBindRenderbuffer;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000265 interface->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus;
bsalomon@google.com74913722011-10-27 20:44:19 +0000266 interface->fDeleteFramebuffers = nullGLDeleteFramebuffers;
267 interface->fDeleteRenderbuffers = nullGLDeleteRenderbuffers;
268 interface->fFramebufferRenderbuffer = nullGLFramebufferRenderbuffer;
269 interface->fFramebufferTexture2D = nullGLFramebufferTexture2D;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000270 interface->fGenFramebuffers = noOpGLGenIds;
271 interface->fGenRenderbuffers = noOpGLGenIds;
272 interface->fGetFramebufferAttachmentParameteriv = noOpGLGetFramebufferAttachmentParameteriv;
273 interface->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv;
274 interface->fRenderbufferStorage = noOpGLRenderbufferStorage;
275 interface->fRenderbufferStorageMultisample = noOpGLRenderbufferStorageMultisample;
276 interface->fBlitFramebuffer = noOpGLBlitFramebuffer;
277 interface->fResolveMultisampleFramebuffer = noOpGLResolveMultisampleFramebuffer;
bsalomon@google.com74913722011-10-27 20:44:19 +0000278 interface->fMapBuffer = nullGLMapBuffer;
279 interface->fUnmapBuffer = nullGLUnmapBuffer;
bsalomon@google.com8f943612013-02-26 14:34:43 +0000280 interface->fBindFragDataLocationIndexed = noOpGLBindFragDataLocationIndexed;
bsalomon@google.com74913722011-10-27 20:44:19 +0000281 }
282 glInterface.get()->ref();
283 return glInterface.get();
284}