• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _SGLRCONTEXT_HPP
2 #define _SGLRCONTEXT_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES Utilities
5  * ------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Simplified GLES reference context.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tcuSurface.hpp"
28 #include "gluRenderContext.hpp"
29 #include "sglrShaderProgram.hpp"
30 
31 
32 /*--------------------------------------------------------------------*//*!
33  * \brief Reference OpenGL API implementation
34  *//*--------------------------------------------------------------------*/
35 namespace sglr
36 {
37 
38 // Abstract drawing context with GL-style API
39 
40 class Context
41 {
42 public:
Context(glu::ContextType type)43 						Context					(glu::ContextType type) : m_type(type) {}
~Context(void)44 	virtual				~Context				(void) {}
45 
46 	virtual int			getWidth				(void) const												= DE_NULL;
47 	virtual int			getHeight				(void) const												= DE_NULL;
48 
49 	virtual void		activeTexture			(deUint32 texture)											= DE_NULL;
50 	virtual void		viewport				(int x, int y, int width, int height)						= DE_NULL;
51 
52 	virtual void		bindTexture				(deUint32 target, deUint32 texture)							= DE_NULL;
53 	virtual void		genTextures				(int numTextures, deUint32* textures)						= DE_NULL;
54 	virtual void		deleteTextures			(int numTextures, const deUint32* textures)					= DE_NULL;
55 
56 	virtual void		bindFramebuffer			(deUint32 target, deUint32 framebuffer)						= DE_NULL;
57 	virtual void		genFramebuffers			(int numFramebuffers, deUint32* framebuffers)				= DE_NULL;
58 	virtual void		deleteFramebuffers		(int numFramebuffers, const deUint32* framebuffers)			= DE_NULL;
59 
60 	virtual void		bindRenderbuffer		(deUint32 target, deUint32 renderbuffer)					= DE_NULL;
61 	virtual void		genRenderbuffers		(int numRenderbuffers, deUint32* renderbuffers)				= DE_NULL;
62 	virtual void		deleteRenderbuffers		(int numRenderbuffers, const deUint32* renderbuffers)		= DE_NULL;
63 
64 	virtual void		pixelStorei				(deUint32 pname, int param)									= DE_NULL;
65 	virtual void		texImage1D				(deUint32 target, int level, deUint32 internalFormat, int width, int border, deUint32 format, deUint32 type, const void* data)							= DE_NULL;
66 	virtual void		texImage2D				(deUint32 target, int level, deUint32 internalFormat, int width, int height, int border, deUint32 format, deUint32 type, const void* data)				= DE_NULL;
67 	virtual void		texImage3D				(deUint32 target, int level, deUint32 internalFormat, int width, int height, int depth, int border, deUint32 format, deUint32 type, const void* data)	= DE_NULL;
68 	virtual void		texSubImage1D			(deUint32 target, int level, int xoffset, int width, deUint32 format, deUint32 type, const void* data)										= DE_NULL;
69 	virtual void		texSubImage2D			(deUint32 target, int level, int xoffset, int yoffset, int width, int height, deUint32 format, deUint32 type, const void* data)							= DE_NULL;
70 	virtual void		texSubImage3D			(deUint32 target, int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth, deUint32 format, deUint32 type, const void* data)	= DE_NULL;
71 	virtual void		copyTexImage1D			(deUint32 target, int level, deUint32 internalFormat, int x, int y, int width, int border)																= DE_NULL;
72 	virtual void		copyTexImage2D			(deUint32 target, int level, deUint32 internalFormat, int x, int y, int width, int height, int border)													= DE_NULL;
73 	virtual void		copyTexSubImage1D		(deUint32 target, int level, int xoffset, int x, int y, int width)																			= DE_NULL;
74 	virtual void		copyTexSubImage2D		(deUint32 target, int level, int xoffset, int yoffset, int x, int y, int width, int height)																= DE_NULL;
75 	virtual void		copyTexSubImage3D		(deUint32 target, int level, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height)												= DE_NULL;
76 
77 	virtual void		texStorage2D			(deUint32 target, int levels, deUint32 internalFormat, int width, int height)				= DE_NULL;
78 	virtual void		texStorage3D			(deUint32 target, int levels, deUint32 internalFormat, int width, int height, int depth)	= DE_NULL;
79 
80 	virtual void		texParameteri			(deUint32 target, deUint32 pname, int value)					= DE_NULL;
81 
82 	virtual void		framebufferTexture2D	(deUint32 target, deUint32 attachment, deUint32 textarget, deUint32 texture, int level)	= DE_NULL;
83 	virtual void		framebufferTextureLayer	(deUint32 target, deUint32 attachment, deUint32 texture, int level, int layer)	= DE_NULL;
84 	virtual void		framebufferRenderbuffer	(deUint32 target, deUint32 attachment, deUint32 renderbuffertarget, deUint32 renderbuffer) = DE_NULL;
85 	virtual deUint32	checkFramebufferStatus	(deUint32 target)												= DE_NULL;
86 
87 	virtual void		getFramebufferAttachmentParameteriv	(deUint32 target, deUint32 attachment, deUint32 pname, int* params) = DE_NULL;
88 
89 	virtual void		renderbufferStorage				(deUint32 target, deUint32 internalformat, int width, int height) = DE_NULL;
90 	virtual void		renderbufferStorageMultisample	(deUint32 target, int samples, deUint32 internalFormat, int width, int height) = DE_NULL;
91 
92 	virtual void		bindBuffer				(deUint32 target, deUint32 buffer)							= DE_NULL;
93 	virtual void		genBuffers				(int numBuffers, deUint32* buffers)							= DE_NULL;
94 	virtual void		deleteBuffers			(int numBuffers, const deUint32* buffers)					= DE_NULL;
95 
96 	virtual void		bufferData				(deUint32 target, deIntptr size, const void* data, deUint32 usage)	= DE_NULL;
97 	virtual void		bufferSubData			(deUint32 target, deIntptr offset, deIntptr size, const void* data)	= DE_NULL;
98 
99 	virtual void		clearColor				(float red, float green, float blue, float alpha)			= DE_NULL;
100 	virtual void		clearDepthf				(float depth)												= DE_NULL;
101 	virtual void		clearStencil			(int stencil)												= DE_NULL;
102 
103 	virtual void		clear					(deUint32 buffers)											= DE_NULL;
104 	virtual void		clearBufferiv			(deUint32 buffer, int drawbuffer, const int* value)			= DE_NULL;
105 	virtual void		clearBufferfv			(deUint32 buffer, int drawbuffer, const float* value)		= DE_NULL;
106 	virtual void		clearBufferuiv			(deUint32 buffer, int drawbuffer, const deUint32* value)	= DE_NULL;
107 	virtual void		clearBufferfi			(deUint32 buffer, int drawbuffer, float depth, int stencil)	= DE_NULL;
108 	virtual void		scissor					(int x, int y, int width, int height)						= DE_NULL;
109 
110 	virtual void		enable					(deUint32 cap)												= DE_NULL;
111 	virtual void		disable					(deUint32 cap)												= DE_NULL;
112 
113 	virtual void		stencilFunc				(deUint32 func, int ref, deUint32 mask)						= DE_NULL;
114 	virtual void		stencilOp				(deUint32 sfail, deUint32 dpfail, deUint32 dppass)			= DE_NULL;
115 	virtual void		stencilFuncSeparate		(deUint32 face, deUint32 func, int ref, deUint32 mask)		= DE_NULL;
116 	virtual void		stencilOpSeparate		(deUint32 face, deUint32 sfail, deUint32 dpfail, deUint32 dppass) = DE_NULL;
117 
118 	virtual void		depthFunc				(deUint32 func)												= DE_NULL;
119 	virtual void		depthRangef				(float n, float f)											= DE_NULL;
120 	virtual void		depthRange				(double n, double f)										= DE_NULL;
121 
122 	virtual void		polygonOffset			(float factor, float units)									= DE_NULL;
123 	virtual void		provokingVertex			(deUint32 convention)										= DE_NULL;
124 	virtual void		primitiveRestartIndex	(deUint32 index)											= DE_NULL;
125 
126 	virtual void		blendEquation			(deUint32 mode)												= DE_NULL;
127 	virtual void		blendEquationSeparate	(deUint32 modeRGB, deUint32 modeAlpha)						= DE_NULL;
128 	virtual void		blendFunc				(deUint32 src, deUint32 dst)								= DE_NULL;
129 	virtual void		blendFuncSeparate		(deUint32 srcRGB, deUint32 dstRGB, deUint32 srcAlpha, deUint32 dstAlpha) = DE_NULL;
130 	virtual void		blendColor				(float red, float green, float blue, float alpha)			= DE_NULL;
131 
132 	virtual void		colorMask				(deBool r, deBool g, deBool b, deBool a)					= DE_NULL;
133 	virtual void		depthMask				(deBool mask)												= DE_NULL;
134 	virtual void		stencilMask				(deUint32 mask)												= DE_NULL;
135 	virtual void		stencilMaskSeparate		(deUint32 face, deUint32 mask)								= DE_NULL;
136 
137 	virtual void		blitFramebuffer			(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, deUint32 mask, deUint32 filter) = DE_NULL;
138 
139 	virtual void		invalidateSubFramebuffer(deUint32 target, int numAttachments, const deUint32* attachments, int x, int y, int width, int height)	= DE_NULL;
140 	virtual void		invalidateFramebuffer	(deUint32 target, int numAttachments, const deUint32* attachments)										= DE_NULL;
141 
142 	virtual void		bindVertexArray			(deUint32 array)											= DE_NULL;
143 	virtual void		genVertexArrays			(int numArrays, deUint32* vertexArrays)						= DE_NULL;
144 	virtual void		deleteVertexArrays		(int numArrays, const deUint32* vertexArrays)				= DE_NULL;
145 
146 	virtual void		vertexAttribPointer		(deUint32 index, int size, deUint32 type, deBool normalized, int stride, const void *pointer)	= DE_NULL;
147 	virtual void		vertexAttribIPointer	(deUint32 index, int size, deUint32 type, int stride, const void *pointer)						= DE_NULL;
148 	virtual void		enableVertexAttribArray	(deUint32 index)											= DE_NULL;
149 	virtual void		disableVertexAttribArray(deUint32 index)											= DE_NULL;
150 	virtual void		vertexAttribDivisor		(deUint32 index, deUint32 divisor)							= DE_NULL;
151 
152 	virtual void		vertexAttrib1f			(deUint32 index, float)										= DE_NULL;
153 	virtual void		vertexAttrib2f			(deUint32 index, float, float)								= DE_NULL;
154 	virtual void		vertexAttrib3f			(deUint32 index, float, float, float)						= DE_NULL;
155 	virtual void		vertexAttrib4f			(deUint32 index, float, float, float, float)				= DE_NULL;
156 	virtual void		vertexAttribI4i			(deUint32 index, deInt32, deInt32, deInt32, deInt32)		= DE_NULL;
157 	virtual void		vertexAttribI4ui		(deUint32 index, deUint32, deUint32, deUint32, deUint32)	= DE_NULL;
158 
159 	virtual deInt32		getAttribLocation		(deUint32 program, const char *name)						= DE_NULL;
160 
161 	virtual void		uniform1f				(deInt32 index, float)										= DE_NULL;
162 	virtual void		uniform1i				(deInt32 index, deInt32)									= DE_NULL;
163 	virtual void		uniform1fv				(deInt32 index, deInt32 count, const float*)				= DE_NULL;
164 	virtual void		uniform2fv				(deInt32 index, deInt32 count, const float*)				= DE_NULL;
165 	virtual void		uniform3fv				(deInt32 index, deInt32 count, const float*)				= DE_NULL;
166 	virtual void		uniform4fv				(deInt32 index, deInt32 count, const float*)				= DE_NULL;
167 	virtual void		uniform1iv				(deInt32 index, deInt32 count, const deInt32*)				= DE_NULL;
168 	virtual void		uniform2iv				(deInt32 index, deInt32 count, const deInt32*)				= DE_NULL;
169 	virtual void		uniform3iv				(deInt32 index, deInt32 count, const deInt32*)				= DE_NULL;
170 	virtual void		uniform4iv				(deInt32 index, deInt32 count, const deInt32*)				= DE_NULL;
171 	virtual void		uniformMatrix3fv		(deInt32 location, deInt32 count, deBool transpose, const float *value)	= DE_NULL;
172 	virtual void		uniformMatrix4fv		(deInt32 location, deInt32 count, deBool transpose, const float *value)	= DE_NULL;
173 	virtual deInt32		getUniformLocation		(deUint32 program, const char *name)						= DE_NULL;
174 
175 	virtual void		lineWidth				(float)														= DE_NULL;
176 
177 	virtual void		drawArrays				(deUint32 mode, int first, int count)															= DE_NULL;
178 	virtual void		drawArraysInstanced		(deUint32 mode, int first, int count, int instanceCount)										= DE_NULL;
179 	virtual void		drawElements			(deUint32 mode, int count, deUint32 type, const void *indices)									= DE_NULL;
180 	virtual void		drawElementsInstanced	(deUint32 mode, int count, deUint32 type, const void *indices, int instanceCount)				= DE_NULL;
181 	virtual void		drawElementsBaseVertex	(deUint32 mode, int count, deUint32 type, const void *indices, int baseVertex)					= DE_NULL;
182 	virtual void		drawElementsInstancedBaseVertex	(deUint32 mode, int count, deUint32 type, const void *indices, int instanceCount, int baseVertex) = DE_NULL;
183 	virtual void		drawRangeElements		(deUint32 mode, deUint32 start, deUint32 end, int count, deUint32 type, const void *indices)	= DE_NULL;
184 	virtual void		drawRangeElementsBaseVertex	(deUint32 mode, deUint32 start, deUint32 end, int count, deUint32 type, const void *indices, int baseVertex) = DE_NULL;
185 	virtual void		drawArraysIndirect		(deUint32 mode, const void *indirect)															= DE_NULL;
186 	virtual void		drawElementsIndirect	(deUint32 mode, deUint32 type, const void *indirect)											= DE_NULL;
187 
188 	virtual void		multiDrawArrays			(deUint32 mode, const int* first, const int* count, int primCount)								= DE_NULL;
189 	virtual void		multiDrawElements		(deUint32 mode, const int* count, deUint32 type, const void** indices, int primCount)			= DE_NULL;
190 	virtual void		multiDrawElementsBaseVertex (deUint32 mode, const int* count, deUint32 type, const void** indices, int primCount, const int* baseVertex) = DE_NULL;
191 
192 	virtual deUint32	createProgram			(ShaderProgram* program)															= DE_NULL;
193 	virtual void		useProgram				(deUint32 program)																	= DE_NULL;
194 	virtual void		deleteProgram			(deUint32 program)																	= DE_NULL;
195 
196 
197 	virtual void		readPixels				(int x, int y, int width, int height, deUint32 format, deUint32 type, void* data)	= DE_NULL;
198 	virtual deUint32	getError				(void)																				= DE_NULL;
199 	virtual void		finish					(void)																				= DE_NULL;
200 
201 	virtual void		getIntegerv				(deUint32 pname, int* params)														= DE_NULL;
202 	virtual const char*	getString				(deUint32 pname)																	= DE_NULL;
203 
204 	// Helpers implemented by Context.
205 	virtual void		texImage2D				(deUint32 target, int level, deUint32 internalFormat, const tcu::Surface& src);
206 	virtual void		texImage2D				(deUint32 target, int level, deUint32 internalFormat, int width, int height);
207 	virtual void		texSubImage2D			(deUint32 target, int level, int xoffset, int yoffset, const tcu::Surface& src);
208 	virtual void		readPixels				(tcu::Surface& dst, int x, int y, int width, int height);
209 
getType(void)210 	glu::ContextType	getType					(void)	{ return m_type; }
211 
212 private:
213 	const glu::ContextType	m_type;
214 } DE_WARN_UNUSED_TYPE;
215 
216 } // sglr
217 
218 #endif // _SGLRCONTEXT_HPP
219