1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
3 * ------------------------------------------------
4 *
5 * Copyright 2014 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 *//*!
20 * \file
21 * \brief GL Rendering Context.
22 *//*--------------------------------------------------------------------*/
23
24 #include "sglrGLContext.hpp"
25 #include "sglrShaderProgram.hpp"
26 #include "gluPixelTransfer.hpp"
27 #include "gluTexture.hpp"
28 #include "gluCallLogWrapper.hpp"
29 #include "gluStrUtil.hpp"
30 #include "glwFunctions.hpp"
31 #include "glwEnums.hpp"
32
33 namespace sglr
34 {
35
36 using std::string;
37 using std::vector;
38 using tcu::TestLog;
39 using tcu::TextureFormat;
40 using tcu::Vec4;
41
GLContext(const glu::RenderContext & context,tcu::TestLog & log,uint32_t logFlags,const tcu::IVec4 & baseViewport)42 GLContext::GLContext(const glu::RenderContext &context, tcu::TestLog &log, uint32_t logFlags,
43 const tcu::IVec4 &baseViewport)
44 : Context(context.getType())
45 , m_context(context)
46 , m_log(log)
47 , m_logFlags(logFlags)
48 , m_baseViewport(baseViewport)
49 , m_curViewport(0, 0, m_baseViewport.z(), m_baseViewport.w())
50 , m_curScissor(0, 0, m_baseViewport.z(), m_baseViewport.w())
51 , m_readFramebufferBinding(0)
52 , m_drawFramebufferBinding(0)
53 , m_wrapper(DE_NULL)
54 {
55 const glw::Functions &gl = m_context.getFunctions();
56
57 // Logging?
58 m_wrapper = new glu::CallLogWrapper(gl, log);
59 m_wrapper->enableLogging((logFlags & GLCONTEXT_LOG_CALLS) != 0);
60
61 // Setup base viewport. This offset is active when default framebuffer is active.
62 // \note Calls related to setting up base viewport are not included in log.
63 gl.viewport(baseViewport.x(), baseViewport.y(), baseViewport.z(), baseViewport.w());
64 }
65
~GLContext(void)66 GLContext::~GLContext(void)
67 {
68 const glw::Functions &gl = m_context.getFunctions();
69
70 // Clean up all still alive objects
71 for (std::set<uint32_t>::const_iterator i = m_allocatedFbos.begin(); i != m_allocatedFbos.end(); i++)
72 {
73 uint32_t fbo = *i;
74 gl.deleteFramebuffers(1, &fbo);
75 }
76
77 for (std::set<uint32_t>::const_iterator i = m_allocatedRbos.begin(); i != m_allocatedRbos.end(); i++)
78 {
79 uint32_t rbo = *i;
80 gl.deleteRenderbuffers(1, &rbo);
81 }
82
83 for (std::set<uint32_t>::const_iterator i = m_allocatedTextures.begin(); i != m_allocatedTextures.end(); i++)
84 {
85 uint32_t tex = *i;
86 gl.deleteTextures(1, &tex);
87 }
88
89 for (std::set<uint32_t>::const_iterator i = m_allocatedBuffers.begin(); i != m_allocatedBuffers.end(); i++)
90 {
91 uint32_t buf = *i;
92 gl.deleteBuffers(1, &buf);
93 }
94
95 for (std::set<uint32_t>::const_iterator i = m_allocatedVaos.begin(); i != m_allocatedVaos.end(); i++)
96 {
97 uint32_t vao = *i;
98 gl.deleteVertexArrays(1, &vao);
99 }
100
101 for (std::vector<glu::ShaderProgram *>::iterator i = m_programs.begin(); i != m_programs.end(); i++)
102 {
103 delete *i;
104 }
105
106 gl.useProgram(0);
107
108 delete m_wrapper;
109 }
110
enableLogging(uint32_t logFlags)111 void GLContext::enableLogging(uint32_t logFlags)
112 {
113 m_logFlags = logFlags;
114 m_wrapper->enableLogging((logFlags & GLCONTEXT_LOG_CALLS) != 0);
115 }
116
getDrawOffset(void) const117 tcu::IVec2 GLContext::getDrawOffset(void) const
118 {
119 if (m_drawFramebufferBinding)
120 return tcu::IVec2(0, 0);
121 else
122 return tcu::IVec2(m_baseViewport.x(), m_baseViewport.y());
123 }
124
getReadOffset(void) const125 tcu::IVec2 GLContext::getReadOffset(void) const
126 {
127 if (m_readFramebufferBinding)
128 return tcu::IVec2(0, 0);
129 else
130 return tcu::IVec2(m_baseViewport.x(), m_baseViewport.y());
131 }
132
getWidth(void) const133 int GLContext::getWidth(void) const
134 {
135 return m_baseViewport.z();
136 }
137
getHeight(void) const138 int GLContext::getHeight(void) const
139 {
140 return m_baseViewport.w();
141 }
142
activeTexture(uint32_t texture)143 void GLContext::activeTexture(uint32_t texture)
144 {
145 m_wrapper->glActiveTexture(texture);
146 }
147
texParameteri(uint32_t target,uint32_t pname,int value)148 void GLContext::texParameteri(uint32_t target, uint32_t pname, int value)
149 {
150 m_wrapper->glTexParameteri(target, pname, value);
151 }
152
checkFramebufferStatus(uint32_t target)153 uint32_t GLContext::checkFramebufferStatus(uint32_t target)
154 {
155 return m_wrapper->glCheckFramebufferStatus(target);
156 }
157
viewport(int x,int y,int width,int height)158 void GLContext::viewport(int x, int y, int width, int height)
159 {
160 m_curViewport = tcu::IVec4(x, y, width, height);
161 tcu::IVec2 offset = getDrawOffset();
162
163 // \note For clarity don't add the offset to log
164 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
165 m_log << TestLog::Message << "glViewport(" << x << ", " << y << ", " << width << ", " << height << ");"
166 << TestLog::EndMessage;
167 m_context.getFunctions().viewport(x + offset.x(), y + offset.y(), width, height);
168 }
169
bindTexture(uint32_t target,uint32_t texture)170 void GLContext::bindTexture(uint32_t target, uint32_t texture)
171 {
172 m_allocatedTextures.insert(texture);
173 m_wrapper->glBindTexture(target, texture);
174 }
175
genTextures(int numTextures,uint32_t * textures)176 void GLContext::genTextures(int numTextures, uint32_t *textures)
177 {
178 m_wrapper->glGenTextures(numTextures, textures);
179 if (numTextures > 0)
180 m_allocatedTextures.insert(textures, textures + numTextures);
181 }
182
deleteTextures(int numTextures,const uint32_t * textures)183 void GLContext::deleteTextures(int numTextures, const uint32_t *textures)
184 {
185 for (int i = 0; i < numTextures; i++)
186 m_allocatedTextures.erase(textures[i]);
187 m_wrapper->glDeleteTextures(numTextures, textures);
188 }
189
bindFramebuffer(uint32_t target,uint32_t framebuffer)190 void GLContext::bindFramebuffer(uint32_t target, uint32_t framebuffer)
191 {
192 // \todo [2011-10-13 pyry] This is a bit of a hack since test cases assumes 0 default fbo.
193 uint32_t defaultFbo = m_context.getDefaultFramebuffer();
194 TCU_CHECK(framebuffer == 0 || framebuffer != defaultFbo);
195
196 bool isValidTarget = target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER;
197
198 if (isValidTarget && framebuffer != 0)
199 m_allocatedFbos.insert(framebuffer);
200
201 // Update bindings.
202 if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER)
203 m_readFramebufferBinding = framebuffer;
204
205 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER)
206 m_drawFramebufferBinding = framebuffer;
207
208 if (framebuffer == 0) // Redirect 0 to platform-defined default framebuffer.
209 m_wrapper->glBindFramebuffer(target, defaultFbo);
210 else
211 m_wrapper->glBindFramebuffer(target, framebuffer);
212
213 // Update viewport and scissor if we updated draw framebuffer binding \note Not logged for clarity
214 if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER)
215 {
216 tcu::IVec2 offset = getDrawOffset();
217 m_context.getFunctions().viewport(m_curViewport.x() + offset.x(), m_curViewport.y() + offset.y(),
218 m_curViewport.z(), m_curViewport.w());
219 m_context.getFunctions().scissor(m_curScissor.x() + offset.x(), m_curScissor.y() + offset.y(), m_curScissor.z(),
220 m_curScissor.w());
221 }
222 }
223
genFramebuffers(int numFramebuffers,uint32_t * framebuffers)224 void GLContext::genFramebuffers(int numFramebuffers, uint32_t *framebuffers)
225 {
226 m_wrapper->glGenFramebuffers(numFramebuffers, framebuffers);
227 if (numFramebuffers > 0)
228 m_allocatedFbos.insert(framebuffers, framebuffers + numFramebuffers);
229 }
230
deleteFramebuffers(int numFramebuffers,const uint32_t * framebuffers)231 void GLContext::deleteFramebuffers(int numFramebuffers, const uint32_t *framebuffers)
232 {
233 for (int i = 0; i < numFramebuffers; i++)
234 m_allocatedFbos.erase(framebuffers[i]);
235 m_wrapper->glDeleteFramebuffers(numFramebuffers, framebuffers);
236 }
237
bindRenderbuffer(uint32_t target,uint32_t renderbuffer)238 void GLContext::bindRenderbuffer(uint32_t target, uint32_t renderbuffer)
239 {
240 m_allocatedRbos.insert(renderbuffer);
241 m_wrapper->glBindRenderbuffer(target, renderbuffer);
242 }
243
genRenderbuffers(int numRenderbuffers,uint32_t * renderbuffers)244 void GLContext::genRenderbuffers(int numRenderbuffers, uint32_t *renderbuffers)
245 {
246 m_wrapper->glGenRenderbuffers(numRenderbuffers, renderbuffers);
247 if (numRenderbuffers > 0)
248 m_allocatedRbos.insert(renderbuffers, renderbuffers + numRenderbuffers);
249 }
250
deleteRenderbuffers(int numRenderbuffers,const uint32_t * renderbuffers)251 void GLContext::deleteRenderbuffers(int numRenderbuffers, const uint32_t *renderbuffers)
252 {
253 for (int i = 0; i < numRenderbuffers; i++)
254 m_allocatedRbos.erase(renderbuffers[i]);
255 m_wrapper->glDeleteRenderbuffers(numRenderbuffers, renderbuffers);
256 }
257
pixelStorei(uint32_t pname,int param)258 void GLContext::pixelStorei(uint32_t pname, int param)
259 {
260 m_wrapper->glPixelStorei(pname, param);
261 }
262
texImage1D(uint32_t target,int level,uint32_t internalFormat,int width,int border,uint32_t format,uint32_t type,const void * data)263 void GLContext::texImage1D(uint32_t target, int level, uint32_t internalFormat, int width, int border, uint32_t format,
264 uint32_t type, const void *data)
265 {
266 m_wrapper->glTexImage1D(target, level, internalFormat, width, border, format, type, data);
267 }
268
texImage2D(uint32_t target,int level,uint32_t internalFormat,int width,int height,int border,uint32_t format,uint32_t type,const void * data)269 void GLContext::texImage2D(uint32_t target, int level, uint32_t internalFormat, int width, int height, int border,
270 uint32_t format, uint32_t type, const void *data)
271 {
272 m_wrapper->glTexImage2D(target, level, internalFormat, width, height, border, format, type, data);
273 }
274
texImage3D(uint32_t target,int level,uint32_t internalFormat,int width,int height,int depth,int border,uint32_t format,uint32_t type,const void * data)275 void GLContext::texImage3D(uint32_t target, int level, uint32_t internalFormat, int width, int height, int depth,
276 int border, uint32_t format, uint32_t type, const void *data)
277 {
278 m_wrapper->glTexImage3D(target, level, internalFormat, width, height, depth, border, format, type, data);
279 }
280
texSubImage1D(uint32_t target,int level,int xoffset,int width,uint32_t format,uint32_t type,const void * data)281 void GLContext::texSubImage1D(uint32_t target, int level, int xoffset, int width, uint32_t format, uint32_t type,
282 const void *data)
283 {
284 m_wrapper->glTexSubImage1D(target, level, xoffset, width, format, type, data);
285 }
286
texSubImage2D(uint32_t target,int level,int xoffset,int yoffset,int width,int height,uint32_t format,uint32_t type,const void * data)287 void GLContext::texSubImage2D(uint32_t target, int level, int xoffset, int yoffset, int width, int height,
288 uint32_t format, uint32_t type, const void *data)
289 {
290 m_wrapper->glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
291 }
292
texSubImage3D(uint32_t target,int level,int xoffset,int yoffset,int zoffset,int width,int height,int depth,uint32_t format,uint32_t type,const void * data)293 void GLContext::texSubImage3D(uint32_t target, int level, int xoffset, int yoffset, int zoffset, int width, int height,
294 int depth, uint32_t format, uint32_t type, const void *data)
295 {
296 m_wrapper->glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, data);
297 }
298
copyTexImage1D(uint32_t target,int level,uint32_t internalFormat,int x,int y,int width,int border)299 void GLContext::copyTexImage1D(uint32_t target, int level, uint32_t internalFormat, int x, int y, int width, int border)
300 {
301 // Don't log offset.
302 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
303 m_log << TestLog::Message << "glCopyTexImage1D(" << glu::getTextureTargetStr(target) << ", " << level << ", "
304 << glu::getTextureFormatStr(internalFormat) << ", " << x << ", " << y << ", " << width << ", " << border
305 << ")" << TestLog::EndMessage;
306
307 tcu::IVec2 offset = getReadOffset();
308 m_context.getFunctions().copyTexImage1D(target, level, internalFormat, offset.x() + x, offset.y() + y, width,
309 border);
310 }
311
copyTexImage2D(uint32_t target,int level,uint32_t internalFormat,int x,int y,int width,int height,int border)312 void GLContext::copyTexImage2D(uint32_t target, int level, uint32_t internalFormat, int x, int y, int width, int height,
313 int border)
314 {
315 // Don't log offset.
316 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
317 m_log << TestLog::Message << "glCopyTexImage2D(" << glu::getTextureTargetStr(target) << ", " << level << ", "
318 << glu::getTextureFormatStr(internalFormat) << ", " << x << ", " << y << ", " << width << ", " << height
319 << ", " << border << ")" << TestLog::EndMessage;
320
321 tcu::IVec2 offset = getReadOffset();
322 m_context.getFunctions().copyTexImage2D(target, level, internalFormat, offset.x() + x, offset.y() + y, width,
323 height, border);
324 }
325
copyTexSubImage1D(uint32_t target,int level,int xoffset,int x,int y,int width)326 void GLContext::copyTexSubImage1D(uint32_t target, int level, int xoffset, int x, int y, int width)
327 {
328 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
329 m_log << TestLog::Message << "glCopyTexSubImage1D(" << glu::getTextureTargetStr(target) << ", " << level << ", "
330 << xoffset << ", " << x << ", " << y << ", " << width << ")" << TestLog::EndMessage;
331
332 tcu::IVec2 offset = getReadOffset();
333 m_context.getFunctions().copyTexSubImage1D(target, level, xoffset, offset.x() + x, offset.y() + y, width);
334 }
335
copyTexSubImage2D(uint32_t target,int level,int xoffset,int yoffset,int x,int y,int width,int height)336 void GLContext::copyTexSubImage2D(uint32_t target, int level, int xoffset, int yoffset, int x, int y, int width,
337 int height)
338 {
339 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
340 m_log << TestLog::Message << "glCopyTexSubImage2D(" << glu::getTextureTargetStr(target) << ", " << level << ", "
341 << xoffset << ", " << yoffset << ", " << x << ", " << y << ", " << width << ", " << height << ")"
342 << TestLog::EndMessage;
343
344 tcu::IVec2 offset = getReadOffset();
345 m_context.getFunctions().copyTexSubImage2D(target, level, xoffset, yoffset, offset.x() + x, offset.y() + y, width,
346 height);
347 }
348
copyTexSubImage3D(uint32_t target,int level,int xoffset,int yoffset,int zoffset,int x,int y,int width,int height)349 void GLContext::copyTexSubImage3D(uint32_t target, int level, int xoffset, int yoffset, int zoffset, int x, int y,
350 int width, int height)
351 {
352 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
353 m_log << TestLog::Message << "glCopyTexSubImage3D(" << glu::getTextureTargetStr(target) << ", " << level << ", "
354 << xoffset << ", " << yoffset << ", " << zoffset << ", " << x << ", " << y << ", " << width << ", "
355 << height << ")" << TestLog::EndMessage;
356
357 tcu::IVec2 offset = getReadOffset();
358 m_context.getFunctions().copyTexSubImage3D(target, level, xoffset, yoffset, zoffset, offset.x() + x, offset.y() + y,
359 width, height);
360 }
361
texStorage2D(uint32_t target,int levels,uint32_t internalFormat,int width,int height)362 void GLContext::texStorage2D(uint32_t target, int levels, uint32_t internalFormat, int width, int height)
363 {
364 m_wrapper->glTexStorage2D(target, levels, internalFormat, width, height);
365 }
366
texStorage3D(uint32_t target,int levels,uint32_t internalFormat,int width,int height,int depth)367 void GLContext::texStorage3D(uint32_t target, int levels, uint32_t internalFormat, int width, int height, int depth)
368 {
369 m_wrapper->glTexStorage3D(target, levels, internalFormat, width, height, depth);
370 }
371
framebufferTexture2D(uint32_t target,uint32_t attachment,uint32_t textarget,uint32_t texture,int level)372 void GLContext::framebufferTexture2D(uint32_t target, uint32_t attachment, uint32_t textarget, uint32_t texture,
373 int level)
374 {
375 m_wrapper->glFramebufferTexture2D(target, attachment, textarget, texture, level);
376 }
377
framebufferTextureLayer(uint32_t target,uint32_t attachment,uint32_t texture,int level,int layer)378 void GLContext::framebufferTextureLayer(uint32_t target, uint32_t attachment, uint32_t texture, int level, int layer)
379 {
380 m_wrapper->glFramebufferTextureLayer(target, attachment, texture, level, layer);
381 }
382
framebufferRenderbuffer(uint32_t target,uint32_t attachment,uint32_t renderbuffertarget,uint32_t renderbuffer)383 void GLContext::framebufferRenderbuffer(uint32_t target, uint32_t attachment, uint32_t renderbuffertarget,
384 uint32_t renderbuffer)
385 {
386 m_wrapper->glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
387 }
388
getFramebufferAttachmentParameteriv(uint32_t target,uint32_t attachment,uint32_t pname,int * params)389 void GLContext::getFramebufferAttachmentParameteriv(uint32_t target, uint32_t attachment, uint32_t pname, int *params)
390 {
391 m_wrapper->glGetFramebufferAttachmentParameteriv(target, attachment, pname, params);
392 }
393
renderbufferStorage(uint32_t target,uint32_t internalformat,int width,int height)394 void GLContext::renderbufferStorage(uint32_t target, uint32_t internalformat, int width, int height)
395 {
396 m_wrapper->glRenderbufferStorage(target, internalformat, width, height);
397 }
398
renderbufferStorageMultisample(uint32_t target,int samples,uint32_t internalFormat,int width,int height)399 void GLContext::renderbufferStorageMultisample(uint32_t target, int samples, uint32_t internalFormat, int width,
400 int height)
401 {
402 m_wrapper->glRenderbufferStorageMultisample(target, samples, internalFormat, width, height);
403 }
404
bindBuffer(uint32_t target,uint32_t buffer)405 void GLContext::bindBuffer(uint32_t target, uint32_t buffer)
406 {
407 m_allocatedBuffers.insert(buffer);
408 m_wrapper->glBindBuffer(target, buffer);
409 }
410
genBuffers(int numBuffers,uint32_t * buffers)411 void GLContext::genBuffers(int numBuffers, uint32_t *buffers)
412 {
413 m_wrapper->glGenBuffers(numBuffers, buffers);
414 if (numBuffers > 0)
415 m_allocatedBuffers.insert(buffers, buffers + numBuffers);
416 }
417
deleteBuffers(int numBuffers,const uint32_t * buffers)418 void GLContext::deleteBuffers(int numBuffers, const uint32_t *buffers)
419 {
420 m_wrapper->glDeleteBuffers(numBuffers, buffers);
421 for (int i = 0; i < numBuffers; i++)
422 m_allocatedBuffers.erase(buffers[i]);
423 }
424
bufferData(uint32_t target,intptr_t size,const void * data,uint32_t usage)425 void GLContext::bufferData(uint32_t target, intptr_t size, const void *data, uint32_t usage)
426 {
427 m_wrapper->glBufferData(target, (glw::GLsizeiptr)size, data, usage);
428 }
429
bufferSubData(uint32_t target,intptr_t offset,intptr_t size,const void * data)430 void GLContext::bufferSubData(uint32_t target, intptr_t offset, intptr_t size, const void *data)
431 {
432 m_wrapper->glBufferSubData(target, (glw::GLintptr)offset, (glw::GLsizeiptr)size, data);
433 }
434
clearColor(float red,float green,float blue,float alpha)435 void GLContext::clearColor(float red, float green, float blue, float alpha)
436 {
437 m_wrapper->glClearColor(red, green, blue, alpha);
438 }
439
clearDepthf(float depth)440 void GLContext::clearDepthf(float depth)
441 {
442 m_wrapper->glClearDepthf(depth);
443 }
444
clearStencil(int stencil)445 void GLContext::clearStencil(int stencil)
446 {
447 m_wrapper->glClearStencil(stencil);
448 }
449
clear(uint32_t buffers)450 void GLContext::clear(uint32_t buffers)
451 {
452 m_wrapper->glClear(buffers);
453 }
454
clearBufferiv(uint32_t buffer,int drawbuffer,const int * value)455 void GLContext::clearBufferiv(uint32_t buffer, int drawbuffer, const int *value)
456 {
457 m_wrapper->glClearBufferiv(buffer, drawbuffer, value);
458 }
459
clearBufferfv(uint32_t buffer,int drawbuffer,const float * value)460 void GLContext::clearBufferfv(uint32_t buffer, int drawbuffer, const float *value)
461 {
462 m_wrapper->glClearBufferfv(buffer, drawbuffer, value);
463 }
464
clearBufferuiv(uint32_t buffer,int drawbuffer,const uint32_t * value)465 void GLContext::clearBufferuiv(uint32_t buffer, int drawbuffer, const uint32_t *value)
466 {
467 m_wrapper->glClearBufferuiv(buffer, drawbuffer, value);
468 }
469
clearBufferfi(uint32_t buffer,int drawbuffer,float depth,int stencil)470 void GLContext::clearBufferfi(uint32_t buffer, int drawbuffer, float depth, int stencil)
471 {
472 m_wrapper->glClearBufferfi(buffer, drawbuffer, depth, stencil);
473 }
474
scissor(int x,int y,int width,int height)475 void GLContext::scissor(int x, int y, int width, int height)
476 {
477 m_curScissor = tcu::IVec4(x, y, width, height);
478
479 // \note For clarity don't add the offset to log
480 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
481 m_log << TestLog::Message << "glScissor(" << x << ", " << y << ", " << width << ", " << height << ");"
482 << TestLog::EndMessage;
483
484 tcu::IVec2 offset = getDrawOffset();
485 m_context.getFunctions().scissor(offset.x() + x, offset.y() + y, width, height);
486 }
487
enable(uint32_t cap)488 void GLContext::enable(uint32_t cap)
489 {
490 m_wrapper->glEnable(cap);
491 }
492
disable(uint32_t cap)493 void GLContext::disable(uint32_t cap)
494 {
495 m_wrapper->glDisable(cap);
496 }
497
stencilFunc(uint32_t func,int ref,uint32_t mask)498 void GLContext::stencilFunc(uint32_t func, int ref, uint32_t mask)
499 {
500 m_wrapper->glStencilFunc(func, ref, mask);
501 }
502
stencilOp(uint32_t sfail,uint32_t dpfail,uint32_t dppass)503 void GLContext::stencilOp(uint32_t sfail, uint32_t dpfail, uint32_t dppass)
504 {
505 m_wrapper->glStencilOp(sfail, dpfail, dppass);
506 }
507
depthFunc(uint32_t func)508 void GLContext::depthFunc(uint32_t func)
509 {
510 m_wrapper->glDepthFunc(func);
511 }
512
depthRangef(float n,float f)513 void GLContext::depthRangef(float n, float f)
514 {
515 m_wrapper->glDepthRangef(n, f);
516 }
517
depthRange(double n,double f)518 void GLContext::depthRange(double n, double f)
519 {
520 m_wrapper->glDepthRange(n, f);
521 }
522
polygonOffset(float factor,float units)523 void GLContext::polygonOffset(float factor, float units)
524 {
525 m_wrapper->glPolygonOffset(factor, units);
526 }
527
provokingVertex(uint32_t convention)528 void GLContext::provokingVertex(uint32_t convention)
529 {
530 m_wrapper->glProvokingVertex(convention);
531 }
532
primitiveRestartIndex(uint32_t index)533 void GLContext::primitiveRestartIndex(uint32_t index)
534 {
535 m_wrapper->glPrimitiveRestartIndex(index);
536 }
537
stencilFuncSeparate(uint32_t face,uint32_t func,int ref,uint32_t mask)538 void GLContext::stencilFuncSeparate(uint32_t face, uint32_t func, int ref, uint32_t mask)
539 {
540 m_wrapper->glStencilFuncSeparate(face, func, ref, mask);
541 }
542
stencilOpSeparate(uint32_t face,uint32_t sfail,uint32_t dpfail,uint32_t dppass)543 void GLContext::stencilOpSeparate(uint32_t face, uint32_t sfail, uint32_t dpfail, uint32_t dppass)
544 {
545 m_wrapper->glStencilOpSeparate(face, sfail, dpfail, dppass);
546 }
547
blendEquation(uint32_t mode)548 void GLContext::blendEquation(uint32_t mode)
549 {
550 m_wrapper->glBlendEquation(mode);
551 }
552
blendEquationSeparate(uint32_t modeRGB,uint32_t modeAlpha)553 void GLContext::blendEquationSeparate(uint32_t modeRGB, uint32_t modeAlpha)
554 {
555 m_wrapper->glBlendEquationSeparate(modeRGB, modeAlpha);
556 }
557
blendFunc(uint32_t src,uint32_t dst)558 void GLContext::blendFunc(uint32_t src, uint32_t dst)
559 {
560 m_wrapper->glBlendFunc(src, dst);
561 }
562
blendFuncSeparate(uint32_t srcRGB,uint32_t dstRGB,uint32_t srcAlpha,uint32_t dstAlpha)563 void GLContext::blendFuncSeparate(uint32_t srcRGB, uint32_t dstRGB, uint32_t srcAlpha, uint32_t dstAlpha)
564 {
565 m_wrapper->glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
566 }
567
blendColor(float red,float green,float blue,float alpha)568 void GLContext::blendColor(float red, float green, float blue, float alpha)
569 {
570 m_wrapper->glBlendColor(red, green, blue, alpha);
571 }
572
colorMask(bool r,bool g,bool b,bool a)573 void GLContext::colorMask(bool r, bool g, bool b, bool a)
574 {
575 m_wrapper->glColorMask((glw::GLboolean)r, (glw::GLboolean)g, (glw::GLboolean)b, (glw::GLboolean)a);
576 }
577
depthMask(bool mask)578 void GLContext::depthMask(bool mask)
579 {
580 m_wrapper->glDepthMask((glw::GLboolean)mask);
581 }
582
stencilMask(uint32_t mask)583 void GLContext::stencilMask(uint32_t mask)
584 {
585 m_wrapper->glStencilMask(mask);
586 }
587
stencilMaskSeparate(uint32_t face,uint32_t mask)588 void GLContext::stencilMaskSeparate(uint32_t face, uint32_t mask)
589 {
590 m_wrapper->glStencilMaskSeparate(face, mask);
591 }
592
blitFramebuffer(int srcX0,int srcY0,int srcX1,int srcY1,int dstX0,int dstY0,int dstX1,int dstY1,uint32_t mask,uint32_t filter)593 void GLContext::blitFramebuffer(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1,
594 uint32_t mask, uint32_t filter)
595 {
596 tcu::IVec2 drawOffset = getDrawOffset();
597 tcu::IVec2 readOffset = getReadOffset();
598
599 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
600 m_log << TestLog::Message << "glBlitFramebuffer(" << srcX0 << ", " << srcY0 << ", " << srcX1 << ", " << srcY1
601 << ", " << dstX0 << ", " << dstY0 << ", " << dstX1 << ", " << dstY1 << ", " << glu::getBufferMaskStr(mask)
602 << ", " << glu::getTextureFilterStr(filter) << ")" << TestLog::EndMessage;
603
604 m_context.getFunctions().blitFramebuffer(readOffset.x() + srcX0, readOffset.y() + srcY0, readOffset.x() + srcX1,
605 readOffset.y() + srcY1, drawOffset.x() + dstX0, drawOffset.y() + dstY0,
606 drawOffset.x() + dstX1, drawOffset.y() + dstY1, mask, filter);
607 }
608
invalidateSubFramebuffer(uint32_t target,int numAttachments,const uint32_t * attachments,int x,int y,int width,int height)609 void GLContext::invalidateSubFramebuffer(uint32_t target, int numAttachments, const uint32_t *attachments, int x, int y,
610 int width, int height)
611 {
612 tcu::IVec2 drawOffset = getDrawOffset();
613
614 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
615 m_log << TestLog::Message << "glInvalidateSubFramebuffer(" << glu::getFramebufferTargetStr(target) << ", "
616 << numAttachments << ", " << glu::getInvalidateAttachmentStr(attachments, numAttachments) << ", " << x
617 << ", " << y << ", " << width << ", " << height << ")" << TestLog::EndMessage;
618
619 m_context.getFunctions().invalidateSubFramebuffer(target, numAttachments, attachments, x + drawOffset.x(),
620 y + drawOffset.y(), width, height);
621 }
622
invalidateFramebuffer(uint32_t target,int numAttachments,const uint32_t * attachments)623 void GLContext::invalidateFramebuffer(uint32_t target, int numAttachments, const uint32_t *attachments)
624 {
625 m_wrapper->glInvalidateFramebuffer(target, numAttachments, attachments);
626 }
627
bindVertexArray(uint32_t array)628 void GLContext::bindVertexArray(uint32_t array)
629 {
630 m_wrapper->glBindVertexArray(array);
631 }
632
genVertexArrays(int numArrays,uint32_t * vertexArrays)633 void GLContext::genVertexArrays(int numArrays, uint32_t *vertexArrays)
634 {
635 m_wrapper->glGenVertexArrays(numArrays, vertexArrays);
636 if (numArrays > 0)
637 m_allocatedVaos.insert(vertexArrays, vertexArrays + numArrays);
638 }
639
deleteVertexArrays(int numArrays,const uint32_t * vertexArrays)640 void GLContext::deleteVertexArrays(int numArrays, const uint32_t *vertexArrays)
641 {
642 for (int i = 0; i < numArrays; i++)
643 m_allocatedVaos.erase(vertexArrays[i]);
644 m_wrapper->glDeleteVertexArrays(numArrays, vertexArrays);
645 }
646
vertexAttribPointer(uint32_t index,int size,uint32_t type,bool normalized,int stride,const void * pointer)647 void GLContext::vertexAttribPointer(uint32_t index, int size, uint32_t type, bool normalized, int stride,
648 const void *pointer)
649 {
650 m_wrapper->glVertexAttribPointer(index, size, type, (glw::GLboolean)normalized, stride, pointer);
651 }
652
vertexAttribIPointer(uint32_t index,int size,uint32_t type,int stride,const void * pointer)653 void GLContext::vertexAttribIPointer(uint32_t index, int size, uint32_t type, int stride, const void *pointer)
654 {
655 m_wrapper->glVertexAttribIPointer(index, size, type, stride, pointer);
656 }
657
enableVertexAttribArray(uint32_t index)658 void GLContext::enableVertexAttribArray(uint32_t index)
659 {
660 m_wrapper->glEnableVertexAttribArray(index);
661 }
662
disableVertexAttribArray(uint32_t index)663 void GLContext::disableVertexAttribArray(uint32_t index)
664 {
665 m_wrapper->glDisableVertexAttribArray(index);
666 }
667
vertexAttribDivisor(uint32_t index,uint32_t divisor)668 void GLContext::vertexAttribDivisor(uint32_t index, uint32_t divisor)
669 {
670 m_wrapper->glVertexAttribDivisor(index, divisor);
671 }
672
vertexAttrib1f(uint32_t index,float x)673 void GLContext::vertexAttrib1f(uint32_t index, float x)
674 {
675 m_wrapper->glVertexAttrib1f(index, x);
676 }
677
vertexAttrib2f(uint32_t index,float x,float y)678 void GLContext::vertexAttrib2f(uint32_t index, float x, float y)
679 {
680 m_wrapper->glVertexAttrib2f(index, x, y);
681 }
682
vertexAttrib3f(uint32_t index,float x,float y,float z)683 void GLContext::vertexAttrib3f(uint32_t index, float x, float y, float z)
684 {
685 m_wrapper->glVertexAttrib3f(index, x, y, z);
686 }
687
vertexAttrib4f(uint32_t index,float x,float y,float z,float w)688 void GLContext::vertexAttrib4f(uint32_t index, float x, float y, float z, float w)
689 {
690 m_wrapper->glVertexAttrib4f(index, x, y, z, w);
691 }
692
vertexAttribI4i(uint32_t index,int32_t x,int32_t y,int32_t z,int32_t w)693 void GLContext::vertexAttribI4i(uint32_t index, int32_t x, int32_t y, int32_t z, int32_t w)
694 {
695 m_wrapper->glVertexAttribI4i(index, x, y, z, w);
696 }
697
vertexAttribI4ui(uint32_t index,uint32_t x,uint32_t y,uint32_t z,uint32_t w)698 void GLContext::vertexAttribI4ui(uint32_t index, uint32_t x, uint32_t y, uint32_t z, uint32_t w)
699 {
700 m_wrapper->glVertexAttribI4ui(index, x, y, z, w);
701 }
702
getAttribLocation(uint32_t program,const char * name)703 int32_t GLContext::getAttribLocation(uint32_t program, const char *name)
704 {
705 return m_wrapper->glGetAttribLocation(program, name);
706 }
707
uniform1f(int32_t location,float v0)708 void GLContext::uniform1f(int32_t location, float v0)
709 {
710 m_wrapper->glUniform1f(location, v0);
711 }
712
uniform1i(int32_t location,int32_t v0)713 void GLContext::uniform1i(int32_t location, int32_t v0)
714 {
715 m_wrapper->glUniform1i(location, v0);
716 }
717
uniform1fv(int32_t location,int32_t count,const float * value)718 void GLContext::uniform1fv(int32_t location, int32_t count, const float *value)
719 {
720 m_wrapper->glUniform1fv(location, count, value);
721 }
722
uniform2fv(int32_t location,int32_t count,const float * value)723 void GLContext::uniform2fv(int32_t location, int32_t count, const float *value)
724 {
725 m_wrapper->glUniform2fv(location, count, value);
726 }
727
uniform3fv(int32_t location,int32_t count,const float * value)728 void GLContext::uniform3fv(int32_t location, int32_t count, const float *value)
729 {
730 m_wrapper->glUniform3fv(location, count, value);
731 }
732
uniform4fv(int32_t location,int32_t count,const float * value)733 void GLContext::uniform4fv(int32_t location, int32_t count, const float *value)
734 {
735 m_wrapper->glUniform4fv(location, count, value);
736 }
737
uniform1iv(int32_t location,int32_t count,const int32_t * value)738 void GLContext::uniform1iv(int32_t location, int32_t count, const int32_t *value)
739 {
740 m_wrapper->glUniform1iv(location, count, value);
741 }
742
uniform2iv(int32_t location,int32_t count,const int32_t * value)743 void GLContext::uniform2iv(int32_t location, int32_t count, const int32_t *value)
744 {
745 m_wrapper->glUniform2iv(location, count, value);
746 }
747
uniform3iv(int32_t location,int32_t count,const int32_t * value)748 void GLContext::uniform3iv(int32_t location, int32_t count, const int32_t *value)
749 {
750 m_wrapper->glUniform3iv(location, count, value);
751 }
752
uniform4iv(int32_t location,int32_t count,const int32_t * value)753 void GLContext::uniform4iv(int32_t location, int32_t count, const int32_t *value)
754 {
755 m_wrapper->glUniform4iv(location, count, value);
756 }
757
uniformMatrix3fv(int32_t location,int32_t count,bool transpose,const float * value)758 void GLContext::uniformMatrix3fv(int32_t location, int32_t count, bool transpose, const float *value)
759 {
760 m_wrapper->glUniformMatrix3fv(location, count, (glw::GLboolean)transpose, value);
761 }
762
uniformMatrix4fv(int32_t location,int32_t count,bool transpose,const float * value)763 void GLContext::uniformMatrix4fv(int32_t location, int32_t count, bool transpose, const float *value)
764 {
765 m_wrapper->glUniformMatrix4fv(location, count, (glw::GLboolean)transpose, value);
766 }
getUniformLocation(uint32_t program,const char * name)767 int32_t GLContext::getUniformLocation(uint32_t program, const char *name)
768 {
769 return m_wrapper->glGetUniformLocation(program, name);
770 }
771
lineWidth(float w)772 void GLContext::lineWidth(float w)
773 {
774 m_wrapper->glLineWidth(w);
775 }
776
drawArrays(uint32_t mode,int first,int count)777 void GLContext::drawArrays(uint32_t mode, int first, int count)
778 {
779 m_wrapper->glDrawArrays(mode, first, count);
780 }
781
drawArraysInstanced(uint32_t mode,int first,int count,int instanceCount)782 void GLContext::drawArraysInstanced(uint32_t mode, int first, int count, int instanceCount)
783 {
784 m_wrapper->glDrawArraysInstanced(mode, first, count, instanceCount);
785 }
786
drawElements(uint32_t mode,int count,uint32_t type,const void * indices)787 void GLContext::drawElements(uint32_t mode, int count, uint32_t type, const void *indices)
788 {
789 m_wrapper->glDrawElements(mode, count, type, indices);
790 }
791
drawElementsInstanced(uint32_t mode,int count,uint32_t type,const void * indices,int instanceCount)792 void GLContext::drawElementsInstanced(uint32_t mode, int count, uint32_t type, const void *indices, int instanceCount)
793 {
794 m_wrapper->glDrawElementsInstanced(mode, count, type, indices, instanceCount);
795 }
796
drawElementsBaseVertex(uint32_t mode,int count,uint32_t type,const void * indices,int baseVertex)797 void GLContext::drawElementsBaseVertex(uint32_t mode, int count, uint32_t type, const void *indices, int baseVertex)
798 {
799 m_wrapper->glDrawElementsBaseVertex(mode, count, type, indices, baseVertex);
800 }
801
drawElementsInstancedBaseVertex(uint32_t mode,int count,uint32_t type,const void * indices,int instanceCount,int baseVertex)802 void GLContext::drawElementsInstancedBaseVertex(uint32_t mode, int count, uint32_t type, const void *indices,
803 int instanceCount, int baseVertex)
804 {
805 m_wrapper->glDrawElementsInstancedBaseVertex(mode, count, type, indices, instanceCount, baseVertex);
806 }
807
drawRangeElements(uint32_t mode,uint32_t start,uint32_t end,int count,uint32_t type,const void * indices)808 void GLContext::drawRangeElements(uint32_t mode, uint32_t start, uint32_t end, int count, uint32_t type,
809 const void *indices)
810 {
811 m_wrapper->glDrawRangeElements(mode, start, end, count, type, indices);
812 }
813
drawRangeElementsBaseVertex(uint32_t mode,uint32_t start,uint32_t end,int count,uint32_t type,const void * indices,int baseVertex)814 void GLContext::drawRangeElementsBaseVertex(uint32_t mode, uint32_t start, uint32_t end, int count, uint32_t type,
815 const void *indices, int baseVertex)
816 {
817 m_wrapper->glDrawRangeElementsBaseVertex(mode, start, end, count, type, indices, baseVertex);
818 }
819
drawArraysIndirect(uint32_t mode,const void * indirect)820 void GLContext::drawArraysIndirect(uint32_t mode, const void *indirect)
821 {
822 m_wrapper->glDrawArraysIndirect(mode, indirect);
823 }
824
drawElementsIndirect(uint32_t mode,uint32_t type,const void * indirect)825 void GLContext::drawElementsIndirect(uint32_t mode, uint32_t type, const void *indirect)
826 {
827 m_wrapper->glDrawElementsIndirect(mode, type, indirect);
828 }
829
multiDrawArrays(uint32_t mode,const int * first,const int * count,int primCount)830 void GLContext::multiDrawArrays(uint32_t mode, const int *first, const int *count, int primCount)
831 {
832 m_wrapper->glMultiDrawArrays(mode, first, count, primCount);
833 }
834
multiDrawElements(uint32_t mode,const int * count,uint32_t type,const void ** indices,int primCount)835 void GLContext::multiDrawElements(uint32_t mode, const int *count, uint32_t type, const void **indices, int primCount)
836 {
837 m_wrapper->glMultiDrawElements(mode, count, type, indices, primCount);
838 }
839
multiDrawElementsBaseVertex(uint32_t mode,const int * count,uint32_t type,const void ** indices,int primCount,const int * baseVertex)840 void GLContext::multiDrawElementsBaseVertex(uint32_t mode, const int *count, uint32_t type, const void **indices,
841 int primCount, const int *baseVertex)
842 {
843 m_wrapper->glMultiDrawElementsBaseVertex(mode, count, type, indices, primCount, baseVertex);
844 }
845
createProgram(ShaderProgram * shader)846 uint32_t GLContext::createProgram(ShaderProgram *shader)
847 {
848 m_programs.reserve(m_programs.size() + 1);
849
850 glu::ShaderProgram *program = DE_NULL;
851
852 if (!shader->m_hasGeometryShader)
853 program = new glu::ShaderProgram(m_context, glu::makeVtxFragSources(shader->m_vertSrc, shader->m_fragSrc));
854 else
855 program = new glu::ShaderProgram(m_context, glu::ProgramSources() << glu::VertexSource(shader->m_vertSrc)
856 << glu::FragmentSource(shader->m_fragSrc)
857 << glu::GeometrySource(shader->m_geomSrc));
858
859 if (!program->isOk())
860 {
861 m_log << *program;
862 delete program;
863 TCU_FAIL("Compile failed");
864 }
865
866 if ((m_logFlags & GLCONTEXT_LOG_PROGRAMS) != 0)
867 m_log << *program;
868
869 m_programs.push_back(program);
870 return program->getProgram();
871 }
872
deleteProgram(uint32_t program)873 void GLContext::deleteProgram(uint32_t program)
874 {
875 for (std::vector<glu::ShaderProgram *>::iterator i = m_programs.begin(); i != m_programs.end(); i++)
876 {
877 if ((*i)->getProgram() == program)
878 {
879 delete *i;
880 m_programs.erase(i);
881 return;
882 }
883 }
884
885 DE_FATAL("invalid delete");
886 }
887
useProgram(uint32_t program)888 void GLContext::useProgram(uint32_t program)
889 {
890 m_wrapper->glUseProgram(program);
891 }
892
readPixels(int x,int y,int width,int height,uint32_t format,uint32_t type,void * data)893 void GLContext::readPixels(int x, int y, int width, int height, uint32_t format, uint32_t type, void *data)
894 {
895 // Don't log offset.
896 if ((m_logFlags & GLCONTEXT_LOG_CALLS) != 0)
897 m_log << TestLog::Message << "glReadPixels(" << x << ", " << y << ", " << width << ", " << height << ", "
898 << glu::getTextureFormatStr(format) << ", " << glu::getTypeStr(type) << ", " << data << ")"
899 << TestLog::EndMessage;
900
901 tcu::IVec2 offset = getReadOffset();
902 m_context.getFunctions().readPixels(x + offset.x(), y + offset.y(), width, height, format, type, data);
903 }
904
getError(void)905 uint32_t GLContext::getError(void)
906 {
907 return m_wrapper->glGetError();
908 }
909
finish(void)910 void GLContext::finish(void)
911 {
912 m_wrapper->glFinish();
913 }
914
getIntegerv(uint32_t pname,int * params)915 void GLContext::getIntegerv(uint32_t pname, int *params)
916 {
917 m_wrapper->glGetIntegerv(pname, params);
918 }
919
getString(uint32_t pname)920 const char *GLContext::getString(uint32_t pname)
921 {
922 return (const char *)m_wrapper->glGetString(pname);
923 }
924
925 } // namespace sglr
926