Revert to tizen branch.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-gl-abstraction.h
1 #ifndef __TEST_GL_ABSTRACTION_H__
2 #define __TEST_GL_ABSTRACTION_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdio>  // fprintf
23 #include <sstream>
24 #include <string>
25 #include <cstring> // for strcpy, strncpy
26 #include <map>
27
28 // INTERNAL INCLUDES
29 #include <dali/public-api/dali-core.h>
30 #include <dali/integration-api/core.h>
31 #include <dali/integration-api/gl-abstraction.h>
32 #include <dali/integration-api/gl-defines.h>
33 #include "test-trace-call-stack.h"
34
35 namespace Dali
36 {
37
38 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 64;
39 static const char *mStdAttribs[MAX_ATTRIBUTE_CACHE_SIZE] =
40 {
41     "aPosition",    // ATTRIB_POSITION
42     "aNormal",      // ATTRIB_NORMAL
43     "aTexCoord",    // ATTRIB_TEXCOORD
44     "aColor",       // ATTRIB_COLOR
45     "aBoneWeights", // ATTRIB_BONE_WEIGHTS
46     "aBoneIndices"  // ATTRIB_BONE_INDICES
47 };
48
49 class DALI_IMPORT_API TestGlAbstraction: public Dali::Integration::GlAbstraction
50 {
51 public:
52   TestGlAbstraction();
53   ~TestGlAbstraction();
54   void Initialize();
55
56   void PreRender();
57   void PostRender(unsigned int timeDelta);
58
59   /* OpenGL ES 2.0 */
60
61   inline void ActiveTexture( GLenum textureUnit )
62   {
63     mActiveTextureUnit = textureUnit - GL_TEXTURE0;
64   }
65
66   inline GLenum GetActiveTextureUnit() const
67   {
68     return mActiveTextureUnit + GL_TEXTURE0;
69   }
70
71   inline void AttachShader( GLuint program, GLuint shader )
72   {
73     std::stringstream out;
74     out << program << ", " << shader;
75     mShaderTrace.PushCall("AttachShader", out.str());
76   }
77
78   inline void BindAttribLocation( GLuint program, GLuint index, const char* name )
79   {
80   }
81
82   inline void BindBuffer( GLenum target, GLuint buffer )
83   {
84   }
85
86   inline void BindFramebuffer( GLenum target, GLuint framebuffer )
87   {
88   }
89
90   inline void BindRenderbuffer( GLenum target, GLuint renderbuffer )
91   {
92   }
93
94   /**
95    * This method can be used by test cases, to query the texture IDs that have been bound by BindTexture.
96    * @return A vector containing the IDs that were bound.
97    */
98   inline const std::vector<GLuint>& GetBoundTextures() const
99   {
100     return mBoundTextures;
101   }
102
103   /**
104    * Query the texture IDs that have been bound with BindTexture, with a specific active texture unit.
105    * @param[in] activeTextureUnit The specific active texture unit.
106    * @return A vector containing the IDs that were bound.
107    */
108   inline const std::vector<GLuint>& GetBoundTextures( GLuint activeTextureUnit ) const
109   {
110     return mActiveTextures[ activeTextureUnit - GL_TEXTURE0 ].mBoundTextures;
111   }
112
113   /**
114    * This method can be used by test cases, to clear the record of texture IDs that have been bound by BindTexture.
115    */
116   inline void ClearBoundTextures()
117   {
118     mBoundTextures.clear();
119
120     for( unsigned int i=0; i<MIN_TEXTURE_UNIT_LIMIT; ++i )
121     {
122       mActiveTextures[ i ].mBoundTextures.clear();
123     }
124   }
125
126   inline void BindTexture( GLenum target, GLuint texture )
127   {
128     // Record the bound textures for future checks
129     if( texture )
130     {
131       mBoundTextures.push_back( texture );
132
133       if( mActiveTextureUnit < MIN_TEXTURE_UNIT_LIMIT )
134       {
135         mActiveTextures[ mActiveTextureUnit ].mBoundTextures.push_back( texture );
136       }
137     }
138
139     std::stringstream out;
140     out << target << ", " << texture;
141     mTextureTrace.PushCall("BindTexture", out.str());
142   }
143
144   inline void BlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
145   {
146     mLastBlendColor.r = red;
147     mLastBlendColor.g = green;
148     mLastBlendColor.b = blue;
149     mLastBlendColor.a = alpha;
150   }
151
152   inline const Vector4& GetLastBlendColor() const
153   {
154     return mLastBlendColor;
155   }
156
157   inline void BlendEquation( GLenum mode )
158   {
159     mLastBlendEquationRgb   = mode;
160     mLastBlendEquationAlpha = mode;
161   }
162
163   inline void BlendEquationSeparate( GLenum modeRgb, GLenum modeAlpha )
164   {
165     mLastBlendEquationRgb   = modeRgb;
166     mLastBlendEquationAlpha = modeAlpha;
167   }
168
169   inline GLenum GetLastBlendEquationRgb() const
170   {
171     return mLastBlendEquationRgb;
172   }
173
174   inline GLenum GetLastBlendEquationAlpha() const
175   {
176     return mLastBlendEquationAlpha;
177   }
178
179   inline void BlendFunc(GLenum sfactor, GLenum dfactor)
180   {
181     mLastBlendFuncSrcRgb = sfactor;
182     mLastBlendFuncDstRgb = dfactor;
183     mLastBlendFuncSrcAlpha = sfactor;
184     mLastBlendFuncDstAlpha = dfactor;
185   }
186
187   inline void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
188   {
189     mLastBlendFuncSrcRgb = srcRGB;
190     mLastBlendFuncDstRgb = dstRGB;
191     mLastBlendFuncSrcAlpha = srcAlpha;
192     mLastBlendFuncDstAlpha = dstAlpha;
193   }
194
195   inline GLenum GetLastBlendFuncSrcRgb() const
196   {
197     return mLastBlendFuncSrcRgb;
198   }
199
200   inline GLenum GetLastBlendFuncDstRgb() const
201   {
202     return mLastBlendFuncDstRgb;
203   }
204
205   inline GLenum GetLastBlendFuncSrcAlpha() const
206   {
207     return mLastBlendFuncSrcAlpha;
208   }
209
210   inline GLenum GetLastBlendFuncDstAlpha() const
211   {
212     return mLastBlendFuncDstAlpha;
213   }
214
215   inline void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
216   {
217   }
218
219   inline void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
220   {
221   }
222
223   inline GLenum CheckFramebufferStatus(GLenum target)
224   {
225     return mCheckFramebufferStatusResult;
226   }
227
228   inline void Clear(GLbitfield mask)
229   {
230   }
231
232   inline void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
233   {
234   }
235
236   inline void ClearDepthf(GLclampf depth)
237   {
238   }
239
240   inline void ClearStencil(GLint s)
241   {
242   }
243
244   inline void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
245   {
246   }
247
248   inline void CompileShader(GLuint shader)
249   {
250     std::stringstream out;
251     out << shader;
252     mShaderTrace.PushCall("CompileShader", out.str());
253   }
254
255   inline void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data)
256   {
257   }
258
259   inline void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data)
260   {
261   }
262
263   inline void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
264   {
265   }
266
267   inline void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
268   {
269   }
270
271   inline GLuint CreateProgram(void)
272   {
273     mShaderTrace.PushCall("CreateProgram", "");
274
275     ++mLastProgramIdUsed;
276     mUniforms[mLastProgramIdUsed] = UniformIDMap();
277     return mLastProgramIdUsed;
278   }
279
280   inline GLuint CreateShader(GLenum type)
281   {
282     std::stringstream out;
283     out << type;
284     mShaderTrace.PushCall("CreateShader", out.str());
285
286     return ++mLastShaderIdUsed;
287   }
288
289   inline void CullFace(GLenum mode)
290   {
291     std::stringstream out;
292     out << mode;
293     mCullFaceTrace.PushCall("CullFace", out.str());
294   }
295
296   inline void DeleteBuffers(GLsizei n, const GLuint* buffers)
297   {
298   }
299
300   inline void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
301   {
302   }
303
304   inline void DeleteProgram(GLuint program)
305   {
306     std::stringstream out;
307     out << program;
308     mShaderTrace.PushCall("DeleteProgram", out.str());
309   }
310
311   inline void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
312   {
313   }
314
315   inline void DeleteShader(GLuint shader)
316   {
317     std::stringstream out;
318     out << shader;
319     mShaderTrace.PushCall("DeleteShader", out.str());
320   }
321
322   inline void DeleteTextures(GLsizei n, const GLuint* textures)
323   {
324     std::stringstream out;
325     out << n << ", " << textures << " = [" ;
326
327     for(GLsizei i=0; i<n; i++)
328     {
329       out << textures[i] << ", " ;
330       mDeletedTextureIds.push_back(textures[i]);
331     }
332     out << "]";
333     mTextureTrace.PushCall("DeleteTextures", out.str());
334   }
335
336   inline bool CheckNoTexturesDeleted()
337   {
338     return mDeletedTextureIds.size() == 0;
339   }
340
341   inline bool CheckTextureDeleted( GLuint textureId )
342   {
343     bool found = false;
344
345     for(std::vector<GLuint>::iterator iter=mDeletedTextureIds.begin(); iter != mDeletedTextureIds.end(); ++iter)
346     {
347       if(*iter == textureId)
348       {
349         found = true;
350         break;
351       }
352     }
353     return found;
354   }
355
356   inline void ClearDeletedTextures()
357   {
358     mDeletedTextureIds.clear();
359   }
360
361   inline void DepthFunc(GLenum func)
362   {
363   }
364
365   inline void DepthMask(GLboolean flag)
366   {
367   }
368
369   inline void DepthRangef(GLclampf zNear, GLclampf zFar)
370   {
371   }
372
373   inline void DetachShader(GLuint program, GLuint shader)
374   {
375     std::stringstream out;
376     out << program << ", " << shader;
377     mShaderTrace.PushCall("DetachShader", out.str());
378   }
379
380   inline void Disable(GLenum cap)
381   {
382     std::stringstream out;
383     out << cap;
384     mCullFaceTrace.PushCall("Disable", out.str());
385   }
386
387   inline void DisableVertexAttribArray(GLuint index)
388   {
389     SetVertexAttribArray( index, false );
390   }
391
392   inline void DrawArrays(GLenum mode, GLint first, GLsizei count)
393   {
394     std::stringstream out;
395     out << mode << ", " << first << ", " << count;
396     mDrawTrace.PushCall("DrawArrays", out.str());
397   }
398
399   inline void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
400   {
401     std::stringstream out;
402     out << mode << ", " << count << ", " << type << ", indices";
403     mDrawTrace.PushCall("DrawElements", out.str());
404   }
405
406   inline void Enable(GLenum cap)
407   {
408     std::stringstream out;
409     out << cap;
410     mCullFaceTrace.PushCall("Enable", out.str());
411   }
412
413   inline void EnableVertexAttribArray(GLuint index)
414   {
415     SetVertexAttribArray( index, true);
416   }
417
418   inline void Finish(void)
419   {
420   }
421
422   inline void Flush(void)
423   {
424   }
425
426   inline void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
427   {
428   }
429
430   inline void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
431   {
432   }
433
434   inline void FrontFace(GLenum mode)
435   {
436   }
437
438   inline void GenBuffers(GLsizei n, GLuint* buffers)
439   {
440     // avoids an assert in GpuBuffers
441     *buffers = 1u;
442   }
443
444   inline void GenerateMipmap(GLenum target)
445   {
446   }
447
448   inline void GenFramebuffers(GLsizei n, GLuint* framebuffers)
449   {
450   }
451
452   inline void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
453   {
454   }
455
456   /**
457    * This method can be used by test cases, to manipulate the texture IDs generated by GenTextures.
458    * @param[in] ids A vector containing the next IDs to be generated
459    */
460   inline void SetNextTextureIds( const std::vector<GLuint>& ids )
461   {
462     mNextTextureIds = ids;
463   }
464
465   inline const std::vector<GLuint>& GetNextTextureIds()
466   {
467     return mNextTextureIds;
468   }
469
470   inline void GenTextures(GLsizei n, GLuint* textures)
471   {
472     for( int i=0; i<n; ++i )
473     {
474       if( !mNextTextureIds.empty() )
475       {
476         *(textures+i) = mNextTextureIds[0];
477         mNextTextureIds.erase( mNextTextureIds.begin() );
478       }
479       else
480       {
481         *(textures+i) = ++mLastAutoTextureIdUsed;
482       }
483     }
484
485     std::stringstream out;
486     for(int i=0; i<n; i++)
487     {
488       out << textures[i];
489       if(i<n-1)
490       {
491         out << ", ";
492       }
493     }
494     mTextureTrace.PushCall("GenTexture", out.str());
495   }
496
497   inline void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
498   {
499   }
500
501   inline void GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
502   {
503   }
504
505   inline void GetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
506   {
507   }
508
509   inline int  GetAttribLocation(GLuint program, const char* name)
510   {
511     std::string attribName(name);
512
513     for( unsigned int i = 0; i < ATTRIB_TYPE_LAST; ++i )
514     {
515       if( mStdAttribs[i] == attribName )
516       {
517         return i;
518       }
519     }
520
521     // 0 is a valid location
522     return 0;
523   }
524
525   inline void GetBooleanv(GLenum pname, GLboolean* params)
526   {
527   }
528
529   inline void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
530   {
531   }
532
533   inline GLenum GetError(void)
534   {
535     return mGetErrorResult;
536   }
537
538   inline void GetFloatv(GLenum pname, GLfloat* params)
539   {
540   }
541
542   inline void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
543   {
544   }
545
546   inline void GetIntegerv(GLenum pname, GLint* params)
547   {
548     switch( pname )
549     {
550       case GL_MAX_TEXTURE_SIZE:
551         *params = 2048;
552         break;
553       case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
554         *params = 8;
555         break;
556       case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
557         *params = mNumBinaryFormats;
558         break;
559       case GL_PROGRAM_BINARY_FORMATS_OES:
560         *params = mBinaryFormats;
561         break;
562     }
563   }
564
565   inline void GetProgramiv(GLuint program, GLenum pname, GLint* params)
566   {
567     switch( pname ) {
568       case GL_LINK_STATUS:
569         *params = mLinkStatus;
570         break;
571       case GL_PROGRAM_BINARY_LENGTH_OES:
572         *params = mProgramBinaryLength;
573         break;
574     }
575   }
576
577   inline void GetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog)
578   {
579   }
580
581
582   inline void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
583   {
584   }
585
586   inline void GetShaderiv(GLuint shader, GLenum pname, GLint* params)
587   {
588     switch( pname ) {
589       case GL_COMPILE_STATUS:
590         *params = mCompileStatus;
591         break;
592     }
593   }
594
595   inline void GetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog)
596   {
597   }
598
599   inline void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
600   {
601   }
602
603   inline const GLubyte* GetString(GLenum name)
604   {
605     return mGetStringResult;
606   }
607
608   inline void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
609   {
610   }
611
612   inline void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
613   {
614   }
615
616   inline void GetUniformfv(GLuint program, GLint location, GLfloat* params)
617   {
618   }
619
620   inline void GetUniformiv(GLuint program, GLint location, GLint* params)
621   {
622   }
623
624   inline GLint GetUniformLocation(GLuint program, const char* name)
625   {
626     ProgramUniformMap::iterator it = mUniforms.find(program);
627     if( it == mUniforms.end() )
628     {
629       // Not a valid program ID
630       mGetErrorResult = GL_INVALID_OPERATION;
631       return -1;
632     }
633
634     UniformIDMap& uniformIDs = it->second;
635     UniformIDMap::iterator it2 = uniformIDs.find( name );
636     if( it2 == uniformIDs.end() )
637     {
638       // Uniform not found, so add it...
639       uniformIDs[name] = ++mLastUniformIdUsed;
640       return mLastUniformIdUsed;
641     }
642
643     return it2->second;
644   }
645
646   inline void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
647   {
648   }
649
650   inline void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
651   {
652   }
653
654   inline void GetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer)
655   {
656   }
657
658   inline void Hint(GLenum target, GLenum mode)
659   {
660   }
661
662   inline GLboolean IsBuffer(GLuint buffer)
663   {
664     return mIsBufferResult;
665   }
666
667   inline GLboolean IsEnabled(GLenum cap)
668   {
669     return mIsEnabledResult;
670   }
671
672   inline GLboolean IsFramebuffer(GLuint framebuffer)
673   {
674     return mIsFramebufferResult;
675   }
676
677   inline GLboolean IsProgram(GLuint program)
678   {
679     return mIsProgramResult;
680   }
681
682   inline GLboolean IsRenderbuffer(GLuint renderbuffer)
683   {
684     return mIsRenderbufferResult;
685   }
686
687   inline GLboolean IsShader(GLuint shader)
688   {
689     return mIsShaderResult;
690   }
691
692   inline GLboolean IsTexture(GLuint texture)
693   {
694     return mIsTextureResult;
695   }
696
697   inline void LineWidth(GLfloat width)
698   {
699   }
700
701   inline void LinkProgram(GLuint program)
702   {
703     std::stringstream out;
704     out << program;
705     mShaderTrace.PushCall("LinkProgram", out.str());
706   }
707
708   inline void PixelStorei(GLenum pname, GLint param)
709   {
710   }
711
712   inline void PolygonOffset(GLfloat factor, GLfloat units)
713   {
714   }
715
716   inline void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
717   {
718   }
719
720   inline void ReleaseShaderCompiler(void)
721   {
722   }
723
724   inline void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
725   {
726   }
727
728   inline void SampleCoverage(GLclampf value, GLboolean invert)
729   {
730   }
731
732   inline void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
733   {
734     mScissorParams.x = x;
735     mScissorParams.y = y;
736     mScissorParams.width = width;
737     mScissorParams.height = height;
738   }
739
740   inline void ShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
741   {
742   }
743
744   inline void ShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
745   {
746     std::string stringBuilder;
747     for(int i = 0; i < count; ++i)
748     {
749       stringBuilder += string[i];
750     }
751     mShaderSources[shader] = stringBuilder;
752     mLastShaderCompiled = shader;
753   }
754
755   inline void GetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source)
756   {
757     const std::string shaderSource = mShaderSources[shader];
758     if( static_cast<int>(shaderSource.length()) < bufsize )
759     {
760       strcpy(source, shaderSource.c_str());
761       *length = shaderSource.length();
762     }
763     else
764     {
765       *length = bufsize -1;
766       strncpy(source, shaderSource.c_str(), *length);
767       source[*length] = 0x0;
768     }
769   }
770
771   inline std::string GetShaderSource(GLuint shader)
772   {
773     return mShaderSources[shader];
774   }
775
776   inline void StencilFunc(GLenum func, GLint ref, GLuint mask)
777   {
778   }
779
780   inline void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
781   {
782   }
783
784   inline void StencilMask(GLuint mask)
785   {
786   }
787
788   inline void StencilMaskSeparate(GLenum face, GLuint mask)
789   {
790   }
791
792   inline void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
793   {
794   }
795
796   inline void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
797   {
798   }
799
800   inline void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels)
801   {
802     std::stringstream out;
803     out << width << ", " << height;
804     mTextureTrace.PushCall("TexImage2D", out.str());
805   }
806
807   inline void TexParameterf(GLenum target, GLenum pname, GLfloat param)
808   {
809     std::stringstream out;
810     out << target << ", " << pname << ", " << param;
811     mTexParamaterTrace.PushCall("TexParameterf", out.str());
812   }
813
814   inline void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
815   {
816     std::stringstream out;
817     out << target << ", " << pname << ", " << params[0];
818     mTexParamaterTrace.PushCall("TexParameterfv", out.str());
819   }
820
821   inline void TexParameteri(GLenum target, GLenum pname, GLint param)
822   {
823     std::stringstream out;
824     out << target << ", " << pname << ", " << param;
825     mTexParamaterTrace.PushCall("TexParameteri", out.str());
826   }
827
828   inline void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
829   {
830     std::stringstream out;
831     out << target << ", " << pname << ", " << params[0];
832     mTexParamaterTrace.PushCall("TexParameteriv", out.str());
833   }
834
835   inline void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
836   {
837     std::stringstream out;
838     out << xoffset << ", " << yoffset << ", " << width << ", " << height;
839     mTextureTrace.PushCall("TexSubImage2D", out.str());
840   }
841
842   inline void Uniform1f(GLint location, GLfloat x)
843   {
844     if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, x ) )
845     {
846       mGetErrorResult = GL_INVALID_OPERATION;
847     }
848   }
849
850   inline void Uniform1fv(GLint location, GLsizei count, const GLfloat* v)
851   {
852     for( int i = 0; i < count; ++i )
853     {
854       if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, v[i] ) )
855       {
856         mGetErrorResult = GL_INVALID_OPERATION;
857         break;
858       }
859     }
860   }
861
862   inline void Uniform1i(GLint location, GLint x)
863   {
864     if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram, location, x ) )
865     {
866       mGetErrorResult = GL_INVALID_OPERATION;
867     }
868   }
869
870   inline void Uniform1iv(GLint location, GLsizei count, const GLint* v)
871   {
872     for( int i = 0; i < count; ++i )
873     {
874       if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram,
875                                                  location,
876                                                  v[i] ) )
877       {
878         mGetErrorResult = GL_INVALID_OPERATION;
879         break;
880       }
881     }
882   }
883
884   inline void Uniform2f(GLint location, GLfloat x, GLfloat y)
885   {
886     if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
887                                                location,
888                                                Vector2( x, y ) ) )
889     {
890       mGetErrorResult = GL_INVALID_OPERATION;
891     }
892   }
893
894   inline void Uniform2fv(GLint location, GLsizei count, const GLfloat* v)
895   {
896     for( int i = 0; i < count; ++i )
897     {
898       if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
899                                                  location,
900                                                  Vector2( v[2*i], v[2*i+1] ) ) )
901       {
902         mGetErrorResult = GL_INVALID_OPERATION;
903         break;
904       }
905     }
906   }
907
908   inline void Uniform2i(GLint location, GLint x, GLint y)
909   {
910   }
911
912   inline void Uniform2iv(GLint location, GLsizei count, const GLint* v)
913   {
914   }
915
916   inline void Uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
917   {
918     if( ! mProgramUniforms3f.SetUniformValue( mCurrentProgram,
919                                                location,
920                                                Vector3( x, y, z ) ) )
921     {
922       mGetErrorResult = GL_INVALID_OPERATION;
923     }
924   }
925
926   inline void Uniform3fv(GLint location, GLsizei count, const GLfloat* v)
927   {
928     for( int i = 0; i < count; ++i )
929     {
930       if( ! mProgramUniforms3f.SetUniformValue(
931           mCurrentProgram,
932           location,
933           Vector3( v[3*i], v[3*i+1], v[3*i+2] ) ) )
934       {
935         mGetErrorResult = GL_INVALID_OPERATION;
936         break;
937       }
938     }
939   }
940
941   inline void Uniform3i(GLint location, GLint x, GLint y, GLint z)
942   {
943   }
944
945   inline void Uniform3iv(GLint location, GLsizei count, const GLint* v)
946   {
947   }
948
949   inline void Uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
950   {
951     if( ! mProgramUniforms4f.SetUniformValue( mCurrentProgram,
952                                               location,
953                                               Vector4( x, y, z, w ) ) )
954     {
955       mGetErrorResult = GL_INVALID_OPERATION;
956     }
957   }
958
959   inline void Uniform4fv(GLint location, GLsizei count, const GLfloat* v)
960   {
961     for( int i = 0; i < count; ++i )
962     {
963       if( ! mProgramUniforms4f.SetUniformValue(
964           mCurrentProgram,
965           location,
966           Vector4( v[4*i], v[4*i+1], v[4*i+2], v[4*i+3] ) ) )
967       {
968         mGetErrorResult = GL_INVALID_OPERATION;
969         break;
970       }
971     }
972   }
973
974   inline void Uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
975   {
976   }
977
978   inline void Uniform4iv(GLint location, GLsizei count, const GLint* v)
979   {
980   }
981
982   inline void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
983   {
984   }
985
986   inline void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
987   {
988     for( int i = 0; i < count; ++i )
989     {
990       if( ! mProgramUniformsMat3.SetUniformValue(
991             mCurrentProgram,
992             location,
993             Matrix3( value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8] ) ) )
994       {
995         mGetErrorResult = GL_INVALID_OPERATION;
996         break;
997       }
998     }
999   }
1000
1001   inline void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1002   {
1003     for( int i = 0; i < count; ++i )
1004     {
1005       if( ! mProgramUniformsMat4.SetUniformValue(
1006           mCurrentProgram,
1007           location,
1008           Matrix( value ) ) )
1009       {
1010         mGetErrorResult = GL_INVALID_OPERATION;
1011         break;
1012       }
1013     }
1014   }
1015
1016   inline void UseProgram(GLuint program)
1017   {
1018     mCurrentProgram = program;
1019   }
1020
1021   inline void ValidateProgram(GLuint program)
1022   {
1023   }
1024
1025   inline void VertexAttrib1f(GLuint indx, GLfloat x)
1026   {
1027   }
1028
1029   inline void VertexAttrib1fv(GLuint indx, const GLfloat* values)
1030   {
1031   }
1032
1033   inline void VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
1034   {
1035   }
1036
1037   inline void VertexAttrib2fv(GLuint indx, const GLfloat* values)
1038   {
1039   }
1040
1041   inline void VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
1042   {
1043   }
1044
1045   inline void VertexAttrib3fv(GLuint indx, const GLfloat* values)
1046   {
1047   }
1048
1049   inline void VertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
1050   {
1051   }
1052
1053   inline void VertexAttrib4fv(GLuint indx, const GLfloat* values)
1054   {
1055   }
1056
1057   inline void VertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
1058   {
1059   }
1060
1061   inline void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1062   {
1063   }
1064
1065   /* OpenGL ES 3.0 */
1066
1067   inline void ReadBuffer(GLenum mode)
1068   {
1069   }
1070
1071   inline void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
1072   {
1073   }
1074
1075   inline void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
1076   {
1077   }
1078
1079   inline 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)
1080   {
1081   }
1082
1083   inline void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1084   {
1085   }
1086
1087   inline void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
1088   {
1089   }
1090
1091   inline 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)
1092   {
1093   }
1094
1095   inline void GenQueries(GLsizei n, GLuint* ids)
1096   {
1097   }
1098
1099   inline void DeleteQueries(GLsizei n, const GLuint* ids)
1100   {
1101   }
1102
1103   inline GLboolean IsQuery(GLuint id)
1104   {
1105     return false;
1106   }
1107
1108   inline void BeginQuery(GLenum target, GLuint id)
1109   {
1110   }
1111
1112   inline void EndQuery(GLenum target)
1113   {
1114   }
1115
1116   inline void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1117   {
1118   }
1119
1120   inline void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1121   {
1122   }
1123
1124   inline GLboolean UnmapBuffer(GLenum target)
1125   {
1126     return false;
1127   }
1128
1129   inline void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1130   {
1131   }
1132
1133   inline void DrawBuffers(GLsizei n, const GLenum* bufs)
1134   {
1135   }
1136
1137   inline void UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1138   {
1139   }
1140
1141   inline void UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1142   {
1143   }
1144
1145   inline void UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1146   {
1147   }
1148
1149   inline void UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1150   {
1151   }
1152
1153   inline void UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1154   {
1155   }
1156
1157   inline void UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1158   {
1159   }
1160
1161   inline void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
1162   {
1163   }
1164
1165   inline void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1166   {
1167   }
1168
1169   inline void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1170   {
1171   }
1172
1173   inline GLvoid* MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
1174   {
1175     return NULL;
1176   }
1177
1178   inline void FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
1179   {
1180   }
1181
1182   inline void BindVertexArray(GLuint array)
1183   {
1184   }
1185
1186   inline void DeleteVertexArrays(GLsizei n, const GLuint* arrays)
1187   {
1188   }
1189
1190   inline void GenVertexArrays(GLsizei n, GLuint* arrays)
1191   {
1192   }
1193
1194   inline GLboolean IsVertexArray(GLuint array)
1195   {
1196     return false;
1197   }
1198
1199   inline void GetIntegeri_v(GLenum target, GLuint index, GLint* data)
1200   {
1201   }
1202
1203   inline void BeginTransformFeedback(GLenum primitiveMode)
1204   {
1205   }
1206
1207   inline void EndTransformFeedback(void)
1208   {
1209   }
1210
1211   inline void BindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
1212   {
1213   }
1214
1215   inline void BindBufferBase(GLenum target, GLuint index, GLuint buffer)
1216   {
1217   }
1218
1219   inline void TransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
1220   {
1221   }
1222
1223   inline void GetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
1224   {
1225   }
1226
1227   inline void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
1228   {
1229   }
1230
1231   inline void GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
1232   {
1233   }
1234
1235   inline void GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
1236   {
1237   }
1238
1239   inline void VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
1240   {
1241   }
1242
1243   inline void VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
1244   {
1245   }
1246
1247   inline void VertexAttribI4iv(GLuint index, const GLint* v)
1248   {
1249   }
1250
1251   inline void VertexAttribI4uiv(GLuint index, const GLuint* v)
1252   {
1253   }
1254
1255   inline void GetUniformuiv(GLuint program, GLint location, GLuint* params)
1256   {
1257   }
1258
1259   inline GLint GetFragDataLocation(GLuint program, const GLchar *name)
1260   {
1261     return -1;
1262   }
1263
1264   inline void Uniform1ui(GLint location, GLuint v0)
1265   {
1266   }
1267
1268   inline void Uniform2ui(GLint location, GLuint v0, GLuint v1)
1269   {
1270   }
1271
1272   inline void Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
1273   {
1274   }
1275
1276   inline void Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1277   {
1278   }
1279
1280   inline void Uniform1uiv(GLint location, GLsizei count, const GLuint* value)
1281   {
1282   }
1283
1284   inline void Uniform2uiv(GLint location, GLsizei count, const GLuint* value)
1285   {
1286   }
1287
1288   inline void Uniform3uiv(GLint location, GLsizei count, const GLuint* value)
1289   {
1290   }
1291
1292   inline void Uniform4uiv(GLint location, GLsizei count, const GLuint* value)
1293   {
1294   }
1295
1296   inline void ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
1297   {
1298   }
1299
1300   inline void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
1301   {
1302   }
1303
1304   inline void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
1305   {
1306   }
1307
1308   inline void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
1309   {
1310   }
1311
1312   inline const GLubyte* GetStringi(GLenum name, GLuint index)
1313   {
1314     return NULL;
1315   }
1316
1317   inline void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
1318   {
1319   }
1320
1321   inline void GetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
1322   {
1323   }
1324
1325   inline void GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
1326   {
1327   }
1328
1329   inline GLuint GetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
1330   {
1331     return GL_INVALID_INDEX;
1332   }
1333
1334   inline void GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
1335   {
1336   }
1337
1338   inline void GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
1339   {
1340   }
1341
1342   inline void UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
1343   {
1344   }
1345
1346   inline void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
1347   {
1348   }
1349
1350   inline void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
1351   {
1352   }
1353
1354   inline GLsync FenceSync(GLenum condition, GLbitfield flags)
1355   {
1356     return NULL;
1357   }
1358
1359   inline GLboolean IsSync(GLsync sync)
1360   {
1361     return false;
1362   }
1363
1364   inline void DeleteSync(GLsync sync)
1365   {
1366   }
1367
1368   inline GLenum ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1369   {
1370     return 0;
1371   }
1372
1373   inline void WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1374   {
1375   }
1376
1377   inline void GetInteger64v(GLenum pname, GLint64* params)
1378   {
1379   }
1380
1381   inline void GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
1382   {
1383   }
1384
1385   inline void GetInteger64i_v(GLenum target, GLuint index, GLint64* data)
1386   {
1387   }
1388
1389   inline void GetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
1390   {
1391   }
1392
1393   inline void GenSamplers(GLsizei count, GLuint* samplers)
1394   {
1395   }
1396
1397   inline void DeleteSamplers(GLsizei count, const GLuint* samplers)
1398   {
1399   }
1400
1401   inline GLboolean IsSampler(GLuint sampler)
1402   {
1403     return false;
1404   }
1405
1406   inline void BindSampler(GLuint unit, GLuint sampler)
1407   {
1408   }
1409
1410   inline void SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
1411   {
1412   }
1413
1414   inline void SamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
1415   {
1416   }
1417
1418   inline void SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
1419   {
1420   }
1421
1422   inline void SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
1423   {
1424   }
1425
1426   inline void GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
1427   {
1428   }
1429
1430   inline void GetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
1431   {
1432   }
1433
1434   inline void VertexAttribDivisor(GLuint index, GLuint divisor)
1435   {
1436   }
1437
1438   inline void BindTransformFeedback(GLenum target, GLuint id)
1439   {
1440   }
1441
1442   inline void DeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
1443   {
1444   }
1445
1446   inline void GenTransformFeedbacks(GLsizei n, GLuint* ids)
1447   {
1448   }
1449
1450   inline GLboolean IsTransformFeedback(GLuint id)
1451   {
1452     return false;
1453   }
1454
1455   inline void PauseTransformFeedback(void)
1456   {
1457   }
1458
1459   inline void ResumeTransformFeedback(void)
1460   {
1461   }
1462
1463   inline void GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
1464   {
1465   }
1466
1467   inline void ProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
1468   {
1469   }
1470
1471   inline void ProgramParameteri(GLuint program, GLenum pname, GLint value)
1472   {
1473   }
1474
1475   inline void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
1476   {
1477   }
1478
1479   inline void InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
1480   {
1481   }
1482
1483   inline void TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
1484   {
1485   }
1486
1487   inline void TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
1488   {
1489   }
1490
1491   inline void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
1492   {
1493   }
1494
1495 public: // TEST FUNCTIONS
1496   inline void SetCompileStatus( GLuint value ) { mCompileStatus = value; }
1497   inline void SetLinkStatus( GLuint value ) { mLinkStatus = value; }
1498   inline void SetGetAttribLocationResult(  int result) { mGetAttribLocationResult = result; }
1499   inline void SetGetErrorResult(  GLenum result) { mGetErrorResult = result; }
1500   inline void SetGetStringResult(  GLubyte* result) { mGetStringResult = result; }
1501   inline void SetIsBufferResult(  GLboolean result) { mIsBufferResult = result; }
1502   inline void SetIsEnabledResult(  GLboolean result) { mIsEnabledResult = result; }
1503   inline void SetIsFramebufferResult(  GLboolean result) { mIsFramebufferResult = result; }
1504   inline void SetIsProgramResult(  GLboolean result) { mIsProgramResult = result; }
1505   inline void SetIsRenderbufferResult(  GLboolean result) { mIsRenderbufferResult = result; }
1506   inline void SetIsShaderResult(  GLboolean result) { mIsShaderResult = result; }
1507   inline void SetIsTextureResult(  GLboolean result) { mIsTextureResult = result; }
1508   inline void SetCheckFramebufferStatusResult(  GLenum result) { mCheckFramebufferStatusResult = result; }
1509   inline void SetNumBinaryFormats( GLint numFormats ) { mNumBinaryFormats = numFormats; }
1510   inline void SetBinaryFormats( GLint binaryFormats ) { mBinaryFormats = binaryFormats; }
1511   inline void SetProgramBinaryLength( GLint length ) { mProgramBinaryLength = length; }
1512
1513   inline bool GetVertexAttribArrayState(GLuint index)
1514   {
1515     if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1516     {
1517       // out of range
1518       return false;
1519     }
1520     return mVertexAttribArrayState[ index ];
1521   }
1522   inline void ClearVertexAttribArrayChanged() {  mVertexAttribArrayChanged = false; }
1523   inline bool GetVertexAttribArrayChanged()  { return mVertexAttribArrayChanged; }
1524
1525   //Methods for CullFace verification
1526   inline void EnableCullFaceCallTrace(bool enable) { mCullFaceTrace.Enable(enable); }
1527   inline void ResetCullFaceCallStack() { mCullFaceTrace.Reset(); }
1528   inline TraceCallStack& GetCullFaceTrace() { return mCullFaceTrace; }
1529
1530   //Methods for Shader verification
1531   inline void EnableShaderCallTrace(bool enable) { mShaderTrace.Enable(enable); }
1532   inline void ResetShaderCallStack() { mShaderTrace.Reset(); }
1533   inline TraceCallStack& GetShaderTrace() { return mShaderTrace; }
1534
1535   //Methods for Texture verification
1536   inline void EnableTextureCallTrace(bool enable) { mTextureTrace.Enable(enable); }
1537   inline void ResetTextureCallStack() { mTextureTrace.Reset(); }
1538   inline TraceCallStack& GetTextureTrace() { return mTextureTrace; }
1539
1540   //Methods for Texture verification
1541   inline void EnableTexParameterCallTrace(bool enable) { mTexParamaterTrace.Enable(enable); }
1542   inline void ResetTexParameterCallStack() { mTexParamaterTrace.Reset(); }
1543   inline TraceCallStack& GetTexParameterTrace() { return mTexParamaterTrace; }
1544
1545   //Methods for Draw verification
1546   inline void EnableDrawCallTrace(bool enable) { mDrawTrace.Enable(enable); }
1547   inline void ResetDrawCallStack() { mDrawTrace.Reset(); }
1548   inline TraceCallStack& GetDrawTrace() { return mDrawTrace; }
1549
1550   template <typename T>
1551   inline bool CheckUniformValue( const char* name, const T& value ) const
1552   {
1553     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1554           program_it != mUniforms.end();
1555           ++program_it )
1556     {
1557       const UniformIDMap &uniformIDs = program_it->second;
1558
1559       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1560       if( uniform_it != uniformIDs.end() )
1561       {
1562         // found one matching uniform name, lets check the value...
1563         GLuint programId = program_it->first;
1564         GLint uniformId = uniform_it->second;
1565
1566         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
1567         if( mProgramUniforms.CheckUniformValue( programId, uniformId, value ) )
1568         {
1569           // the value matches
1570           return true;
1571         }
1572       }
1573     }
1574
1575     fprintf(stderr, "Not found, printing possible values:" );
1576     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1577           program_it != mUniforms.end();
1578           ++program_it )
1579     {
1580       const UniformIDMap &uniformIDs = program_it->second;
1581
1582       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1583       if( uniform_it != uniformIDs.end() )
1584       {
1585         // found one matching uniform name, lets check the value...
1586         GLuint programId = program_it->first;
1587         GLint uniformId = uniform_it->second;
1588
1589         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
1590         T origValue;
1591         if ( mProgramUniforms.GetUniformValue(programId, uniformId, origValue) )
1592         {
1593           std::stringstream out;
1594           out << uniform_it->first << ": " << origValue;
1595           fprintf(stderr, "%s", out.str().c_str() );
1596         }
1597       }
1598     }
1599     return false;
1600   }
1601
1602   template <typename T>
1603   inline bool GetUniformValue( GLuint programId, GLuint uniformId, T& outValue) const
1604   {
1605     const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( outValue );
1606     return mProgramUniforms.GetUniformValue( programId, uniformId, outValue );
1607   }
1608
1609   inline bool GetUniformIds( const char* name, GLuint& programId, GLuint& uniformId ) const
1610   {
1611     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1612           program_it != mUniforms.end();
1613           ++program_it )
1614     {
1615       const UniformIDMap &uniformIDs = program_it->second;
1616
1617       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1618       if( uniform_it != uniformIDs.end() )
1619       {
1620         programId = program_it->first;
1621         uniformId = uniform_it->second;
1622         return true;
1623       }
1624     }
1625     return false;
1626   }
1627
1628
1629
1630   inline GLuint GetLastShaderCompiled() const
1631   {
1632     return mLastShaderCompiled;
1633   }
1634
1635   inline GLuint GetLastProgramCreated() const
1636   {
1637     return mLastProgramIdUsed;
1638   }
1639
1640   enum AttribType
1641   {
1642     ATTRIB_UNKNOWN = -1,
1643     ATTRIB_POSITION,
1644     ATTRIB_NORMAL,
1645     ATTRIB_TEXCOORD,
1646     ATTRIB_COLOR,
1647     ATTRIB_BONE_WEIGHTS,
1648     ATTRIB_BONE_INDICES,
1649     ATTRIB_TYPE_LAST
1650   };
1651
1652   struct ScissorParams
1653   {
1654     GLint x;
1655     GLint y;
1656     GLsizei width;
1657     GLsizei height;
1658
1659     ScissorParams() : x( 0 ), y( 0 ), width( 0 ), height( 0 ) { }
1660   };
1661
1662   // Methods to check scissor tests
1663   inline const ScissorParams& GetScissorParams() const { return mScissorParams; }
1664
1665 private:
1666   GLuint     mCurrentProgram;
1667   GLuint     mCompileStatus;
1668   GLuint     mLinkStatus;
1669   GLint      mGetAttribLocationResult;
1670   GLenum     mGetErrorResult;
1671   GLubyte*   mGetStringResult;
1672   GLboolean  mIsBufferResult;
1673   GLboolean  mIsEnabledResult;
1674   GLboolean  mIsFramebufferResult;
1675   GLboolean  mIsProgramResult;
1676   GLboolean  mIsRenderbufferResult;
1677   GLboolean  mIsShaderResult;
1678   GLboolean  mIsTextureResult;
1679   GLenum     mActiveTextureUnit;
1680   GLenum     mCheckFramebufferStatusResult;
1681   GLint      mNumBinaryFormats;
1682   GLint      mBinaryFormats;
1683   GLint      mProgramBinaryLength;
1684   bool       mVertexAttribArrayState[MAX_ATTRIBUTE_CACHE_SIZE];
1685   bool       mVertexAttribArrayChanged;                            // whether the vertex attrib array has been changed
1686   typedef std::map< GLuint, std::string> ShaderSourceMap;
1687   ShaderSourceMap mShaderSources;
1688   GLuint     mLastShaderCompiled;
1689
1690   Vector4 mLastBlendColor;
1691   GLenum  mLastBlendEquationRgb;
1692   GLenum  mLastBlendEquationAlpha;
1693   GLenum  mLastBlendFuncSrcRgb;
1694   GLenum  mLastBlendFuncDstRgb;
1695   GLenum  mLastBlendFuncSrcAlpha;
1696   GLenum  mLastBlendFuncDstAlpha;
1697
1698   // Data for manipulating the IDs returned by GenTextures
1699   GLuint mLastAutoTextureIdUsed;
1700   std::vector<GLuint> mNextTextureIds;
1701   std::vector<GLuint> mDeletedTextureIds;
1702   std::vector<GLuint> mBoundTextures;
1703
1704   struct ActiveTextureType
1705   {
1706     std::vector<GLuint> mBoundTextures;
1707   };
1708
1709   ActiveTextureType mActiveTextures[ MIN_TEXTURE_UNIT_LIMIT ];
1710
1711   TraceCallStack mCullFaceTrace;
1712   TraceCallStack mShaderTrace;
1713   TraceCallStack mTextureTrace;
1714   TraceCallStack mTexParamaterTrace;
1715   TraceCallStack mDrawTrace;
1716
1717   // Shaders & Uniforms
1718   GLuint mLastShaderIdUsed;
1719   GLuint mLastProgramIdUsed;
1720   GLuint mLastUniformIdUsed;
1721   typedef std::map< std::string, GLint > UniformIDMap;
1722   typedef std::map< GLuint, UniformIDMap > ProgramUniformMap;
1723   ProgramUniformMap mUniforms;
1724
1725   template <typename T>
1726   struct ProgramUniformValue : public std::map< GLuint, std::map< GLint, T > >
1727   {
1728   public:
1729     typedef std::map< GLint, T > UniformValueMap;
1730     typedef std::map< GLuint, UniformValueMap > Map;
1731
1732     bool SetUniformValue( GLuint program, GLuint uniform, const T& value )
1733     {
1734       if( program == 0 )
1735       {
1736         return false;
1737       }
1738
1739       typename Map::iterator it = Map::find( program );
1740       if( it == Map::end() )
1741       {
1742         // if its the first uniform for this program add it
1743         std::pair< typename Map::iterator, bool > result =
1744             Map::insert( typename Map::value_type( program, UniformValueMap() ) );
1745         it = result.first;
1746       }
1747
1748       UniformValueMap& uniforms = it->second;
1749       uniforms[uniform] = value;
1750
1751       return true;
1752     }
1753
1754     bool CheckUniformValue( GLuint program, GLuint uniform, const T& value ) const
1755     {
1756       T uniformValue;
1757       if ( GetUniformValue( program, uniform, uniformValue ) )
1758       {
1759         return value == uniformValue;
1760       }
1761
1762       return false;
1763     }
1764
1765     bool GetUniformValue( GLuint program, GLuint uniform, T& value ) const
1766     {
1767       if( program == 0 )
1768       {
1769         return false;
1770       }
1771
1772       typename Map::const_iterator it = Map::find( program );
1773       if( it == Map::end() )
1774       {
1775         // Uniform values always initialised as 0
1776         value = GetZero();
1777         return true;
1778       }
1779
1780       const UniformValueMap& uniforms = it->second;
1781       typename UniformValueMap::const_iterator it2 = uniforms.find( uniform );
1782       if( it2 == uniforms.end() )
1783       {
1784         // Uniform values always initialised as 0
1785         value = GetZero();
1786         return true;
1787       }
1788       value = it2->second;
1789
1790       return true;
1791     }
1792
1793     T GetZero() const;
1794   };
1795   ProgramUniformValue<int> mProgramUniforms1i;
1796   ProgramUniformValue<float> mProgramUniforms1f;
1797   ProgramUniformValue<Vector2> mProgramUniforms2f;
1798   ProgramUniformValue<Vector3> mProgramUniforms3f;
1799   ProgramUniformValue<Vector4> mProgramUniforms4f;
1800   ProgramUniformValue<Matrix> mProgramUniformsMat4;
1801   ProgramUniformValue<Matrix3> mProgramUniformsMat3;
1802
1803   inline const ProgramUniformValue<int>& GetProgramUniformsForType( const int ) const
1804   {
1805     return mProgramUniforms1i;
1806   }
1807   inline const ProgramUniformValue<float>& GetProgramUniformsForType( const float ) const
1808   {
1809     return mProgramUniforms1f;
1810   }
1811   inline const ProgramUniformValue<Vector2>& GetProgramUniformsForType( const Vector2& ) const
1812   {
1813     return mProgramUniforms2f;
1814   }
1815   inline const ProgramUniformValue<Vector3>& GetProgramUniformsForType( const Vector3& ) const
1816   {
1817     return mProgramUniforms3f;
1818   }
1819   inline const ProgramUniformValue<Vector4>& GetProgramUniformsForType( const Vector4& ) const
1820   {
1821     return mProgramUniforms4f;
1822   }
1823   inline const ProgramUniformValue<Matrix>& GetProgramUniformsForType( const Matrix& ) const
1824   {
1825     return mProgramUniformsMat4;
1826   }
1827   inline const ProgramUniformValue<Matrix3>& GetProgramUniformsForType( const Matrix3& ) const
1828   {
1829     return mProgramUniformsMat3;
1830   }
1831   inline void SetVertexAttribArray(GLuint index, bool state)
1832   {
1833     if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1834     {
1835       // out of range
1836       return;
1837     }
1838     mVertexAttribArrayState[ index ] = state;
1839     mVertexAttribArrayChanged = true;
1840   }
1841
1842   ScissorParams mScissorParams;
1843 };
1844
1845 template <>
1846 inline int TestGlAbstraction::ProgramUniformValue<int>::GetZero() const
1847 {
1848   return 0;
1849 }
1850
1851 template <>
1852 inline float TestGlAbstraction::ProgramUniformValue<float>::GetZero() const
1853 {
1854   return 0.0f;
1855 }
1856
1857 template <>
1858 inline Vector2 TestGlAbstraction::ProgramUniformValue<Vector2>::GetZero() const
1859 {
1860   return Vector2::ZERO;
1861 }
1862
1863 template <>
1864 inline Vector3 TestGlAbstraction::ProgramUniformValue<Vector3>::GetZero() const
1865 {
1866   return Vector3::ZERO;
1867 }
1868
1869 template <>
1870 inline Vector4 TestGlAbstraction::ProgramUniformValue<Vector4>::GetZero() const
1871 {
1872   return Vector4::ZERO;
1873 }
1874
1875 template <>
1876 inline Matrix TestGlAbstraction::ProgramUniformValue<Matrix>::GetZero() const
1877 {
1878   return Matrix();
1879 }
1880
1881 template <>
1882 inline Matrix3 TestGlAbstraction::ProgramUniformValue<Matrix3>::GetZero() const
1883 {
1884   return Matrix3( Matrix() );
1885 }
1886
1887 } // namespace Dali
1888
1889 bool BlendEnabled(const Dali::TraceCallStack& callStack);
1890 bool BlendDisabled(const Dali::TraceCallStack& callStack);
1891
1892
1893
1894
1895 #endif // __TEST_GL_ES_H__