Home | History | Annotate | Download | only in simplereference
      1 #ifndef _SGLRGLCONTEXT_HPP
      2 #define _SGLRGLCONTEXT_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 GL Rendering Context.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "tcuDefs.hpp"
     27 #include "sglrContext.hpp"
     28 #include "tcuTestLog.hpp"
     29 #include "tcuVector.hpp"
     30 #include "gluRenderContext.hpp"
     31 #include "gluShaderProgram.hpp"
     32 
     33 #include <set>
     34 #include <vector>
     35 
     36 namespace glu
     37 {
     38 class CallLogWrapper;
     39 }
     40 
     41 namespace sglr
     42 {
     43 
     44 enum GLContextLogFlag
     45 {
     46 	GLCONTEXT_LOG_CALLS		= (1 << 0),
     47 	GLCONTEXT_LOG_PROGRAMS	= (1 << 1)
     48 };
     49 
     50 class GLContext : public Context
     51 {
     52 public:
     53 										GLContext				(const glu::RenderContext& context, tcu::TestLog& log, deUint32 logFlags, const tcu::IVec4& baseViewport);
     54 	virtual								~GLContext				(void);
     55 
     56 	void								enableLogging			(deUint32 logFlags);
     57 
     58 	virtual int							getWidth				(void) const;
     59 	virtual int							getHeight				(void) const;
     60 
     61 	virtual void						viewport				(int x, int y, int width, int height);
     62 	virtual void						activeTexture			(deUint32 texture);
     63 
     64 	virtual void						bindTexture				(deUint32 target, deUint32 texture);
     65 	virtual void						genTextures				(int numTextures, deUint32* textures);
     66 	virtual void						deleteTextures			(int numTextures, const deUint32* textures);
     67 
     68 	virtual void						bindFramebuffer			(deUint32 target, deUint32 framebuffer);
     69 	virtual void						genFramebuffers			(int numFramebuffers, deUint32* framebuffers);
     70 	virtual void						deleteFramebuffers		(int numFramebuffers, const deUint32* framebuffers);
     71 
     72 	virtual void						bindRenderbuffer		(deUint32 target, deUint32 renderbuffer);
     73 	virtual void						genRenderbuffers		(int numRenderbuffers, deUint32* renderbuffers);
     74 	virtual void						deleteRenderbuffers		(int numRenderbuffers, const deUint32* renderbuffers);
     75 
     76 	virtual void						pixelStorei				(deUint32 pname, int param);
     77 	virtual void						texImage1D				(deUint32 target, int level, deUint32 internalFormat, int width, int border, deUint32 format, deUint32 type, const void* data);
     78 	virtual void						texImage2D				(deUint32 target, int level, deUint32 internalFormat, int width, int height, int border, deUint32 format, deUint32 type, const void* data);
     79 	virtual void						texImage3D				(deUint32 target, int level, deUint32 internalFormat, int width, int height, int depth, int border, deUint32 format, deUint32 type, const void* data);
     80 	virtual void						texSubImage1D			(deUint32 target, int level, int xoffset, int width, deUint32 format, deUint32 type, const void* data);
     81 	virtual void						texSubImage2D			(deUint32 target, int level, int xoffset, int yoffset, int width, int height, deUint32 format, deUint32 type, const void* data);
     82 	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);
     83 	virtual void						copyTexImage1D			(deUint32 target, int level, deUint32 internalFormat, int x, int y, int width, int border);
     84 	virtual void						copyTexImage2D			(deUint32 target, int level, deUint32 internalFormat, int x, int y, int width, int height, int border);
     85 	virtual void						copyTexSubImage1D		(deUint32 target, int level, int xoffset, int x, int y, int width);
     86 	virtual void						copyTexSubImage2D		(deUint32 target, int level, int xoffset, int yoffset, int x, int y, int width, int height);
     87 	virtual void						copyTexSubImage3D		(deUint32 target, int level, int xoffset, int yoffset, int zoffset, int x, int y, int width, int height);
     88 
     89 	virtual void						texStorage2D			(deUint32 target, int levels, deUint32 internalFormat, int width, int height);
     90 	virtual void						texStorage3D			(deUint32 target, int levels, deUint32 internalFormat, int width, int height, int depth);
     91 
     92 	virtual void						texParameteri			(deUint32 target, deUint32 pname, int value);
     93 
     94 	virtual void						framebufferTexture2D	(deUint32 target, deUint32 attachment, deUint32 textarget, deUint32 texture, int level);
     95 	virtual void						framebufferTextureLayer	(deUint32 target, deUint32 attachment, deUint32 texture, int level, int layer);
     96 	virtual void						framebufferRenderbuffer	(deUint32 target, deUint32 attachment, deUint32 renderbuffertarget, deUint32 renderbuffer);
     97 	virtual deUint32					checkFramebufferStatus	(deUint32 target);
     98 
     99 	virtual void						getFramebufferAttachmentParameteriv	(deUint32 target, deUint32 attachment, deUint32 pname, int* params);
    100 
    101 	virtual void						renderbufferStorage				(deUint32 target, deUint32 internalformat, int width, int height);
    102 	virtual void						renderbufferStorageMultisample	(deUint32 target, int samples, deUint32 internalFormat, int width, int height);
    103 
    104 	virtual void						bindBuffer				(deUint32 target, deUint32 buffer);
    105 	virtual void						genBuffers				(int numBuffers, deUint32* buffers);
    106 	virtual void						deleteBuffers			(int numBuffers, const deUint32* buffers);
    107 
    108 	virtual void						bufferData				(deUint32 target, deIntptr size, const void* data, deUint32 usage);
    109 	virtual void						bufferSubData			(deUint32 target, deIntptr offset, deIntptr size, const void* data);
    110 
    111 	virtual void						clearColor				(float red, float green, float blue, float alpha);
    112 	virtual void						clearDepthf				(float depth);
    113 	virtual void						clearStencil			(int stencil);
    114 
    115 	virtual void						clear					(deUint32 buffers);
    116 	virtual void						clearBufferiv			(deUint32 buffer, int drawbuffer, const int* value);
    117 	virtual void						clearBufferfv			(deUint32 buffer, int drawbuffer, const float* value);
    118 	virtual void						clearBufferuiv			(deUint32 buffer, int drawbuffer, const deUint32* value);
    119 	virtual void						clearBufferfi			(deUint32 buffer, int drawbuffer, float depth, int stencil);
    120 	virtual void						scissor					(int x, int y, int width, int height);
    121 
    122 	virtual void						enable					(deUint32 cap);
    123 	virtual void						disable					(deUint32 cap);
    124 
    125 	virtual void						stencilFunc				(deUint32 func, int ref, deUint32 mask);
    126 	virtual void						stencilOp				(deUint32 sfail, deUint32 dpfail, deUint32 dppass);
    127 	virtual void						stencilFuncSeparate		(deUint32 face, deUint32 func, int ref, deUint32 mask);
    128 	virtual void						stencilOpSeparate		(deUint32 face, deUint32 sfail, deUint32 dpfail, deUint32 dppass);
    129 
    130 	virtual void						depthFunc				(deUint32 func);
    131 	virtual void						depthRangef				(float n, float f);
    132 	virtual void						depthRange				(double n, double f);
    133 
    134 	virtual void						polygonOffset			(float factor, float units);
    135 	virtual void						provokingVertex			(deUint32 convention);
    136 	virtual void						primitiveRestartIndex	(deUint32 index);
    137 
    138 	virtual void						blendEquation			(deUint32 mode);
    139 	virtual void						blendEquationSeparate	(deUint32 modeRGB, deUint32 modeAlpha);
    140 	virtual void						blendFunc				(deUint32 src, deUint32 dst);
    141 	virtual void						blendFuncSeparate		(deUint32 srcRGB, deUint32 dstRGB, deUint32 srcAlpha, deUint32 dstAlpha);
    142 	virtual void						blendColor				(float red, float green, float blue, float alpha);
    143 
    144 	virtual void						colorMask				(deBool r, deBool g, deBool b, deBool a);
    145 	virtual void						depthMask				(deBool mask);
    146 	virtual void						stencilMask				(deUint32 mask);
    147 	virtual void						stencilMaskSeparate		(deUint32 face, deUint32 mask);
    148 
    149 	virtual void						blitFramebuffer			(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, deUint32 mask, deUint32 filter);
    150 
    151 	virtual void						invalidateSubFramebuffer(deUint32 target, int numAttachments, const deUint32* attachments, int x, int y, int width, int height);
    152 	virtual void						invalidateFramebuffer	(deUint32 target, int numAttachments, const deUint32* attachments);
    153 
    154 	virtual void						bindVertexArray			(deUint32 array);
    155 	virtual void						genVertexArrays			(int numArrays, deUint32* vertexArrays);
    156 	virtual void						deleteVertexArrays		(int numArrays, const deUint32* vertexArrays);
    157 
    158 	virtual void						vertexAttribPointer		(deUint32 index, int size, deUint32 type, deBool normalized, int stride, const void *pointer);
    159 	virtual void						vertexAttribIPointer	(deUint32 index, int size, deUint32 type, int stride, const void *pointer);
    160 	virtual void						enableVertexAttribArray	(deUint32 index);
    161 	virtual void						disableVertexAttribArray(deUint32 index);
    162 	virtual void						vertexAttribDivisor		(deUint32 index, deUint32 divisor);
    163 
    164 	virtual void						vertexAttrib1f			(deUint32 index, float);
    165 	virtual void						vertexAttrib2f			(deUint32 index, float, float);
    166 	virtual void						vertexAttrib3f			(deUint32 index, float, float, float);
    167 	virtual void						vertexAttrib4f			(deUint32 index, float, float, float, float);
    168 	virtual void						vertexAttribI4i			(deUint32 index, deInt32, deInt32, deInt32, deInt32);
    169 	virtual void						vertexAttribI4ui		(deUint32 index, deUint32, deUint32, deUint32, deUint32);
    170 
    171 	virtual deInt32						getAttribLocation		(deUint32 program, const char *name);
    172 
    173 	virtual void						uniform1f				(deInt32 location, float);
    174 	virtual void						uniform1i				(deInt32 location, deInt32);
    175 	virtual void						uniform1fv				(deInt32 index, deInt32 count, const float*);
    176 	virtual void						uniform2fv				(deInt32 index, deInt32 count, const float*);
    177 	virtual void						uniform3fv				(deInt32 index, deInt32 count, const float*);
    178 	virtual void						uniform4fv				(deInt32 index, deInt32 count, const float*);
    179 	virtual void						uniform1iv				(deInt32 index, deInt32 count, const deInt32*);
    180 	virtual void						uniform2iv				(deInt32 index, deInt32 count, const deInt32*);
    181 	virtual void						uniform3iv				(deInt32 index, deInt32 count, const deInt32*);
    182 	virtual void						uniform4iv				(deInt32 index, deInt32 count, const deInt32*);
    183 	virtual void						uniformMatrix3fv		(deInt32 location, deInt32 count, deBool transpose, const float *value);
    184 	virtual void						uniformMatrix4fv		(deInt32 location, deInt32 count, deBool transpose, const float *value);
    185 	virtual deInt32						getUniformLocation		(deUint32 program, const char *name);
    186 
    187 	virtual void						lineWidth				(float);
    188 
    189 	virtual void						drawArrays				(deUint32 mode, int first, int count);
    190 	virtual void						drawArraysInstanced		(deUint32 mode, int first, int count, int instanceCount);
    191 	virtual void						drawElements			(deUint32 mode, int count, deUint32 type, const void *indices);
    192 	virtual void						drawElementsInstanced	(deUint32 mode, int count, deUint32 type, const void *indices, int instanceCount);
    193 	virtual void						drawElementsBaseVertex	(deUint32 mode, int count, deUint32 type, const void *indices, int baseVertex);
    194 	virtual void						drawElementsInstancedBaseVertex	(deUint32 mode, int count, deUint32 type, const void *indices, int instanceCount, int baseVertex);
    195 	virtual void						drawRangeElements		(deUint32 mode, deUint32 start, deUint32 end, int count, deUint32 type, const void *indices);
    196 	virtual void						drawRangeElementsBaseVertex	(deUint32 mode, deUint32 start, deUint32 end, int count, deUint32 type, const void *indices, int baseVertex);
    197 	virtual void						drawArraysIndirect		(deUint32 mode, const void *indirect);
    198 	virtual void						drawElementsIndirect	(deUint32 mode, deUint32 type, const void *indirect);
    199 
    200 	virtual void						multiDrawArrays			(deUint32 mode, const int* first, const int* count, int primCount);
    201 	virtual void						multiDrawElements		(deUint32 mode, const int* count, deUint32 type, const void** indices, int primCount);
    202 	virtual void						multiDrawElementsBaseVertex (deUint32 mode, const int* count, deUint32 type, const void** indices, int primCount, const int* baseVertex);
    203 
    204 	virtual deUint32					createProgram			(ShaderProgram*);
    205 	virtual void						deleteProgram			(deUint32 program);
    206 	virtual void						useProgram				(deUint32 program);
    207 
    208 	virtual void						readPixels				(int x, int y, int width, int height, deUint32 format, deUint32 type, void* data);
    209 	virtual deUint32					getError				(void);
    210 	virtual void						finish					(void);
    211 
    212 	virtual void						getIntegerv				(deUint32 pname, int* params);
    213 	virtual const char*					getString				(deUint32 pname);
    214 
    215 	// Expose helpers from Context.
    216 	using Context::readPixels;
    217 	using Context::texImage2D;
    218 	using Context::texSubImage2D;
    219 
    220 private:
    221 										GLContext				(const GLContext& other);
    222 	GLContext&							operator=				(const GLContext& other);
    223 
    224 	tcu::IVec2							getReadOffset			(void) const;
    225 	tcu::IVec2							getDrawOffset			(void) const;
    226 
    227 	const glu::RenderContext&			m_context;
    228 	tcu::TestLog&						m_log;
    229 
    230 	deUint32							m_logFlags;
    231 	tcu::IVec4							m_baseViewport;
    232 	tcu::IVec4							m_curViewport;
    233 	tcu::IVec4							m_curScissor;
    234 	deUint32							m_readFramebufferBinding;
    235 	deUint32							m_drawFramebufferBinding;
    236 
    237 	glu::CallLogWrapper*				m_wrapper;
    238 
    239 	// For cleanup
    240 	std::set<deUint32>					m_allocatedTextures;
    241 	std::set<deUint32>					m_allocatedFbos;
    242 	std::set<deUint32>					m_allocatedRbos;
    243 	std::set<deUint32>					m_allocatedBuffers;
    244 	std::set<deUint32>					m_allocatedVaos;
    245 	std::vector<glu::ShaderProgram*>	m_programs;
    246 } DE_WARN_UNUSED_TYPE;
    247 
    248 } // sglr
    249 
    250 #endif // _SGLRGLCONTEXT_HPP
    251