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