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