098f555a5fdedfd989269af3a268465c87cfe07b
[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 GLuint CheckFramebufferColorAttachmentCount()
256   {
257     return mFramebufferColorAttachmentCount;
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_ATTACHMENT0 + Dali::FrameBuffer::MAX_COLOR_ATTACHMENTS))
588     {
589       uint8_t mask = 1 << (attachment - GL_COLOR_ATTACHMENT0);
590       if ((mFrameBufferColorStatus & mask) == 0)
591       {
592         mFrameBufferColorStatus |= mask;
593         ++mFramebufferColorAttachmentCount;
594       }
595     }
596   }
597
598   inline void FrontFace(GLenum mode)
599   {
600   }
601
602   inline void GenBuffers(GLsizei n, GLuint* buffers)
603   {
604     // avoids an assert in GpuBuffers
605     *buffers = 1u;
606   }
607
608   inline void GenerateMipmap(GLenum target)
609   {
610     std::stringstream out;
611     out<<target;
612     TraceCallStack::NamedParams namedParams;
613     namedParams["target"] = ToString(target);
614
615     mTextureTrace.PushCall("GenerateMipmap", out.str(), namedParams);
616   }
617
618   inline void GenFramebuffers(GLsizei n, GLuint* framebuffers)
619   {
620     for( int i = 0; i < n; i++ )
621     {
622       framebuffers[i] = i + 1;
623     }
624
625     //Add 001 bit, this function needs to be called the first one in the chain
626     mFramebufferStatus = 1;
627   }
628
629   inline void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
630   {
631     for( int i = 0; i < n; i++ )
632     {
633       renderbuffers[i] = i + 1;
634     }
635   }
636
637   /**
638    * This method can be used by test cases, to manipulate the texture IDs generated by GenTextures.
639    * @param[in] ids A vector containing the next IDs to be generated
640    */
641   inline void SetNextTextureIds( const std::vector<GLuint>& ids )
642   {
643     mNextTextureIds = ids;
644   }
645
646   inline const std::vector<GLuint>& GetNextTextureIds()
647   {
648     return mNextTextureIds;
649   }
650
651   inline void GenTextures(GLsizei count, GLuint* textures)
652   {
653     for( int i=0; i<count; ++i )
654     {
655       if( !mNextTextureIds.empty() )
656       {
657         *(textures+i) = mNextTextureIds[0];
658         mNextTextureIds.erase( mNextTextureIds.begin() );
659       }
660       else
661       {
662         *(textures+i) = ++mLastAutoTextureIdUsed;
663       }
664       mNumGeneratedTextures++;
665     }
666
667     TraceCallStack::NamedParams namedParams;
668     namedParams["count"] = ToString(count);
669
670     std::stringstream out;
671     for(int i=0; i<count; i++)
672     {
673       out << textures[i];
674       if(i<count-1)
675       {
676         out << ", ";
677       }
678       std::ostringstream oss;
679       oss<<"indices["<<i<<"]";
680       namedParams[oss.str()] = ToString(textures[i]);
681     }
682
683     mTextureTrace.PushCall("GenTextures", out.str(), namedParams);
684   }
685
686   inline GLuint GetLastGenTextureId()
687   {
688     return mLastAutoTextureIdUsed;
689   }
690   inline GLuint GetNumGeneratedTextures()
691   {
692     return mNumGeneratedTextures;
693   }
694
695   inline void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
696   {
697   }
698
699   inline void GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
700   {
701     switch(index)
702     {
703       case 0:
704         *length = snprintf(name, bufsize, "sTexture");
705         *type = GL_SAMPLER_2D;
706         *size = 1;
707         break;
708       case 1:
709         *length = snprintf(name, bufsize, "sEffect");
710         *type = GL_SAMPLER_2D;
711         *size = 1;
712         break;
713       case 2:
714         *length = snprintf(name, bufsize, "sGloss");
715         *type = GL_SAMPLER_2D;
716         *size = 1;
717         break;
718       default:
719         break;
720     }
721   }
722
723   inline void GetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
724   {
725   }
726
727   inline int  GetAttribLocation(GLuint program, const char* name)
728   {
729     std::string attribName(name);
730
731     for( unsigned int i = 0; i < ATTRIB_TYPE_LAST; ++i )
732     {
733       if( mStdAttribs[i] == attribName )
734       {
735         return i;
736       }
737     }
738
739     // 0 is a valid location
740     return 0;
741   }
742
743   inline void GetBooleanv(GLenum pname, GLboolean* params)
744   {
745   }
746
747   inline void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
748   {
749   }
750
751   inline GLenum GetError(void)
752   {
753     return mGetErrorResult;
754   }
755
756   inline void GetFloatv(GLenum pname, GLfloat* params)
757   {
758   }
759
760   inline void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
761   {
762   }
763
764   inline void GetIntegerv(GLenum pname, GLint* params)
765   {
766     switch( pname )
767     {
768       case GL_MAX_TEXTURE_SIZE:
769         *params = 2048;
770         break;
771       case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
772         *params = 8;
773         break;
774       case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
775         *params = mNumBinaryFormats;
776         break;
777       case GL_PROGRAM_BINARY_FORMATS_OES:
778         *params = mBinaryFormats;
779         break;
780     }
781   }
782
783   inline void GetProgramiv(GLuint program, GLenum pname, GLint* params)
784   {
785     switch( pname )
786     {
787       case GL_LINK_STATUS:
788         *params = mLinkStatus;
789         break;
790       case GL_PROGRAM_BINARY_LENGTH_OES:
791         *params = mProgramBinaryLength;
792         break;
793       case GL_ACTIVE_UNIFORMS:
794         *params = mNumberOfActiveUniforms;
795         break;
796       case GL_ACTIVE_UNIFORM_MAX_LENGTH:
797         *params = 100;
798         break;
799     }
800   }
801
802   inline void GetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog)
803   {
804   }
805
806   inline void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
807   {
808   }
809
810   inline void GetShaderiv(GLuint shader, GLenum pname, GLint* params)
811   {
812     switch( pname ) {
813       case GL_COMPILE_STATUS:
814         *params = mCompileStatus;
815         break;
816     }
817   }
818
819   inline void GetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog)
820   {
821   }
822
823   inline void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
824   {
825   }
826
827   inline const GLubyte* GetString(GLenum name)
828   {
829     return mGetStringResult;
830   }
831
832   inline void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
833   {
834   }
835
836   inline void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
837   {
838   }
839
840   inline void GetUniformfv(GLuint program, GLint location, GLfloat* params)
841   {
842   }
843
844   inline void GetUniformiv(GLuint program, GLint location, GLint* params)
845   {
846   }
847
848   inline GLint GetUniformLocation(GLuint program, const char* name)
849   {
850     ProgramUniformMap::iterator it = mUniforms.find(program);
851     if( it == mUniforms.end() )
852     {
853       // Not a valid program ID
854       mGetErrorResult = GL_INVALID_OPERATION;
855       return -1;
856     }
857
858     UniformIDMap& uniformIDs = it->second;
859     UniformIDMap::iterator it2 = uniformIDs.find( name );
860     if( it2 == uniformIDs.end() )
861     {
862       // Uniform not found, so add it...
863       uniformIDs[name] = ++mLastUniformIdUsed;
864       return mLastUniformIdUsed;
865     }
866
867     return it2->second;
868   }
869
870   inline void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
871   {
872   }
873
874   inline void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
875   {
876   }
877
878   inline void GetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer)
879   {
880   }
881
882   inline void Hint(GLenum target, GLenum mode)
883   {
884   }
885
886   inline GLboolean IsBuffer(GLuint buffer)
887   {
888     return mIsBufferResult;
889   }
890
891   inline GLboolean IsEnabled(GLenum cap)
892   {
893     return mIsEnabledResult;
894   }
895
896   inline GLboolean IsFramebuffer(GLuint framebuffer)
897   {
898     return mIsFramebufferResult;
899   }
900
901   inline GLboolean IsProgram(GLuint program)
902   {
903     return mIsProgramResult;
904   }
905
906   inline GLboolean IsRenderbuffer(GLuint renderbuffer)
907   {
908     return mIsRenderbufferResult;
909   }
910
911   inline GLboolean IsShader(GLuint shader)
912   {
913     return mIsShaderResult;
914   }
915
916   inline GLboolean IsTexture(GLuint texture)
917   {
918     return mIsTextureResult;
919   }
920
921   inline void LineWidth(GLfloat width)
922   {
923   }
924
925   inline void LinkProgram(GLuint program)
926   {
927     std::stringstream out;
928     out << program;
929
930     TraceCallStack::NamedParams namedParams;
931     namedParams["program"] = ToString(program);
932     mShaderTrace.PushCall("LinkProgram", out.str(), namedParams);
933
934     mNumberOfActiveUniforms=3;
935     GetUniformLocation(program, "sTexture");
936     GetUniformLocation(program, "sEffect");
937     GetUniformLocation(program, "sGloss");
938   }
939
940   inline void PixelStorei(GLenum pname, GLint param)
941   {
942   }
943
944   inline void PolygonOffset(GLfloat factor, GLfloat units)
945   {
946   }
947
948   inline void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
949   {
950   }
951
952   inline void ReleaseShaderCompiler(void)
953   {
954   }
955
956   inline void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
957   {
958   }
959
960   inline void SampleCoverage(GLclampf value, GLboolean invert)
961   {
962   }
963
964   inline void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
965   {
966     mScissorParams.x = x;
967     mScissorParams.y = y;
968     mScissorParams.width = width;
969     mScissorParams.height = height;
970
971     std::stringstream out;
972     out << x << ", " << y << ", " << width << ", " << height;
973     TraceCallStack::NamedParams namedParams;
974     namedParams["x"] = ToString( x );
975     namedParams["y"] = ToString( y );
976     namedParams["width"] = ToString( width );
977     namedParams["height"] = ToString( height );
978     mScissorTrace.PushCall( "Scissor", out.str(), namedParams );
979   }
980
981   inline void ShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
982   {
983   }
984
985   inline void ShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
986   {
987     std::string stringBuilder;
988     for(int i = 0; i < count; ++i)
989     {
990       stringBuilder += string[i];
991     }
992     mShaderSources[shader] = stringBuilder;
993     mLastShaderCompiled = shader;
994   }
995
996   inline void GetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source)
997   {
998     const std::string shaderSource = mShaderSources[shader];
999     const int shaderSourceLength = static_cast<int>(shaderSource.length());
1000     if( shaderSourceLength < bufsize )
1001     {
1002       strncpy( source, shaderSource.c_str(), shaderSourceLength );
1003       *length = shaderSourceLength;
1004     }
1005     else
1006     {
1007       *length = bufsize -1;
1008       strncpy(source, shaderSource.c_str(), *length);
1009       source[*length] = 0x0;
1010     }
1011   }
1012
1013   inline std::string GetShaderSource(GLuint shader)
1014   {
1015     return mShaderSources[shader];
1016   }
1017
1018   inline void StencilFunc(GLenum func, GLint ref, GLuint mask)
1019   {
1020     std::stringstream out;
1021     out << func << ", " << ref << ", " << mask;
1022
1023     TraceCallStack::NamedParams namedParams;
1024     namedParams["func"] = ToString( func );
1025     namedParams["ref"] = ToString( ref );
1026     namedParams["mask"] = ToString( mask );
1027
1028     mStencilFunctionTrace.PushCall( "StencilFunc", out.str(), namedParams );
1029   }
1030
1031   inline void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
1032   {
1033     std::stringstream out;
1034     out << face << ", " << func << ", " << ref << ", " << mask;
1035
1036     TraceCallStack::NamedParams namedParams;
1037     namedParams["face"] = ToString( face );
1038     namedParams["func"] = ToString( func );
1039     namedParams["ref"] = ToString( ref );
1040     namedParams["mask"] = ToString( mask );
1041
1042     mStencilFunctionTrace.PushCall( "StencilFuncSeparate", out.str(), namedParams );
1043   }
1044
1045   inline void StencilMask(GLuint mask)
1046   {
1047     std::stringstream out;
1048     out << mask;
1049
1050     TraceCallStack::NamedParams namedParams;
1051     namedParams["mask"] = ToString( mask );
1052
1053     mStencilFunctionTrace.PushCall( "StencilMask", out.str(), namedParams );
1054   }
1055
1056   inline void StencilMaskSeparate(GLenum face, GLuint mask)
1057   {
1058     std::stringstream out;
1059     out << face << ", " << mask;
1060
1061     TraceCallStack::NamedParams namedParams;
1062     namedParams["face"] = ToString( face );
1063     namedParams["mask"] = ToString( mask );
1064
1065     mStencilFunctionTrace.PushCall( "StencilMaskSeparate", out.str(), namedParams );
1066   }
1067
1068   inline void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
1069   {
1070     std::stringstream out;
1071     out << fail << ", " << zfail << ", " << zpass;
1072
1073     TraceCallStack::NamedParams namedParams;
1074     namedParams["fail"] = ToString( fail );
1075     namedParams["zfail"] = ToString( zfail );
1076     namedParams["zpass"] = ToString( zpass );
1077
1078     mStencilFunctionTrace.PushCall( "StencilOp", out.str(), namedParams );
1079   }
1080
1081   inline void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
1082   {
1083     std::stringstream out;
1084     out << face << ", " << fail << ", " << zfail << "," << zpass;
1085
1086     TraceCallStack::NamedParams namedParams;
1087     namedParams["face"] = ToString( face );
1088     namedParams["fail"] = ToString( fail );
1089     namedParams["zfail"] = ToString( zfail );
1090     namedParams["zpass"] = ToString( zpass );
1091
1092     mStencilFunctionTrace.PushCall( "StencilOpSeparate", out.str(), namedParams );
1093   }
1094
1095   inline void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels)
1096   {
1097     std::stringstream out;
1098     out << target<<", "<<level<<", "<<width << ", " << height;
1099
1100     TraceCallStack::NamedParams namedParams;
1101     namedParams["target"] = ToString(target);
1102     namedParams["level"] = ToString(level);
1103     namedParams["internalformat"] = ToString(internalformat);
1104     namedParams["width"] = ToString(width);
1105     namedParams["height"] = ToString(height);
1106     namedParams["border"] = ToString(border);
1107     namedParams["format"] = ToString(format);
1108     namedParams["type"] = ToString(type);
1109
1110     mTextureTrace.PushCall("TexImage2D", out.str(), namedParams);
1111   }
1112
1113   inline void TexParameterf(GLenum target, GLenum pname, GLfloat param)
1114   {
1115     std::stringstream out;
1116     out << target << ", " << pname << ", " << param;
1117
1118     TraceCallStack::NamedParams namedParams;
1119     namedParams["target"] = ToString(target);
1120     namedParams["pname"] = ToString(pname);
1121     namedParams["param"] = ToString(param);
1122
1123     mTexParamaterTrace.PushCall("TexParameterf", out.str(), namedParams);
1124   }
1125
1126   inline void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
1127   {
1128     std::stringstream out;
1129     out << target << ", " << pname << ", " << params[0];
1130
1131     TraceCallStack::NamedParams namedParams;
1132     namedParams["target"] = ToString(target);
1133     namedParams["pname"] = ToString(pname);
1134     namedParams["params[0]"] = ToString(params[0]);
1135
1136     mTexParamaterTrace.PushCall("TexParameterfv", out.str(), namedParams);
1137   }
1138
1139   inline void TexParameteri(GLenum target, GLenum pname, GLint param)
1140   {
1141     std::stringstream out;
1142     out << target << ", " << pname << ", " << param;
1143     TraceCallStack::NamedParams namedParams;
1144     namedParams["target"] = ToString(target);
1145     namedParams["pname"] = ToString(pname);
1146     namedParams["param"] = ToString(param);
1147     mTexParamaterTrace.PushCall("TexParameteri", out.str(), namedParams);
1148   }
1149
1150   inline void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
1151   {
1152     std::stringstream out;
1153     out << target << ", " << pname << ", " << params[0];
1154     TraceCallStack::NamedParams namedParams;
1155     namedParams["target"] = ToString(target);
1156     namedParams["pname"] = ToString(pname);
1157     namedParams["params[0]"] = ToString(params[0]);
1158     mTexParamaterTrace.PushCall("TexParameteriv", out.str(), namedParams);
1159   }
1160
1161   inline void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
1162   {
1163     std::stringstream out;
1164     out << target << ", "<<level <<", " << xoffset << ", " << yoffset << ", " << width << ", " << height;
1165
1166     TraceCallStack::NamedParams namedParams;
1167     namedParams["target"] = ToString(target);
1168     namedParams["level"] = ToString(level);
1169     namedParams["xoffset"] = ToString(xoffset);
1170     namedParams["yoffset"] = ToString(yoffset);
1171     namedParams["width"] = ToString(width);
1172     namedParams["height"] = ToString(height);
1173     mTextureTrace.PushCall("TexSubImage2D", out.str(), namedParams);
1174   }
1175
1176   inline void Uniform1f(GLint location, GLfloat value )
1177   {
1178     std::string params = ToString( value );
1179     AddUniformCallToTraceStack( location, params );
1180
1181     if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, value ) )
1182     {
1183       mGetErrorResult = GL_INVALID_OPERATION;
1184     }
1185   }
1186
1187   inline void Uniform1fv(GLint location, GLsizei count, const GLfloat* v)
1188   {
1189     std::string params;
1190     for( int i = 0; i < count; ++i )
1191     {
1192       params = params + ToString( v[i] ) + ",";
1193     }
1194
1195     AddUniformCallToTraceStack( location, params );
1196
1197     for( int i = 0; i < count; ++i )
1198     {
1199       if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, v[i] ) )
1200       {
1201         mGetErrorResult = GL_INVALID_OPERATION;
1202         break;
1203       }
1204     }
1205   }
1206
1207   inline void Uniform1i(GLint location, GLint x)
1208   {
1209     std::string params = ToString( x );
1210
1211     AddUniformCallToTraceStack( location,  params );
1212
1213     if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram, location, x ) )
1214     {
1215       mGetErrorResult = GL_INVALID_OPERATION;
1216     }
1217   }
1218
1219   inline void Uniform1iv(GLint location, GLsizei count, const GLint* v)
1220   {
1221     std::string params = ToString( v );
1222     AddUniformCallToTraceStack( location, params );
1223
1224     for( int i = 0; i < count; ++i )
1225     {
1226       if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram,
1227                                                  location,
1228                                                  v[i] ) )
1229       {
1230         mGetErrorResult = GL_INVALID_OPERATION;
1231         break;
1232       }
1233     }
1234   }
1235
1236   inline void Uniform2f(GLint location, GLfloat x, GLfloat y)
1237   {
1238     std::string params = ToString( x ) + "," + ToString( y );
1239     AddUniformCallToTraceStack( location, params );
1240
1241     if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
1242                                                location,
1243                                                Vector2( x, y ) ) )
1244     {
1245       mGetErrorResult = GL_INVALID_OPERATION;
1246     }
1247   }
1248
1249   inline void Uniform2fv(GLint location, GLsizei count, const GLfloat* v)
1250   {
1251     std::string params = ToString( v );
1252     AddUniformCallToTraceStack( location, params );
1253
1254     for( int i = 0; i < count; ++i )
1255     {
1256       if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
1257                                                  location,
1258                                                  Vector2( v[2*i], v[2*i+1] ) ) )
1259       {
1260         mGetErrorResult = GL_INVALID_OPERATION;
1261         break;
1262       }
1263     }
1264   }
1265
1266   inline void Uniform2i(GLint location, GLint x, GLint y)
1267   {
1268     std::string params = ToString( x ) + "," + ToString( y );
1269     AddUniformCallToTraceStack( location, params );
1270   }
1271
1272   inline void Uniform2iv(GLint location, GLsizei count, const GLint* v)
1273   {
1274     std::string params = ToString( v );
1275     AddUniformCallToTraceStack( location, params );
1276   }
1277
1278   inline void Uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
1279   {
1280     std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z );
1281     AddUniformCallToTraceStack( location, params );
1282
1283     if( ! mProgramUniforms3f.SetUniformValue( mCurrentProgram,
1284                                                location,
1285                                                Vector3( x, y, z ) ) )
1286     {
1287       mGetErrorResult = GL_INVALID_OPERATION;
1288     }
1289   }
1290
1291   inline void Uniform3fv(GLint location, GLsizei count, const GLfloat* v)
1292   {
1293     std::string params = ToString( v );
1294     AddUniformCallToTraceStack( location, params );
1295
1296     for( int i = 0; i < count; ++i )
1297     {
1298       if( ! mProgramUniforms3f.SetUniformValue(
1299           mCurrentProgram,
1300           location,
1301           Vector3( v[3*i], v[3*i+1], v[3*i+2] ) ) )
1302       {
1303         mGetErrorResult = GL_INVALID_OPERATION;
1304         break;
1305       }
1306     }
1307   }
1308
1309   inline void Uniform3i(GLint location, GLint x, GLint y, GLint z)
1310   {
1311     std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z );
1312     AddUniformCallToTraceStack( location, params );
1313   }
1314
1315   inline void Uniform3iv(GLint location, GLsizei count, const GLint* v)
1316   {
1317     std::string params = ToString( v );
1318     AddUniformCallToTraceStack( location, params );
1319   }
1320
1321   inline void Uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
1322   {
1323     std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z ) + "," + ToString( w );
1324     AddUniformCallToTraceStack( location, params );
1325
1326     if( ! mProgramUniforms4f.SetUniformValue( mCurrentProgram,
1327                                               location,
1328                                               Vector4( x, y, z, w ) ) )
1329     {
1330       mGetErrorResult = GL_INVALID_OPERATION;
1331     }
1332   }
1333
1334   inline void Uniform4fv(GLint location, GLsizei count, const GLfloat* v)
1335   {
1336     std::string params = ToString( v );
1337     AddUniformCallToTraceStack( location, params );
1338
1339     for( int i = 0; i < count; ++i )
1340     {
1341       if( ! mProgramUniforms4f.SetUniformValue(
1342           mCurrentProgram,
1343           location,
1344           Vector4( v[4*i], v[4*i+1], v[4*i+2], v[4*i+3] ) ) )
1345       {
1346         mGetErrorResult = GL_INVALID_OPERATION;
1347         break;
1348       }
1349     }
1350   }
1351
1352   inline void Uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
1353   {
1354     std::string params = ToString( x ) + "," + ToString( y ) + "," + ToString( z ) + "," + ToString( w );
1355     AddUniformCallToTraceStack( location, params );
1356   }
1357
1358   inline void Uniform4iv(GLint location, GLsizei count, const GLint* v)
1359   {
1360     std::string params = ToString( v );
1361     AddUniformCallToTraceStack( location, params );
1362   }
1363
1364   inline void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1365   {
1366     std::string params = ToString( value );
1367     AddUniformCallToTraceStack( location, params );
1368   }
1369
1370   inline void UniformMatrix3fv(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( ! mProgramUniformsMat3.SetUniformValue(
1378             mCurrentProgram,
1379             location,
1380             Matrix3( value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8] ) ) )
1381       {
1382         mGetErrorResult = GL_INVALID_OPERATION;
1383         break;
1384       }
1385     }
1386   }
1387
1388   inline void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1389   {
1390     std::string params = ToString( value );
1391     AddUniformCallToTraceStack( location, params );
1392
1393     for( int i = 0; i < count; ++i )
1394     {
1395       if( ! mProgramUniformsMat4.SetUniformValue(
1396           mCurrentProgram,
1397           location,
1398           Matrix( value ) ) )
1399       {
1400         mGetErrorResult = GL_INVALID_OPERATION;
1401         break;
1402       }
1403     }
1404   }
1405
1406   inline void UseProgram(GLuint program)
1407   {
1408     mCurrentProgram = program;
1409   }
1410
1411   inline void ValidateProgram(GLuint program)
1412   {
1413   }
1414
1415   inline void VertexAttrib1f(GLuint indx, GLfloat x)
1416   {
1417   }
1418
1419   inline void VertexAttrib1fv(GLuint indx, const GLfloat* values)
1420   {
1421   }
1422
1423   inline void VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
1424   {
1425   }
1426
1427   inline void VertexAttrib2fv(GLuint indx, const GLfloat* values)
1428   {
1429   }
1430
1431   inline void VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
1432   {
1433   }
1434
1435   inline void VertexAttrib3fv(GLuint indx, const GLfloat* values)
1436   {
1437   }
1438
1439   inline void VertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
1440   {
1441   }
1442
1443   inline void VertexAttrib4fv(GLuint indx, const GLfloat* values)
1444   {
1445   }
1446
1447   inline void VertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
1448   {
1449   }
1450
1451   inline void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1452   {
1453     std::string commaString(", ");
1454     std::string params( std::to_string(x) + commaString + std::to_string(y) + commaString + std::to_string(width) + commaString + std::to_string(height) );
1455
1456     mViewportTrace.PushCall("Viewport", params);
1457   }
1458
1459   /* OpenGL ES 3.0 */
1460
1461   inline void ReadBuffer(GLenum mode)
1462   {
1463   }
1464
1465   inline void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
1466   {
1467   }
1468
1469   inline void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
1470   {
1471   }
1472
1473   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)
1474   {
1475   }
1476
1477   inline void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1478   {
1479   }
1480
1481   inline void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
1482   {
1483   }
1484
1485   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)
1486   {
1487   }
1488
1489   inline void GenQueries(GLsizei n, GLuint* ids)
1490   {
1491   }
1492
1493   inline void DeleteQueries(GLsizei n, const GLuint* ids)
1494   {
1495   }
1496
1497   inline GLboolean IsQuery(GLuint id)
1498   {
1499     return false;
1500   }
1501
1502   inline void BeginQuery(GLenum target, GLuint id)
1503   {
1504   }
1505
1506   inline void EndQuery(GLenum target)
1507   {
1508   }
1509
1510   inline void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1511   {
1512   }
1513
1514   inline void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1515   {
1516   }
1517
1518   inline GLboolean UnmapBuffer(GLenum target)
1519   {
1520     return false;
1521   }
1522
1523   inline void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1524   {
1525   }
1526
1527   inline void DrawBuffers(GLsizei n, const GLenum* bufs)
1528   {
1529   }
1530
1531   inline void UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1532   {
1533   }
1534
1535   inline void UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1536   {
1537   }
1538
1539   inline void UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1540   {
1541   }
1542
1543   inline void UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1544   {
1545   }
1546
1547   inline void UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1548   {
1549   }
1550
1551   inline void UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1552   {
1553   }
1554
1555   inline void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
1556   {
1557   }
1558
1559   inline void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1560   {
1561   }
1562
1563   inline void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1564   {
1565   }
1566
1567   inline GLvoid* MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
1568   {
1569     return NULL;
1570   }
1571
1572   inline void FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
1573   {
1574   }
1575
1576   inline void BindVertexArray(GLuint array)
1577   {
1578   }
1579
1580   inline void DeleteVertexArrays(GLsizei n, const GLuint* arrays)
1581   {
1582   }
1583
1584   inline void GenVertexArrays(GLsizei n, GLuint* arrays)
1585   {
1586   }
1587
1588   inline GLboolean IsVertexArray(GLuint array)
1589   {
1590     return false;
1591   }
1592
1593   inline void GetIntegeri_v(GLenum target, GLuint index, GLint* data)
1594   {
1595   }
1596
1597   inline void BeginTransformFeedback(GLenum primitiveMode)
1598   {
1599   }
1600
1601   inline void EndTransformFeedback(void)
1602   {
1603   }
1604
1605   inline void BindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
1606   {
1607   }
1608
1609   inline void BindBufferBase(GLenum target, GLuint index, GLuint buffer)
1610   {
1611   }
1612
1613   inline void TransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
1614   {
1615   }
1616
1617   inline void GetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
1618   {
1619   }
1620
1621   inline void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
1622   {
1623   }
1624
1625   inline void GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
1626   {
1627   }
1628
1629   inline void GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
1630   {
1631   }
1632
1633   inline void VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
1634   {
1635   }
1636
1637   inline void VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
1638   {
1639   }
1640
1641   inline void VertexAttribI4iv(GLuint index, const GLint* v)
1642   {
1643   }
1644
1645   inline void VertexAttribI4uiv(GLuint index, const GLuint* v)
1646   {
1647   }
1648
1649   inline void GetUniformuiv(GLuint program, GLint location, GLuint* params)
1650   {
1651   }
1652
1653   inline GLint GetFragDataLocation(GLuint program, const GLchar *name)
1654   {
1655     return -1;
1656   }
1657
1658   inline void Uniform1ui(GLint location, GLuint v0)
1659   {
1660   }
1661
1662   inline void Uniform2ui(GLint location, GLuint v0, GLuint v1)
1663   {
1664   }
1665
1666   inline void Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
1667   {
1668   }
1669
1670   inline void Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1671   {
1672   }
1673
1674   inline void Uniform1uiv(GLint location, GLsizei count, const GLuint* value)
1675   {
1676   }
1677
1678   inline void Uniform2uiv(GLint location, GLsizei count, const GLuint* value)
1679   {
1680   }
1681
1682   inline void Uniform3uiv(GLint location, GLsizei count, const GLuint* value)
1683   {
1684   }
1685
1686   inline void Uniform4uiv(GLint location, GLsizei count, const GLuint* value)
1687   {
1688   }
1689
1690   inline void ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
1691   {
1692   }
1693
1694   inline void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
1695   {
1696   }
1697
1698   inline void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
1699   {
1700   }
1701
1702   inline void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
1703   {
1704   }
1705
1706   inline const GLubyte* GetStringi(GLenum name, GLuint index)
1707   {
1708     return NULL;
1709   }
1710
1711   inline void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
1712   {
1713   }
1714
1715   inline void GetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
1716   {
1717   }
1718
1719   inline void GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
1720   {
1721   }
1722
1723   inline GLuint GetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
1724   {
1725     return GL_INVALID_INDEX;
1726   }
1727
1728   inline void GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
1729   {
1730   }
1731
1732   inline void GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
1733   {
1734   }
1735
1736   inline void UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
1737   {
1738   }
1739
1740   inline void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
1741   {
1742   }
1743
1744   inline void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
1745   {
1746   }
1747
1748   inline GLsync FenceSync(GLenum condition, GLbitfield flags)
1749   {
1750     return NULL;
1751   }
1752
1753   inline GLboolean IsSync(GLsync sync)
1754   {
1755     return false;
1756   }
1757
1758   inline void DeleteSync(GLsync sync)
1759   {
1760   }
1761
1762   inline GLenum ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1763   {
1764     return 0;
1765   }
1766
1767   inline void WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1768   {
1769   }
1770
1771   inline void GetInteger64v(GLenum pname, GLint64* params)
1772   {
1773   }
1774
1775   inline void GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
1776   {
1777   }
1778
1779   inline void GetInteger64i_v(GLenum target, GLuint index, GLint64* data)
1780   {
1781   }
1782
1783   inline void GetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
1784   {
1785   }
1786
1787   inline void GenSamplers(GLsizei count, GLuint* samplers)
1788   {
1789   }
1790
1791   inline void DeleteSamplers(GLsizei count, const GLuint* samplers)
1792   {
1793   }
1794
1795   inline GLboolean IsSampler(GLuint sampler)
1796   {
1797     return false;
1798   }
1799
1800   inline void BindSampler(GLuint unit, GLuint sampler)
1801   {
1802   }
1803
1804   inline void SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
1805   {
1806   }
1807
1808   inline void SamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
1809   {
1810   }
1811
1812   inline void SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
1813   {
1814   }
1815
1816   inline void SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
1817   {
1818   }
1819
1820   inline void GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
1821   {
1822   }
1823
1824   inline void GetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
1825   {
1826   }
1827
1828   inline void VertexAttribDivisor(GLuint index, GLuint divisor)
1829   {
1830   }
1831
1832   inline void BindTransformFeedback(GLenum target, GLuint id)
1833   {
1834   }
1835
1836   inline void DeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
1837   {
1838   }
1839
1840   inline void GenTransformFeedbacks(GLsizei n, GLuint* ids)
1841   {
1842   }
1843
1844   inline GLboolean IsTransformFeedback(GLuint id)
1845   {
1846     return false;
1847   }
1848
1849   inline void PauseTransformFeedback(void)
1850   {
1851   }
1852
1853   inline void ResumeTransformFeedback(void)
1854   {
1855   }
1856
1857   inline void GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
1858   {
1859     mGetProgramBinaryCalled = true;
1860   }
1861
1862   inline void ProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
1863   {
1864   }
1865
1866   inline void ProgramParameteri(GLuint program, GLenum pname, GLint value)
1867   {
1868   }
1869
1870   inline void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
1871   {
1872   }
1873
1874   inline void InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
1875   {
1876   }
1877
1878   inline void TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
1879   {
1880   }
1881
1882   inline void TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
1883   {
1884   }
1885
1886   inline void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
1887   {
1888   }
1889
1890 private:
1891
1892   inline void AddUniformCallToTraceStack( GLint location, std::string& value )
1893     {
1894     std::string name = "<not found>";
1895     bool matched = false;
1896
1897     UniformIDMap& map = mUniforms[mCurrentProgram];
1898     for (UniformIDMap::iterator it=map.begin(); it!=map.end(); ++it)
1899     {
1900       if( it->second == location )
1901       {
1902         name = it->first;
1903         matched = true;
1904         break;
1905       }
1906     }
1907
1908     if ( matched )
1909     {
1910       mSetUniformTrace.PushCall( name, value );
1911     }
1912   }
1913
1914
1915 public: // TEST FUNCTIONS
1916   inline void SetCompileStatus( GLuint value ) { mCompileStatus = value; }
1917   inline void SetLinkStatus( GLuint value ) { mLinkStatus = value; }
1918   inline void SetGetAttribLocationResult(  int result) { mGetAttribLocationResult = result; }
1919   inline void SetGetErrorResult(  GLenum result) { mGetErrorResult = result; }
1920   inline void SetGetStringResult(  GLubyte* result) { mGetStringResult = result; }
1921   inline void SetIsBufferResult(  GLboolean result) { mIsBufferResult = result; }
1922   inline void SetIsEnabledResult(  GLboolean result) { mIsEnabledResult = result; }
1923   inline void SetIsFramebufferResult(  GLboolean result) { mIsFramebufferResult = result; }
1924   inline void SetIsProgramResult(  GLboolean result) { mIsProgramResult = result; }
1925   inline void SetIsRenderbufferResult(  GLboolean result) { mIsRenderbufferResult = result; }
1926   inline void SetIsShaderResult(  GLboolean result) { mIsShaderResult = result; }
1927   inline void SetIsTextureResult(  GLboolean result) { mIsTextureResult = result; }
1928   inline void SetCheckFramebufferStatusResult(  GLenum result) { mCheckFramebufferStatusResult = result; }
1929   inline void SetNumBinaryFormats( GLint numFormats ) { mNumBinaryFormats = numFormats; }
1930   inline void SetBinaryFormats( GLint binaryFormats ) { mBinaryFormats = binaryFormats; }
1931   inline void SetProgramBinaryLength( GLint length ) { mProgramBinaryLength = length; }
1932
1933   inline bool GetVertexAttribArrayState(GLuint index)
1934   {
1935     if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1936     {
1937       // out of range
1938       return false;
1939     }
1940     return mVertexAttribArrayState[ index ];
1941   }
1942   inline void ClearVertexAttribArrayChanged() {  mVertexAttribArrayChanged = false; }
1943   inline bool GetVertexAttribArrayChanged()  { return mVertexAttribArrayChanged; }
1944
1945   //Methods for CullFace verification
1946   inline void EnableCullFaceCallTrace(bool enable) { mCullFaceTrace.Enable(enable); }
1947   inline void ResetCullFaceCallStack() { mCullFaceTrace.Reset(); }
1948   inline TraceCallStack& GetCullFaceTrace() { return mCullFaceTrace; }
1949
1950   //Methods for Enable/Disable call verification
1951   inline void EnableEnableDisableCallTrace(bool enable) { mEnableDisableTrace.Enable(enable); }
1952   inline void ResetEnableDisableCallStack() { mEnableDisableTrace.Reset(); }
1953   inline TraceCallStack& GetEnableDisableTrace() { return mEnableDisableTrace; }
1954
1955   //Methods for Shader verification
1956   inline void EnableShaderCallTrace(bool enable) { mShaderTrace.Enable(enable); }
1957   inline void ResetShaderCallStack() { mShaderTrace.Reset(); }
1958   inline TraceCallStack& GetShaderTrace() { return mShaderTrace; }
1959
1960   //Methods for Texture verification
1961   inline void EnableTextureCallTrace(bool enable) { mTextureTrace.Enable(enable); }
1962   inline void ResetTextureCallStack() { mTextureTrace.Reset(); }
1963   inline TraceCallStack& GetTextureTrace() { return mTextureTrace; }
1964
1965   //Methods for Texture verification
1966   inline void EnableTexParameterCallTrace(bool enable) { mTexParamaterTrace.Enable(enable); }
1967   inline void ResetTexParameterCallStack() { mTexParamaterTrace.Reset(); }
1968   inline TraceCallStack& GetTexParameterTrace() { return mTexParamaterTrace; }
1969
1970   //Methods for Draw verification
1971   inline void EnableDrawCallTrace(bool enable) { mDrawTrace.Enable(enable); }
1972   inline void ResetDrawCallStack() { mDrawTrace.Reset(); }
1973   inline TraceCallStack& GetDrawTrace() { return mDrawTrace; }
1974
1975   //Methods for Depth function verification
1976   inline void EnableDepthFunctionCallTrace(bool enable) { mDepthFunctionTrace.Enable(enable); }
1977   inline void ResetDepthFunctionCallStack() { mDepthFunctionTrace.Reset(); }
1978   inline TraceCallStack& GetDepthFunctionTrace() { return mDepthFunctionTrace; }
1979
1980   //Methods for Stencil function verification
1981   inline void EnableStencilFunctionCallTrace(bool enable) { mStencilFunctionTrace.Enable(enable); }
1982   inline void ResetStencilFunctionCallStack() { mStencilFunctionTrace.Reset(); }
1983   inline TraceCallStack& GetStencilFunctionTrace() { return mStencilFunctionTrace; }
1984
1985   //Methods for Scissor verification
1986   inline void EnableScissorCallTrace(bool enable) { mScissorTrace.Enable(enable); }
1987   inline void ResetScissorCallStack() { mScissorTrace.Reset(); }
1988   inline TraceCallStack& GetScissorTrace() { return mScissorTrace; }
1989
1990   //Methods for Uniform function verification
1991   inline void EnableSetUniformCallTrace(bool enable) { mSetUniformTrace.Enable(enable); }
1992   inline void ResetSetUniformCallStack() { mSetUniformTrace.Reset(); }
1993   inline TraceCallStack& GetSetUniformTrace() { return mSetUniformTrace; }
1994
1995   //Methods for Viewport verification
1996   inline void EnableViewportCallTrace(bool enable) { mViewportTrace.Enable(enable); }
1997   inline void ResetViewportCallStack() { mViewportTrace.Reset(); }
1998   inline TraceCallStack& GetViewportTrace() { return mViewportTrace; }
1999
2000   template <typename T>
2001   inline bool GetUniformValue( const char* name, T& value ) const
2002   {
2003     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
2004           program_it != mUniforms.end();
2005           ++program_it )
2006     {
2007       const UniformIDMap &uniformIDs = program_it->second;
2008
2009       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
2010       if( uniform_it != uniformIDs.end() )
2011       {
2012         // found one matching uniform name, lets check the value...
2013         GLuint programId = program_it->first;
2014         GLint uniformId = uniform_it->second;
2015
2016         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
2017         return mProgramUniforms.GetUniformValue( programId, uniformId, value );
2018       }
2019     }
2020     return false;
2021   }
2022
2023
2024   template <typename T>
2025   inline bool CheckUniformValue( const char* name, const T& value ) const
2026   {
2027     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
2028           program_it != mUniforms.end();
2029           ++program_it )
2030     {
2031       const UniformIDMap &uniformIDs = program_it->second;
2032
2033       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
2034       if( uniform_it != uniformIDs.end() )
2035       {
2036         // found one matching uniform name, lets check the value...
2037         GLuint programId = program_it->first;
2038         GLint uniformId = uniform_it->second;
2039
2040         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
2041         if( mProgramUniforms.CheckUniformValue( programId, uniformId, value ) )
2042         {
2043           // the value matches
2044           return true;
2045         }
2046       }
2047     }
2048
2049     fprintf(stderr, "Not found, printing possible values:\n" );
2050     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
2051           program_it != mUniforms.end();
2052           ++program_it )
2053     {
2054       const UniformIDMap &uniformIDs = program_it->second;
2055
2056       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
2057       if( uniform_it != uniformIDs.end() )
2058       {
2059         // found one matching uniform name, lets check the value...
2060         GLuint programId = program_it->first;
2061         GLint uniformId = uniform_it->second;
2062
2063         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
2064         T origValue;
2065         if ( mProgramUniforms.GetUniformValue(programId, uniformId, origValue) )
2066         {
2067           std::stringstream out;
2068           out << uniform_it->first << ": " << origValue;
2069           fprintf(stderr, "%s\n", out.str().c_str() );
2070         }
2071       }
2072     }
2073     return false;
2074   }
2075
2076   template <typename T>
2077   inline bool GetUniformValue( GLuint programId, GLuint uniformId, T& outValue) const
2078   {
2079     const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( outValue );
2080     return mProgramUniforms.GetUniformValue( programId, uniformId, outValue );
2081   }
2082
2083   inline bool GetUniformIds( const char* name, GLuint& programId, GLuint& uniformId ) const
2084   {
2085     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
2086           program_it != mUniforms.end();
2087           ++program_it )
2088     {
2089       const UniformIDMap &uniformIDs = program_it->second;
2090
2091       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
2092       if( uniform_it != uniformIDs.end() )
2093       {
2094         programId = program_it->first;
2095         uniformId = uniform_it->second;
2096         return true;
2097       }
2098     }
2099     return false;
2100   }
2101
2102   inline GLuint GetLastShaderCompiled() const
2103   {
2104     return mLastShaderCompiled;
2105   }
2106
2107   inline GLuint GetLastProgramCreated() const
2108   {
2109     return mLastProgramIdUsed;
2110   }
2111
2112   inline GLbitfield GetLastClearMask() const
2113   {
2114     return mLastClearBitMask;
2115   }
2116
2117   enum AttribType
2118   {
2119     ATTRIB_UNKNOWN = -1,
2120     ATTRIB_POSITION,
2121     ATTRIB_NORMAL,
2122     ATTRIB_TEXCOORD,
2123     ATTRIB_COLOR,
2124     ATTRIB_BONE_WEIGHTS,
2125     ATTRIB_BONE_INDICES,
2126     ATTRIB_TYPE_LAST
2127   };
2128
2129   struct ScissorParams
2130   {
2131     GLint x;
2132     GLint y;
2133     GLsizei width;
2134     GLsizei height;
2135
2136     ScissorParams() : x( 0 ), y( 0 ), width( 0 ), height( 0 ) { }
2137   };
2138
2139   // Methods to check scissor tests
2140   inline const ScissorParams& GetScissorParams() const { return mScissorParams; }
2141
2142   struct ColorMaskParams
2143   {
2144     GLboolean red;
2145     GLboolean green;
2146     GLboolean blue;
2147     GLboolean alpha;
2148
2149     ColorMaskParams() : red( true ), green( true ), blue( true ), alpha( true ) { }
2150   };
2151
2152   inline bool GetProgramBinaryCalled() const { return mGetProgramBinaryCalled; }
2153
2154   inline unsigned int GetClearCountCalled() const { return mClearCount; }
2155
2156   inline const ColorMaskParams& GetColorMaskParams() const { return mColorMaskParams; }
2157
2158   typedef std::vector<size_t> BufferDataCalls;
2159   inline const BufferDataCalls& GetBufferDataCalls() const { return mBufferDataCalls; }
2160   inline void ResetBufferDataCalls() { mBufferDataCalls.clear(); }
2161
2162   typedef std::vector<size_t> BufferSubDataCalls;
2163   inline const BufferSubDataCalls& GetBufferSubDataCalls() const { return mBufferSubDataCalls; }
2164   inline void ResetBufferSubDataCalls() { mBufferSubDataCalls.clear(); }
2165
2166 private:
2167   GLuint     mCurrentProgram;
2168   GLuint     mCompileStatus;
2169   BufferDataCalls mBufferDataCalls;
2170   BufferSubDataCalls mBufferSubDataCalls;
2171   GLuint     mLinkStatus;
2172   GLint      mNumberOfActiveUniforms;
2173   GLint      mGetAttribLocationResult;
2174   GLenum     mGetErrorResult;
2175   GLubyte*   mGetStringResult;
2176   GLboolean  mIsBufferResult;
2177   GLboolean  mIsEnabledResult;
2178   GLboolean  mIsFramebufferResult;
2179   GLboolean  mIsProgramResult;
2180   GLboolean  mIsRenderbufferResult;
2181   GLboolean  mIsShaderResult;
2182   GLboolean  mIsTextureResult;
2183   GLenum     mActiveTextureUnit;
2184   GLenum     mCheckFramebufferStatusResult;
2185   GLint      mFramebufferStatus;
2186   GLenum     mFramebufferDepthAttached;
2187   GLenum     mFramebufferStencilAttached;
2188   GLuint     mFramebufferColorAttachmentCount;
2189   GLuint     mFrameBufferColorStatus;
2190   GLint      mNumBinaryFormats;
2191   GLint      mBinaryFormats;
2192   GLint      mProgramBinaryLength;
2193   bool       mVertexAttribArrayState[MAX_ATTRIBUTE_CACHE_SIZE];
2194   bool       mVertexAttribArrayChanged;                            // whether the vertex attrib array has been changed
2195   bool       mGetProgramBinaryCalled;
2196   typedef std::map< GLuint, std::string> ShaderSourceMap;
2197   ShaderSourceMap mShaderSources;
2198   GLuint     mLastShaderCompiled;
2199   GLbitfield mLastClearBitMask;
2200   Vector4 mLastClearColor;
2201   unsigned int mClearCount;
2202
2203   Vector4 mLastBlendColor;
2204   GLenum  mLastBlendEquationRgb;
2205   GLenum  mLastBlendEquationAlpha;
2206   GLenum  mLastBlendFuncSrcRgb;
2207   GLenum  mLastBlendFuncDstRgb;
2208   GLenum  mLastBlendFuncSrcAlpha;
2209   GLenum  mLastBlendFuncDstAlpha;
2210
2211   GLboolean mLastDepthMask;
2212
2213   // Data for manipulating the IDs returned by GenTextures
2214   GLuint mLastAutoTextureIdUsed;
2215   GLuint mNumGeneratedTextures;
2216   std::vector<GLuint> mNextTextureIds;
2217   std::vector<GLuint> mDeletedTextureIds;
2218   std::vector<GLuint> mBoundTextures;
2219
2220   struct ActiveTextureType
2221   {
2222     std::vector<GLuint> mBoundTextures;
2223   };
2224
2225   ActiveTextureType mActiveTextures[ MIN_TEXTURE_UNIT_LIMIT ];
2226
2227   TraceCallStack mCullFaceTrace;
2228   TraceCallStack mEnableDisableTrace;
2229   TraceCallStack mShaderTrace;
2230   TraceCallStack mTextureTrace;
2231   TraceCallStack mTexParamaterTrace;
2232   TraceCallStack mDrawTrace;
2233   TraceCallStack mDepthFunctionTrace;
2234   TraceCallStack mStencilFunctionTrace;
2235   TraceCallStack mScissorTrace;
2236   TraceCallStack mSetUniformTrace;
2237   TraceCallStack mViewportTrace;
2238
2239   // Shaders & Uniforms
2240   GLuint mLastShaderIdUsed;
2241   GLuint mLastProgramIdUsed;
2242   GLuint mLastUniformIdUsed;
2243   typedef std::map< std::string, GLint > UniformIDMap;
2244   typedef std::map< GLuint, UniformIDMap > ProgramUniformMap;
2245   ProgramUniformMap mUniforms;
2246
2247   template <typename T>
2248   struct ProgramUniformValue : public std::map< GLuint, std::map< GLint, T > >
2249   {
2250   public:
2251     typedef std::map< GLint, T > UniformValueMap;
2252     typedef std::map< GLuint, UniformValueMap > Map;
2253
2254     bool SetUniformValue( GLuint program, GLuint uniform, const T& value )
2255     {
2256       if( program == 0 )
2257       {
2258         return false;
2259       }
2260
2261       typename Map::iterator it = Map::find( program );
2262       if( it == Map::end() )
2263       {
2264         // if its the first uniform for this program add it
2265         std::pair< typename Map::iterator, bool > result =
2266             Map::insert( typename Map::value_type( program, UniformValueMap() ) );
2267         it = result.first;
2268       }
2269
2270       UniformValueMap& uniforms = it->second;
2271       uniforms[uniform] = value;
2272
2273       return true;
2274     }
2275
2276     bool CheckUniformValue( GLuint program, GLuint uniform, const T& value ) const
2277     {
2278       T uniformValue;
2279       if ( GetUniformValue( program, uniform, uniformValue ) )
2280       {
2281         return CompareType<T>(value, uniformValue, Math::MACHINE_EPSILON_10);
2282       }
2283
2284       return false;
2285     }
2286
2287     bool GetUniformValue( GLuint program, GLuint uniform, T& value ) const
2288     {
2289       if( program == 0 )
2290       {
2291         return false;
2292       }
2293
2294       typename Map::const_iterator it = Map::find( program );
2295       if( it == Map::end() )
2296       {
2297         // Uniform values always initialised as 0
2298         value = GetZero();
2299         return true;
2300       }
2301
2302       const UniformValueMap& uniforms = it->second;
2303       typename UniformValueMap::const_iterator it2 = uniforms.find( uniform );
2304       if( it2 == uniforms.end() )
2305       {
2306         // Uniform values always initialised as 0
2307         value = GetZero();
2308         return true;
2309       }
2310       value = it2->second;
2311
2312       return true;
2313     }
2314
2315     T GetZero() const;
2316   };
2317   ProgramUniformValue<int> mProgramUniforms1i;
2318   ProgramUniformValue<float> mProgramUniforms1f;
2319   ProgramUniformValue<Vector2> mProgramUniforms2f;
2320   ProgramUniformValue<Vector3> mProgramUniforms3f;
2321   ProgramUniformValue<Vector4> mProgramUniforms4f;
2322   ProgramUniformValue<Matrix> mProgramUniformsMat4;
2323   ProgramUniformValue<Matrix3> mProgramUniformsMat3;
2324
2325   inline const ProgramUniformValue<int>& GetProgramUniformsForType( const int ) const
2326   {
2327     return mProgramUniforms1i;
2328   }
2329   inline const ProgramUniformValue<float>& GetProgramUniformsForType( const float ) const
2330   {
2331     return mProgramUniforms1f;
2332   }
2333   inline const ProgramUniformValue<Vector2>& GetProgramUniformsForType( const Vector2& ) const
2334   {
2335     return mProgramUniforms2f;
2336   }
2337   inline const ProgramUniformValue<Vector3>& GetProgramUniformsForType( const Vector3& ) const
2338   {
2339     return mProgramUniforms3f;
2340   }
2341   inline const ProgramUniformValue<Vector4>& GetProgramUniformsForType( const Vector4& ) const
2342   {
2343     return mProgramUniforms4f;
2344   }
2345   inline const ProgramUniformValue<Matrix>& GetProgramUniformsForType( const Matrix& ) const
2346   {
2347     return mProgramUniformsMat4;
2348   }
2349   inline const ProgramUniformValue<Matrix3>& GetProgramUniformsForType( const Matrix3& ) const
2350   {
2351     return mProgramUniformsMat3;
2352   }
2353   inline void SetVertexAttribArray(GLuint index, bool state)
2354   {
2355     if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
2356     {
2357       // out of range
2358       return;
2359     }
2360     mVertexAttribArrayState[ index ] = state;
2361     mVertexAttribArrayChanged = true;
2362   }
2363
2364   ScissorParams mScissorParams;
2365   ColorMaskParams mColorMaskParams;
2366 };
2367
2368 template <>
2369 inline int TestGlAbstraction::ProgramUniformValue<int>::GetZero() const
2370 {
2371   return 0;
2372 }
2373
2374 template <>
2375 inline float TestGlAbstraction::ProgramUniformValue<float>::GetZero() const
2376 {
2377   return 0.0f;
2378 }
2379
2380 template <>
2381 inline Vector2 TestGlAbstraction::ProgramUniformValue<Vector2>::GetZero() const
2382 {
2383   return Vector2::ZERO;
2384 }
2385
2386 template <>
2387 inline Vector3 TestGlAbstraction::ProgramUniformValue<Vector3>::GetZero() const
2388 {
2389   return Vector3::ZERO;
2390 }
2391
2392 template <>
2393 inline Vector4 TestGlAbstraction::ProgramUniformValue<Vector4>::GetZero() const
2394 {
2395   return Vector4::ZERO;
2396 }
2397
2398 template <>
2399 inline Matrix TestGlAbstraction::ProgramUniformValue<Matrix>::GetZero() const
2400 {
2401   return Matrix();
2402 }
2403
2404 template <>
2405 inline Matrix3 TestGlAbstraction::ProgramUniformValue<Matrix3>::GetZero() const
2406 {
2407   return Matrix3( Matrix() );
2408 }
2409
2410 } // namespace Dali
2411
2412 bool BlendEnabled(const Dali::TraceCallStack& callStack);
2413 bool BlendDisabled(const Dali::TraceCallStack& callStack);
2414
2415
2416 #endif // TEST_GL_ABSTRACTION_H