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