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