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