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