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