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