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