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