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