Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / automated-tests / dali-test-suite-utils / test-gl-abstraction.h
1 #ifndef __TEST_GL_ABSTRACTION_H__
2 #define __TEST_GL_ABSTRACTION_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <sstream>
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/dali-core.h>
26
27 #include <dali/integration-api/core.h>
28 #include <dali/integration-api/gl-abstraction.h>
29 #include <test-trace-call-stack.h>
30
31 namespace Dali
32 {
33
34 static const unsigned int MAX_ATTRIBUTE_CACHE_SIZE = 64;
35 static const char *mStdAttribs[MAX_ATTRIBUTE_CACHE_SIZE] =
36 {
37     "aPosition",    // ATTRIB_POSITION
38     "aNormal",      // ATTRIB_NORMAL
39     "aTexCoord",    // ATTRIB_TEXCOORD
40     "aColor",       // ATTRIB_COLOR
41     "aBoneWeights", // ATTRIB_BONE_WEIGHTS
42     "aBoneIndices"  // ATTRIB_BONE_INDICES
43 };
44
45 class DALI_IMPORT_API TestGlAbstraction: public Dali::Integration::GlAbstraction
46 {
47 public:
48   TestGlAbstraction()
49   {
50     Initialize();
51   }
52
53   ~TestGlAbstraction() {}
54
55   void Initialize()
56   {
57     mCurrentProgram = 0;
58     mCompileStatus = GL_TRUE;
59     mLinkStatus = GL_TRUE;
60
61     mGetAttribLocationResult = 0;
62     mGetErrorResult = 0;
63     mGetStringResult = NULL;
64     mIsBufferResult = 0;
65     mIsEnabledResult = 0;
66     mIsFramebufferResult = 0;
67     mIsProgramResult = 0;
68     mIsRenderbufferResult = 0;
69     mIsShaderResult = 0;
70     mIsTextureResult = 0;
71     mVertexAttribArrayChanged = false;
72
73     mCheckFramebufferStatusResult = 0;
74     mNumBinaryFormats = 1;
75     mBinaryFormats = 1;
76     mProgramBinaryLength = 0;
77
78     mLastAutoTextureIdUsed = 0;
79
80     mLastShaderIdUsed = 0;
81     mLastProgramIdUsed = 0;
82     mLastUniformIdUsed = 0;
83     mLastShaderCompiled = 0;
84
85     mLastBlendEquationRgb   = 0;
86     mLastBlendEquationAlpha = 0;
87     mLastBlendFuncSrcRgb    = 0;
88     mLastBlendFuncDstRgb    = 0;
89     mLastBlendFuncSrcAlpha  = 0;
90     mLastBlendFuncDstAlpha  = 0;
91
92     mUniforms.clear();
93     mProgramUniforms1i.clear();
94     mProgramUniforms1f.clear();
95     mProgramUniforms2f.clear();
96     mProgramUniforms3f.clear();
97     mProgramUniforms4f.clear();
98   }
99
100   /* OpenGL ES 2.0 */
101
102   void ActiveTexture( GLenum textureUnit )
103   {
104     mActiveTextureUnit = textureUnit - GL_TEXTURE0;
105   }
106
107   GLenum GetActiveTextureUnit() const
108   {
109     return mActiveTextureUnit + GL_TEXTURE0;
110   }
111
112   void AttachShader( GLuint program, GLuint shader )
113   {
114     std::stringstream out;
115     out << program << ", " << shader;
116     mShaderTrace.PushCall("AttachShader", out.str());
117   }
118
119   void BindAttribLocation( GLuint program, GLuint index, const char* name )
120   {
121   }
122
123   void BindBuffer( GLenum target, GLuint buffer )
124   {
125   }
126
127   void BindFramebuffer( GLenum target, GLuint framebuffer )
128   {
129   }
130
131   void BindRenderbuffer( GLenum target, GLuint renderbuffer )
132   {
133   }
134
135   /**
136    * This method can be used by test cases, to query the texture IDs that have been bound by BindTexture.
137    * @return A vector containing the IDs that were bound.
138    */
139   const std::vector<GLuint>& GetBoundTextures() const
140   {
141     return mBoundTextures;
142   }
143
144   /**
145    * Query the texture IDs that have been bound with BindTexture, with a specific active texture unit.
146    * @param[in] activeTextureUnit The specific active texture unit.
147    * @return A vector containing the IDs that were bound.
148    */
149   const std::vector<GLuint>& GetBoundTextures( GLuint activeTextureUnit ) const
150   {
151     return mActiveTextures[ activeTextureUnit - GL_TEXTURE0 ].mBoundTextures;
152   }
153
154   /**
155    * This method can be used by test cases, to clear the record of texture IDs that have been bound by BindTexture.
156    */
157   void ClearBoundTextures()
158   {
159     mBoundTextures.clear();
160
161     for( unsigned int i=0; i<MIN_TEXTURE_UNIT_LIMIT; ++i )
162     {
163       mActiveTextures[ i ].mBoundTextures.clear();
164     }
165   }
166
167   void BindTexture( GLenum target, GLuint texture )
168   {
169     // Record the bound textures for future checks
170     if( texture )
171     {
172       mBoundTextures.push_back( texture );
173
174       if( mActiveTextureUnit < MIN_TEXTURE_UNIT_LIMIT )
175       {
176         mActiveTextures[ mActiveTextureUnit ].mBoundTextures.push_back( texture );
177       }
178     }
179   }
180
181   void BlendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
182   {
183     mLastBlendColor.r = red;
184     mLastBlendColor.g = green;
185     mLastBlendColor.b = blue;
186     mLastBlendColor.a = alpha;
187   }
188
189   const Vector4& GetLastBlendColor() const
190   {
191     return mLastBlendColor;
192   }
193
194   void BlendEquation( GLenum mode )
195   {
196     mLastBlendEquationRgb   = mode;
197     mLastBlendEquationAlpha = mode;
198   }
199
200   void BlendEquationSeparate( GLenum modeRgb, GLenum modeAlpha )
201   {
202     mLastBlendEquationRgb   = modeRgb;
203     mLastBlendEquationAlpha = modeAlpha;
204   }
205
206   GLenum GetLastBlendEquationRgb() const
207   {
208     return mLastBlendEquationRgb;
209   }
210
211   GLenum GetLastBlendEquationAlpha() const
212   {
213     return mLastBlendEquationAlpha;
214   }
215
216   void BlendFunc(GLenum sfactor, GLenum dfactor)
217   {
218     mLastBlendFuncSrcRgb = sfactor;
219     mLastBlendFuncDstRgb = dfactor;
220     mLastBlendFuncSrcAlpha = sfactor;
221     mLastBlendFuncDstAlpha = dfactor;
222   }
223
224   void BlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
225   {
226     mLastBlendFuncSrcRgb = srcRGB;
227     mLastBlendFuncDstRgb = dstRGB;
228     mLastBlendFuncSrcAlpha = srcAlpha;
229     mLastBlendFuncDstAlpha = dstAlpha;
230   }
231
232   GLenum GetLastBlendFuncSrcRgb() const
233   {
234     return mLastBlendFuncSrcRgb;
235   }
236
237   GLenum GetLastBlendFuncDstRgb() const
238   {
239     return mLastBlendFuncDstRgb;
240   }
241
242   GLenum GetLastBlendFuncSrcAlpha() const
243   {
244     return mLastBlendFuncSrcAlpha;
245   }
246
247   GLenum GetLastBlendFuncDstAlpha() const
248   {
249     return mLastBlendFuncDstAlpha;
250   }
251
252   void BufferData(GLenum target, GLsizeiptr size, const void* data, GLenum usage)
253   {
254   }
255
256   void BufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void* data)
257   {
258   }
259
260   GLenum CheckFramebufferStatus(GLenum target)
261   {
262     return mCheckFramebufferStatusResult;
263   }
264
265   void Clear(GLbitfield mask)
266   {
267   }
268
269   void ClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
270   {
271   }
272
273   void ClearDepthf(GLclampf depth)
274   {
275   }
276
277   void ClearStencil(GLint s)
278   {
279   }
280
281   void ColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
282   {
283   }
284
285   void CompileShader(GLuint shader)
286   {
287     std::stringstream out;
288     out << shader;
289     mShaderTrace.PushCall("CompileShader", out.str());
290   }
291
292   void CompressedTexImage2D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void* data)
293   {
294   }
295
296   void CompressedTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void* data)
297   {
298   }
299
300   void CopyTexImage2D(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
301   {
302   }
303
304   void CopyTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
305   {
306   }
307
308   GLuint CreateProgram(void)
309   {
310     mShaderTrace.PushCall("CreateProgram", "");
311
312     ++mLastProgramIdUsed;
313     mUniforms[mLastProgramIdUsed] = UniformIDMap();
314     return mLastProgramIdUsed;
315   }
316
317   GLuint CreateShader(GLenum type)
318   {
319     std::stringstream out;
320     out << type;
321     mShaderTrace.PushCall("CreateShader", out.str());
322
323     return ++mLastShaderIdUsed;
324   }
325
326   void CullFace(GLenum mode)
327   {
328     std::stringstream out;
329     out << mode;
330     mCullFaceTrace.PushCall("CullFace", out.str());
331   }
332
333   void DeleteBuffers(GLsizei n, const GLuint* buffers)
334   {
335   }
336
337   void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers)
338   {
339   }
340
341   void DeleteProgram(GLuint program)
342   {
343     std::stringstream out;
344     out << program;
345     mShaderTrace.PushCall("DeleteProgram", out.str());
346   }
347
348   void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers)
349   {
350   }
351
352   void DeleteShader(GLuint shader)
353   {
354     std::stringstream out;
355     out << shader;
356     mShaderTrace.PushCall("DeleteShader", out.str());
357   }
358
359   void DeleteTextures(GLsizei n, const GLuint* textures)
360   {
361     std::stringstream out;
362     out << n << ", " << textures << " = [";
363
364     for(GLsizei i=0; i<n; i++)
365     {
366       out << textures[i] << ", ";
367       mDeletedTextureIds.push_back(textures[i]);
368     }
369     out << "]";
370     mTextureTrace.PushCall("DeleteTextures", out.str());
371   }
372
373   bool CheckNoTexturesDeleted()
374   {
375     return mDeletedTextureIds.size() == 0;
376   }
377
378   bool CheckTextureDeleted( GLuint textureId )
379   {
380     bool found = false;
381
382     for(std::vector<GLuint>::iterator iter=mDeletedTextureIds.begin(); iter != mDeletedTextureIds.end(); ++iter)
383     {
384       if(*iter == textureId)
385       {
386         found = true;
387         break;
388       }
389     }
390     return found;
391   }
392
393   void ClearDeletedTextures()
394   {
395     mDeletedTextureIds.clear();
396   }
397
398   void DepthFunc(GLenum func)
399   {
400   }
401
402   void DepthMask(GLboolean flag)
403   {
404   }
405
406   void DepthRangef(GLclampf zNear, GLclampf zFar)
407   {
408   }
409
410   void DetachShader(GLuint program, GLuint shader)
411   {
412     std::stringstream out;
413     out << program << ", " << shader;
414     mShaderTrace.PushCall("DetachShader", out.str());
415   }
416
417   void Disable(GLenum cap)
418   {
419     std::stringstream out;
420     out << cap;
421     mCullFaceTrace.PushCall("Disable", out.str());
422   }
423
424   void DisableVertexAttribArray(GLuint index)
425   {
426     SetVertexAttribArray( index, false );
427   }
428
429   void DrawArrays(GLenum mode, GLint first, GLsizei count)
430   {
431     std::stringstream out;
432     out << mode << ", " << first << ", " << count;
433     mDrawTrace.PushCall("DrawArrays", out.str());
434   }
435
436   void DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
437   {
438     std::stringstream out;
439     out << mode << ", " << count << ", " << type << ", indices";
440     mDrawTrace.PushCall("DrawElements", out.str());
441   }
442
443   void Enable(GLenum cap)
444   {
445     std::stringstream out;
446     out << cap;
447     mCullFaceTrace.PushCall("Enable", out.str());
448   }
449
450   void EnableVertexAttribArray(GLuint index)
451   {
452     SetVertexAttribArray( index, true);
453   }
454
455   void Finish(void)
456   {
457   }
458
459   void Flush(void)
460   {
461   }
462
463   void FramebufferRenderbuffer(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer)
464   {
465   }
466
467   void FramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
468   {
469   }
470
471   void FrontFace(GLenum mode)
472   {
473   }
474
475   void GenBuffers(GLsizei n, GLuint* buffers)
476   {
477     // avoids an assert in GpuBuffers
478     *buffers = 1u;
479   }
480
481   void GenerateMipmap(GLenum target)
482   {
483   }
484
485   void GenFramebuffers(GLsizei n, GLuint* framebuffers)
486   {
487   }
488
489   void GenRenderbuffers(GLsizei n, GLuint* renderbuffers)
490   {
491   }
492
493   /**
494    * This method can be used by test cases, to manipulate the texture IDs generated by GenTextures.
495    * @param[in] ids A vector containing the next IDs to be generated
496    */
497   void SetNextTextureIds( const std::vector<GLuint>& ids )
498   {
499     mNextTextureIds = ids;
500   }
501
502   const std::vector<GLuint>& GetNextTextureIds()
503   {
504     return mNextTextureIds;
505   }
506
507   void GenTextures(GLsizei n, GLuint* textures)
508   {
509     for( int i=0; i<n; ++i )
510     {
511       if( !mNextTextureIds.empty() )
512       {
513         *(textures+i) = mNextTextureIds[0];
514         mNextTextureIds.erase( mNextTextureIds.begin() );
515       }
516       else
517       {
518         *(textures+i) = ++mLastAutoTextureIdUsed;
519       }
520     }
521   }
522
523   void GetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
524   {
525   }
526
527   void GetActiveUniform(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, char* name)
528   {
529   }
530
531   void GetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders)
532   {
533   }
534
535   int  GetAttribLocation(GLuint program, const char* name)
536   {
537     std::string attribName(name);
538
539     for( unsigned int i = 0; i < ATTRIB_TYPE_LAST; ++i )
540     {
541       if( mStdAttribs[i] == attribName )
542       {
543         return i;
544       }
545     }
546
547     // 0 is a valid location
548     return 0;
549   }
550
551   void GetBooleanv(GLenum pname, GLboolean* params)
552   {
553   }
554
555   void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
556   {
557   }
558
559   GLenum GetError(void)
560   {
561     return mGetErrorResult;
562   }
563
564   void GetFloatv(GLenum pname, GLfloat* params)
565   {
566   }
567
568   void GetFramebufferAttachmentParameteriv(GLenum target, GLenum attachment, GLenum pname, GLint* params)
569   {
570   }
571
572   void GetIntegerv(GLenum pname, GLint* params)
573   {
574     switch( pname )
575     {
576       case GL_MAX_TEXTURE_SIZE:
577         *params = 2048;
578         break;
579       case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
580         *params = 8;
581         break;
582       case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
583         *params = mNumBinaryFormats;
584         break;
585       case GL_PROGRAM_BINARY_FORMATS_OES:
586         *params = mBinaryFormats;
587         break;
588     }
589   }
590
591   void GetProgramiv(GLuint program, GLenum pname, GLint* params)
592   {
593     switch( pname ) {
594       case GL_LINK_STATUS:
595         *params = mLinkStatus;
596         break;
597       case GL_PROGRAM_BINARY_LENGTH_OES:
598         *params = mProgramBinaryLength;
599         break;
600     }
601   }
602
603   void GetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length, char* infolog)
604   {
605   }
606
607
608   void GetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params)
609   {
610   }
611
612   void GetShaderiv(GLuint shader, GLenum pname, GLint* params)
613   {
614     switch( pname ) {
615       case GL_COMPILE_STATUS:
616         *params = mCompileStatus;
617         break;
618     }
619   }
620
621   void GetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length, char* infolog)
622   {
623   }
624
625   void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision)
626   {
627   }
628
629   const GLubyte* GetString(GLenum name)
630   {
631     return mGetStringResult;
632   }
633
634   void GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
635   {
636   }
637
638   void GetTexParameteriv(GLenum target, GLenum pname, GLint* params)
639   {
640   }
641
642   void GetUniformfv(GLuint program, GLint location, GLfloat* params)
643   {
644   }
645
646   void GetUniformiv(GLuint program, GLint location, GLint* params)
647   {
648   }
649
650   GLint GetUniformLocation(GLuint program, const char* name)
651   {
652     ProgramUniformMap::iterator it = mUniforms.find(program);
653     if( it == mUniforms.end() )
654     {
655       // Not a valid program ID
656       mGetErrorResult = GL_INVALID_OPERATION;
657       return -1;
658     }
659
660     UniformIDMap& uniformIDs = it->second;
661     UniformIDMap::iterator it2 = uniformIDs.find( name );
662     if( it2 == uniformIDs.end() )
663     {
664       // Uniform not found, so add it...
665       uniformIDs[name] = ++mLastUniformIdUsed;
666       return mLastUniformIdUsed;
667     }
668
669     return it2->second;
670   }
671
672   void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
673   {
674   }
675
676   void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
677   {
678   }
679
680   void GetVertexAttribPointerv(GLuint index, GLenum pname, void** pointer)
681   {
682   }
683
684   void Hint(GLenum target, GLenum mode)
685   {
686   }
687
688   GLboolean IsBuffer(GLuint buffer)
689   {
690     return mIsBufferResult;
691   }
692
693   GLboolean IsEnabled(GLenum cap)
694   {
695     return mIsEnabledResult;
696   }
697
698   GLboolean IsFramebuffer(GLuint framebuffer)
699   {
700     return mIsFramebufferResult;
701   }
702
703   GLboolean IsProgram(GLuint program)
704   {
705     return mIsProgramResult;
706   }
707
708   GLboolean IsRenderbuffer(GLuint renderbuffer)
709   {
710     return mIsRenderbufferResult;
711   }
712
713   GLboolean IsShader(GLuint shader)
714   {
715     return mIsShaderResult;
716   }
717
718   GLboolean IsTexture(GLuint texture)
719   {
720     return mIsTextureResult;
721   }
722
723   void LineWidth(GLfloat width)
724   {
725   }
726
727   void LinkProgram(GLuint program)
728   {
729     std::stringstream out;
730     out << program;
731     mShaderTrace.PushCall("LinkProgram", out.str());
732   }
733
734   void PixelStorei(GLenum pname, GLint param)
735   {
736   }
737
738   void PolygonOffset(GLfloat factor, GLfloat units)
739   {
740   }
741
742   void ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void* pixels)
743   {
744   }
745
746   void ReleaseShaderCompiler(void)
747   {
748   }
749
750   void RenderbufferStorage(GLenum target, GLenum internalformat, GLsizei width, GLsizei height)
751   {
752   }
753
754   void SampleCoverage(GLclampf value, GLboolean invert)
755   {
756   }
757
758   void Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
759   {
760   }
761
762   void ShaderBinary(GLsizei n, const GLuint* shaders, GLenum binaryformat, const void* binary, GLsizei length)
763   {
764   }
765
766   void ShaderSource(GLuint shader, GLsizei count, const char** string, const GLint* length)
767   {
768     std::string stringBuilder;
769     for(int i = 0; i < count; ++i)
770     {
771       stringBuilder += string[i];
772     }
773     mShaderSources[shader] = stringBuilder;
774     mLastShaderCompiled = shader;
775   }
776
777   void GetShaderSource(GLuint shader, GLsizei bufsize, GLsizei* length, char* source)
778   {
779     const std::string shaderSource = mShaderSources[shader];
780     if( static_cast<int>(shaderSource.length()) < bufsize )
781     {
782       strcpy(source, shaderSource.c_str());
783       *length = shaderSource.length();
784     }
785     else
786     {
787       *length = bufsize -1;
788       strncpy(source, shaderSource.c_str(), *length);
789       source[*length] = 0x0;
790     }
791   }
792
793   void StencilFunc(GLenum func, GLint ref, GLuint mask)
794   {
795   }
796
797   void StencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
798   {
799   }
800
801   void StencilMask(GLuint mask)
802   {
803   }
804
805   void StencilMaskSeparate(GLenum face, GLuint mask)
806   {
807   }
808
809   void StencilOp(GLenum fail, GLenum zfail, GLenum zpass)
810   {
811   }
812
813   void StencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
814   {
815   }
816
817   void TexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void* pixels)
818   {
819     std::stringstream out;
820     out << width << ", " << height;
821     mTextureTrace.PushCall("TexImage2D", out.str());
822   }
823
824   void TexParameterf(GLenum target, GLenum pname, GLfloat param)
825   {
826   }
827
828   void TexParameterfv(GLenum target, GLenum pname, const GLfloat* params)
829   {
830   }
831
832   void TexParameteri(GLenum target, GLenum pname, GLint param)
833   {
834   }
835
836   void TexParameteriv(GLenum target, GLenum pname, const GLint* params)
837   {
838   }
839
840   void TexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels)
841   {
842     std::stringstream out;
843     out << xoffset << ", " << yoffset << ", " << width << ", " << height;
844     mTextureTrace.PushCall("TexSubImage2D", out.str());
845   }
846
847   void Uniform1f(GLint location, GLfloat x)
848   {
849     if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, x ) )
850     {
851       mGetErrorResult = GL_INVALID_OPERATION;
852     }
853   }
854
855   void Uniform1fv(GLint location, GLsizei count, const GLfloat* v)
856   {
857     for( int i = 0; i < count; ++i )
858     {
859       if( ! mProgramUniforms1f.SetUniformValue( mCurrentProgram, location, v[i] ) )
860       {
861         mGetErrorResult = GL_INVALID_OPERATION;
862         break;
863       }
864     }
865   }
866
867   void Uniform1i(GLint location, GLint x)
868   {
869     if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram, location, x ) )
870     {
871       mGetErrorResult = GL_INVALID_OPERATION;
872     }
873   }
874
875   void Uniform1iv(GLint location, GLsizei count, const GLint* v)
876   {
877     for( int i = 0; i < count; ++i )
878     {
879       if( ! mProgramUniforms1i.SetUniformValue( mCurrentProgram,
880                                                  location,
881                                                  v[i] ) )
882       {
883         mGetErrorResult = GL_INVALID_OPERATION;
884         break;
885       }
886     }
887   }
888
889   void Uniform2f(GLint location, GLfloat x, GLfloat y)
890   {
891     if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
892                                                location,
893                                                Vector2( x, y ) ) )
894     {
895       mGetErrorResult = GL_INVALID_OPERATION;
896     }
897   }
898
899   void Uniform2fv(GLint location, GLsizei count, const GLfloat* v)
900   {
901     for( int i = 0; i < count; ++i )
902     {
903       if( ! mProgramUniforms2f.SetUniformValue( mCurrentProgram,
904                                                  location,
905                                                  Vector2( v[2*i], v[2*i+1] ) ) )
906       {
907         mGetErrorResult = GL_INVALID_OPERATION;
908         break;
909       }
910     }
911   }
912
913   void Uniform2i(GLint location, GLint x, GLint y)
914   {
915   }
916
917   void Uniform2iv(GLint location, GLsizei count, const GLint* v)
918   {
919   }
920
921   void Uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
922   {
923     if( ! mProgramUniforms3f.SetUniformValue( mCurrentProgram,
924                                                location,
925                                                Vector3( x, y, z ) ) )
926     {
927       mGetErrorResult = GL_INVALID_OPERATION;
928     }
929   }
930
931   void Uniform3fv(GLint location, GLsizei count, const GLfloat* v)
932   {
933     for( int i = 0; i < count; ++i )
934     {
935       if( ! mProgramUniforms3f.SetUniformValue(
936           mCurrentProgram,
937           location,
938           Vector3( v[3*i], v[3*i+1], v[3*i+2] ) ) )
939       {
940         mGetErrorResult = GL_INVALID_OPERATION;
941         break;
942       }
943     }
944   }
945
946   void Uniform3i(GLint location, GLint x, GLint y, GLint z)
947   {
948   }
949
950   void Uniform3iv(GLint location, GLsizei count, const GLint* v)
951   {
952   }
953
954   void Uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
955   {
956     if( ! mProgramUniforms4f.SetUniformValue( mCurrentProgram,
957                                               location,
958                                               Vector4( x, y, z, w ) ) )
959     {
960       mGetErrorResult = GL_INVALID_OPERATION;
961     }
962   }
963
964   void Uniform4fv(GLint location, GLsizei count, const GLfloat* v)
965   {
966     for( int i = 0; i < count; ++i )
967     {
968       if( ! mProgramUniforms4f.SetUniformValue(
969           mCurrentProgram,
970           location,
971           Vector4( v[4*i], v[4*i+1], v[4*i+2], v[4*i+3] ) ) )
972       {
973         mGetErrorResult = GL_INVALID_OPERATION;
974         break;
975       }
976     }
977   }
978
979   void Uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
980   {
981   }
982
983   void Uniform4iv(GLint location, GLsizei count, const GLint* v)
984   {
985   }
986
987   void UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
988   {
989   }
990
991   void UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
992   {
993     for( int i = 0; i < count; ++i )
994     {
995       if( ! mProgramUniformsMat3.SetUniformValue(
996             mCurrentProgram,
997             location,
998             Matrix3( value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8] ) ) )
999       {
1000         mGetErrorResult = GL_INVALID_OPERATION;
1001         break;
1002       }
1003     }
1004   }
1005
1006   void UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1007   {
1008     for( int i = 0; i < count; ++i )
1009     {
1010       if( ! mProgramUniformsMat4.SetUniformValue(
1011           mCurrentProgram,
1012           location,
1013           Matrix( value ) ) )
1014       {
1015         mGetErrorResult = GL_INVALID_OPERATION;
1016         break;
1017       }
1018     }
1019   }
1020
1021   void UseProgram(GLuint program)
1022   {
1023     mCurrentProgram = program;
1024   }
1025
1026   void ValidateProgram(GLuint program)
1027   {
1028   }
1029
1030   void VertexAttrib1f(GLuint indx, GLfloat x)
1031   {
1032   }
1033
1034   void VertexAttrib1fv(GLuint indx, const GLfloat* values)
1035   {
1036   }
1037
1038   void VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y)
1039   {
1040   }
1041
1042   void VertexAttrib2fv(GLuint indx, const GLfloat* values)
1043   {
1044   }
1045
1046   void VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z)
1047   {
1048   }
1049
1050   void VertexAttrib3fv(GLuint indx, const GLfloat* values)
1051   {
1052   }
1053
1054   void VertexAttrib4f(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
1055   {
1056   }
1057
1058   void VertexAttrib4fv(GLuint indx, const GLfloat* values)
1059   {
1060   }
1061
1062   void VertexAttribPointer(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void* ptr)
1063   {
1064   }
1065
1066   void Viewport(GLint x, GLint y, GLsizei width, GLsizei height)
1067   {
1068   }
1069
1070   /* OpenGL ES 3.0 */
1071
1072   void ReadBuffer(GLenum mode)
1073   {
1074   }
1075
1076   void DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices)
1077   {
1078   }
1079
1080   void TexImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels)
1081   {
1082   }
1083
1084   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)
1085   {
1086   }
1087
1088   void CopyTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height)
1089   {
1090   }
1091
1092   void CompressedTexImage3D(GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data)
1093   {
1094   }
1095
1096   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)
1097   {
1098   }
1099
1100   void GenQueries(GLsizei n, GLuint* ids)
1101   {
1102   }
1103
1104   void DeleteQueries(GLsizei n, const GLuint* ids)
1105   {
1106   }
1107
1108   GLboolean IsQuery(GLuint id)
1109   {
1110     return false;
1111   }
1112
1113   void BeginQuery(GLenum target, GLuint id)
1114   {
1115   }
1116
1117   void EndQuery(GLenum target)
1118   {
1119   }
1120
1121   void GetQueryiv(GLenum target, GLenum pname, GLint* params)
1122   {
1123   }
1124
1125   void GetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params)
1126   {
1127   }
1128
1129   GLboolean UnmapBuffer(GLenum target)
1130   {
1131     return false;
1132   }
1133
1134   void GetBufferPointerv(GLenum target, GLenum pname, GLvoid** params)
1135   {
1136   }
1137
1138   void DrawBuffers(GLsizei n, const GLenum* bufs)
1139   {
1140   }
1141
1142   void UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1143   {
1144   }
1145
1146   void UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1147   {
1148   }
1149
1150   void UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1151   {
1152   }
1153
1154   void UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1155   {
1156   }
1157
1158   void UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1159   {
1160   }
1161
1162   void UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
1163   {
1164   }
1165
1166   void BlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter)
1167   {
1168   }
1169
1170   void RenderbufferStorageMultisample(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height)
1171   {
1172   }
1173
1174   void FramebufferTextureLayer(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer)
1175   {
1176   }
1177
1178   GLvoid* MapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
1179   {
1180     return NULL;
1181   }
1182
1183   void FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
1184   {
1185   }
1186
1187   void BindVertexArray(GLuint array)
1188   {
1189   }
1190
1191   void DeleteVertexArrays(GLsizei n, const GLuint* arrays)
1192   {
1193   }
1194
1195   void GenVertexArrays(GLsizei n, GLuint* arrays)
1196   {
1197   }
1198
1199   GLboolean IsVertexArray(GLuint array)
1200   {
1201     return false;
1202   }
1203
1204   void GetIntegeri_v(GLenum target, GLuint index, GLint* data)
1205   {
1206   }
1207
1208   void BeginTransformFeedback(GLenum primitiveMode)
1209   {
1210   }
1211
1212   void EndTransformFeedback(void)
1213   {
1214   }
1215
1216   void BindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size)
1217   {
1218   }
1219
1220   void BindBufferBase(GLenum target, GLuint index, GLuint buffer)
1221   {
1222   }
1223
1224   void TransformFeedbackVaryings(GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode)
1225   {
1226   }
1227
1228   void GetTransformFeedbackVarying(GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name)
1229   {
1230   }
1231
1232   void VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer)
1233   {
1234   }
1235
1236   void GetVertexAttribIiv(GLuint index, GLenum pname, GLint* params)
1237   {
1238   }
1239
1240   void GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params)
1241   {
1242   }
1243
1244   void VertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
1245   {
1246   }
1247
1248   void VertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
1249   {
1250   }
1251
1252   void VertexAttribI4iv(GLuint index, const GLint* v)
1253   {
1254   }
1255
1256   void VertexAttribI4uiv(GLuint index, const GLuint* v)
1257   {
1258   }
1259
1260   void GetUniformuiv(GLuint program, GLint location, GLuint* params)
1261   {
1262   }
1263
1264   GLint GetFragDataLocation(GLuint program, const GLchar *name)
1265   {
1266     return -1;
1267   }
1268
1269   void Uniform1ui(GLint location, GLuint v0)
1270   {
1271   }
1272
1273   void Uniform2ui(GLint location, GLuint v0, GLuint v1)
1274   {
1275   }
1276
1277   void Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
1278   {
1279   }
1280
1281   void Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1282   {
1283   }
1284
1285   void Uniform1uiv(GLint location, GLsizei count, const GLuint* value)
1286   {
1287   }
1288
1289   void Uniform2uiv(GLint location, GLsizei count, const GLuint* value)
1290   {
1291   }
1292
1293   void Uniform3uiv(GLint location, GLsizei count, const GLuint* value)
1294   {
1295   }
1296
1297   void Uniform4uiv(GLint location, GLsizei count, const GLuint* value)
1298   {
1299   }
1300
1301   void ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value)
1302   {
1303   }
1304
1305   void ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint* value)
1306   {
1307   }
1308
1309   void ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value)
1310   {
1311   }
1312
1313   void ClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
1314   {
1315   }
1316
1317   const GLubyte* GetStringi(GLenum name, GLuint index)
1318   {
1319     return NULL;
1320   }
1321
1322   void CopyBufferSubData(GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
1323   {
1324   }
1325
1326   void GetUniformIndices(GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices)
1327   {
1328   }
1329
1330   void GetActiveUniformsiv(GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params)
1331   {
1332   }
1333
1334   GLuint GetUniformBlockIndex(GLuint program, const GLchar* uniformBlockName)
1335   {
1336     return GL_INVALID_INDEX;
1337   }
1338
1339   void GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params)
1340   {
1341   }
1342
1343   void GetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName)
1344   {
1345   }
1346
1347   void UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding)
1348   {
1349   }
1350
1351   void DrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
1352   {
1353   }
1354
1355   void DrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount)
1356   {
1357   }
1358
1359   GLsync FenceSync(GLenum condition, GLbitfield flags)
1360   {
1361     return NULL;
1362   }
1363
1364   GLboolean IsSync(GLsync sync)
1365   {
1366     return false;
1367   }
1368
1369   void DeleteSync(GLsync sync)
1370   {
1371   }
1372
1373   GLenum ClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1374   {
1375     return 0;
1376   }
1377
1378   void WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
1379   {
1380   }
1381
1382   void GetInteger64v(GLenum pname, GLint64* params)
1383   {
1384   }
1385
1386   void GetSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values)
1387   {
1388   }
1389
1390   void GetInteger64i_v(GLenum target, GLuint index, GLint64* data)
1391   {
1392   }
1393
1394   void GetBufferParameteri64v(GLenum target, GLenum pname, GLint64* params)
1395   {
1396   }
1397
1398   void GenSamplers(GLsizei count, GLuint* samplers)
1399   {
1400   }
1401
1402   void DeleteSamplers(GLsizei count, const GLuint* samplers)
1403   {
1404   }
1405
1406   GLboolean IsSampler(GLuint sampler)
1407   {
1408     return false;
1409   }
1410
1411   void BindSampler(GLuint unit, GLuint sampler)
1412   {
1413   }
1414
1415   void SamplerParameteri(GLuint sampler, GLenum pname, GLint param)
1416   {
1417   }
1418
1419   void SamplerParameteriv(GLuint sampler, GLenum pname, const GLint* param)
1420   {
1421   }
1422
1423   void SamplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
1424   {
1425   }
1426
1427   void SamplerParameterfv(GLuint sampler, GLenum pname, const GLfloat* param)
1428   {
1429   }
1430
1431   void GetSamplerParameteriv(GLuint sampler, GLenum pname, GLint* params)
1432   {
1433   }
1434
1435   void GetSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat* params)
1436   {
1437   }
1438
1439   void VertexAttribDivisor(GLuint index, GLuint divisor)
1440   {
1441   }
1442
1443   void BindTransformFeedback(GLenum target, GLuint id)
1444   {
1445   }
1446
1447   void DeleteTransformFeedbacks(GLsizei n, const GLuint* ids)
1448   {
1449   }
1450
1451   void GenTransformFeedbacks(GLsizei n, GLuint* ids)
1452   {
1453   }
1454
1455   GLboolean IsTransformFeedback(GLuint id)
1456   {
1457     return false;
1458   }
1459
1460   void PauseTransformFeedback(void)
1461   {
1462   }
1463
1464   void ResumeTransformFeedback(void)
1465   {
1466   }
1467
1468   void GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary)
1469   {
1470   }
1471
1472   void ProgramBinary(GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length)
1473   {
1474   }
1475
1476   void ProgramParameteri(GLuint program, GLenum pname, GLint value)
1477   {
1478   }
1479
1480   void InvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments)
1481   {
1482   }
1483
1484   void InvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height)
1485   {
1486   }
1487
1488   void TexStorage2D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height)
1489   {
1490   }
1491
1492   void TexStorage3D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth)
1493   {
1494   }
1495
1496   void GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params)
1497   {
1498   }
1499
1500 public: // TEST FUNCTIONS
1501   void SetCompileStatus( GLuint value ) { mCompileStatus = value; }
1502   void SetLinkStatus( GLuint value ) { mLinkStatus = value; }
1503   void SetGetAttribLocationResult(  int result) { mGetAttribLocationResult = result; }
1504   void SetGetErrorResult(  GLenum result) { mGetErrorResult = result; }
1505   void SetGetStringResult(  GLubyte* result) { mGetStringResult = result; }
1506   void SetIsBufferResult(  GLboolean result) { mIsBufferResult = result; }
1507   void SetIsEnabledResult(  GLboolean result) { mIsEnabledResult = result; }
1508   void SetIsFramebufferResult(  GLboolean result) { mIsFramebufferResult = result; }
1509   void SetIsProgramResult(  GLboolean result) { mIsProgramResult = result; }
1510   void SetIsRenderbufferResult(  GLboolean result) { mIsRenderbufferResult = result; }
1511   void SetIsShaderResult(  GLboolean result) { mIsShaderResult = result; }
1512   void SetIsTextureResult(  GLboolean result) { mIsTextureResult = result; }
1513   void SetCheckFramebufferStatusResult(  GLenum result) { mCheckFramebufferStatusResult = result; }
1514   void SetNumBinaryFormats( GLint numFormats ) { mNumBinaryFormats = numFormats; }
1515   void SetBinaryFormats( GLint binaryFormats ) { mBinaryFormats = binaryFormats; }
1516   void SetProgramBinaryLength( GLint length ) { mProgramBinaryLength = length; }
1517
1518   bool GetVertexAttribArrayState(GLuint index)
1519   {
1520     if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1521     {
1522       // out of range
1523       return false;
1524     }
1525     return mVertexAttribArrayState[ index ];
1526   }
1527   void ClearVertexAttribArrayChanged() {  mVertexAttribArrayChanged = false; }
1528   bool GetVertexAttribArrayChanged()  { return mVertexAttribArrayChanged; }
1529
1530   //Methods for CullFace verification
1531   void EnableCullFaceCallTrace(bool enable) { mCullFaceTrace.Enable(enable); }
1532   void ResetCullFaceCallStack() { mCullFaceTrace.Reset(); }
1533   TraceCallStack& GetCullFaceTrace() { return mCullFaceTrace; }
1534
1535   //Methods for Shader verification
1536   void EnableShaderCallTrace(bool enable) { mShaderTrace.Enable(enable); }
1537   void ResetShaderCallStack() { mShaderTrace.Reset(); }
1538   TraceCallStack& GetShaderTrace() { return mShaderTrace; }
1539
1540   //Methods for Texture verification
1541   void EnableTextureCallTrace(bool enable) { mTextureTrace.Enable(enable); }
1542   void ResetTextureCallStack() { mTextureTrace.Reset(); }
1543   TraceCallStack& GetTextureTrace() { return mTextureTrace; }
1544
1545   //Methods for Draw verification
1546   void EnableDrawCallTrace(bool enable) { mDrawTrace.Enable(enable); }
1547   void ResetDrawCallStack() { mDrawTrace.Reset(); }
1548   TraceCallStack& GetDrawTrace() { return mDrawTrace; }
1549
1550   template <typename T>
1551   bool CheckUniformValue( const char* name, const T& value ) const
1552   {
1553     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1554           program_it != mUniforms.end();
1555           ++program_it )
1556     {
1557       const UniformIDMap &uniformIDs = program_it->second;
1558
1559       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1560       if( uniform_it != uniformIDs.end() )
1561       {
1562         // found one matching uniform name, lets check the value...
1563         GLuint programId = program_it->first;
1564         GLint uniformId = uniform_it->second;
1565
1566         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
1567         if( mProgramUniforms.CheckUniformValue( programId, uniformId, value ) )
1568         {
1569           // the value matches
1570           return true;
1571         }
1572       }
1573     }
1574
1575     tet_infoline( "Not found, printing possible values:" );
1576     for( ProgramUniformMap::const_iterator program_it = mUniforms.begin();
1577           program_it != mUniforms.end();
1578           ++program_it )
1579     {
1580       const UniformIDMap &uniformIDs = program_it->second;
1581
1582       UniformIDMap::const_iterator uniform_it = uniformIDs.find( name );
1583       if( uniform_it != uniformIDs.end() )
1584       {
1585         // found one matching uniform name, lets check the value...
1586         GLuint programId = program_it->first;
1587         GLint uniformId = uniform_it->second;
1588
1589         const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( value );
1590         T origValue;
1591         if ( mProgramUniforms.GetUniformValue(programId, uniformId, origValue) )
1592         {
1593           std::stringstream out;
1594           out << uniform_it->first << ": " << origValue;
1595           tet_printf( "%s", out.str().c_str() );
1596         }
1597       }
1598     }
1599     return false;
1600   }
1601
1602   template <typename T>
1603   bool GetUniformValue( GLuint programId, GLuint uniformId, T& outValue) const
1604   {
1605     const ProgramUniformValue<T> &mProgramUniforms = GetProgramUniformsForType( outValue );
1606     return mProgramUniforms.GetUniformValue( programId, uniformId, outValue );
1607   }
1608
1609   GLuint GetLastShaderCompiled() const
1610   {
1611     return mLastShaderCompiled;
1612   }
1613
1614   GLuint GetLastProgramCreated() const
1615   {
1616     return mLastProgramIdUsed;
1617   }
1618
1619   enum AttribType
1620   {
1621     ATTRIB_UNKNOWN = -1,
1622     ATTRIB_POSITION,
1623     ATTRIB_NORMAL,
1624     ATTRIB_TEXCOORD,
1625     ATTRIB_COLOR,
1626     ATTRIB_BONE_WEIGHTS,
1627     ATTRIB_BONE_INDICES,
1628     ATTRIB_TYPE_LAST
1629   };
1630
1631
1632 private:
1633   GLuint     mCurrentProgram;
1634   GLuint     mCompileStatus;
1635   GLuint     mLinkStatus;
1636   GLint      mGetAttribLocationResult;
1637   GLenum     mGetErrorResult;
1638   GLubyte*   mGetStringResult;
1639   GLboolean  mIsBufferResult;
1640   GLboolean  mIsEnabledResult;
1641   GLboolean  mIsFramebufferResult;
1642   GLboolean  mIsProgramResult;
1643   GLboolean  mIsRenderbufferResult;
1644   GLboolean  mIsShaderResult;
1645   GLboolean  mIsTextureResult;
1646   GLenum     mActiveTextureUnit;
1647   GLenum     mCheckFramebufferStatusResult;
1648   GLint      mNumBinaryFormats;
1649   GLint      mBinaryFormats;
1650   GLint      mProgramBinaryLength;
1651   bool       mVertexAttribArrayState[MAX_ATTRIBUTE_CACHE_SIZE];
1652   bool       mVertexAttribArrayChanged;                            // whether the vertex attrib array has been changed
1653   typedef std::map< GLuint, std::string> ShaderSourceMap;
1654   ShaderSourceMap mShaderSources;
1655   GLuint     mLastShaderCompiled;
1656
1657   Vector4 mLastBlendColor;
1658   GLenum  mLastBlendEquationRgb;
1659   GLenum  mLastBlendEquationAlpha;
1660   GLenum  mLastBlendFuncSrcRgb;
1661   GLenum  mLastBlendFuncDstRgb;
1662   GLenum  mLastBlendFuncSrcAlpha;
1663   GLenum  mLastBlendFuncDstAlpha;
1664
1665   // Data for manipulating the IDs returned by GenTextures
1666   GLuint mLastAutoTextureIdUsed;
1667   std::vector<GLuint> mNextTextureIds;
1668   std::vector<GLuint> mDeletedTextureIds;
1669   std::vector<GLuint> mBoundTextures;
1670
1671   struct ActiveTextureType
1672   {
1673     std::vector<GLuint> mBoundTextures;
1674   };
1675
1676   ActiveTextureType mActiveTextures[ MIN_TEXTURE_UNIT_LIMIT ];
1677
1678   TraceCallStack mCullFaceTrace;
1679   TraceCallStack mShaderTrace;
1680   TraceCallStack mTextureTrace;
1681   TraceCallStack mDrawTrace;
1682
1683   // Shaders & Uniforms
1684   GLuint mLastShaderIdUsed;
1685   GLuint mLastProgramIdUsed;
1686   GLuint mLastUniformIdUsed;
1687   typedef std::map< std::string, GLint > UniformIDMap;
1688   typedef std::map< GLuint, UniformIDMap > ProgramUniformMap;
1689   ProgramUniformMap mUniforms;
1690
1691   template <typename T>
1692   struct ProgramUniformValue : public std::map< GLuint, std::map< GLint, T > >
1693   {
1694   public:
1695     typedef std::map< GLint, T > UniformValueMap;
1696     typedef std::map< GLuint, UniformValueMap > Map;
1697
1698     bool SetUniformValue( GLuint program, GLuint uniform, const T& value )
1699     {
1700       if( program == 0 )
1701       {
1702         return false;
1703       }
1704
1705       typename Map::iterator it = Map::find( program );
1706       if( it == Map::end() )
1707       {
1708         // if its the first uniform for this program add it
1709         std::pair< typename Map::iterator, bool > result =
1710             Map::insert( typename Map::value_type( program, UniformValueMap() ) );
1711         it = result.first;
1712       }
1713
1714       UniformValueMap& uniforms = it->second;
1715       uniforms[uniform] = value;
1716
1717       return true;
1718     }
1719
1720     bool CheckUniformValue( GLuint program, GLuint uniform, const T& value ) const
1721     {
1722       T uniformValue;
1723       if ( GetUniformValue( program, uniform, uniformValue ) )
1724       {
1725         return value == uniformValue;
1726       }
1727
1728       return false;
1729     }
1730
1731     bool GetUniformValue( GLuint program, GLuint uniform, T& value ) const
1732     {
1733       if( program == 0 )
1734       {
1735         return false;
1736       }
1737
1738       typename Map::const_iterator it = Map::find( program );
1739       if( it == Map::end() )
1740       {
1741         // Uniform values always initialised as 0
1742         value = GetZero();
1743         return true;
1744       }
1745
1746       const UniformValueMap& uniforms = it->second;
1747       typename UniformValueMap::const_iterator it2 = uniforms.find( uniform );
1748       if( it2 == uniforms.end() )
1749       {
1750         // Uniform values always initialised as 0
1751         value = GetZero();
1752         return true;
1753       }
1754       value = it2->second;
1755
1756       return true;
1757     }
1758
1759     T GetZero() const;
1760   };
1761   ProgramUniformValue<int> mProgramUniforms1i;
1762   ProgramUniformValue<float> mProgramUniforms1f;
1763   ProgramUniformValue<Vector2> mProgramUniforms2f;
1764   ProgramUniformValue<Vector3> mProgramUniforms3f;
1765   ProgramUniformValue<Vector4> mProgramUniforms4f;
1766   ProgramUniformValue<Matrix> mProgramUniformsMat4;
1767   ProgramUniformValue<Matrix3> mProgramUniformsMat3;
1768
1769   const ProgramUniformValue<int>& GetProgramUniformsForType( const int ) const
1770   {
1771     return mProgramUniforms1i;
1772   }
1773   const ProgramUniformValue<float>& GetProgramUniformsForType( const float ) const
1774   {
1775     return mProgramUniforms1f;
1776   }
1777   const ProgramUniformValue<Vector2>& GetProgramUniformsForType( const Vector2& ) const
1778   {
1779     return mProgramUniforms2f;
1780   }
1781   const ProgramUniformValue<Vector3>& GetProgramUniformsForType( const Vector3& ) const
1782   {
1783     return mProgramUniforms3f;
1784   }
1785   const ProgramUniformValue<Vector4>& GetProgramUniformsForType( const Vector4& ) const
1786   {
1787     return mProgramUniforms4f;
1788   }
1789   const ProgramUniformValue<Matrix>& GetProgramUniformsForType( const Matrix& ) const
1790   {
1791     return mProgramUniformsMat4;
1792   }
1793   const ProgramUniformValue<Matrix3>& GetProgramUniformsForType( const Matrix3& ) const
1794   {
1795     return mProgramUniformsMat3;
1796   }
1797   void SetVertexAttribArray(GLuint index, bool state)
1798   {
1799     if( index >= MAX_ATTRIBUTE_CACHE_SIZE )
1800     {
1801       // out of range
1802       return;
1803     }
1804     mVertexAttribArrayState[ index ] = state;
1805     mVertexAttribArrayChanged = true;
1806   }
1807
1808 };
1809
1810 template <>
1811 inline int TestGlAbstraction::ProgramUniformValue<int>::GetZero() const
1812 {
1813   return 0;
1814 }
1815
1816 template <>
1817 inline float TestGlAbstraction::ProgramUniformValue<float>::GetZero() const
1818 {
1819   return 0.0f;
1820 }
1821
1822 template <>
1823 inline Vector2 TestGlAbstraction::ProgramUniformValue<Vector2>::GetZero() const
1824 {
1825   return Vector2::ZERO;
1826 }
1827
1828 template <>
1829 inline Vector3 TestGlAbstraction::ProgramUniformValue<Vector3>::GetZero() const
1830 {
1831   return Vector3::ZERO;
1832 }
1833
1834 template <>
1835 inline Vector4 TestGlAbstraction::ProgramUniformValue<Vector4>::GetZero() const
1836 {
1837   return Vector4::ZERO;
1838 }
1839
1840 template <>
1841 inline Matrix TestGlAbstraction::ProgramUniformValue<Matrix>::GetZero() const
1842 {
1843   return Matrix();
1844 }
1845
1846 template <>
1847 inline Matrix3 TestGlAbstraction::ProgramUniformValue<Matrix3>::GetZero() const
1848 {
1849   return Matrix3( Matrix() );
1850 }
1851
1852 } // namespace Dali
1853
1854 extern bool BlendEnabled(const TraceCallStack& callStack);
1855 extern bool BlendDisabled(const TraceCallStack& callStack);
1856
1857
1858 #endif // header