1 #ifndef GLES_CONTEXT_H 2 #define GLES_CONTEXT_H 3 4 #include "GLDispatch.h" 5 #include "GLESpointer.h" 6 #include "objectNameManager.h" 7 #include <utils/threads.h> 8 #include <string> 9 10 typedef std::map<GLenum,GLESpointer*> ArraysMap; 11 12 enum TextureTarget { 13 TEXTURE_2D, 14 TEXTURE_CUBE_MAP, 15 NUM_TEXTURE_TARGETS 16 }; 17 18 typedef struct _textureTargetState { 19 GLuint texture; 20 GLboolean enabled; 21 } textureTargetState; 22 23 typedef textureTargetState textureUnitState[NUM_TEXTURE_TARGETS]; 24 25 class Version{ 26 public: 27 Version(); 28 Version(int major,int minor,int release); 29 Version(const char* versionString); 30 Version(const Version& ver); 31 bool operator<(const Version& ver) const; 32 Version& operator=(const Version& ver); 33 private: 34 int m_major; 35 int m_minor; 36 int m_release; 37 }; 38 39 struct GLSupport { 40 GLSupport():maxLights(0),maxVertexAttribs(0),maxClipPlane(0),maxTexUnits(0), \ 41 maxTexImageUnits(0),maxTexSize(0) , \ 42 GL_EXT_TEXTURE_FORMAT_BGRA8888(false), GL_EXT_FRAMEBUFFER_OBJECT(false), \ 43 GL_ARB_VERTEX_BLEND(false), GL_ARB_MATRIX_PALETTE(false), \ 44 GL_EXT_PACKED_DEPTH_STENCIL(false) , GL_OES_READ_FORMAT(false), \ 45 GL_ARB_HALF_FLOAT_PIXEL(false), GL_NV_HALF_FLOAT(false), \ 46 GL_ARB_HALF_FLOAT_VERTEX(false),GL_SGIS_GENERATE_MIPMAP(false), 47 GL_ARB_ES2_COMPATIBILITY(false),GL_OES_STANDARD_DERIVATIVES(false) {} ; 48 int maxLights; 49 int maxVertexAttribs; 50 int maxClipPlane; 51 int maxTexUnits; 52 int maxTexImageUnits; 53 int maxTexSize; 54 Version glslVersion; 55 bool GL_EXT_TEXTURE_FORMAT_BGRA8888; 56 bool GL_EXT_FRAMEBUFFER_OBJECT; 57 bool GL_ARB_VERTEX_BLEND; 58 bool GL_ARB_MATRIX_PALETTE; 59 bool GL_EXT_PACKED_DEPTH_STENCIL; 60 bool GL_OES_READ_FORMAT; 61 bool GL_ARB_HALF_FLOAT_PIXEL; 62 bool GL_NV_HALF_FLOAT; 63 bool GL_ARB_HALF_FLOAT_VERTEX; 64 bool GL_SGIS_GENERATE_MIPMAP; 65 bool GL_ARB_ES2_COMPATIBILITY; 66 bool GL_OES_STANDARD_DERIVATIVES; 67 68 }; 69 70 struct ArrayData{ 71 ArrayData():data(NULL), 72 type(0), 73 stride(0), 74 allocated(false){}; 75 76 void* data; 77 GLenum type; 78 unsigned int stride; 79 bool allocated; 80 }; 81 82 class GLESConversionArrays 83 { 84 public: 85 GLESConversionArrays():m_current(0){}; 86 void setArr(void* data,unsigned int stride,GLenum type); 87 void allocArr(unsigned int size,GLenum type); 88 ArrayData& operator[](int i); 89 void* getCurrentData(); 90 ArrayData& getCurrentArray(); 91 unsigned int getCurrentIndex(); 92 void operator++(); 93 94 ~GLESConversionArrays(); 95 private: 96 std::map<GLenum,ArrayData> m_arrays; 97 unsigned int m_current; 98 }; 99 100 class GLEScontext{ 101 public: 102 virtual void init(); 103 GLEScontext(); 104 GLenum getGLerror(); 105 void setGLerror(GLenum err); 106 void setShareGroup(ShareGroupPtr grp){m_shareGroup = grp;}; 107 ShareGroupPtr shareGroup() const { return m_shareGroup; } 108 virtual void setActiveTexture(GLenum tex); 109 unsigned int getBindedTexture(GLenum target); 110 unsigned int getBindedTexture(GLenum unit,GLenum target); 111 void setBindedTexture(GLenum target,unsigned int tex); 112 bool isTextureUnitEnabled(GLenum unit); 113 void setTextureEnabled(GLenum target, GLenum enable); 114 ObjectLocalName getDefaultTextureName(GLenum target); 115 bool isInitialized() { return m_initialized; }; 116 void setUnpackAlignment(GLint param){ m_unpackAlignment = param; }; 117 GLint getUnpackAlignment(){ return m_unpackAlignment; }; 118 119 bool isArrEnabled(GLenum); 120 void enableArr(GLenum arr,bool enable); 121 const GLvoid* setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false); 122 virtual const GLESpointer* getPointer(GLenum arrType); 123 virtual void setupArraysPointers(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) = 0; 124 void bindBuffer(GLenum target,GLuint buffer); 125 void unbindBuffer(GLuint buffer); 126 bool isBuffer(GLuint buffer); 127 bool isBindedBuffer(GLenum target); 128 GLvoid* getBindedBuffer(GLenum target); 129 void getBufferSize(GLenum target,GLint* param); 130 void getBufferUsage(GLenum target,GLint* param); 131 bool setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage); 132 bool setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data); 133 const char * getExtensionString(); 134 void getGlobalLock(); 135 void releaseGlobalLock(); 136 virtual GLSupport* getCaps(){return &s_glSupport;}; 137 virtual ~GLEScontext(); 138 virtual int getMaxTexUnits() = 0; 139 virtual void drawValidate(void); 140 141 void setRenderbufferBinding(GLuint rb) { m_renderbuffer = rb; } 142 GLuint getRenderbufferBinding() const { return m_renderbuffer; } 143 void setFramebufferBinding(GLuint fb) { m_framebuffer = fb; } 144 GLuint getFramebufferBinding() const { return m_framebuffer; } 145 146 static GLDispatch& dispatcher(){return s_glDispatch;}; 147 148 static int getMaxLights(){return s_glSupport.maxLights;} 149 static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;} 150 static int getMaxTexSize(){return s_glSupport.maxTexSize;} 151 static Version glslVersion(){return s_glSupport.glslVersion;} 152 static bool isAutoMipmapSupported(){return s_glSupport.GL_SGIS_GENERATE_MIPMAP;} 153 static TextureTarget GLTextureTargetToLocal(GLenum target); 154 static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices); 155 156 virtual bool glGetIntegerv(GLenum pname, GLint *params); 157 virtual bool glGetBooleanv(GLenum pname, GLboolean *params); 158 virtual bool glGetFloatv(GLenum pname, GLfloat *params); 159 virtual bool glGetFixedv(GLenum pname, GLfixed *params); 160 161 protected: 162 virtual bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) = 0; 163 void convertDirect(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p); 164 void convertDirectVBO(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p); 165 void convertIndirect(GLESConversionArrays& fArrs,GLsizei count,GLenum type,const GLvoid* indices,GLenum array_id,GLESpointer* p); 166 void convertIndirectVBO(GLESConversionArrays& fArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p); 167 void initCapsLocked(const GLubyte * extensionString); 168 virtual void initExtensionString() =0; 169 static android::Mutex s_lock; 170 static GLDispatch s_glDispatch; 171 bool m_initialized; 172 unsigned int m_activeTexture; 173 GLint m_unpackAlignment; 174 ArraysMap m_map; 175 static std::string* s_glExtensions; 176 static GLSupport s_glSupport; 177 178 private: 179 180 virtual void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride, GLboolean normalized, int pointsIndex = -1) = 0 ; 181 GLuint getBuffer(GLenum target); 182 183 ShareGroupPtr m_shareGroup; 184 GLenum m_glError; 185 textureUnitState* m_texState; 186 unsigned int m_arrayBuffer; 187 unsigned int m_elementBuffer; 188 GLuint m_renderbuffer; 189 GLuint m_framebuffer; 190 }; 191 192 #endif 193 194