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