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