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