Home | History | Annotate | Download | only in GLcommon
      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     const char * getRendererString() const;
    135     void getGlobalLock();
    136     void releaseGlobalLock();
    137     virtual GLSupport*  getCaps(){return &s_glSupport;};
    138     virtual ~GLEScontext();
    139     virtual int getMaxTexUnits() = 0;
    140     virtual void drawValidate(void);
    141 
    142     void setRenderbufferBinding(GLuint rb) { m_renderbuffer = rb; }
    143     GLuint getRenderbufferBinding() const { return m_renderbuffer; }
    144     void setFramebufferBinding(GLuint fb) { m_framebuffer = fb; }
    145     GLuint getFramebufferBinding() const { return m_framebuffer; }
    146 
    147     static GLDispatch& dispatcher(){return s_glDispatch;};
    148 
    149     static int getMaxLights(){return s_glSupport.maxLights;}
    150     static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;}
    151     static int getMaxTexSize(){return s_glSupport.maxTexSize;}
    152     static Version glslVersion(){return s_glSupport.glslVersion;}
    153     static bool isAutoMipmapSupported(){return s_glSupport.GL_SGIS_GENERATE_MIPMAP;}
    154     static TextureTarget GLTextureTargetToLocal(GLenum target);
    155     static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices);
    156 
    157     virtual bool glGetIntegerv(GLenum pname, GLint *params);
    158     virtual bool glGetBooleanv(GLenum pname, GLboolean *params);
    159     virtual bool glGetFloatv(GLenum pname, GLfloat *params);
    160     virtual bool glGetFixedv(GLenum pname, GLfixed *params);
    161 
    162 protected:
    163     virtual bool needConvert(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id) = 0;
    164     void convertDirect(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p);
    165     void convertDirectVBO(GLESConversionArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p);
    166     void convertIndirect(GLESConversionArrays& fArrs,GLsizei count,GLenum type,const GLvoid* indices,GLenum array_id,GLESpointer* p);
    167     void convertIndirectVBO(GLESConversionArrays& fArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p);
    168     void initCapsLocked(const GLubyte * extensionString);
    169     virtual void initExtensionString() =0;
    170     static android::Mutex s_lock;
    171     static GLDispatch     s_glDispatch;
    172     bool                  m_initialized;
    173     unsigned int          m_activeTexture;
    174     GLint                 m_unpackAlignment;
    175     ArraysMap             m_map;
    176     static std::string*   s_glExtensions;
    177     static std::string    s_glRenderer;
    178     static GLSupport      s_glSupport;
    179 
    180 private:
    181 
    182     virtual void setupArr(const GLvoid* arr,GLenum arrayType,GLenum dataType,GLint size,GLsizei stride, GLboolean normalized, int pointsIndex = -1) = 0 ;
    183     GLuint getBuffer(GLenum target);
    184 
    185     ShareGroupPtr         m_shareGroup;
    186     GLenum                m_glError;
    187     textureUnitState*     m_texState;
    188     unsigned int          m_arrayBuffer;
    189     unsigned int          m_elementBuffer;
    190     GLuint                m_renderbuffer;
    191     GLuint                m_framebuffer;
    192 };
    193 
    194 #endif
    195 
    196