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