1 #ifndef __TEST_GL_ABSTRACTION_H__
2 #define __TEST_GL_ABSTRACTION_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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
11 // http://floralicense.org/license/
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.
25 #include <dali/public-api/dali-core.h>
27 #include <dali/integration-api/core.h>
28 #include <dali/integration-api/gl-abstraction.h>
29 #include <test-trace-call-stack.h>
34 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 64;
35 static const char *mStdAttribs[MAX_ATTRIBUTE_CACHE_SIZE] =
37 "aPosition", // ATTRIB_POSITION
38 "aNormal", // ATTRIB_NORMAL
39 "aTexCoord", // ATTRIB_TEXCOORD
40 "aColor", // ATTRIB_COLOR
41 "aBoneWeights", // ATTRIB_BONE_WEIGHTS
42 "aBoneIndices" // ATTRIB_BONE_INDICES
45 class DALI_IMPORT_API TestGlAbstraction: public Dali::Integration::GlAbstraction
53 ~TestGlAbstraction() {}
58 mCompileStatus = GL_TRUE;
59 mLinkStatus = GL_TRUE;
61 mGetAttribLocationResult = 0;
63 mGetStringResult = NULL;
66 mIsFramebufferResult = 0;
68 mIsRenderbufferResult = 0;
71 mVertexAttribArrayChanged = false;
73 mCheckFramebufferStatusResult = 0;
74 mNumBinaryFormats = 1;
76 mProgramBinaryLength = 0;
78 mLastAutoTextureIdUsed = 0;
80 mLastShaderIdUsed = 0;
81 mLastProgramIdUsed = 0;
82 mLastUniformIdUsed = 0;
83 mLastShaderCompiled = 0;
85 mLastBlendEquationRgb = 0;
86 mLastBlendEquationAlpha = 0;
87 mLastBlendFuncSrcRgb = 0;
88 mLastBlendFuncDstRgb = 0;
89 mLastBlendFuncSrcAlpha = 0;
90 mLastBlendFuncDstAlpha = 0;
93 mProgramUniforms1i.clear();
94 mProgramUniforms1f.clear();
95 mProgramUniforms2f.clear();
96 mProgramUniforms3f.clear();
97 mProgramUniforms4f.clear();
102 void ActiveTexture( GLenum textureUnit )
104 mActiveTextureUnit = textureUnit - GL_TEXTURE0;
107 GLenum GetActiveTextureUnit() const
109 return mActiveTextureUnit + GL_TEXTURE0;
112 void AttachShader( GLuint program, GLuint shader )
114 std::stringstream out;
115 out << program << ", " << shader;
116 mShaderTrace.PushCall("AttachShader", out.str());
119 void BindAttribLocation( GLuint program, GLuint index, const char* name )
123 void BindBuffer( GLenum target, GLuint buffer )
127 void BindFramebuffer( GLenum target, GLuint framebuffer )
131 void BindRenderbuffer( GLenum target, GLuint renderbuffer )
136 * This method can be used by test cases, to query the texture IDs that have been bound by BindTexture.
137 * @return A vector containing the IDs that were bound.
139 const std::vector<GLuint>& GetBoundTextures() const
141 return mBoundTextures;
145 * Query the texture IDs that have been bound with BindTexture, with a specific active texture unit.
146 * @param[in] activeTextureUnit The specific active texture unit.
147 * @return A vector containing the IDs that were bound.
149 const std::vector<GLuint>& GetBoundTextures( GLuint activeTextureUnit ) const
151 return mActiveTextures[ activeTextureUnit - GL_TEXTURE0 ].mBoundTextures;
155 * This method can be used by test cases, to clear the record of texture IDs that have been bound by BindTexture.
157 void ClearBoundTextures()
159 mBoundTextures.clear();
161 for( unsigned int i=0; i<MIN_TEXTURE_UNIT_LIMIT; ++i )
163 mActiveTextures[ i ].mBoundTextures.clear();
167 void BindTexture( GLenum target, GLuint texture )
169 // Record the bound textures for future checks
172 mBoundTextures.push_back( texture );
174 if( mActiveTextureUnit < MIN_TEXTURE_UNIT_LIMIT )
176 mActiveTextures[ mActiveTextureUnit ].mBoundTextures.push_back( texture );
181 void BlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
183 mLastBlendColor.r = red;
184 mLastBlendColor.g = green;
185 mLastBlendColor.b = blue;
186 mLastBlendColor.a = alpha;
189 const Vector4& GetLastBlendColor() const
191 return mLastBlendColor;
194 void BlendEquation( GLenum mode )
196 mLastBlendEquationRgb = mode;
197 mLastBlendEquationAlpha = mode;
200 void BlendEquationSeparate( GLenum modeRgb, GLenum modeAlpha )
202 mLastBlendEquationRgb = modeRgb;
203 mLastBlendEquationAlpha = modeAlpha;
206 GLenum GetLastBlendEquationRgb() const
208 return mLastBlendEquationRgb;
211 GLenum GetLastBlendEquationAlpha() const
213 return mLastBlendEquationAlpha;
216 void BlendFunc(GLenum sfactor, GLenum dfactor)
218 mLastBlendFuncSrcRgb = sfactor;
219 mLastBlendFuncDstRgb = dfactor;
220 mLastBlendFuncSrcAlpha = sfactor;
221 mLastBlendFuncDstAlpha = dfactor;
224 void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
226 mLastBlendFuncSrcRgb = srcRGB;
227 mLastBlendFuncDstRgb = dstRGB;
228 mLastBlendFuncSrcAlpha = srcAlpha;
229 mLastBlendFuncDstAlpha = dstAlpha;
232 GLenum GetLastBlendFuncSrcRgb() const
234 return mLastBlendFuncSrcRgb;
237 GLenum GetLastBlendFuncDstRgb() const
239 return mLastBlendFuncDstRgb;
242 GLenum GetLastBlendFuncSrcAlpha() const
244 return mLastBlendFuncSrcAlpha;
247 GLenum GetLastBlendFuncDstAlpha() const
249 return mLastBlendFuncDstAlpha;
252 void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
256 void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
260 GLenum CheckFramebufferStatus(GLenum target)
262 return mCheckFramebufferStatusResult;
265 void Clear(GLbitfield mask)
269 void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
273 void ClearDepthf(GLclampf depth)
277 void ClearStencil(GLint s)
281 void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
285 void CompileShader(GLuint shader)
287 std::stringstream out;
289 mShaderTrace.PushCall("CompileShader", out.str());
292 void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data)
296 void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data)
300 void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
304 void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
308 GLuint CreateProgram(void)
310 mShaderTrace.PushCall("CreateProgram", "");
312 ++mLastProgramIdUsed;
313 mUniforms[mLastProgramIdUsed] = UniformIDMap();
314 return mLastProgramIdUsed;
317 GLuint CreateShader(GLenum type)
319 std::stringstream out;
321 mShaderTrace.PushCall("CreateShader", out.str());
323 return ++mLastShaderIdUsed;
326 void CullFace(GLenum mode)
328 std::stringstream out;
330 mCullFaceTrace.PushCall("CullFace", out.str());
333 void DeleteBuffers(GLsizei n, const GLuint* buffers)
337 void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
341 void DeleteProgram(GLuint program)
343 std::stringstream out;
345 mShaderTrace.PushCall("DeleteProgram", out.str());
348 void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
352 void DeleteShader(GLuint shader)
354 std::stringstream out;
356 mShaderTrace.PushCall("DeleteShader", out.str());
359 void DeleteTextures(GLsizei n, const GLuint* textures)
361 std::stringstream out;
362 out << n << ", " << textures << " = [";
364 for(GLsizei i=0; i<n; i++)
366 out << textures[i] << ", ";
367 mDeletedTextureIds.push_back(textures[i]);
370 mTextureTrace.PushCall("DeleteTextures", out.str());
373 bool CheckNoTexturesDeleted()
375 return mDeletedTextureIds.size() == 0;
378 bool CheckTextureDeleted( GLuint textureId )
382 for(std::vector<GLuint>::iterator iter=mDeletedTextureIds.begin(); iter != mDeletedTextureIds.end(); ++iter)
384 if(*iter == textureId)
393 void ClearDeletedTextures()
395 mDeletedTextureIds.clear();
398 void DepthFunc(GLenum func)
402 void DepthMask(GLboolean flag)
406 void DepthRangef(GLclampf zNear, GLclampf zFar)
410 void DetachShader(GLuint program, GLuint shader)
412 std::stringstream out;
413 out << program << ", " << shader;
414 mShaderTrace.PushCall("DetachShader", out.str());
417 void Disable(GLenum cap)
419 std::stringstream out;
421 mCullFaceTrace.PushCall("Disable", out.str());
424 void DisableVertexAttribArray(GLuint index)
426 SetVertexAttribArray( index, false );
429 void DrawArrays(GLenum mode, GLint first, GLsizei count)
431 std::stringstream out;
432 out << mode << ", " << first << ", " << count;
433 mDrawTrace.PushCall("DrawArrays", out.str());
436 void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
438 std::stringstream out;
439 out << mode << ", " << count << ", " << type << ", indices";
440 mDrawTrace.PushCall("DrawElements", out.str());
443 void Enable(GLenum cap)
445 std::stringstream out;
447 mCullFaceTrace.PushCall("Enable", out.str());
450 void EnableVertexAttribArray(GLuint index)
452 SetVertexAttribArray( index, true);
463 void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
467 void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
471 void FrontFace(GLenum mode)
475 void GenBuffers(GLsizei n, GLuint* buffers)
477 // avoids an assert in GpuBuffers
481 void GenerateMipmap(GLenum target)
485 void GenFramebuffers(GLsizei n, GLuint* framebuffers)
489 void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
494 * This method can be used by test cases, to manipulate the texture IDs generated by GenTextures.
495 * @param[in] ids A vector containing the next IDs to be generated
497 void SetNextTextureIds( const std::vector<GLuint>& ids )
499 mNextTextureIds = ids;
502 const std::vector<GLuint>& GetNextTextureIds()
504 return mNextTextureIds;
507 void GenTextures(GLsizei n, GLuint* textures)
509 for( int i=0; i<n; ++i )
511 if( !mNextTextureIds.empty() )
513 *(textures+i) = mNextTextureIds[0];
514 mNextTextureIds.erase( mNextTextureIds.begin() );
518 *(textures+i) = ++mLastAutoTextureIdUsed;
523 void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
527 void GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
531 void GetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
535 int GetAttribLocation(GLuint program, const char* name)
537 std::string attribName(name);
539 for( unsigned int i = 0; i < ATTRIB_TYPE_LAST; ++i )
541 if( mStdAttribs[i] == attribName )
547 // 0 is a valid location
551 void GetBooleanv(GLenum pname, GLboolean* params)
555 void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
559 GLenum GetError(void)
561 return mGetErrorResult;
564 void GetFloatv(GLenum pname, GLfloat* params)
568 void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
572 void GetIntegerv(GLenum pname, GLint* params)
576 case GL_MAX_TEXTURE_SIZE:
579 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
582 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
583 *params = mNumBinaryFormats;
585 case GL_PROGRAM_BINARY_FORMATS_OES:
586 *params = mBinaryFormats;
591 void GetProgramiv(GLuint program, GLenum pname, GLint* params)
595 *params = mLinkStatus;
597 case GL_PROGRAM_BINARY_LENGTH_OES:
598 *params = mProgramBinaryLength;
603 void GetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog)
608 void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
612 void GetShaderiv(GLuint shader, GLenum pname, GLint* params)
615 case GL_COMPILE_STATUS:
616 *params = mCompileStatus;
621 void GetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog)
625 void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
629 const GLubyte* GetString(GLenum name)
631 return mGetStringResult;
634 void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
638 void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
642 void GetUniformfv(GLuint program, GLint location, GLfloat* params)
646 void GetUniformiv(GLuint program, GLint location, GLint* params)
650 GLint GetUniformLocation(GLuint program, const char* name)
652 ProgramUniformMap::iterator it = mUniforms.find(program);
653 if( it == mUniforms.end() )
655 // Not a valid program ID
656 mGetErrorResult = GL_INVALID_OPERATION;
660 UniformIDMap& uniformIDs = it->second;
661 UniformIDMap::iterator it2 = uniformIDs.find( name );
662 if( it2 == uniformIDs.end() )
664 // Uniform not found, so add it...
665 uniformIDs[name] = ++mLastUniformIdUsed;
666 return mLastUniformIdUsed;
672 void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
676 void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
680 void GetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer)
684 void Hint(GLenum target, GLenum mode)
688 GLboolean IsBuffer(GLuint buffer)
690 return mIsBufferResult;
693 GLboolean IsEnabled(GLenum cap)
695 return mIsEnabledResult;
698 GLboolean IsFramebuffer(GLuint framebuffer)
700 return mIsFramebufferResult;
703 GLboolean IsProgram(GLuint program)
705 return mIsProgramResult;
708 GLboolean IsRenderbuffer(GLuint renderbuffer)
710 return mIsRenderbufferResult;
713 GLboolean IsShader(GLuint shader)
715 return mIsShaderResult;
718 GLboolean IsTexture(GLuint texture)
720 return mIsTextureResult;
723 void LineWidth(GLfloat width)
727 void LinkProgram(GLuint program)
729 std::stringstream out;
731 mShaderTrace.PushCall("LinkProgram", out.str());
734 void PixelStorei(GLenum pname, GLint param)
738 void PolygonOffset(GLfloat factor, GLfloat units)
742 void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
746 void ReleaseShaderCompiler(void)
750 void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
754 void SampleCoverage(GLclampf value, GLboolean invert)
758 void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
762 void ShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
766 void ShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
768 std::string stringBuilder;
769 for(int i = 0; i < count; ++i)
771 stringBuilder += string[i];
773 mShaderSources[shader] = stringBuilder;
774 mLastShaderCompiled = shader;
777 void GetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source)
779 const std::string shaderSource = mShaderSources[shader];
780 if( static_cast<int>(shaderSource.length()) < bufsize )
782 strcpy(source, shaderSource.c_str());
783 *length = shaderSource.length();
787 *length = bufsize -1;
788 strncpy(source, shaderSource.c_str(), *length);
789 source[*length] = 0x0;
793 void StencilFunc(GLenum func, GLint ref, GLuint mask)
797 void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
801 void StencilMask(GLuint mask)
805 void StencilMaskSeparate(GLenum face, GLuint mask)
809 void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
813 void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
817 void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels)
819 std::stringstream out;
820 out << width << ", " << height;
821 mTextureTrace.PushCall("TexImage2D", out.str());
824 void TexParameterf(GLenum target, GLenum pname, GLfloat param)
828 void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
832 void TexParameteri(GLenum target, GLenum pname, GLint param)
836 void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
840 void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
842 std::stringstream out;
843 out << xoffset << ", " << yoffset << ", " << width << ", " << height;
844 mTextureTrace.PushCall("TexSubImage2D", out.str());
847 void Uniform1f(GLint location, GLfloat x)
849 if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, x ) )
851 mGetErrorResult = GL_INVALID_OPERATION;
855 void Uniform1fv(GLint location, GLsizei count, const GLfloat* v)
857 for( int i = 0; i < count; ++i )
859 if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, v[i] ) )
861 mGetErrorResult = GL_INVALID_OPERATION;
867 void Uniform1i(GLint location, GLint x)
869 if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram, location, x ) )
871 mGetErrorResult = GL_INVALID_OPERATION;
875 void Uniform1iv(GLint location, GLsizei count, const GLint* v)
877 for( int i = 0; i < count; ++i )
879 if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram,
883 mGetErrorResult = GL_INVALID_OPERATION;
889 void Uniform2f(GLint location, GLfloat x, GLfloat y)
891 if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
895 mGetErrorResult = GL_INVALID_OPERATION;
899 void Uniform2fv(GLint location, GLsizei count, const GLfloat* v)
901 for( int i = 0; i < count; ++i )
903 if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
905 Vector2( v[2*i], v[2*i+1] ) ) )
907 mGetErrorResult = GL_INVALID_OPERATION;
913 void Uniform2i(GLint location, GLint x, GLint y)
917 void Uniform2iv(GLint location, GLsizei count, const GLint* v)
921 void Uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
923 if( ! mProgramUniforms3f.SetUniformValue( mCurrentProgram,
925 Vector3( x, y, z ) ) )
927 mGetErrorResult = GL_INVALID_OPERATION;
931 void Uniform3fv(GLint location, GLsizei count, const GLfloat* v)
933 for( int i = 0; i < count; ++i )
935 if( ! mProgramUniforms3f.SetUniformValue(
938 Vector3( v[3*i], v[3*i+1], v[3*i+2] ) ) )
940 mGetErrorResult = GL_INVALID_OPERATION;
946 void Uniform3i(GLint location, GLint x, GLint y, GLint z)
950 void Uniform3iv(GLint location, GLsizei count, const GLint* v)
954 void Uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
956 if( ! mProgramUniforms4f.SetUniformValue( mCurrentProgram,
958 Vector4( x, y, z, w ) ) )
960 mGetErrorResult = GL_INVALID_OPERATION;
964 void Uniform4fv(GLint location, GLsizei count, const GLfloat* v)
966 for( int i = 0; i < count; ++i )
968 if( ! mProgramUniforms4f.SetUniformValue(
971 Vector4( v[4*i], v[4*i+1], v[4*i+2], v[4*i+3] ) ) )
973 mGetErrorResult = GL_INVALID_OPERATION;
979 void Uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
983 void Uniform4iv(GLint location, GLsizei count, const GLint* v)
987 void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
991 void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
993 for( int i = 0; i < count; ++i )
995 if( ! mProgramUniformsMat3.SetUniformValue(
998 Matrix3( value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8] ) ) )
1000 mGetErrorResult = GL_INVALID_OPERATION;
1006 void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1008 for( int i = 0; i < count; ++i )
1010 if( ! mProgramUniformsMat4.SetUniformValue(
1015 mGetErrorResult = GL_INVALID_OPERATION;
1021 void UseProgram(GLuint program)
1023 mCurrentProgram = program;
1026 void ValidateProgram(GLuint program)
1030 void VertexAttrib1f(GLuint indx, GLfloat x)
1034 void VertexAttrib1fv(GLuint indx, const GLfloat* values)
1038 void VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
1042 void VertexAttrib2fv(GLuint indx, const GLfloat* values)
1046 void VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
1050 void VertexAttrib3fv(GLuint indx, const GLfloat* values)
1054 void VertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
1058 void VertexAttrib4fv(GLuint indx, const GLfloat* values)
1062 void VertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
1066 void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1072 void ReadBuffer(GLenum mode)
1076 void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
1080 void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
1084 void TexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels)
1088 void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1092 void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
1096 void CompressedTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data)
1100 void GenQueries(GLsizei n, GLuint* ids)
1104 void DeleteQueries(GLsizei n, const GLuint* ids)
1108 GLboolean IsQuery(GLuint id)
1113 void BeginQuery(GLenum target, GLuint id)
1117 void EndQuery(GLenum target)
1121 void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1125 void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1129 GLboolean UnmapBuffer(GLenum target)
1134 void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1138 void DrawBuffers(GLsizei n, const GLenum* bufs)
1142 void UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1146 void UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1150 void UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1154 void UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1158 void UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1162 void UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1166 void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
1170 void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1174 void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1178 GLvoid* MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
1183 void FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
1187 void BindVertexArray(GLuint array)
1191 void DeleteVertexArrays(GLsizei n, const GLuint* arrays)
1195 void GenVertexArrays(GLsizei n, GLuint* arrays)
1199 GLboolean IsVertexArray(GLuint array)
1204 void GetIntegeri_v(GLenum target, GLuint index, GLint* data)
1208 void BeginTransformFeedback(GLenum primitiveMode)
1212 void EndTransformFeedback(void)
1216 void BindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
1220 void BindBufferBase(GLenum target, GLuint index, GLuint buffer)
1224 void TransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
1228 void GetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
1232 void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
1236 void GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
1240 void GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
1244 void VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
1248 void VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
1252 void VertexAttribI4iv(GLuint index, const GLint* v)
1256 void VertexAttribI4uiv(GLuint index, const GLuint* v)
1260 void GetUniformuiv(GLuint program, GLint location, GLuint* params)
1264 GLint GetFragDataLocation(GLuint program, const GLchar *name)
1269 void Uniform1ui(GLint location, GLuint v0)
1273 void Uniform2ui(GLint location, GLuint v0, GLuint v1)
1277 void Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
1281 void Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1285 void Uniform1uiv(GLint location, GLsizei count, const GLuint* value)
1289 void Uniform2uiv(GLint location, GLsizei count, const GLuint* value)
1293 void Uniform3uiv(GLint location, GLsizei count, const GLuint* value)
1297 void Uniform4uiv(GLint location, GLsizei count, const GLuint* value)
1301 void ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
1305 void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
1309 void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
1313 void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
1317 const GLubyte* GetStringi(GLenum name, GLuint index)
1322 void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
1326 void GetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
1330 void GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
1334 GLuint GetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
1336 return GL_INVALID_INDEX;
1339 void GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
1343 void GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
1347 void UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
1351 void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
1355 void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
1359 GLsync FenceSync(GLenum condition, GLbitfield flags)
1364 GLboolean IsSync(GLsync sync)
1369 void DeleteSync(GLsync sync)
1373 GLenum ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1378 void WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1382 void GetInteger64v(GLenum pname, GLint64* params)
1386 void GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
1390 void GetInteger64i_v(GLenum target, GLuint index, GLint64* data)
1394 void GetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
1398 void GenSamplers(GLsizei count, GLuint* samplers)
1402 void DeleteSamplers(GLsizei count, const GLuint* samplers)
1406 GLboolean IsSampler(GLuint sampler)
1411 void BindSampler(GLuint unit, GLuint sampler)
1415 void SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
1419 void SamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
1423 void SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
1427 void SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
1431 void GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
1435 void GetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
1439 void VertexAttribDivisor(GLuint index, GLuint divisor)
1443 void BindTransformFeedback(GLenum target, GLuint id)
1447 void DeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
1451 void GenTransformFeedbacks(GLsizei n, GLuint* ids)
1455 GLboolean IsTransformFeedback(GLuint id)
1460 void PauseTransformFeedback(void)
1464 void ResumeTransformFeedback(void)
1468 void GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
1472 void ProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
1476 void ProgramParameteri(GLuint program, GLenum pname, GLint value)
1480 void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
1484 void InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
1488 void TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
1492 void TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
1496 void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
1500 public: // TEST FUNCTIONS
1501 void SetCompileStatus( GLuint value ) { mCompileStatus = value; }
1502 void SetLinkStatus( GLuint value ) { mLinkStatus = value; }
1503 void SetGetAttribLocationResult( int result) { mGetAttribLocationResult = result; }
1504 void SetGetErrorResult( GLenum result) { mGetErrorResult = result; }
1505 void SetGetStringResult( GLubyte* result) { mGetStringResult = result; }
1506 void SetIsBufferResult( GLboolean result) { mIsBufferResult = result; }
1507 void SetIsEnabledResult( GLboolean result) { mIsEnabledResult = result; }
1508 void SetIsFramebufferResult( GLboolean result) { mIsFramebufferResult = result; }
1509 void SetIsProgramResult( GLboolean result) { mIsProgramResult = result; }
1510 void SetIsRenderbufferResult( GLboolean result) { mIsRenderbufferResult = result; }
1511 void SetIsShaderResult( GLboolean result) { mIsShaderResult = result; }
1512 void SetIsTextureResult( GLboolean result) { mIsTextureResult = result; }
1513 void SetCheckFramebufferStatusResult( GLenum result) { mCheckFramebufferStatusResult = result; }
1514 void SetNumBinaryFormats( GLint numFormats ) { mNumBinaryFormats = numFormats; }
1515 void SetBinaryFormats( GLint binaryFormats ) { mBinaryFormats = binaryFormats; }
1516 void SetProgramBinaryLength( GLint length ) { mProgramBinaryLength = length; }
1518 bool GetVertexAttribArrayState(GLuint index)
1520 if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1525 return mVertexAttribArrayState[ index ];
1527 void ClearVertexAttribArrayChanged() { mVertexAttribArrayChanged = false; }
1528 bool GetVertexAttribArrayChanged() { return mVertexAttribArrayChanged; }
1530 //Methods for CullFace verification
1531 void EnableCullFaceCallTrace(bool enable) { mCullFaceTrace.Enable(enable); }
1532 void ResetCullFaceCallStack() { mCullFaceTrace.Reset(); }
1533 TraceCallStack& GetCullFaceTrace() { return mCullFaceTrace; }
1535 //Methods for Shader verification
1536 void EnableShaderCallTrace(bool enable) { mShaderTrace.Enable(enable); }
1537 void ResetShaderCallStack() { mShaderTrace.Reset(); }
1538 TraceCallStack& GetShaderTrace() { return mShaderTrace; }
1540 //Methods for Texture verification
1541 void EnableTextureCallTrace(bool enable) { mTextureTrace.Enable(enable); }
1542 void ResetTextureCallStack() { mTextureTrace.Reset(); }
1543 TraceCallStack& GetTextureTrace() { return mTextureTrace; }
1545 //Methods for Draw verification
1546 void EnableDrawCallTrace(bool enable) { mDrawTrace.Enable(enable); }
1547 void ResetDrawCallStack() { mDrawTrace.Reset(); }
1548 TraceCallStack& GetDrawTrace() { return mDrawTrace; }
1550 template <typename T>
1551 bool CheckUniformValue( const char* name, const T& value ) const
1553 for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1554 program_it != mUniforms.end();
1557 const UniformIDMap &uniformIDs = program_it->second;
1559 UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1560 if( uniform_it != uniformIDs.end() )
1562 // found one matching uniform name, lets check the value...
1563 GLuint programId = program_it->first;
1564 GLint uniformId = uniform_it->second;
1566 const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
1567 if( mProgramUniforms.CheckUniformValue( programId, uniformId, value ) )
1569 // the value matches
1575 tet_infoline( "Not found, printing possible values:" );
1576 for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1577 program_it != mUniforms.end();
1580 const UniformIDMap &uniformIDs = program_it->second;
1582 UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1583 if( uniform_it != uniformIDs.end() )
1585 // found one matching uniform name, lets check the value...
1586 GLuint programId = program_it->first;
1587 GLint uniformId = uniform_it->second;
1589 const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
1591 if ( mProgramUniforms.GetUniformValue(programId, uniformId, origValue) )
1593 std::stringstream out;
1594 out << uniform_it->first << ": " << origValue;
1595 tet_printf( "%s", out.str().c_str() );
1602 template <typename T>
1603 bool GetUniformValue( GLuint programId, GLuint uniformId, T& outValue) const
1605 const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( outValue );
1606 return mProgramUniforms.GetUniformValue( programId, uniformId, outValue );
1609 GLuint GetLastShaderCompiled() const
1611 return mLastShaderCompiled;
1614 GLuint GetLastProgramCreated() const
1616 return mLastProgramIdUsed;
1621 ATTRIB_UNKNOWN = -1,
1626 ATTRIB_BONE_WEIGHTS,
1627 ATTRIB_BONE_INDICES,
1633 GLuint mCurrentProgram;
1634 GLuint mCompileStatus;
1636 GLint mGetAttribLocationResult;
1637 GLenum mGetErrorResult;
1638 GLubyte* mGetStringResult;
1639 GLboolean mIsBufferResult;
1640 GLboolean mIsEnabledResult;
1641 GLboolean mIsFramebufferResult;
1642 GLboolean mIsProgramResult;
1643 GLboolean mIsRenderbufferResult;
1644 GLboolean mIsShaderResult;
1645 GLboolean mIsTextureResult;
1646 GLenum mActiveTextureUnit;
1647 GLenum mCheckFramebufferStatusResult;
1648 GLint mNumBinaryFormats;
1649 GLint mBinaryFormats;
1650 GLint mProgramBinaryLength;
1651 bool mVertexAttribArrayState[MAX_ATTRIBUTE_CACHE_SIZE];
1652 bool mVertexAttribArrayChanged; // whether the vertex attrib array has been changed
1653 typedef std::map< GLuint, std::string> ShaderSourceMap;
1654 ShaderSourceMap mShaderSources;
1655 GLuint mLastShaderCompiled;
1657 Vector4 mLastBlendColor;
1658 GLenum mLastBlendEquationRgb;
1659 GLenum mLastBlendEquationAlpha;
1660 GLenum mLastBlendFuncSrcRgb;
1661 GLenum mLastBlendFuncDstRgb;
1662 GLenum mLastBlendFuncSrcAlpha;
1663 GLenum mLastBlendFuncDstAlpha;
1665 // Data for manipulating the IDs returned by GenTextures
1666 GLuint mLastAutoTextureIdUsed;
1667 std::vector<GLuint> mNextTextureIds;
1668 std::vector<GLuint> mDeletedTextureIds;
1669 std::vector<GLuint> mBoundTextures;
1671 struct ActiveTextureType
1673 std::vector<GLuint> mBoundTextures;
1676 ActiveTextureType mActiveTextures[ MIN_TEXTURE_UNIT_LIMIT ];
1678 TraceCallStack mCullFaceTrace;
1679 TraceCallStack mShaderTrace;
1680 TraceCallStack mTextureTrace;
1681 TraceCallStack mDrawTrace;
1683 // Shaders & Uniforms
1684 GLuint mLastShaderIdUsed;
1685 GLuint mLastProgramIdUsed;
1686 GLuint mLastUniformIdUsed;
1687 typedef std::map< std::string, GLint > UniformIDMap;
1688 typedef std::map< GLuint, UniformIDMap > ProgramUniformMap;
1689 ProgramUniformMap mUniforms;
1691 template <typename T>
1692 struct ProgramUniformValue : public std::map< GLuint, std::map< GLint, T > >
1695 typedef std::map< GLint, T > UniformValueMap;
1696 typedef std::map< GLuint, UniformValueMap > Map;
1698 bool SetUniformValue( GLuint program, GLuint uniform, const T& value )
1705 typename Map::iterator it = Map::find( program );
1706 if( it == Map::end() )
1708 // if its the first uniform for this program add it
1709 std::pair< typename Map::iterator, bool > result =
1710 Map::insert( typename Map::value_type( program, UniformValueMap() ) );
1714 UniformValueMap& uniforms = it->second;
1715 uniforms[uniform] = value;
1720 bool CheckUniformValue( GLuint program, GLuint uniform, const T& value ) const
1723 if ( GetUniformValue( program, uniform, uniformValue ) )
1725 return value == uniformValue;
1731 bool GetUniformValue( GLuint program, GLuint uniform, T& value ) const
1738 typename Map::const_iterator it = Map::find( program );
1739 if( it == Map::end() )
1741 // Uniform values always initialised as 0
1746 const UniformValueMap& uniforms = it->second;
1747 typename UniformValueMap::const_iterator it2 = uniforms.find( uniform );
1748 if( it2 == uniforms.end() )
1750 // Uniform values always initialised as 0
1754 value = it2->second;
1761 ProgramUniformValue<int> mProgramUniforms1i;
1762 ProgramUniformValue<float> mProgramUniforms1f;
1763 ProgramUniformValue<Vector2> mProgramUniforms2f;
1764 ProgramUniformValue<Vector3> mProgramUniforms3f;
1765 ProgramUniformValue<Vector4> mProgramUniforms4f;
1766 ProgramUniformValue<Matrix> mProgramUniformsMat4;
1767 ProgramUniformValue<Matrix3> mProgramUniformsMat3;
1769 const ProgramUniformValue<int>& GetProgramUniformsForType( const int ) const
1771 return mProgramUniforms1i;
1773 const ProgramUniformValue<float>& GetProgramUniformsForType( const float ) const
1775 return mProgramUniforms1f;
1777 const ProgramUniformValue<Vector2>& GetProgramUniformsForType( const Vector2& ) const
1779 return mProgramUniforms2f;
1781 const ProgramUniformValue<Vector3>& GetProgramUniformsForType( const Vector3& ) const
1783 return mProgramUniforms3f;
1785 const ProgramUniformValue<Vector4>& GetProgramUniformsForType( const Vector4& ) const
1787 return mProgramUniforms4f;
1789 const ProgramUniformValue<Matrix>& GetProgramUniformsForType( const Matrix& ) const
1791 return mProgramUniformsMat4;
1793 const ProgramUniformValue<Matrix3>& GetProgramUniformsForType( const Matrix3& ) const
1795 return mProgramUniformsMat3;
1797 void SetVertexAttribArray(GLuint index, bool state)
1799 if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1804 mVertexAttribArrayState[ index ] = state;
1805 mVertexAttribArrayChanged = true;
1811 inline int TestGlAbstraction::ProgramUniformValue<int>::GetZero() const
1817 inline float TestGlAbstraction::ProgramUniformValue<float>::GetZero() const
1823 inline Vector2 TestGlAbstraction::ProgramUniformValue<Vector2>::GetZero() const
1825 return Vector2::ZERO;
1829 inline Vector3 TestGlAbstraction::ProgramUniformValue<Vector3>::GetZero() const
1831 return Vector3::ZERO;
1835 inline Vector4 TestGlAbstraction::ProgramUniformValue<Vector4>::GetZero() const
1837 return Vector4::ZERO;
1841 inline Matrix TestGlAbstraction::ProgramUniformValue<Matrix>::GetZero() const
1847 inline Matrix3 TestGlAbstraction::ProgramUniformValue<Matrix3>::GetZero() const
1849 return Matrix3( Matrix() );
1854 extern bool BlendEnabled(const TraceCallStack& callStack);
1855 extern bool BlendDisabled(const TraceCallStack& callStack);