Emulators's GLES 2.0 translator implementation

This is the GLESv2 on top of openGL implementation on the host
most of this change is moving code which is necessary by both
GLES 1.0 and GLES 2.0 implementations from GLES_CM folder into
GLcommon folder.

GLESv2Imp - includes GLES 2.0 entry points implementation

Change-Id: I934fb963478a7f596d824612f847a5aa77d2ed9d
This commit is contained in:
Amit Feller
2011-05-12 10:22:16 +03:00
parent fd6ed4dd31
commit 624176d51a
36 changed files with 3997 additions and 317 deletions

View File

@@ -18,6 +18,7 @@
#include <map>
#include <EGL/egl.h>
#include <GLcommon/GLutils.h>
#include <GLcommon/SmartPtr.h>
#include <GLcommon/TranslatorIfaces.h>
#include <GLcommon/objectNameManager.h>
@@ -27,11 +28,6 @@
#include "EglSurface.h"
typedef enum{
GLES_1_1 = 0,
GLES_2_0 = 1,
MAX_GLES_VERSION //Must be last
}GLESVersion;
class EglContext;
typedef SmartPtr<EglContext> ContextPtr;

View File

@@ -159,14 +159,15 @@ static __translator_getGLESIfaceFunc loadIfaces(const char* libName){
return func;
}
#ifdef _WIN32
#define LIB_GLES_NAME "libGLES_CM_translator"
#define LIB_GLES_CM_NAME "libGLES_CM_translator"
#define LIB_GLES_V2_NAME "libGLES_V2_translator"
#elif __linux__
#define LIB_GLES_NAME "libGLES_CM_translator.so"
#define LIB_GLES_CM_NAME "libGLES_CM_translator.so"
#define LIB_GLES_V2_NAME "libGLES_V2_translator.so"
#else
#define LIB_GLES_NAME "libGLES_CM_translator"
#define LIB_GLES_CM_NAME "libGLES_CM_translator"
#define LIB_GLES_V2_NAME "libGLES_V2_translator"
#endif
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay display, EGLint *major, EGLint *minor) {
@@ -177,13 +178,24 @@ EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay display, EGLint *major, E
if(major) *major = MAJOR;
if(minor) *minor = MINOR;
if(!g_eglInfo->getIface(GLES_1_1)) {
__translator_getGLESIfaceFunc func = loadIfaces(LIB_GLES_NAME);
__translator_getGLESIfaceFunc func = NULL;
if(!g_eglInfo->getIface(GLES_1_1)) {
func = loadIfaces(LIB_GLES_CM_NAME);
if(func){
g_eglInfo->setIface(func(&s_eglIface),GLES_1_1);
} else {
fprintf(stderr,"could not find ifaces...\n");
fprintf(stderr,"could not find ifaces for GLES CM 1.1\n");
return EGL_FALSE;
}
}
if(!g_eglInfo->getIface(GLES_2_0)) {
func = loadIfaces(LIB_GLES_V2_NAME);
if(func){
g_eglInfo->setIface(func(&s_eglIface),GLES_2_0);
} else {
fprintf(stderr,"could not find ifaces for GLES 2.0\n");
return EGL_FALSE;
}
}

View File

@@ -8,15 +8,11 @@ translator_path := $(LOCAL_PATH)/..
ifeq (, $(findstring $(HOST_OS), darwin))
LOCAL_SRC_FILES := \
GLDispatch.cpp \
GLEScontext.cpp \
GLESimp.cpp \
GLESpointer.cpp \
GLESvalidate.cpp \
GLESutils.cpp \
GLESbuffer.cpp \
GLEScmImp.cpp \
GLEScmUtils.cpp \
TextureUtils.cpp \
RangeManip.cpp
GLEScmContext.cpp \
GLEScmValidate.cpp
LOCAL_C_INCLUDES += \
$(translator_path)/include \

View File

@@ -0,0 +1,184 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLEScmContext.h"
#include "GLEScmUtils.h"
#include <GLcommon/GLutils.h>
#include <string.h>
#include <GLES/gl.h>
GLcmSupport GLEScmContext::s_glSupport;
void GLEScmContext::init() {
android::Mutex::Autolock mutex(s_lock);
if(!m_initialized) {
int maxTexUnits;
s_glDispatch.dispatchFuncs(GLES_1_1);
s_glDispatch.glGetIntegerv(GL_MAX_CLIP_PLANES,&s_glSupport.maxClipPlane);
s_glDispatch.glGetIntegerv(GL_MAX_LIGHTS,&s_glSupport.maxLights);
s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_SIZE,&s_glSupport.maxTexSize);
s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTexUnits);
s_glSupport.maxTexUnits = maxTexUnits < MAX_TEX_UNITS ? maxTexUnits:MAX_TEX_UNITS;
}
m_texCoords = new GLESpointer[s_glSupport.maxTexUnits];
m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_activeTexture];
m_initialized = true;
}
GLEScmContext::GLEScmContext():GLEScontext(),m_pointsIndex(-1){
m_map[GL_COLOR_ARRAY] = new GLESpointer();
m_map[GL_NORMAL_ARRAY] = new GLESpointer();
m_map[GL_VERTEX_ARRAY] = new GLESpointer();
m_map[GL_POINT_SIZE_ARRAY_OES] = new GLESpointer();
}
void GLEScmContext::setActiveTexture(GLenum tex) {
m_activeTexture = tex - GL_TEXTURE0;
m_map[GL_TEXTURE_COORD_ARRAY] = &m_texCoords[m_activeTexture];
}
GLEScmContext::~GLEScmContext(){
if(m_texCoords){
delete[] m_texCoords;
m_texCoords = NULL;
}
}
//sending data to server side
void GLEScmContext::sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int index) {
switch(arrayType) {
case GL_VERTEX_ARRAY:
s_glDispatch.glVertexPointer(size,GL_FLOAT,stride,arr);
break;
case GL_NORMAL_ARRAY:
s_glDispatch.glNormalPointer(GL_FLOAT,stride,arr);
break;
case GL_TEXTURE_COORD_ARRAY:
s_glDispatch.glTexCoordPointer(size,GL_FLOAT,stride,arr);
break;
case GL_COLOR_ARRAY:
s_glDispatch.glColorPointer(size,GL_FLOAT,stride,arr);
break;
case GL_POINT_SIZE_ARRAY_OES:
m_pointsIndex = index;
break;
}
}
void GLEScmContext::convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) {
ArraysMap::iterator it;
unsigned int index = 0;
m_pointsIndex = -1;
//going over all clients arrays Pointers
for ( it=m_map.begin() ; it != m_map.end(); it++ ) {
GLenum array_id = (*it).first;
GLESpointer* p = (*it).second;
if(array_id == GL_TEXTURE_COORD_ARRAY) continue; //handling textures later
chooseConvertMethod(fArrs,first,count,type,indices,direct,p,array_id,index);
}
unsigned int activeTexture = m_activeTexture + GL_TEXTURE0;
s_lock.lock();
int maxTexUnits = s_glSupport.maxTexUnits;
s_lock.unlock();
//converting all texture coords arrays
for(int i=0; i< maxTexUnits;i++) {
unsigned int tex = GL_TEXTURE0+i;
setActiveTexture(tex);
s_glDispatch.glClientActiveTexture(tex);
GLenum array_id = GL_TEXTURE_COORD_ARRAY;
GLESpointer* p = m_map[array_id];
chooseConvertMethod(fArrs,first,count,type,indices,direct,p,array_id,index);
}
setActiveTexture(activeTexture);
s_glDispatch.glClientActiveTexture(activeTexture);
}
void GLEScmContext::drawPoints(PointSizeIndices* points) {
GLushort* indices = NULL;
int last_size = 0;
//drawing each group of vertices by the points size
for(PointSizeIndices::iterator it = points->begin();it != points->end(); it++) {
int count = (*it).second.size();
int pointSize = (*it).first;
std::vector<int>& arr = (*it).second;
if(count > last_size) {
if(indices) delete [] indices;
indices = new GLushort[count];
}
int i = 0 ;
for(std::vector<int>::iterator it2 = arr.begin();it2 != arr.end();it2++) {
indices[i++] = (*it2);
}
s_glDispatch.glPointSize(pointSize);
s_glDispatch.glDrawElements(GL_POINTS,count,GL_UNSIGNED_SHORT,indices);
}
if(indices) delete [] indices;
}
void GLEScmContext::drawPointsData(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw) {
const GLfloat *pointsArr = NULL;
int stride = 0; //steps in GLfloats
//choosing the right points sizes array source
if(m_pointsIndex >= 0) { //point size array was converted
pointsArr=fArrs.arrays[m_pointsIndex];
stride = 1;
} else {
GLESpointer* p = m_map[GL_POINT_SIZE_ARRAY_OES];
pointsArr = static_cast<const GLfloat*>(isBindedBuffer(GL_ARRAY_BUFFER)?p->getBufferData():p->getArrayData());
stride = p->getStride()?p->getStride()/sizeof(GLfloat):1;
}
//filling arrays before sorting them
PointSizeIndices points;
if(isElemsDraw) {
for(int i=0; i< count; i++) {
GLushort index = (type == GL_UNSIGNED_SHORT?
static_cast<const GLushort*>(indices_in)[i]:
static_cast<const GLubyte*>(indices_in)[i]);
points[pointsArr[index*stride]].push_back(index);
}
} else {
for(int i=0; i< count; i++) {
points[pointsArr[first+i*stride]].push_back(i+first);
}
}
drawPoints(&points);
}
void GLEScmContext::drawPointsArrs(GLESFloatArrays& arrs,GLint first,GLsizei count) {
drawPointsData(arrs,first,count,0,NULL,false);
}
void GLEScmContext::drawPointsElems(GLESFloatArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices_in) {
drawPointsData(arrs,0,count,type,indices_in,true);
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLES_CM_CONTEX_H
#define GLES_CM_CONTEX_H
#include <GLcommon/GLDispatch.h>
#include <GLcommon/GLESpointer.h>
#include <GLcommon/GLESbuffer.h>
#include <GLcommon/GLEScontext.h>
#include <map>
#include <vector>
#include <utils/threads.h>
typedef std::map<GLfloat,std::vector<int> > PointSizeIndices;
struct GLcmSupport {
GLcmSupport():maxLights(0),maxClipPlane(0),maxTexUnits(0),maxTexSize(0){};
int maxLights;
int maxClipPlane;
int maxTexUnits;
int maxTexSize;
};
class GLEScmContext: public GLEScontext
{
public:
void init();
GLEScmContext();
void setActiveTexture(GLenum tex);
void convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
void drawPointsArrs(GLESFloatArrays& arrs,GLint first,GLsizei count);
void drawPointsElems(GLESFloatArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices);
~GLEScmContext();
static int getMaxLights(){return s_glSupport.maxLights;}
static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;}
static int getMaxTexUnits(){return s_glSupport.maxTexUnits;}
static int getMaxTexSize(){return s_glSupport.maxTexSize;}
private:
void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1);
void drawPoints(PointSizeIndices* points);
void drawPointsData(GLESFloatArrays& arrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw);
static GLcmSupport s_glSupport;
GLESpointer* m_texCoords;
int m_pointsIndex;
};
#endif

View File

@@ -18,14 +18,14 @@
#undef GL_API
#define GL_API __declspec(dllexport)
#endif
#include <stdio.h>
#include "GLDispatch.h"
#include "GLEScontext.h"
#include "GLESvalidate.h"
#include "GLESutils.h"
#include "GLfixed_ops.h"
#include "GLEScmContext.h"
#include "GLEScmValidate.h"
#include "GLEScmUtils.h"
#include "TextureUtils.h"
#include <stdio.h>
#include <GLcommon/GLDispatch.h>
#include <GLcommon/GLfixed_ops.h>
#include <GLcommon/TranslatorIfaces.h>
#include <GLcommon/ThreadInfo.h>
#include <GLES/gl.h>
@@ -53,7 +53,6 @@ static ExtentionDescriptor s_glesExtentions[] = {
{"glEGLImageTargetTexture2DOES",(__translatorMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES}
};
/****************************************************************************************************************/
typedef void(*FUNCPTR)();
static EGLiface* s_eglIface = NULL;
static GLESiface s_glesIface = {
@@ -66,14 +65,16 @@ static GLESiface s_glesIface = {
getProcAddress :getProcAddress
};
#include <GLcommon/GLESmacros.h>
extern "C" {
static void initContext(GLEScontext* ctx) {
ctx->init();
}
static GLEScontext* createGLESContext() {
GLEScontext* ctx = new GLEScontext();
return ctx;
return new GLEScmContext();
}
static void deleteGLESContext(GLEScontext* ctx) {
@@ -101,40 +102,6 @@ GL_API GLESiface* __translator_getIfaces(EGLiface* eglIface){
}
#define GET_THREAD() \
ThreadInfo* thrd = NULL; \
if(s_eglIface) { \
thrd = s_eglIface->getThreadInfo(); \
} else { \
fprintf(stderr,"Context wasn't initialized yet \n"); \
}
#define GET_CTX() \
GET_THREAD(); \
if(!thrd) return; \
GLEScontext *ctx = static_cast<GLEScontext*>(thrd->glesContext); \
if(!ctx) return;
#define GET_CTX_RET(failure_ret) \
GET_THREAD(); \
if(!thrd) return failure_ret; \
GLEScontext *ctx = static_cast<GLEScontext*>(thrd->glesContext); \
if(!ctx) return failure_ret;
#define SET_ERROR_IF(condition,err) if((condition)) { \
ctx->setGLerror(err); \
return; \
}
#define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \
ctx->setGLerror(err); \
return ret; \
}
GL_API GLboolean GL_APIENTRY glIsBuffer(GLuint buffer) {
GET_CTX_RET(GL_FALSE)
@@ -146,8 +113,8 @@ GL_API GLboolean GL_APIENTRY glIsBuffer(GLuint buffer) {
}
GL_API GLboolean GL_APIENTRY glIsEnabled( GLenum cap) {
GET_CTX_RET(GL_FALSE)
RET_AND_SET_ERROR_IF(!GLESvalidate::capability(cap,ctx->getMaxLights(),ctx->getMaxClipPlanes()),GL_INVALID_ENUM,GL_FALSE);
GET_CTX_CM_RET(GL_FALSE)
RET_AND_SET_ERROR_IF(!GLEScmValidate::capability(cap,ctx->getMaxLights(),ctx->getMaxClipPlanes()),GL_INVALID_ENUM,GL_FALSE);
if(cap == GL_POINT_SIZE_ARRAY_OES) return ctx->isArrEnabled(cap);
return ctx->dispatcher().glIsEnabled(cap);
@@ -195,28 +162,28 @@ GL_API const GLubyte * GL_APIENTRY glGetString( GLenum name) {
}
GL_API void GL_APIENTRY glActiveTexture( GLenum texture) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
GET_CTX_CM()
SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
ctx->dispatcher().glActiveTexture(texture);
}
GL_API void GL_APIENTRY glAlphaFunc( GLenum func, GLclampf ref) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::alphaFunc(func),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM);
ctx->dispatcher().glAlphaFunc(func,ref);
}
GL_API void GL_APIENTRY glAlphaFuncx( GLenum func, GLclampx ref) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::alphaFunc(func),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::alphaFunc(func),GL_INVALID_ENUM);
ctx->dispatcher().glAlphaFunc(func,X2F(ref));
}
GL_API void GL_APIENTRY glBindBuffer( GLenum target, GLuint buffer) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::bufferTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
//if buffer wasn't generated before,generate one
if(thrd->shareGroup.Ptr() && !thrd->shareGroup->isObject(VERTEXBUFFER,buffer)){
@@ -231,7 +198,7 @@ GL_API void GL_APIENTRY glBindBuffer( GLenum target, GLuint buffer) {
GL_API void GL_APIENTRY glBindTexture( GLenum target, GLuint texture) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::textureTarget(target),GL_INVALID_ENUM)
SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM)
GLuint globalTextureName = texture;
if(texture && thrd->shareGroup.Ptr()){
@@ -248,13 +215,13 @@ GL_API void GL_APIENTRY glBindTexture( GLenum target, GLuint texture) {
GL_API void GL_APIENTRY glBlendFunc( GLenum sfactor, GLenum dfactor) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::blendSrc(sfactor) || !GLESvalidate::blendDst(dfactor),GL_INVALID_ENUM)
SET_ERROR_IF(!GLEScmValidate::blendSrc(sfactor) || !GLEScmValidate::blendDst(dfactor),GL_INVALID_ENUM)
ctx->dispatcher().glBlendFunc(sfactor,dfactor);
}
GL_API void GL_APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::bufferTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
ctx->setBufferData(target,size,data,usage);
}
@@ -262,7 +229,7 @@ GL_API void GL_APIENTRY glBufferData( GLenum target, GLsizeiptr size, const GLv
GL_API void GL_APIENTRY glBufferSubData( GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) {
GET_CTX()
SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
SET_ERROR_IF(!GLESvalidate::bufferTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::bufferTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!ctx->setBufferSubData(target,offset,size,data),GL_INVALID_VALUE);
}
@@ -298,8 +265,8 @@ GL_API void GL_APIENTRY glClearStencil( GLint s) {
}
GL_API void GL_APIENTRY glClientActiveTexture( GLenum texture) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
GET_CTX_CM()
SET_ERROR_IF(!GLEScmValidate::textureEnum(texture,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
ctx->setActiveTexture(texture);
ctx->dispatcher().glClientActiveTexture(texture);
@@ -346,16 +313,16 @@ GL_API void GL_APIENTRY glColorMask( GLboolean red, GLboolean green, GLboolean
GL_API void GL_APIENTRY glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::colorPointerParams(size,stride),GL_INVALID_VALUE);
SET_ERROR_IF(!GLEScmValidate::colorPointerParams(size,stride),GL_INVALID_VALUE);
const GLvoid* data = ctx->setPointer(GL_COLOR_ARRAY,size,type,stride,pointer);
if(type != GL_FIXED) ctx->dispatcher().glColorPointer(size,type,stride,data);
}
GL_API void GL_APIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::texCompImgFrmt(internalformat) && GLESvalidate::textureTarget(target)),GL_INVALID_ENUM);
SET_ERROR_IF(level > log2(ctx->getMaxTexSize())|| border !=0 || level > 0 || !GLESvalidate::texImgDim(width,height,ctx->getMaxTexSize()+2),GL_INVALID_VALUE)
GET_CTX_CM()
SET_ERROR_IF(!(GLEScmValidate::texCompImgFrmt(internalformat) && GLEScmValidate::textureTarget(target)),GL_INVALID_ENUM);
SET_ERROR_IF(level > log2(ctx->getMaxTexSize())|| border !=0 || level > 0 || !GLEScmValidate::texImgDim(width,height,ctx->getMaxTexSize()+2),GL_INVALID_VALUE)
int nMipmaps = -level + 1;
GLsizei tmpWidth = width;
@@ -374,8 +341,8 @@ GL_API void GL_APIENTRY glCompressedTexImage2D( GLenum target, GLint level, GLe
}
GL_API void GL_APIENTRY glCompressedTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::texCompImgFrmt(format) && GLESvalidate::textureTarget(target)),GL_INVALID_ENUM);
GET_CTX_CM()
SET_ERROR_IF(!(GLEScmValidate::texCompImgFrmt(format) && GLEScmValidate::textureTarget(target)),GL_INVALID_ENUM);
SET_ERROR_IF(level < 0 || level > log2(ctx->getMaxTexSize()),GL_INVALID_VALUE)
GLenum uncompressedFrmt;
@@ -386,14 +353,14 @@ GL_API void GL_APIENTRY glCompressedTexSubImage2D( GLenum target, GLint level,
GL_API void GL_APIENTRY glCopyTexImage2D( GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::pixelFrmt(internalformat) && GLESvalidate::textureTarget(target)),GL_INVALID_ENUM);
SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(internalformat) && GLEScmValidate::textureTarget(target)),GL_INVALID_ENUM);
SET_ERROR_IF(border != 0,GL_INVALID_VALUE);
ctx->dispatcher().glCopyTexImage2D(target,level,internalformat,x,y,width,height,border);
}
GL_API void GL_APIENTRY glCopyTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::textureTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM);
ctx->dispatcher().glCopyTexSubImage2D(target,level,xoffset,yoffset,x,y,width,height);
}
@@ -414,6 +381,7 @@ GL_API void GL_APIENTRY glDeleteBuffers( GLsizei n, const GLuint *buffers) {
GL_API void GL_APIENTRY glDeleteTextures( GLsizei n, const GLuint *textures) {
GET_CTX()
SET_ERROR_IF(n<0,GL_INVALID_VALUE);
if(thrd->shareGroup.Ptr()) {
for(int i=0; i < n; i++){
thrd->shareGroup->deleteName(TEXTURE,textures[i]);
@@ -450,7 +418,7 @@ GL_API void GL_APIENTRY glDisable( GLenum cap) {
GL_API void GL_APIENTRY glDisableClientState( GLenum array) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::supportedArrays(array),GL_INVALID_ENUM)
SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM)
ctx->enableArr(array,false);
if(array != GL_POINT_SIZE_ARRAY_OES) ctx->dispatcher().glDisableClientState(array);
@@ -458,9 +426,9 @@ GL_API void GL_APIENTRY glDisableClientState( GLenum array) {
GL_API void GL_APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count) {
GET_CTX()
GET_CTX_CM()
SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
SET_ERROR_IF(!GLESvalidate::drawMode(mode),GL_INVALID_ENUM)
SET_ERROR_IF(!GLEScmValidate::drawMode(mode),GL_INVALID_ENUM)
if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return;
@@ -475,9 +443,11 @@ GL_API void GL_APIENTRY glDrawArrays( GLenum mode, GLint first, GLsizei count)
}
GL_API void GL_APIENTRY glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *elementsIndices) {
GET_CTX()
GET_CTX_CM()
SET_ERROR_IF(count < 0,GL_INVALID_VALUE)
SET_ERROR_IF((!GLESvalidate::drawMode(mode) || !GLESvalidate::drawType(type)),GL_INVALID_ENUM)
SET_ERROR_IF((!GLEScmValidate::drawMode(mode) || !GLEScmValidate::drawType(type)),GL_INVALID_ENUM)
if(!ctx->isArrEnabled(GL_VERTEX_ARRAY)) return;
const GLvoid* indices = elementsIndices;
GLESFloatArrays tmpArrs;
if(ctx->isBindedBuffer(GL_ELEMENT_ARRAY_BUFFER)) { // if vbo is binded take the indices from the vbo
@@ -501,7 +471,7 @@ GL_API void GL_APIENTRY glEnable( GLenum cap) {
GL_API void GL_APIENTRY glEnableClientState( GLenum array) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::supportedArrays(array),GL_INVALID_ENUM)
SET_ERROR_IF(!GLEScmValidate::supportedArrays(array),GL_INVALID_ENUM)
ctx->enableArr(array,true);
if(array != GL_POINT_SIZE_ARRAY_OES) ctx->dispatcher().glEnableClientState(array);
@@ -590,7 +560,7 @@ GL_API void GL_APIENTRY glGetBooleanv( GLenum pname, GLboolean *params) {
GL_API void GL_APIENTRY glGetBufferParameteriv( GLenum target, GLenum pname, GLint *params) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::bufferTarget(target) && GLESvalidate::bufferParam(pname)),GL_INVALID_ENUM);
SET_ERROR_IF(!(GLEScmValidate::bufferTarget(target) && GLEScmValidate::bufferParam(pname)),GL_INVALID_ENUM);
SET_ERROR_IF(!ctx->isBindedBuffer(target),GL_INVALID_OPERATION);
bool ret = true;
switch(pname) {
@@ -753,7 +723,7 @@ GL_API void GL_APIENTRY glGetTexParameterxv( GLenum target, GLenum pname, GLfix
GL_API void GL_APIENTRY glHint( GLenum target, GLenum mode) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::hintTargetMode(target,mode),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::hintTargetMode(target,mode),GL_INVALID_ENUM);
ctx->dispatcher().glHint(target,mode);
}
@@ -904,14 +874,14 @@ GL_API void GL_APIENTRY glMultMatrixx( const GLfixed *m) {
}
GL_API void GL_APIENTRY glMultiTexCoord4f( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
GET_CTX_CM()
SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
ctx->dispatcher().glMultiTexCoord4f(target,s,t,r,q);
}
GL_API void GL_APIENTRY glMultiTexCoord4x( GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
GET_CTX_CM()
SET_ERROR_IF(!GLEScmValidate::textureEnum(target,ctx->getMaxTexUnits()),GL_INVALID_ENUM);
ctx->dispatcher().glMultiTexCoord4f(target,X2F(s),X2F(t),X2F(r),X2F(q));
}
@@ -1013,8 +983,8 @@ GL_API void GL_APIENTRY glPushMatrix(void) {
GL_API void GL_APIENTRY glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::pixelFrmt(format) && GLESvalidate::pixelType(type)),GL_INVALID_ENUM);
SET_ERROR_IF(!(GLESvalidate::pixelOp(format,type)),GL_INVALID_OPERATION);
SET_ERROR_IF(!(GLEScmValidate::pixelFrmt(format) && GLEScmValidate::pixelType(type)),GL_INVALID_ENUM);
SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type)),GL_INVALID_OPERATION);
ctx->dispatcher().glReadPixels(x,y,width,height,format,type,pixels);
}
@@ -1076,7 +1046,7 @@ GL_API void GL_APIENTRY glStencilOp( GLenum fail, GLenum zfail, GLenum zpass) {
GL_API void GL_APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE);
SET_ERROR_IF(!GLEScmValidate::texCoordPointerParams(size,stride),GL_INVALID_VALUE);
const GLvoid* data = ctx->setPointer(GL_TEXTURE_COORD_ARRAY,size,type,stride,pointer);
if(type != GL_FIXED) ctx->dispatcher().glTexCoordPointer(size,type,stride,data);
@@ -1084,38 +1054,38 @@ GL_API void GL_APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei str
GL_API void GL_APIENTRY glTexEnvf( GLenum target, GLenum pname, GLfloat param) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texEnv(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexEnvf(target,pname,param);
}
GL_API void GL_APIENTRY glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texEnv(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexEnvfv(target,pname,params);
}
GL_API void GL_APIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texEnv(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexEnvi(target,pname,param);
}
GL_API void GL_APIENTRY glTexEnviv( GLenum target, GLenum pname, const GLint *params) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texEnv(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexEnviv(target,pname,params);
}
GL_API void GL_APIENTRY glTexEnvx( GLenum target, GLenum pname, GLfixed param) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texEnv(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
GLfloat tmpParam = static_cast<GLfloat>(param);
ctx->dispatcher().glTexEnvf(target,pname,tmpParam);
}
GL_API void GL_APIENTRY glTexEnvxv( GLenum target, GLenum pname, const GLfixed *params) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texEnv(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texEnv(target,pname),GL_INVALID_ENUM);
GLfloat tmpParams[4];
if(pname == GL_TEXTURE_ENV_COLOR) {
@@ -1145,13 +1115,13 @@ static TextureData* getTextureData(){
GL_API void GL_APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::textureTarget(target) &&
GLESvalidate::pixelFrmt(internalformat) &&
GLESvalidate::pixelFrmt(format)&&
GLESvalidate::pixelType(type)),GL_INVALID_ENUM);
SET_ERROR_IF(!(GLEScmValidate::textureTarget(target) &&
GLEScmValidate::pixelFrmt(internalformat) &&
GLEScmValidate::pixelFrmt(format)&&
GLEScmValidate::pixelType(type)),GL_INVALID_ENUM);
//SET_ERROR_IF(level < 0 || border !=0 || level > log2(ctx->getMaxTexSize()) || !GLESvalidate::texImgDim(width,height,ctx->getMaxTexSize()),GL_INVALID_VALUE);
SET_ERROR_IF(!(GLESvalidate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION);
//SET_ERROR_IF(level < 0 || border !=0 || level > log2(ctx->getMaxTexSize()) || !GLEScmValidate::texImgDim(width,height,ctx->getMaxTexSize()),GL_INVALID_VALUE);
SET_ERROR_IF(!(GLEScmValidate::pixelOp(format,type) && internalformat == ((GLint)format)),GL_INVALID_OPERATION);
if (thrd->shareGroup.Ptr()){
unsigned int tex = ctx->getBindedTexture();
@@ -1168,47 +1138,47 @@ GL_API void GL_APIENTRY glTexImage2D( GLenum target, GLint level, GLint interna
GL_API void GL_APIENTRY glTexParameterf( GLenum target, GLenum pname, GLfloat param) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texParams(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexParameterf(target,pname,param);
}
GL_API void GL_APIENTRY glTexParameterfv( GLenum target, GLenum pname, const GLfloat *params) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texParams(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexParameterfv(target,pname,params);
}
GL_API void GL_APIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texParams(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexParameteri(target,pname,param);
}
GL_API void GL_APIENTRY glTexParameteriv( GLenum target, GLenum pname, const GLint *params) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texParams(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexParameteriv(target,pname,params);
}
GL_API void GL_APIENTRY glTexParameterx( GLenum target, GLenum pname, GLfixed param) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texParams(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
ctx->dispatcher().glTexParameterf(target,pname,static_cast<GLfloat>(param));
}
GL_API void GL_APIENTRY glTexParameterxv( GLenum target, GLenum pname, const GLfixed *params) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::texParams(target,pname),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::texParams(target,pname),GL_INVALID_ENUM);
GLfloat param = static_cast<GLfloat>(params[0]);
ctx->dispatcher().glTexParameterfv(target,pname,&param);
}
GL_API void GL_APIENTRY glTexSubImage2D( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) {
GET_CTX()
SET_ERROR_IF(!(GLESvalidate::textureTarget(target) &&
GLESvalidate::pixelFrmt(format)&&
GLESvalidate::pixelType(type)),GL_INVALID_ENUM);
SET_ERROR_IF(!GLESvalidate::pixelOp(format,type),GL_INVALID_OPERATION);
SET_ERROR_IF(!(GLEScmValidate::textureTarget(target) &&
GLEScmValidate::pixelFrmt(format)&&
GLEScmValidate::pixelType(type)),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::pixelOp(format,type),GL_INVALID_OPERATION);
ctx->dispatcher().glTexSubImage2D(target,level,xoffset,yoffset,width,height,format,type,pixels);
}
@@ -1225,7 +1195,7 @@ GL_API void GL_APIENTRY glTranslatex( GLfixed x, GLfixed y, GLfixed z) {
GL_API void GL_APIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) {
GET_CTX()
SET_ERROR_IF(!GLESvalidate::vertexPointerParams(size,stride),GL_INVALID_VALUE);
SET_ERROR_IF(!GLEScmValidate::vertexPointerParams(size,stride),GL_INVALID_VALUE);
const GLvoid* data = ctx->setPointer(GL_VERTEX_ARRAY,size,type,stride,pointer);
if(type != GL_FIXED) ctx->dispatcher().glVertexPointer(size,type,stride,data);
@@ -1239,7 +1209,7 @@ GL_API void GL_APIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei he
void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
{
GET_CTX();
SET_ERROR_IF(!GLESvalidate::textureTarget(target),GL_INVALID_ENUM);
SET_ERROR_IF(!GLEScmValidate::textureTarget(target),GL_INVALID_ENUM);
EglImage *img = s_eglIface->eglAttachEGLImage((unsigned int)image);
if (img) {
// Create the texture object in the underlying EGL implementation,

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESutils.h"
#include "GLEScmUtils.h"
size_t glParamSize(GLenum param)

View File

@@ -13,27 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESvalidate.h"
#include "GLEScmValidate.h"
#include <GLcommon/GLutils.h>
bool GLESvalidate::textureEnum(GLenum e,unsigned int maxTex) {
return e >= GL_TEXTURE0 && e <= (GL_TEXTURE0 + maxTex);
}
bool GLESvalidate::lightEnum(GLenum e,unsigned int maxLights) {
bool GLEScmValidate::lightEnum(GLenum e,unsigned int maxLights) {
return e >=GL_LIGHT0 && e <= (GL_LIGHT0+maxLights);
}
bool GLESvalidate::clipPlaneEnum(GLenum e,unsigned int maxClipPlanes) {
bool GLEScmValidate::clipPlaneEnum(GLenum e,unsigned int maxClipPlanes) {
return e >=GL_CLIP_PLANE0 && e <= (GL_CLIP_PLANE0+maxClipPlanes);
}
bool GLESvalidate::textureTarget(GLenum target) {
bool GLEScmValidate::textureTarget(GLenum target) {
return target == GL_TEXTURE_2D;
}
bool GLESvalidate::alphaFunc(GLenum f) {
bool GLEScmValidate::alphaFunc(GLenum f) {
switch(f) {
case GL_NEVER:
case GL_LESS:
@@ -48,49 +45,20 @@ bool GLESvalidate::alphaFunc(GLenum f) {
return false;
}
bool GLESvalidate::blendSrc(GLenum s) {
switch(s) {
case GL_ZERO:
case GL_ONE:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
return true;
}
return false;
}
bool GLESvalidate::blendDst(GLenum d) {
switch(d) {
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
return true;
}
return false;
}
bool GLESvalidate::vertexPointerParams(GLint size,GLsizei stride) {
bool GLEScmValidate::vertexPointerParams(GLint size,GLsizei stride) {
return ((size >=2) && (size <= 4)) && (stride >=0) ;
}
bool GLESvalidate::colorPointerParams(GLint size,GLsizei stride) {
bool GLEScmValidate::colorPointerParams(GLint size,GLsizei stride) {
return ((size >=3) && (size <= 4)) && (stride >=0) ;
}
bool GLESvalidate::texCoordPointerParams(GLint size,GLsizei stride) {
bool GLEScmValidate::texCoordPointerParams(GLint size,GLsizei stride) {
return ((size >=1) && (size <= 4)) && (stride >=0) ;
}
bool GLESvalidate::supportedArrays(GLenum arr) {
bool GLEScmValidate::supportedArrays(GLenum arr) {
switch(arr) {
case GL_COLOR_ARRAY:
case GL_NORMAL_ARRAY:
@@ -102,25 +70,8 @@ bool GLESvalidate::supportedArrays(GLenum arr) {
return false;
}
bool GLESvalidate::drawMode(GLenum mode) {
switch(mode) {
case GL_POINTS:
case GL_LINE_STRIP:
case GL_LINE_LOOP:
case GL_LINES:
case GL_TRIANGLE_STRIP:
case GL_TRIANGLE_FAN:
case GL_TRIANGLES:
return true;
}
return false;
}
bool GLESvalidate::drawType(GLenum mode) {
return mode == GL_UNSIGNED_BYTE || mode == GL_UNSIGNED_SHORT;
}
bool GLESvalidate::hintTargetMode(GLenum target,GLenum mode) {
bool GLEScmValidate::hintTargetMode(GLenum target,GLenum mode) {
switch(target) {
case GL_FOG_HINT:
case GL_GENERATE_MIPMAP_HINT:
@@ -140,7 +91,7 @@ bool GLESvalidate::hintTargetMode(GLenum target,GLenum mode) {
return true;
}
bool GLESvalidate::texParams(GLenum target,GLenum pname) {
bool GLEScmValidate::texParams(GLenum target,GLenum pname) {
switch(pname) {
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
@@ -153,7 +104,7 @@ bool GLESvalidate::texParams(GLenum target,GLenum pname) {
return target == GL_TEXTURE_2D;
}
bool GLESvalidate::texEnv(GLenum target,GLenum pname) {
bool GLEScmValidate::texEnv(GLenum target,GLenum pname) {
switch(pname) {
case GL_TEXTURE_ENV_MODE:
case GL_COMBINE_RGB:
@@ -180,7 +131,7 @@ bool GLESvalidate::texEnv(GLenum target,GLenum pname) {
return (target == GL_TEXTURE_ENV || target == GL_POINT_SPRITE_OES);
}
bool GLESvalidate::capability(GLenum cap,int maxLights,int maxClipPlanes) {
bool GLEScmValidate::capability(GLenum cap,int maxLights,int maxClipPlanes) {
switch(cap) {
case GL_ALPHA_TEST:
case GL_BLEND:
@@ -211,33 +162,12 @@ bool GLESvalidate::capability(GLenum cap,int maxLights,int maxClipPlanes) {
case GL_VERTEX_ARRAY:
return true;
}
return GLESvalidate::lightEnum(cap,maxLights) || GLESvalidate::clipPlaneEnum(cap,maxClipPlanes);
return GLEScmValidate::lightEnum(cap,maxLights) || GLEScmValidate::clipPlaneEnum(cap,maxClipPlanes);
}
bool GLESvalidate::pixelType(GLenum type) {
switch(type) {
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
return true;
}
return false;
}
bool GLESvalidate::pixelFrmt(GLenum format) {
switch(format) {
case GL_ALPHA:
case GL_RGB:
case GL_RGBA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
return true;
}
return false;
}
bool GLESvalidate::texCompImgFrmt(GLenum format) {
bool GLEScmValidate::texCompImgFrmt(GLenum format) {
switch(format) {
case GL_PALETTE4_RGB8_OES:
case GL_PALETTE4_RGBA8_OES:
@@ -254,28 +184,42 @@ bool GLESvalidate::texCompImgFrmt(GLenum format) {
return false;
}
bool GLESvalidate::pixelOp(GLenum format,GLenum type) {
switch(type) {
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
return format == GL_RGBA;
case GL_UNSIGNED_SHORT_5_6_5:
return format == GL_RGB;
}
return true;
}
bool GLESvalidate::texImgDim(GLsizei width,GLsizei height,int maxTexSize) {
bool GLEScmValidate::texImgDim(GLsizei width,GLsizei height,int maxTexSize) {
if( width < 0 || height < 0 || width > maxTexSize || height > maxTexSize)
return false;
return isPowerOf2(width) && isPowerOf2(height);
}
bool GLESvalidate::bufferTarget(GLenum target) {
return target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER;
bool GLEScmValidate::blendSrc(GLenum s) {
switch(s) {
case GL_ZERO:
case GL_ONE:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
return true;
}
return false;
}
bool GLESvalidate::bufferParam(GLenum param) {
return (param == GL_BUFFER_SIZE) || (param == GL_BUFFER_USAGE);
bool GLEScmValidate::blendDst(GLenum d) {
switch(d) {
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
return true;
}
return false;
}

View File

@@ -13,38 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLES_VALIDATE_H
#define GLES_VALIDATE_H
#ifndef GLES_CM_VALIDATE_H
#define GLES_CM_VALIDATE_H
#include <GLES/gl.h>
struct GLESvalidate
#include <GLcommon/GLESvalidate.h>
struct GLEScmValidate : public GLESvalidate
{
static bool blendSrc(GLenum s);
static bool blendDst(GLenum d);
static bool lightEnum(GLenum e,unsigned int maxLIghts);
static bool clipPlaneEnum(GLenum e,unsigned int maxClipPlanes);
static bool alphaFunc(GLenum f);
static bool blendSrc(GLenum s);
static bool blendDst(GLenum d);
static bool vertexPointerParams(GLint size,GLsizei stride);
static bool colorPointerParams(GLint size,GLsizei stride);
static bool supportedArrays(GLenum arr);
static bool drawMode(GLenum mode);
static bool drawType(GLenum mode);
static bool hintTargetMode(GLenum target,GLenum mode);
static bool capability(GLenum cap,int maxLights,int maxClipPlanes);
static bool texParams(GLenum target,GLenum pname);
static bool texCoordPointerParams(GLint size,GLsizei stride);
static bool textureTarget(GLenum target);
static bool textureEnum(GLenum e,unsigned int maxTex);
static bool texEnv(GLenum target,GLenum pname);
static bool pixelFrmt(GLenum format);
static bool pixelType(GLenum type);
static bool pixelOp(GLenum format,GLenum type);
static bool texCompImgFrmt(GLenum format);
static bool texImgDim(GLsizei width,GLsizei height,int maxTexSize);
static bool bufferTarget(GLenum target);
static bool bufferParam(GLenum param);
};
#endif

View File

@@ -0,0 +1,29 @@
LOCAL_PATH := $(call my-dir)
### GLES_CM host implementation (On top of OpenGL) ########################
include $(CLEAR_VARS)
translator_path := $(LOCAL_PATH)/..
#exclude darwin builds
ifeq (, $(findstring $(HOST_OS), darwin))
LOCAL_SRC_FILES := \
GLESv2Context.cpp \
GLESv2Validate.cpp \
GLESv2Imp.cpp
LOCAL_C_INCLUDES += \
$(translator_path)/include \
LOCAL_SHARED_LIBRARIES := \
libGLcommon
LOCAL_CFLAGS := -g -O0
LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := libGLES_V2_translator
include $(BUILD_HOST_SHARED_LIBRARY)
endif

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESv2Context.h"
GLv2Support GLESv2Context::s_glSupport;
void GLESv2Context::init() {
android::Mutex::Autolock mutex(s_lock);
if(!m_initialized) {
int maxTexUnits;
s_glDispatch.dispatchFuncs(GLES_2_0);
s_glDispatch.glGetIntegerv(GL_MAX_VERTEX_ATTRIBS,&s_glSupport.maxVertexAttribs);
s_glDispatch.glGetIntegerv(GL_MAX_TEXTURE_UNITS,&maxTexUnits);
s_glSupport.maxTexUnits = maxTexUnits < MAX_TEX_UNITS ? maxTexUnits:MAX_TEX_UNITS;
for(int i=0; i < s_glSupport.maxVertexAttribs;i++){
m_map[i] = new GLESpointer();
}
}
m_initialized = true;
}
GLESv2Context::GLESv2Context():GLEScontext(){};
void GLESv2Context::convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) {
ArraysMap::iterator it;
unsigned int index = 0;
//going over all clients arrays Pointers
for ( it=m_map.begin() ; it != m_map.end(); it++ ) {
GLenum array_id = (*it).first;
GLESpointer* p = (*it).second;
chooseConvertMethod(fArrs,first,count,type,indices,direct,p,array_id,index);
}
}
//sending data to server side
void GLESv2Context::sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int index) {
s_glDispatch.glVertexAttribPointer(arrayType,size,GL_FLOAT,GL_FALSE,stride,arr);
}

View File

@@ -0,0 +1,45 @@
#ifndef GLES_V2_CONTEXT_H
#define GLES_V2_CONTEXT_H
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <GLcommon/GLDispatch.h>
#include <GLcommon/GLEScontext.h>
#include <GLcommon/objectNameManager.h>
#include <utils/threads.h>
struct GLv2Support {
GLv2Support():maxTexUnits(0),maxVertexAttribs(0){};
int maxTexUnits;
int maxVertexAttribs;
};
class GLESv2Context : public GLEScontext{
public:
void init();
GLESv2Context();
void convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
static unsigned int getMaxTexUnits(){return s_glSupport.maxTexUnits;};
private:
void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1);
static GLv2Support s_glSupport;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,184 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESv2Validate.h"
bool GLESv2Validate::blendEquationMode(GLenum mode){
return mode == GL_FUNC_ADD ||
mode == GL_FUNC_SUBTRACT ||
mode == GL_FUNC_REVERSE_SUBTRACT;
}
bool GLESv2Validate::blendSrc(GLenum s) {
switch(s) {
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_CONSTANT_COLOR:
case GL_ONE_MINUS_CONSTANT_COLOR:
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
case GL_SRC_ALPHA_SATURATE:
return true;
}
return false;
}
bool GLESv2Validate::blendDst(GLenum d) {
switch(d) {
case GL_ZERO:
case GL_ONE:
case GL_SRC_COLOR:
case GL_ONE_MINUS_SRC_COLOR:
case GL_DST_COLOR:
case GL_ONE_MINUS_DST_COLOR:
case GL_SRC_ALPHA:
case GL_ONE_MINUS_SRC_ALPHA:
case GL_DST_ALPHA:
case GL_ONE_MINUS_DST_ALPHA:
case GL_CONSTANT_COLOR:
case GL_ONE_MINUS_CONSTANT_COLOR:
case GL_CONSTANT_ALPHA:
case GL_ONE_MINUS_CONSTANT_ALPHA:
return true;
}
return false;
}
bool GLESv2Validate::textureTarget(GLenum target){
return target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP;
}
bool GLESv2Validate::textureParams(GLenum param){
switch(param) {
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
return true;
default:
return false;
}
}
bool GLESv2Validate::hintTargetMode(GLenum target,GLenum mode){
switch(mode) {
case GL_FASTEST:
case GL_NICEST:
case GL_DONT_CARE:
break;
default: return false;
}
return target == GL_GENERATE_MIPMAP_HINT;
}
bool GLESv2Validate::capability(GLenum cap){
switch(cap){
case GL_BLEND:
case GL_CULL_FACE:
case GL_DEPTH_TEST:
case GL_DITHER:
case GL_POLYGON_OFFSET_FILL:
case GL_SAMPLE_ALPHA_TO_COVERAGE:
case GL_SAMPLE_COVERAGE:
case GL_SCISSOR_TEST:
case GL_STENCIL_TEST:
return true;
}
return false;
}
bool GLESv2Validate::pixelStoreParam(GLenum param){
return param == GL_PACK_ALIGNMENT || param == GL_UNPACK_ALIGNMENT;
}
bool GLESv2Validate::readPixelFrmt(GLenum format){
switch(format) {
case GL_ALPHA:
case GL_RGB:
case GL_RGBA:
return true;
}
return false;
}
bool GLESv2Validate::textureTargetEx(GLenum target){
switch(target){
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
return true;
}
return false;
}
bool GLESv2Validate::framebufferTarget(GLenum target){
return target == GL_FRAMEBUFFER;
}
bool GLESv2Validate::framebufferAttachment(GLenum attachment){
switch(attachment){
case GL_COLOR_ATTACHMENT0:
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
return true;
}
return false;
}
bool GLESv2Validate::framebufferAttachmentParams(GLenum pname){
switch(pname){
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
return true;
}
return false;
}
bool GLESv2Validate::renderbufferTarget(GLenum target){
return target == GL_RENDERBUFFER;
}
bool GLESv2Validate::renderbufferParams(GLenum pname){
switch(pname){
case GL_RENDERBUFFER_WIDTH:
case GL_RENDERBUFFER_HEIGHT:
case GL_RENDERBUFFER_INTERNAL_FORMAT:
case GL_RENDERBUFFER_RED_SIZE:
case GL_RENDERBUFFER_GREEN_SIZE:
case GL_RENDERBUFFER_BLUE_SIZE:
case GL_RENDERBUFFER_ALPHA_SIZE:
case GL_RENDERBUFFER_DEPTH_SIZE:
case GL_RENDERBUFFER_STENCIL_SIZE:
return true;
}
return false;
}

View File

@@ -0,0 +1,42 @@
#ifndef GLES_V2_VALIDATE_H
#define GLES_V2_VALIDATE_H
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <GLES2/gl2.h>
#include <GLcommon/GLESvalidate.h>
struct GLESv2Validate:public GLESvalidate{
static bool blendEquationMode(GLenum mode);
static bool blendSrc(GLenum s);
static bool blendDst(GLenum d);
static bool textureTarget(GLenum target);
static bool textureTargetEx(GLenum target);
static bool textureParams(GLenum param);
static bool hintTargetMode(GLenum target,GLenum mode);
static bool capability(GLenum cap);
static bool pixelStoreParam(GLenum param);
static bool readPixelFrmt(GLenum format);
static bool framebufferTarget(GLenum target);
static bool framebufferAttachment(GLenum attachment);
static bool framebufferAttachmentParams(GLenum pname);
static bool renderbufferTarget(GLenum target);
static bool renderbufferParams(GLenum pname);
};
#endif

View File

@@ -7,14 +7,22 @@ include $(CLEAR_VARS)
translator_path := $(LOCAL_PATH)/..
LOCAL_SRC_FILES := \
GLDispatch.cpp \
GLutils.cpp \
GLEScontext.cpp \
GLESvalidate.cpp \
GLESpointer.cpp \
GLESbuffer.cpp \
RangeManip.cpp \
objectNameManager.cpp
LOCAL_C_INCLUDES += \
$(translator_path)/include
$(translator_path)/include \
$(translator_path)/../../../shared
LOCAL_STATIC_LIBRARIES := \
libOpenglOsUtils \
libutils \
libcutils
@@ -23,6 +31,11 @@ LOCAL_MODULE_TAGS := debug
LOCAL_MODULE := libGLcommon
ifeq ($(HOST_OS),linux)
LOCAL_LDFLAGS := -Wl,--whole-archive
LOCAL_LDLIBS := -lGL -ldl
endif
ifeq ($(HOST_OS),windows)
LOCAL_LDLIBS := -lopengl32 -lgdi32
endif
include $(BUILD_HOST_SHARED_LIBRARY)

View File

@@ -0,0 +1,479 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <GLcommon/GLDispatch.h>
#include <stdio.h>
#include <OpenglOsUtils/osDynLibrary.h>
#ifdef __linux__
#include <GL/glx.h>
#elif defined(WIN32)
#include <windows.h>
#endif
typedef void (*GL_FUNC_PTR)();
static GL_FUNC_PTR getGLFuncAddress(const char *funcName) {
GL_FUNC_PTR ret = NULL;
#ifdef __linux__
static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("GL");
ret = (GL_FUNC_PTR)glXGetProcAddress((const GLubyte*)funcName);
#elif defined(WIN32)
static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("opengl32");
ret = (GL_FUNC_PTR)wglGetProcAddress(funcName);
#else //mac
static osUtils::dynLibrary* libGL = NULL;
#endif
if(!ret && libGL){
ret = libGL->findSymbol(funcName);
}
return ret;
}
#define LOAD_GL_FUNC(name) { void * funcAddrs = NULL; \
if(name == NULL){ \
funcAddrs = (void *)getGLFuncAddress(#name); \
if(funcAddrs) \
*(void**)(&name) = funcAddrs; \
else \
fprintf(stderr,"could not load func %s\n",#name); \
} \
}
/* initializing static GLDispatch members*/
android::Mutex GLDispatch::s_lock;
void (GLAPIENTRY *GLDispatch::glActiveTexture)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glBindBuffer)(GLenum,GLuint) = NULL;
void (GLAPIENTRY *GLDispatch::glBindTexture)(GLenum, GLuint) = NULL;
void (GLAPIENTRY *GLDispatch::glBlendFunc)(GLenum,GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glBufferData)(GLenum,GLsizeiptr,const GLvoid *,GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glBufferSubData)(GLenum,GLintptr,GLsizeiptr,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glClear)(GLbitfield) = NULL;
void (GLAPIENTRY *GLDispatch::glClearColor)(GLclampf,GLclampf,GLclampf,GLclampf) = NULL;
void (GLAPIENTRY *GLDispatch::glClearStencil)(GLint) = NULL;
void (GLAPIENTRY *GLDispatch::glColorMask)(GLboolean,GLboolean,GLboolean,GLboolean) = NULL;
void (GLAPIENTRY *GLDispatch::glCompressedTexImage2D)(GLenum,GLint,GLenum,GLsizei,GLsizei,GLint,GLsizei, const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glCompressedTexSubImage2D)(GLenum,GLint,GLint,GLint,GLsizei,GLsizei,GLenum,GLsizei,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glCopyTexImage2D)(GLenum,GLint,GLenum,GLint,GLint,GLsizei,GLsizei,GLint) = NULL;
void (GLAPIENTRY *GLDispatch::glCopyTexSubImage2D)(GLenum,GLint,GLint,GLint,GLint,GLint,GLsizei,GLsizei) = NULL;
void (GLAPIENTRY *GLDispatch::glCullFace)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glDeleteBuffers)(GLsizei,const GLuint *) = NULL;
void (GLAPIENTRY *GLDispatch::glDeleteTextures)(GLsizei,const GLuint *) = NULL;
void (GLAPIENTRY *GLDispatch::glDepthFunc)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glDepthMask)(GLboolean) = NULL;
void (GLAPIENTRY *GLDispatch::glDisable)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glDrawArrays)(GLenum,GLint,GLsizei) = NULL;
void (GLAPIENTRY *GLDispatch::glDrawElements)(GLenum,GLsizei,GLenum,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glEnable)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glFinish)() = NULL;
void (GLAPIENTRY *GLDispatch::glFlush)() = NULL;
void (GLAPIENTRY *GLDispatch::glFrontFace)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glGenBuffers)(GLsizei,GLuint *) = NULL;
void (GLAPIENTRY *GLDispatch::glGenTextures)(GLsizei,GLuint *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetBooleanv)(GLenum,GLboolean *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetBufferParameteriv)(GLenum, GLenum, GLint *) = NULL;
GLenum (GLAPIENTRY *GLDispatch::glGetError)() = NULL;
void (GLAPIENTRY *GLDispatch::glGetFloatv)(GLenum,GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetIntegerv)(GLenum,GLint *) = NULL;
const GLubyte * (GLAPIENTRY *GLDispatch::glGetString) (GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glGetTexParameterfv)(GLenum,GLenum,GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetTexParameteriv)(GLenum,GLenum,GLint *) = NULL;
void (GLAPIENTRY *GLDispatch::glHint)(GLenum,GLenum) = NULL;
GLboolean (GLAPIENTRY *GLDispatch::glIsBuffer)(GLuint) = NULL;
GLboolean (GLAPIENTRY *GLDispatch::glIsEnabled)(GLenum) = NULL;
GLboolean (GLAPIENTRY *GLDispatch::glIsTexture)(GLuint) = NULL;
void (GLAPIENTRY *GLDispatch::glLineWidth)(GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glPolygonOffset)(GLfloat, GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glPixelStorei)(GLenum,GLint) = NULL;
void (GLAPIENTRY *GLDispatch::glReadPixels)(GLint,GLint,GLsizei,GLsizei,GLenum,GLenum,GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glSampleCoverage)(GLclampf,GLboolean) = NULL;
void (GLAPIENTRY *GLDispatch::glScissor)(GLint,GLint,GLsizei,GLsizei) = NULL;
void (GLAPIENTRY *GLDispatch::glStencilFunc)(GLenum,GLint,GLuint) = NULL;
void (GLAPIENTRY *GLDispatch::glStencilMask)(GLuint) = NULL;
void (GLAPIENTRY *GLDispatch::glStencilOp)(GLenum, GLenum,GLenum);
void (GLAPIENTRY *GLDispatch::glTexImage2D)(GLenum,GLint,GLint,GLsizei,GLsizei,GLint,GLenum,GLenum,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glTexParameteri)(GLenum,GLenum,GLint) = NULL;
void (GLAPIENTRY *GLDispatch::glTexParameteriv)(GLenum,GLenum,const GLint *) = NULL;
void (GLAPIENTRY *GLDispatch::glTexSubImage2D)(GLenum,GLint,GLint,GLint,GLsizei,GLsizei,GLenum,GLenum,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glViewport)(GLint,GLint,GLsizei,GLsizei) = NULL;
/*GLES 1.1*/
void (GLAPIENTRY *GLDispatch::glAlphaFunc)(GLenum,GLclampf) = NULL;
void (GLAPIENTRY *GLDispatch::glBegin)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glClearDepth)(GLclampd) = NULL;
void (GLAPIENTRY *GLDispatch::glClientActiveTexture)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glClipPlane)(GLenum,const GLdouble *) = NULL;
void (GLAPIENTRY *GLDispatch::glColor4d)(GLdouble,GLdouble,GLdouble,GLdouble) = NULL;
void (GLAPIENTRY *GLDispatch::glColor4f)(GLfloat,GLfloat,GLfloat,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glColor4fv)(const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glColor4ub)(GLubyte,GLubyte,GLubyte,GLubyte) = NULL;
void (GLAPIENTRY *GLDispatch::glColor4ubv)(const GLubyte *) = NULL;
void (GLAPIENTRY *GLDispatch::glColorPointer)(GLint,GLenum,GLsizei,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glDepthRange)(GLclampd,GLclampd) = NULL;
void (GLAPIENTRY *GLDispatch::glDisableClientState)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glEnableClientState)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glEnd)() = NULL;
void (GLAPIENTRY *GLDispatch::glFogf)(GLenum, GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glFogfv)(GLenum,const GLfloat *);
void (GLAPIENTRY *GLDispatch::glFrustum)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble) = NULL;
void (GLAPIENTRY *GLDispatch::glGetClipPlane)(GLenum,GLdouble *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetDoublev)(GLenum,GLdouble *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetLightfv)(GLenum,GLenum,GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetMaterialfv)(GLenum,GLenum,GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetPointerv)(GLenum,GLvoid**) = NULL;
void (GLAPIENTRY *GLDispatch::glGetTexEnvfv)(GLenum,GLenum,GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glGetTexEnviv)(GLenum,GLenum,GLint *)= NULL;
void (GLAPIENTRY *GLDispatch::glLightf)(GLenum,GLenum,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glLightfv)(GLenum,GLenum,const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glLightModelf)(GLenum,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glLightModelfv)(GLenum,const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glLoadIdentity)() = NULL;
void (GLAPIENTRY *GLDispatch::glLoadMatrixf)(const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glLogicOp)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glMaterialf)(GLenum,GLenum,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glMaterialfv)(GLenum,GLenum,const GLfloat *);
void (GLAPIENTRY *GLDispatch::glMultiTexCoord2fv)(GLenum, const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glMultiTexCoord2sv)(GLenum, const GLshort *) = NULL;
void (GLAPIENTRY *GLDispatch::glMultiTexCoord3fv)(GLenum, const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glMultiTexCoord3sv)(GLenum,const GLshort *) = NULL;
void (GLAPIENTRY *GLDispatch::glMultiTexCoord4f)(GLenum,GLfloat,GLfloat,GLfloat,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glMultiTexCoord4fv)(GLenum,const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glMultiTexCoord4sv)(GLenum,const GLshort *) = NULL;
void (GLAPIENTRY *GLDispatch::glMultMatrixf)(const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glNormal3f)(GLfloat,GLfloat,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glNormal3fv)(const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glNormal3sv)(const GLshort *) = NULL;
void (GLAPIENTRY *GLDispatch::glOrtho)(GLdouble,GLdouble,GLdouble,GLdouble,GLdouble,GLdouble) = NULL;
void (GLAPIENTRY *GLDispatch::glPointParameterf)(GLenum, GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glPointParameterfv)(GLenum, const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glPointSize)(GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glRotatef)(GLfloat,GLfloat,GLfloat,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glScalef)(GLfloat,GLfloat,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glTexEnvf)(GLenum,GLenum,GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glTexEnvfv)(GLenum,GLenum,const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glTexParameterf)(GLenum,GLenum, GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glTexParameterfv)(GLenum,GLenum,const GLfloat *) = NULL;
void (GLAPIENTRY *GLDispatch::glMatrixMode)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glNormalPointer)(GLenum,GLsizei,const GLvoid *) = NULL;
void (GLAPIENTRY *GLDispatch::glPopMatrix)() = NULL;
void (GLAPIENTRY *GLDispatch::glPushMatrix)() = NULL;
void (GLAPIENTRY *GLDispatch::glShadeModel)(GLenum) = NULL;
void (GLAPIENTRY *GLDispatch::glTexCoordPointer)(GLint,GLenum, GLsizei, const GLvoid*) = NULL;
void (GLAPIENTRY *GLDispatch::glTexEnvi)(GLenum ,GLenum,GLint) = NULL;
void (GLAPIENTRY *GLDispatch::glTexEnviv)(GLenum, GLenum, const GLint *) = NULL;
void (GLAPIENTRY *GLDispatch::glTranslatef)(GLfloat,GLfloat, GLfloat) = NULL;
void (GLAPIENTRY *GLDispatch::glVertexPointer)(GLint,GLenum,GLsizei, const GLvoid *) = NULL;
/* GLES 2.0*/
void (GL_APIENTRY *GLDispatch::glBlendColor)(GLclampf,GLclampf,GLclampf,GLclampf) = NULL;
void (GL_APIENTRY *GLDispatch::glBlendEquation)(GLenum) = NULL;
void (GL_APIENTRY *GLDispatch::glBlendEquationSeparate)(GLenum,GLenum) = NULL;
void (GL_APIENTRY *GLDispatch::glBlendFuncSeparate)(GLenum,GLenum,GLenum,GLenum) = NULL;
void (GL_APIENTRY *GLDispatch::glStencilFuncSeparate)(GLenum,GLenum,GLint,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glStencilMaskSeparate)(GLenum,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glGenerateMipmap)(GLenum) = NULL;
void (GL_APIENTRY *GLDispatch::glBindFramebuffer)(GLenum,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glBindRenderbuffer)(GLenum,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glDeleteFramebuffers)(GLsizei,const GLuint*) = NULL;
void (GL_APIENTRY *GLDispatch::glDeleteRenderbuffers)(GLsizei,const GLuint*) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib1f)(GLuint,GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib1fv)(GLuint,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib2f)(GLuint,GLfloat, GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib2fv)(GLuint,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib3f)(GLuint,GLfloat, GLfloat,GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib3fv)(GLuint,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib4f)(GLuint,GLfloat,GLfloat,GLfloat,GLfloat ) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttrib4fv)(GLuint,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glVertexAttribPointer)(GLuint,GLint,GLenum,GLboolean,GLsizei,const GLvoid*) = NULL;
void (GL_APIENTRY *GLDispatch::glDisableVertexAttribArray)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glEnableVertexAttribArray)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glGetVertexAttribfv)(GLuint,GLenum,GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetVertexAttribiv)(GLuint,GLenum,GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetVertexAttribPointerv)(GLuint,GLenum,GLvoid**) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform1f)(GLint,GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform1fv)(GLint,GLsizei,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform1i)(GLint,GLint) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform1iv)(GLint,GLsizei,const GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform2f)(GLint,GLfloat,GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform2fv)(GLint,GLsizei,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform2i)(GLint,GLint,GLint) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform2iv)(GLint ,GLsizei,const GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform3f)(GLint,GLfloat,GLfloat,GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform3fv)(GLint,GLsizei,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform3i)(GLint,GLint,GLint,GLint) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform3iv)(GLint,GLsizei,const GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform4f)(GLint,GLfloat,GLfloat,GLfloat,GLfloat) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform4fv)(GLint,GLsizei,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform4i)(GLint,GLint,GLint,GLint,GLint) = NULL;
void (GL_APIENTRY *GLDispatch::glUniform4iv)(GLint,GLsizei,const GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniformMatrix2fv)(GLint,GLsizei,GLboolean,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniformMatrix3fv)(GLint,GLsizei,GLboolean,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glUniformMatrix4fv)(GLint,GLsizei,GLboolean,const GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetFramebufferAttachmentParameteriv)(GLenum,GLenum,GLenum,GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetRenderbufferParameteriv)(GLenum,GLenum,GLint*) = NULL;
GLboolean (GL_APIENTRY *GLDispatch::glIsFramebuffer)(GLuint) = NULL;
GLboolean (GL_APIENTRY *GLDispatch::glIsRenderbuffer)(GLuint) = NULL;
GLenum (GL_APIENTRY *GLDispatch::glCheckFramebufferStatus)(GLenum) = NULL;
void (GL_APIENTRY *GLDispatch::glAttachShader)(GLuint,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glBindAttribLocation)(GLuint,GLuint,const GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glCompileShader)(GLuint) = NULL;
GLuint (GL_APIENTRY *GLDispatch::glCreateProgram)() = NULL;
GLuint (GL_APIENTRY *GLDispatch::glCreateShader)(GLenum) = NULL;
void (GL_APIENTRY *GLDispatch::glDeleteProgram)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glDeleteShader)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glDetachShader)(GLuint,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glLinkProgram)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glUseProgram)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glValidateProgram)(GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glGetActiveAttrib)(GLuint,GLuint,GLsizei,GLsizei*,GLint*,GLenum*,GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetActiveUniform)(GLuint,GLuint,GLsizei,GLsizei*,GLint*,GLenum*,GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetAttachedShaders)(GLuint,GLsizei,GLsizei*,GLuint*) = NULL;
int (GL_APIENTRY *GLDispatch::glGetAttribLocation)(GLuint,const GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetProgramiv)(GLuint,GLenum,GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetProgramInfoLog)(GLuint,GLsizei,GLsizei*,GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetShaderiv)(GLuint,GLenum,GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetShaderInfoLog)(GLuint,GLsizei,GLsizei*,GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetShaderPrecisionFormat)(GLenum,GLenum,GLint*,GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetShaderSource)(GLuint,GLsizei,GLsizei*,GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetUniformfv)(GLuint,GLint,GLfloat*) = NULL;
void (GL_APIENTRY *GLDispatch::glGetUniformiv)(GLuint,GLint,GLint*) = NULL;
int (GL_APIENTRY *GLDispatch::glGetUniformLocation)(GLuint,const GLchar*) = NULL;
void (GL_APIENTRY *GLDispatch::glReleaseShaderCompiler)() = NULL;
void (GL_APIENTRY *GLDispatch::glRenderbufferStorage)(GLenum,GLenum,GLsizei,GLsizei) = NULL;
void (GL_APIENTRY *GLDispatch::glShaderBinary)(GLsizei,const GLuint*,GLenum,const GLvoid*,GLsizei) = NULL;
void (GL_APIENTRY *GLDispatch::glShaderSource)(GLuint,GLsizei,const GLchar**,const GLint*) = NULL;
void (GL_APIENTRY *GLDispatch::glFramebufferRenderbuffer)(GLenum,GLenum,GLenum,GLuint) = NULL;
void (GL_APIENTRY *GLDispatch::glFramebufferTexture2D)(GLenum,GLenum,GLenum,GLuint,GLint) = NULL;
GLDispatch::GLDispatch():m_isLoaded(false){};
void GLDispatch::dispatchFuncs(GLESVersion version){
android::Mutex::Autolock mutex(s_lock);
if(m_isLoaded)
return;
/* Loading OpenGL functions which are needed for implementing BOTH GLES 1.1 & GLES 2.0*/
LOAD_GL_FUNC(glActiveTexture);
LOAD_GL_FUNC(glBindBuffer);
LOAD_GL_FUNC(glBindTexture);
LOAD_GL_FUNC(glBlendFunc);
LOAD_GL_FUNC(glBufferData);
LOAD_GL_FUNC(glBufferSubData);
LOAD_GL_FUNC(glClear);
LOAD_GL_FUNC(glClearColor);
LOAD_GL_FUNC(glClearStencil);
LOAD_GL_FUNC(glColorMask);
LOAD_GL_FUNC(glCompressedTexImage2D);
LOAD_GL_FUNC(glCompressedTexSubImage2D);
LOAD_GL_FUNC(glCopyTexImage2D);
LOAD_GL_FUNC(glCopyTexSubImage2D);
LOAD_GL_FUNC(glCullFace);
LOAD_GL_FUNC(glDeleteBuffers);
LOAD_GL_FUNC(glDeleteTextures);
LOAD_GL_FUNC(glDepthFunc);
LOAD_GL_FUNC(glDepthMask);
LOAD_GL_FUNC(glDisable);
LOAD_GL_FUNC(glDrawArrays);
LOAD_GL_FUNC(glDrawElements);
LOAD_GL_FUNC(glEnable);
LOAD_GL_FUNC(glFinish);
LOAD_GL_FUNC(glFlush);
LOAD_GL_FUNC(glFrontFace);
LOAD_GL_FUNC(glGenBuffers);
LOAD_GL_FUNC(glGenTextures);
LOAD_GL_FUNC(glGetBooleanv);
LOAD_GL_FUNC(glGetBufferParameteriv);
LOAD_GL_FUNC(glGetError);
LOAD_GL_FUNC(glGetFloatv);
LOAD_GL_FUNC(glGetIntegerv);
LOAD_GL_FUNC(glGetString);
LOAD_GL_FUNC(glGetTexParameterfv);
LOAD_GL_FUNC(glGetTexParameteriv);
LOAD_GL_FUNC(glHint);
LOAD_GL_FUNC(glIsBuffer);
LOAD_GL_FUNC(glIsEnabled);
LOAD_GL_FUNC(glIsTexture);
LOAD_GL_FUNC(glLineWidth);
LOAD_GL_FUNC(glPolygonOffset);
LOAD_GL_FUNC(glPixelStorei);
LOAD_GL_FUNC(glReadPixels);
LOAD_GL_FUNC(glSampleCoverage);
LOAD_GL_FUNC(glScissor);
LOAD_GL_FUNC(glStencilFunc);
LOAD_GL_FUNC(glStencilMask);
LOAD_GL_FUNC(glStencilOp);
LOAD_GL_FUNC(glTexImage2D);
LOAD_GL_FUNC(glTexParameteri);
LOAD_GL_FUNC(glTexParameteriv);
LOAD_GL_FUNC(glTexSubImage2D);
LOAD_GL_FUNC(glViewport);
/* Loading OpenGL functions which are needed ONLY for implementing GLES 1.1*/
if(version == GLES_1_1){
LOAD_GL_FUNC(glAlphaFunc);
LOAD_GL_FUNC(glBegin);
LOAD_GL_FUNC(glClearDepth);
LOAD_GL_FUNC(glClientActiveTexture);
LOAD_GL_FUNC(glClipPlane);
LOAD_GL_FUNC(glColor4d);
LOAD_GL_FUNC(glColor4f);
LOAD_GL_FUNC(glColor4fv);
LOAD_GL_FUNC(glColor4ub);
LOAD_GL_FUNC(glColor4ubv);
LOAD_GL_FUNC(glColorPointer);
LOAD_GL_FUNC(glDepthRange);
LOAD_GL_FUNC(glDisableClientState);
LOAD_GL_FUNC(glEnableClientState);
LOAD_GL_FUNC(glEnd);
LOAD_GL_FUNC(glFogf);
LOAD_GL_FUNC(glFogfv);
LOAD_GL_FUNC(glFrustum);
LOAD_GL_FUNC(glGetClipPlane);
LOAD_GL_FUNC(glGetDoublev);
LOAD_GL_FUNC(glGetLightfv);
LOAD_GL_FUNC(glGetMaterialfv);
LOAD_GL_FUNC(glGetPointerv);
LOAD_GL_FUNC(glGetTexEnvfv);
LOAD_GL_FUNC(glGetTexEnviv);
LOAD_GL_FUNC(glLightf);
LOAD_GL_FUNC(glLightfv);
LOAD_GL_FUNC(glLightModelf);
LOAD_GL_FUNC(glLightModelfv);
LOAD_GL_FUNC(glLoadIdentity);
LOAD_GL_FUNC(glLoadMatrixf);
LOAD_GL_FUNC(glLogicOp);
LOAD_GL_FUNC(glMaterialf);
LOAD_GL_FUNC(glMaterialfv);
LOAD_GL_FUNC(glMultiTexCoord2fv);
LOAD_GL_FUNC(glMultiTexCoord2sv);
LOAD_GL_FUNC(glMultiTexCoord3fv);
LOAD_GL_FUNC(glMultiTexCoord3sv);
LOAD_GL_FUNC(glMultiTexCoord4fv);
LOAD_GL_FUNC(glMultiTexCoord4sv);
LOAD_GL_FUNC(glMultiTexCoord4f);
LOAD_GL_FUNC(glMultMatrixf);
LOAD_GL_FUNC(glNormal3f);
LOAD_GL_FUNC(glNormal3fv);
LOAD_GL_FUNC(glNormal3sv);
LOAD_GL_FUNC(glOrtho);
LOAD_GL_FUNC(glPointParameterf);
LOAD_GL_FUNC(glPointParameterfv);
LOAD_GL_FUNC(glPointSize);
LOAD_GL_FUNC(glRotatef);
LOAD_GL_FUNC(glScalef);
LOAD_GL_FUNC(glTexEnvf);
LOAD_GL_FUNC(glTexEnvfv);
LOAD_GL_FUNC(glTexParameterf);
LOAD_GL_FUNC(glTexParameterfv);
LOAD_GL_FUNC(glMatrixMode);
LOAD_GL_FUNC(glNormalPointer);
LOAD_GL_FUNC(glPopMatrix);
LOAD_GL_FUNC(glPushMatrix);
LOAD_GL_FUNC(glShadeModel);
LOAD_GL_FUNC(glTexCoordPointer);
LOAD_GL_FUNC(glTexEnvi);
LOAD_GL_FUNC(glTexEnviv);
LOAD_GL_FUNC(glTranslatef);
LOAD_GL_FUNC(glVertexPointer);
} else if (version == GLES_2_0){
/* Loading OpenGL functions which are needed ONLY for implementing GLES 2.0*/
LOAD_GL_FUNC(glBlendColor);
LOAD_GL_FUNC(glBlendEquation);
LOAD_GL_FUNC(glBlendEquationSeparate);
LOAD_GL_FUNC(glBlendFuncSeparate);
LOAD_GL_FUNC(glBlendFuncSeparate);
LOAD_GL_FUNC(glStencilFuncSeparate);
LOAD_GL_FUNC(glGenerateMipmap);
LOAD_GL_FUNC(glBindFramebuffer);
LOAD_GL_FUNC(glBindRenderbuffer);
LOAD_GL_FUNC(glDeleteFramebuffers);
LOAD_GL_FUNC(glDeleteRenderbuffers);
LOAD_GL_FUNC(glVertexAttrib1f);
LOAD_GL_FUNC(glVertexAttrib1fv);
LOAD_GL_FUNC(glVertexAttrib2f);
LOAD_GL_FUNC(glVertexAttrib2fv);
LOAD_GL_FUNC(glVertexAttrib3f);
LOAD_GL_FUNC(glVertexAttrib3fv);
LOAD_GL_FUNC(glVertexAttrib4f);
LOAD_GL_FUNC(glVertexAttrib4fv);
LOAD_GL_FUNC(glVertexAttribPointer);
LOAD_GL_FUNC(glDisableVertexAttribArray);
LOAD_GL_FUNC(glEnableVertexAttribArray);
LOAD_GL_FUNC(glGetVertexAttribfv);
LOAD_GL_FUNC(glGetVertexAttribiv);
LOAD_GL_FUNC(glGetVertexAttribPointerv);
LOAD_GL_FUNC(glIsFramebuffer);
LOAD_GL_FUNC(glIsRenderbuffer);
LOAD_GL_FUNC(glUniform1f);
LOAD_GL_FUNC(glUniform1fv);
LOAD_GL_FUNC(glUniform1i);
LOAD_GL_FUNC(glUniform1iv);
LOAD_GL_FUNC(glUniform2f);
LOAD_GL_FUNC(glUniform2fv);
LOAD_GL_FUNC(glUniform2i);
LOAD_GL_FUNC(glUniform2iv);
LOAD_GL_FUNC(glUniform3f);
LOAD_GL_FUNC(glUniform3fv);
LOAD_GL_FUNC(glUniform3i);
LOAD_GL_FUNC(glUniform3iv);
LOAD_GL_FUNC(glUniform4f);
LOAD_GL_FUNC(glUniform4fv);
LOAD_GL_FUNC(glUniform4i);
LOAD_GL_FUNC(glUniform4iv);
LOAD_GL_FUNC(glUniformMatrix2fv);
LOAD_GL_FUNC(glUniformMatrix3fv);
LOAD_GL_FUNC(glUniformMatrix4fv);
LOAD_GL_FUNC(glCheckFramebufferStatus);
LOAD_GL_FUNC(glGetFramebufferAttachmentParameteriv);
LOAD_GL_FUNC(glGetRenderbufferParameteriv);
LOAD_GL_FUNC(glAttachShader);
LOAD_GL_FUNC(glBindAttribLocation);
LOAD_GL_FUNC(glCompileShader);
LOAD_GL_FUNC(glCreateProgram);
LOAD_GL_FUNC(glCreateShader);
LOAD_GL_FUNC(glDeleteProgram);
LOAD_GL_FUNC(glDeleteShader);
LOAD_GL_FUNC(glDetachShader);
LOAD_GL_FUNC(glLinkProgram);
LOAD_GL_FUNC(glUseProgram);
LOAD_GL_FUNC(glValidateProgram);
LOAD_GL_FUNC(glGetActiveAttrib);
LOAD_GL_FUNC(glGetActiveUniform);
LOAD_GL_FUNC(glGetAttachedShaders);
LOAD_GL_FUNC(glGetAttribLocation);
LOAD_GL_FUNC(glGetProgramiv);
LOAD_GL_FUNC(glGetProgramInfoLog);
LOAD_GL_FUNC(glGetShaderiv);
LOAD_GL_FUNC(glGetShaderInfoLog);
LOAD_GL_FUNC(glGetShaderPrecisionFormat);
LOAD_GL_FUNC(glGetShaderSource);
LOAD_GL_FUNC(glGetUniformfv);
LOAD_GL_FUNC(glGetUniformiv);
LOAD_GL_FUNC(glGetUniformLocation);
LOAD_GL_FUNC(glReleaseShaderCompiler);
LOAD_GL_FUNC(glRenderbufferStorage);
LOAD_GL_FUNC(glShaderBinary);
LOAD_GL_FUNC(glShaderSource);
LOAD_GL_FUNC(glFramebufferRenderbuffer);
LOAD_GL_FUNC(glFramebufferTexture2D);
}
m_isLoaded = true;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESbuffer.h"
#include <GLcommon/GLESbuffer.h>
#include <string.h>
bool GLESbuffer::setBuffer(GLuint size,GLuint usage,const GLvoid* data) {

View File

@@ -0,0 +1,317 @@
#include <GLcommon/GLEScontext.h>
#include <GLcommon/GLfixed_ops.h>
//decleration
static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices);
static void convertDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize);
static void convertIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize);
GLESFloatArrays::~GLESFloatArrays() {
for(std::map<GLenum,GLfloat*>::iterator it = arrays.begin(); it != arrays.end();it++) {
GLfloat* p = (*it).second;
if(p) {
delete[] p;
}
}
}
GLDispatch GLEScontext::s_glDispatch;
android::Mutex GLEScontext::s_lock;
GLEScontext::GLEScontext():
m_initialized(false) ,
m_activeTexture(0) ,
m_glError(GL_NO_ERROR) ,
m_arrayBuffer(0) ,
m_elementBuffer(0){};
GLenum GLEScontext::getGLerror() {
return m_glError;
}
void GLEScontext::setGLerror(GLenum err) {
m_glError = err;
}
void GLEScontext::setActiveTexture(GLenum tex) {
m_activeTexture = tex - GL_TEXTURE0;
}
GLEScontext::~GLEScontext() {
for(ArraysMap::iterator it = m_map.begin(); it != m_map.end();it++) {
GLESpointer* p = (*it).second;
if(p) {
delete p;
}
}
}
const GLvoid* GLEScontext::setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) {
GLuint bufferName = m_arrayBuffer;
if(bufferName) {
unsigned int offset = reinterpret_cast<unsigned int>(data);
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
m_map[arrType]->setBuffer(size,type,stride,vbo,offset,normalize);
return static_cast<const unsigned char*>(vbo->getData()) + offset;
}
m_map[arrType]->setArray(size,type,stride,data,normalize);
return data;
}
void GLEScontext::enableArr(GLenum arr,bool enable) {
m_map[arr]->enable(enable);
}
bool GLEScontext::isArrEnabled(GLenum arr) {
return m_map[arr]->isEnable();
}
const GLESpointer* GLEScontext::getPointer(GLenum arrType) {
if(m_map.find(arrType) != m_map.end()) return m_map[arrType];
return NULL;
}
static void convertDirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,unsigned int nBytes,unsigned int strideOut,int attribSize) {
for(unsigned int i = 0; i < nBytes;i+=strideOut) {
const GLfixed* fixed_data = (const GLfixed *)dataIn;
//filling attrib
for(int j=0;j<attribSize;j++) {
reinterpret_cast<GLfloat*>(&static_cast<unsigned char*>(dataOut)[i])[j] = X2F(fixed_data[j]);
}
dataIn += strideIn;
}
}
static void convertIndirectLoop(const char* dataIn,unsigned int strideIn,void* dataOut,GLsizei count,GLenum indices_type,const GLvoid* indices,unsigned int strideOut,int attribSize) {
for(int i = 0 ;i < count ;i++) {
unsigned short index = indices_type == GL_UNSIGNED_BYTE? ((GLubyte *)indices)[i]:
((GLushort *)indices)[i];
const GLfixed* fixed_data = (GLfixed *)(dataIn + index*strideIn);
GLfloat* float_data = reinterpret_cast<GLfloat*>(static_cast<unsigned char*>(dataOut) + index*strideOut);
for(int j=0;j<attribSize;j++) {
float_data[j] = X2F(fixed_data[j]);
}
}
}
static void directToBytesRanges(GLint first,GLsizei count,GLESpointer* p,RangeList& list) {
int attribSize = p->getSize()*4; //4 is the sizeof GLfixed or GLfloat in bytes
int stride = p->getStride()?p->getStride():attribSize;
int start = p->getBufferOffset()+first*attribSize;
if(!p->getStride()) {
list.addRange(Range(start,count*attribSize));
} else {
for(int i = 0 ;i < count; i++,start+=stride) {
list.addRange(Range(start,attribSize));
}
}
}
static void indirectToBytesRanges(const GLvoid* indices,GLenum indices_type,GLsizei count,GLESpointer* p,RangeList& list) {
int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes
int stride = p->getStride()?p->getStride():attribSize;
int start = p->getBufferOffset();
for(int i=0 ; i < count; i++) {
GLushort index = (indices_type == GL_UNSIGNED_SHORT?
static_cast<const GLushort*>(indices)[i]:
static_cast<const GLubyte*>(indices)[i]);
list.addRange(Range(start+index*stride,attribSize));
}
}
int bytesRangesToIndices(RangeList& ranges,GLESpointer* p,GLushort* indices) {
int attribSize = p->getSize() * 4; //4 is the sizeof GLfixed or GLfloat in bytes
int stride = p->getStride()?p->getStride():attribSize;
int offset = p->getBufferOffset();
int n = 0;
for(int i=0;i<ranges.size();i++) {
int startIndex = (ranges[i].getStart() - offset) / stride;
int nElements = ranges[i].getSize()/attribSize;
for(int j=0;j<nElements;j++) {
indices[n++] = startIndex+j;
}
}
return n;
}
void GLEScontext::convertDirect(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p,unsigned int& index) {
GLenum type = p->getType();
if(isArrEnabled(array_id) && type == GL_FIXED) {
int attribSize = p->getSize();
unsigned int size = attribSize*count + first;
fArrs.arrays[index] = new GLfloat[size];
int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
const char* data = (const char*)p->getArrayData() + (first*stride);
convertDirectLoop(data,stride,fArrs.arrays[index],size*sizeof(GLfloat),attribSize*sizeof(GLfloat),attribSize);
sendArr(fArrs.arrays[index],array_id,attribSize,0,index);
index++;
}
}
void GLEScontext::convertDirectVBO(GLint first,GLsizei count,GLenum array_id,GLESpointer* p) {
GLenum type = p->getType();
if(isArrEnabled(array_id) && type == GL_FIXED) {
RangeList ranges;
RangeList conversions;
GLushort* indices = NULL;
int attribSize = p->getSize();
int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
unsigned int size = p->getStride()?p->getStride()*count:attribSize*count*sizeof(GLfixed);
char* data = (char*)p->getBufferData() + (first*stride);
if(p->bufferNeedConversion()) {
directToBytesRanges(first,count,p,ranges); //converting indices range to buffer bytes ranges by offset
p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted
if(conversions.size()) { // there are some elements to convert
indices = new GLushort[count];
int nIndices = bytesRangesToIndices(conversions,p,indices); //converting bytes ranges by offset to indices in this array
convertIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,indices,stride,attribSize);
}
}
sendArr(data,array_id,attribSize,p->getStride());
if(indices) delete[] indices;
}
}
static int findMaxIndex(GLsizei count,GLenum type,const GLvoid* indices) {
//finding max index
int max = 0;
if(type == GL_UNSIGNED_BYTE) {
GLubyte* b_indices =(GLubyte *)indices;
for(int i=0;i<count;i++) {
if(b_indices[i] > max) max = b_indices[i];
}
} else {
GLushort* us_indices =(GLushort *)indices;
for(int i=0;i<count;i++) {
if(us_indices[i] > max) max = us_indices[i];
}
}
return max;
}
void GLEScontext::convertIndirect(GLESFloatArrays& fArrs,GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p,unsigned int& index_out) {
GLenum type = p->getType();
int maxElements = findMaxIndex(count,type,indices) + 1;
if(isArrEnabled(array_id) && type == GL_FIXED) {
int attribSize = p->getSize();
int size = attribSize * maxElements;
fArrs.arrays[index_out] = new GLfloat[size];
int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
const char* data = (const char*)p->getArrayData();
convertIndirectLoop(data,stride,fArrs.arrays[index_out],count,indices_type,indices,attribSize*sizeof(GLfloat),attribSize);
sendArr(fArrs.arrays[index_out],array_id,attribSize,0,index_out);
index_out++;
}
}
void GLEScontext::convertIndirectVBO(GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p) {
GLenum type = p->getType();
if(isArrEnabled(array_id) && type == GL_FIXED) {
RangeList ranges;
RangeList conversions;
GLushort* conversionIndices = NULL;
int attribSize = p->getSize();
int stride = p->getStride()?p->getStride():sizeof(GLfixed)*attribSize;
char* data = static_cast<char*>(p->getBufferData());
if(p->bufferNeedConversion()) {
indirectToBytesRanges(indices,indices_type,count,p,ranges); //converting indices range to buffer bytes ranges by offset
p->getBufferConversions(ranges,conversions); // getting from the buffer the relevant ranges that still needs to be converted
if(conversions.size()) { // there are some elements to convert
conversionIndices = new GLushort[count];
int nIndices = bytesRangesToIndices(conversions,p,conversionIndices); //converting bytes ranges by offset to indices in this array
convertIndirectLoop(data,stride,data,nIndices,GL_UNSIGNED_SHORT,conversionIndices,stride,attribSize);
}
}
sendArr(data,array_id,attribSize,p->getStride());
if(conversionIndices) delete[] conversionIndices;
}
}
void GLEScontext::chooseConvertMethod(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id, unsigned int& index) {
bool vertexVBO = m_arrayBuffer!= 0;
if(direct) {
if(vertexVBO) {
convertDirectVBO(first,count,array_id,p);
} else {
convertDirect(fArrs,first,count,array_id,p,index);
}
} else {
if(vertexVBO) {
convertIndirectVBO(count,type,indices,array_id,p);
} else {
convertIndirect(fArrs,count,type,indices,array_id,p,index);
}
}
}
void GLEScontext::bindBuffer(GLenum target,GLuint buffer) {
if(target == GL_ARRAY_BUFFER) {
m_arrayBuffer = buffer;
} else {
m_elementBuffer = buffer;
}
}
//checks if any buffer is binded to target
bool GLEScontext::isBindedBuffer(GLenum target) {
if(target == GL_ARRAY_BUFFER) {
return m_arrayBuffer != 0;
} else {
return m_elementBuffer != 0;
}
}
GLuint GLEScontext::getBuffer(GLenum target) {
return target == GL_ARRAY_BUFFER ? m_arrayBuffer:m_elementBuffer;
}
GLvoid* GLEScontext::getBindedBuffer(GLenum target) {
GLuint bufferName = getBuffer(target);
if(!bufferName) return NULL;
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
return vbo->getData();
}
void GLEScontext::getBufferSize(GLenum target,GLint* param) {
GLuint bufferName = getBuffer(target);
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
*param = vbo->getSize();
}
void GLEScontext::getBufferUsage(GLenum target,GLint* param) {
GLuint bufferName = getBuffer(target);
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
*param = vbo->getUsage();
}
bool GLEScontext::setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage) {
GLuint bufferName = getBuffer(target);
if(!bufferName) return false;
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
return vbo->setBuffer(size,usage,data);
}
bool GLEScontext::setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data) {
GLuint bufferName = getBuffer(target);
if(!bufferName) return false;
GLESbuffer* vbo = static_cast<GLESbuffer*>(m_shareGroup->getObjectData(VERTEXBUFFER,bufferName).Ptr());
return vbo->setSubBuffer(offset,size,data);
}

View File

@@ -13,10 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESpointer.h"
#include <GLcommon/GLESpointer.h>
#include <stdlib.h>
GLESpointer::GLESpointer():m_size(0),m_type(0),m_stride(0),m_enabled(false),m_data(NULL),m_buffer(NULL),m_buffOffset(0){};
GLESpointer::GLESpointer():m_size(0),
m_type(0),
m_stride(0),
m_enabled(false),
m_normalize(false),
m_data(NULL),
m_buffer(NULL),
m_buffOffset(0){};
GLenum GLESpointer:: getType() const {
@@ -49,25 +56,31 @@ bool GLESpointer::isEnable() const {
return m_enabled;
}
bool GLESpointer::isNormalize() const {
return m_normalize;
}
void GLESpointer::enable(bool b) {
m_enabled = b;
}
void GLESpointer::setArray(GLint size,GLenum type,GLsizei stride,const GLvoid* data) {
void GLESpointer::setArray(GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize) {
m_size = size;
m_type = type;
m_stride = stride;
m_data = data;
m_buffer = NULL;
m_normalize = normalize;
}
void GLESpointer::setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,int offset) {
void GLESpointer::setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,int offset,bool normalize) {
m_size = size;
m_type = type;
m_stride = stride;
m_data = NULL;
m_buffer = buf;
m_buffOffset = offset;
m_normalize = normalize;
}
void GLESpointer::getBufferConversions(const RangeList& rl,RangeList& rlOut) {

View File

@@ -0,0 +1,66 @@
#include<GLcommon/GLESvalidate.h>
bool GLESvalidate::textureEnum(GLenum e,unsigned int maxTex) {
return e >= GL_TEXTURE0 && e <= (GL_TEXTURE0 + maxTex);
}
bool GLESvalidate::pixelType(GLenum type) {
switch(type) {
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
return true;
}
return false;
}
bool GLESvalidate::pixelOp(GLenum format,GLenum type) {
switch(type) {
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_5_5_1:
return format == GL_RGBA;
case GL_UNSIGNED_SHORT_5_6_5:
return format == GL_RGB;
}
return true;
}
bool GLESvalidate::pixelFrmt(GLenum format) {
switch(format) {
case GL_ALPHA:
case GL_RGB:
case GL_RGBA:
case GL_LUMINANCE:
case GL_LUMINANCE_ALPHA:
return true;
}
return false;
}
bool GLESvalidate::bufferTarget(GLenum target) {
return target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER;
}
bool GLESvalidate::bufferParam(GLenum param) {
return (param == GL_BUFFER_SIZE) || (param == GL_BUFFER_USAGE);
}
bool GLESvalidate::drawMode(GLenum mode) {
switch(mode) {
case GL_POINTS:
case GL_LINE_STRIP:
case GL_LINE_LOOP:
case GL_LINES:
case GL_TRIANGLE_STRIP:
case GL_TRIANGLE_FAN:
case GL_TRIANGLES:
return true;
}
return false;
}
bool GLESvalidate::drawType(GLenum mode) {
return mode == GL_UNSIGNED_BYTE || mode == GL_UNSIGNED_SHORT;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "RangeManip.h"
#include <GLcommon/RangeManip.h>
bool Range::rangeIntersection(const Range& r,Range& rOut) const {

View File

@@ -0,0 +1,248 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLDISPATCHH
#define GLDISPATCHH
#include <GLES/gl.h>
#include <GLES2/gl2.h>
#include <utils/threads.h>
#include "GLutils.h"
#define GLAPIENTRY GL_APIENTRY
typedef double GLclampd; /* double precision float in [0,1] */
typedef double GLdouble; /* double precision float */
typedef void(*FUNCPTR)();
class GLDispatch
{
public:
GLDispatch();
void dispatchFuncs(GLESVersion version);
/* OpenGL functions which are needed for implementing BOTH GLES 1.1 & GLES 2.0*/
static void (GLAPIENTRY *glActiveTexture) ( GLenum texture );
static void (GLAPIENTRY *glBindBuffer) (GLenum target, GLuint buffer);
static void (GLAPIENTRY *glBindTexture) (GLenum target, GLuint texture);
static void (GLAPIENTRY *glBlendFunc) (GLenum sfactor, GLenum dfactor);
static void (GLAPIENTRY *glBufferData) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
static void (GLAPIENTRY *glBufferSubData) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
static void (GLAPIENTRY *glClear) (GLbitfield mask);
static void (GLAPIENTRY *glClearColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
static void (GLAPIENTRY *glClearStencil) (GLint s);
static void (GLAPIENTRY *glColorMask) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
static void (GLAPIENTRY *glCompressedTexImage2D) ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data );
static void (GLAPIENTRY *glCompressedTexSubImage2D) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid *data );
static void (GLAPIENTRY *glCopyTexImage2D) (GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
static void (GLAPIENTRY *glCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
static void (GLAPIENTRY *glCullFace) (GLenum mode);
static void (GLAPIENTRY *glDeleteBuffers) (GLsizei n, const GLuint *buffers);
static void (GLAPIENTRY *glDeleteTextures) (GLsizei n, const GLuint *textures);
static void (GLAPIENTRY *glDepthFunc) (GLenum func);
static void (GLAPIENTRY *glDepthMask) (GLboolean flag);
static void (GLAPIENTRY *glDisable) (GLenum cap);
static void (GLAPIENTRY *glDrawArrays) (GLenum mode, GLint first, GLsizei count);
static void (GLAPIENTRY *glDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
static void (GLAPIENTRY *glEnable) (GLenum cap);
static void (GLAPIENTRY *glFinish) (void);
static void (GLAPIENTRY *glFlush) (void);
static void (GLAPIENTRY *glFrontFace) (GLenum mode);
static void (GLAPIENTRY *glGenBuffers) (GLsizei n, GLuint *buffers);
static void (GLAPIENTRY *glGenTextures) (GLsizei n, GLuint *textures);
static void (GLAPIENTRY *glGetBooleanv) (GLenum pname, GLboolean *params);
static void (GLAPIENTRY *glGetBufferParameteriv) (GLenum, GLenum, GLint *);
static GLenum (GLAPIENTRY *glGetError) (void);
static void (GLAPIENTRY *glGetFloatv) (GLenum pname, GLfloat *params);
static void (GLAPIENTRY *glGetIntegerv) (GLenum pname, GLint *params);
static const GLubyte * (GLAPIENTRY *glGetString) (GLenum name);
static void (GLAPIENTRY *glGetTexParameterfv) (GLenum target, GLenum pname, GLfloat *params);
static void (GLAPIENTRY *glGetTexParameteriv) (GLenum target, GLenum pname, GLint *params);
static void (GLAPIENTRY *glHint) (GLenum target, GLenum mode);
static GLboolean (GLAPIENTRY *glIsBuffer) (GLuint);
static GLboolean (GLAPIENTRY *glIsEnabled) (GLenum cap);
static GLboolean (GLAPIENTRY *glIsTexture) (GLuint texture);
static void (GLAPIENTRY *glLineWidth) (GLfloat width);
static void (GLAPIENTRY *glPolygonOffset) (GLfloat factor, GLfloat units);
static void (GLAPIENTRY *glPixelStorei) (GLenum pname, GLint param);
static void (GLAPIENTRY *glReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
static void (GLAPIENTRY *glSampleCoverage) ( GLclampf value, GLboolean invert );
static void (GLAPIENTRY *glScissor) (GLint x, GLint y, GLsizei width, GLsizei height);
static void (GLAPIENTRY *glStencilFunc) (GLenum func, GLint ref, GLuint mask);
static void (GLAPIENTRY *glStencilMask) (GLuint mask);
static void (GLAPIENTRY *glStencilOp) (GLenum fail, GLenum zfail, GLenum zpass);
static void (GLAPIENTRY *glTexImage2D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
static void (GLAPIENTRY *glTexParameteri) (GLenum target, GLenum pname, GLint param);
static void (GLAPIENTRY *glTexParameteriv) (GLenum target, GLenum pname, const GLint *params);
static void (GLAPIENTRY *glTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
static void (GLAPIENTRY *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height);
/* OpenGL functions which are needed ONLY for implementing GLES 1.1*/
static void (GLAPIENTRY *glAlphaFunc) (GLenum func, GLclampf ref);
static void (GLAPIENTRY *glBegin)( GLenum mode );
static void (GLAPIENTRY *glClearDepth) (GLclampd depth);
static void (GLAPIENTRY *glClientActiveTexture) ( GLenum texture );
static void (GLAPIENTRY *glClipPlane) (GLenum plane, const GLdouble *equation);
static void (GLAPIENTRY *glColor4d) (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha);
static void (GLAPIENTRY *glColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
static void (GLAPIENTRY *glColor4fv) ( const GLfloat *v );
static void (GLAPIENTRY *glColor4ub) (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
static void (GLAPIENTRY *glColor4ubv) ( const GLubyte *v );
static void (GLAPIENTRY *glColorPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
static void (GLAPIENTRY *glDepthRange) (GLclampd zNear, GLclampd zFar);
static void (GLAPIENTRY *glDisableClientState) (GLenum array);
static void (GLAPIENTRY *glEnableClientState) (GLenum array);
static void (GLAPIENTRY *glEnd) (void);
static void (GLAPIENTRY *glFogf) (GLenum pname, GLfloat param);
static void (GLAPIENTRY *glFogfv) (GLenum pname, const GLfloat *params);
static void (GLAPIENTRY *glFrustum) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
static void (GLAPIENTRY *glGetClipPlane) (GLenum plane, GLdouble *equation);
static void (GLAPIENTRY *glGetDoublev) ( GLenum pname, GLdouble *params );
static void (GLAPIENTRY *glGetLightfv) (GLenum light, GLenum pname, GLfloat *params);
static void (GLAPIENTRY *glGetMaterialfv) (GLenum face, GLenum pname, GLfloat *params);
static void (GLAPIENTRY *glGetPointerv) (GLenum pname, GLvoid* *params);
static void (GLAPIENTRY *glGetTexEnvfv) (GLenum target, GLenum pname, GLfloat *params);
static void (GLAPIENTRY *glGetTexEnviv) (GLenum target, GLenum pname, GLint *params);
static void (GLAPIENTRY *glLightf) (GLenum light, GLenum pname, GLfloat param);
static void (GLAPIENTRY *glLightfv) (GLenum light, GLenum pname, const GLfloat *params);
static void (GLAPIENTRY *glLightModelf) (GLenum pname, GLfloat param);
static void (GLAPIENTRY *glLightModelfv) (GLenum pname, const GLfloat *params);
static void (GLAPIENTRY *glLoadIdentity) (void);
static void (GLAPIENTRY *glLoadMatrixf) (const GLfloat *m);
static void (GLAPIENTRY *glLogicOp) (GLenum opcode);
static void (GLAPIENTRY *glMaterialf) (GLenum face, GLenum pname, GLfloat param);
static void (GLAPIENTRY *glMaterialfv) (GLenum face, GLenum pname, const GLfloat *params);
static void (GLAPIENTRY *glMultiTexCoord2fv) ( GLenum target, const GLfloat *v );
static void (GLAPIENTRY *glMultiTexCoord2sv) ( GLenum target, const GLshort *v );
static void (GLAPIENTRY *glMultiTexCoord3fv) ( GLenum target, const GLfloat *v );
static void (GLAPIENTRY *glMultiTexCoord3sv) ( GLenum target, const GLshort *v );
static void (GLAPIENTRY *glMultiTexCoord4f) ( GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q );
static void (GLAPIENTRY *glMultiTexCoord4fv) ( GLenum target, const GLfloat *v );
static void (GLAPIENTRY *glMultiTexCoord4sv) ( GLenum target, const GLshort *v );
static void (GLAPIENTRY *glMultMatrixf) (const GLfloat *m);
static void (GLAPIENTRY *glNormal3f) (GLfloat nx, GLfloat ny, GLfloat nz);
static void (GLAPIENTRY *glNormal3fv) ( const GLfloat *v );
static void (GLAPIENTRY *glNormal3sv) ( const GLshort *v );
static void (GLAPIENTRY *glOrtho) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
static void (GLAPIENTRY *glPointParameterf) (GLenum, GLfloat);
static void (GLAPIENTRY *glPointParameterfv) (GLenum, const GLfloat *);
static void (GLAPIENTRY *glPointSize) (GLfloat size);
static void (GLAPIENTRY *glRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
static void (GLAPIENTRY *glScalef) (GLfloat x, GLfloat y, GLfloat z);
static void (GLAPIENTRY *glTexEnvf) (GLenum target, GLenum pname, GLfloat param);
static void (GLAPIENTRY *glTexEnvfv) (GLenum target, GLenum pname, const GLfloat *params);
static void (GLAPIENTRY *glTexParameterf) (GLenum target, GLenum pname, GLfloat param);
static void (GLAPIENTRY *glTexParameterfv) (GLenum target, GLenum pname, const GLfloat *params);
static void (GLAPIENTRY *glMatrixMode) (GLenum mode);
static void (GLAPIENTRY *glNormalPointer) (GLenum type, GLsizei stride, const GLvoid *pointer);
static void (GLAPIENTRY *glPopMatrix) (void);
static void (GLAPIENTRY *glPushMatrix) (void);
static void (GLAPIENTRY *glShadeModel) (GLenum mode);
static void (GLAPIENTRY *glTexCoordPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
static void (GLAPIENTRY *glTexEnvi) (GLenum target, GLenum pname, GLint param);
static void (GLAPIENTRY *glTexEnviv) (GLenum target, GLenum pname, const GLint *params);
static void (GLAPIENTRY *glTranslatef) (GLfloat x, GLfloat y, GLfloat z);
static void (GLAPIENTRY *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
/* Loading OpenGL functions which are needed ONLY for implementing GLES 2.0*/
static void (GL_APIENTRY *glBlendColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
static void (GL_APIENTRY *glBlendEquation)( GLenum mode );
static void (GL_APIENTRY *glBlendEquationSeparate)(GLenum modeRGB, GLenum modeAlpha);
static void (GL_APIENTRY *glBlendFuncSeparate)(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
static void (GL_APIENTRY *glStencilFuncSeparate)(GLenum face, GLenum func, GLint ref, GLuint mask);
static void (GL_APIENTRY *glStencilMaskSeparate)(GLenum face, GLuint mask);
static void (GL_APIENTRY *glGenerateMipmap)(GLenum target);
static void (GL_APIENTRY *glBindFramebuffer)(GLenum target, GLuint framebuffer);
static void (GL_APIENTRY *glBindRenderbuffer)(GLenum target, GLuint renderbuffer);
static void (GL_APIENTRY *glDeleteFramebuffers)(GLsizei n, const GLuint* framebuffers);
static void (GL_APIENTRY *glDeleteRenderbuffers)(GLsizei n, const GLuint* renderbuffers);
static void (GL_APIENTRY *glVertexAttrib1f)(GLuint indx, GLfloat x);
static void (GL_APIENTRY *glVertexAttrib1fv)(GLuint indx, const GLfloat* values);
static void (GL_APIENTRY *glVertexAttrib2f)(GLuint indx, GLfloat x, GLfloat y);
static void (GL_APIENTRY *glVertexAttrib2fv)(GLuint indx, const GLfloat* values);
static void (GL_APIENTRY *glVertexAttrib3f)(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
static void (GL_APIENTRY *glVertexAttrib3fv)(GLuint indx, const GLfloat* values);
static void (GL_APIENTRY *glVertexAttrib4f)(GLuint indx, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
static void (GL_APIENTRY *glVertexAttrib4fv)(GLuint indx, const GLfloat* values);
static void (GL_APIENTRY *glVertexAttribPointer)(GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
static void (GL_APIENTRY *glDisableVertexAttribArray)(GLuint index);
static void (GL_APIENTRY *glEnableVertexAttribArray)(GLuint index);
static void (GL_APIENTRY *glGetVertexAttribfv)(GLuint index, GLenum pname, GLfloat* params);
static void (GL_APIENTRY *glGetVertexAttribiv)(GLuint index, GLenum pname, GLint* params);
static void (GL_APIENTRY *glGetVertexAttribPointerv)(GLuint index, GLenum pname, GLvoid** pointer);
static void (GL_APIENTRY *glUniform1f)(GLint location, GLfloat x);
static void (GL_APIENTRY *glUniform1fv)(GLint location, GLsizei count, const GLfloat* v);
static void (GL_APIENTRY *glUniform1i)(GLint location, GLint x);
static void (GL_APIENTRY *glUniform1iv)(GLint location, GLsizei count, const GLint* v);
static void (GL_APIENTRY *glUniform2f)(GLint location, GLfloat x, GLfloat y);
static void (GL_APIENTRY *glUniform2fv)(GLint location, GLsizei count, const GLfloat* v);
static void (GL_APIENTRY *glUniform2i)(GLint location, GLint x, GLint y);
static void (GL_APIENTRY *glUniform2iv)(GLint location, GLsizei count, const GLint* v);
static void (GL_APIENTRY *glUniform3f)(GLint location, GLfloat x, GLfloat y, GLfloat z);
static void (GL_APIENTRY *glUniform3fv)(GLint location, GLsizei count, const GLfloat* v);
static void (GL_APIENTRY *glUniform3i)(GLint location, GLint x, GLint y, GLint z);
static void (GL_APIENTRY *glUniform3iv)(GLint location, GLsizei count, const GLint* v);
static void (GL_APIENTRY *glUniform4f)(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
static void (GL_APIENTRY *glUniform4fv)(GLint location, GLsizei count, const GLfloat* v);
static void (GL_APIENTRY *glUniform4i)(GLint location, GLint x, GLint y, GLint z, GLint w);
static void (GL_APIENTRY *glUniform4iv)(GLint location, GLsizei count, const GLint* v);
static void (GL_APIENTRY *glUniformMatrix2fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
static void (GL_APIENTRY *glUniformMatrix3fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
static void (GL_APIENTRY *glUniformMatrix4fv)(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
static void (GL_APIENTRY *glGetFramebufferAttachmentParameteriv)(GLenum target, GLenum attachment, GLenum pname, GLint* params);
static void (GL_APIENTRY *glGetRenderbufferParameteriv)(GLenum target, GLenum pname, GLint* params);
static GLboolean (GL_APIENTRY *glIsFramebuffer)(GLuint framebuffer);
static GLboolean (GL_APIENTRY *glIsRenderbuffer)(GLuint renderbuffer);
static GLenum (GL_APIENTRY *glCheckFramebufferStatus)(GLenum target);
static void (GL_APIENTRY *glAttachShader)(GLuint program, GLuint shader);
static void (GL_APIENTRY *glBindAttribLocation)(GLuint program, GLuint index, const GLchar* name);
static void (GL_APIENTRY *glCompileShader)(GLuint shader);
static GLuint (GL_APIENTRY *glCreateProgram)(void);
static GLuint (GL_APIENTRY *glCreateShader)(GLenum type);
static void (GL_APIENTRY *glDeleteProgram)(GLuint program);
static void (GL_APIENTRY *glDeleteShader)(GLuint shader);
static void (GL_APIENTRY *glDetachShader)(GLuint program, GLuint shader);
static void (GL_APIENTRY *glLinkProgram)(GLuint program);
static void (GL_APIENTRY *glUseProgram)(GLuint program);
static void (GL_APIENTRY *glValidateProgram)(GLuint program);
static void (GL_APIENTRY *glGetActiveAttrib)(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
static void (GL_APIENTRY *glGetActiveUniform)(GLuint program, GLuint index, GLsizei bufsize, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
static void (GL_APIENTRY *glGetAttachedShaders)(GLuint program, GLsizei maxcount, GLsizei* count, GLuint* shaders);
static int (GL_APIENTRY *glGetAttribLocation)(GLuint program, const GLchar* name);
static void (GL_APIENTRY *glGetProgramiv)(GLuint program, GLenum pname, GLint* params);
static void (GL_APIENTRY *glGetProgramInfoLog)(GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog);
static void (GL_APIENTRY *glGetShaderiv)(GLuint shader, GLenum pname, GLint* params);
static void (GL_APIENTRY *glGetShaderInfoLog)(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* infolog);
static void (GL_APIENTRY *glGetShaderPrecisionFormat)(GLenum shadertype, GLenum precisiontype, GLint* range, GLint* precision);
static void (GL_APIENTRY *glGetShaderSource)(GLuint shader, GLsizei bufsize, GLsizei* length, GLchar* source);
static void (GL_APIENTRY *glGetUniformfv)(GLuint program, GLint location, GLfloat* params);
static void (GL_APIENTRY *glGetUniformiv)(GLuint program, GLint location, GLint* params);
static int (GL_APIENTRY *glGetUniformLocation)(GLuint program, const GLchar* name);
static void (GL_APIENTRY *glReleaseShaderCompiler)(void);
static void (GL_APIENTRY *glRenderbufferStorage)(GLenum target, GLenum internalformat, GLsizei width, GLsizei height);
static void (GL_APIENTRY *glShaderBinary)(GLsizei n, const GLuint* shaders, GLenum binaryformat, const GLvoid* binary, GLsizei length);
static void (GL_APIENTRY *glShaderSource)(GLuint shader, GLsizei count, const GLchar** string, const GLint* length);
static void (GL_APIENTRY *glFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
static void (GL_APIENTRY *glFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
private:
bool m_isLoaded;
static android::Mutex s_lock;
};
#endif

View File

@@ -19,7 +19,7 @@
#include <stdio.h>
#include <GLES/gl.h>
#include <GLcommon/objectNameManager.h>
#include "RangeManip.h"
#include <GLcommon/RangeManip.h>
class GLESbuffer: public ObjectData {
public:

View File

@@ -1,32 +1,14 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLES_CONTEX_H
#define GLES_CONTEX_H
#ifndef GLES_CONTEXT_H
#define GLES_CONTEXT_H
#include "GLDispatch.h"
#include "GLESpointer.h"
#include "GLESbuffer.h"
#include <map>
#include <vector>
#include "objectNameManager.h"
#include <utils/threads.h>
#define MAX_TEX_UNITS 8
typedef std::map<GLenum,GLESpointer*> ArraysMap;
typedef std::map<GLfloat,std::vector<int> > PointSizeIndices;
struct GLESFloatArrays
{
@@ -35,35 +17,22 @@ struct GLESFloatArrays
std::map<GLenum,GLfloat*> arrays;
};
struct GLsupport {
GLsupport():maxLights(0),maxClipPlane(0),maxTexUnits(0),maxTexSize(0){};
int maxLights;
int maxClipPlane;
int maxTexUnits;
int maxTexSize;
};
class GLEScontext
{
class GLEScontext{
public:
void init();
virtual void init() = 0;
GLEScontext();
GLenum getGLerror();
void setGLerror(GLenum err);
void setShareGroup(ShareGroupPtr grp){m_shareGroup = grp;};
virtual void setActiveTexture(GLenum tex);
unsigned int getBindedTexture(){return m_tex2DBind[m_activeTexture];};
void setBindedTexture(unsigned int tex){ m_tex2DBind[m_activeTexture] = tex;};
bool isArrEnabled(GLenum);
void enableArr(GLenum arr,bool enable);
void setGLerror(GLenum err);
void setActiveTexture(GLenum tex);
const GLvoid* setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data);
unsigned int getBindedTexture(){return m_tex2DBind[m_activeTexture];};
void setBindedTexture(unsigned int tex){ m_tex2DBind[m_activeTexture] = tex;};
const GLvoid* setPointer(GLenum arrType,GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false);
const GLESpointer* getPointer(GLenum arrType);
void convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct);
void drawPointsArrs(GLESFloatArrays& arrs,GLint first,GLsizei count);
void drawPointsElems(GLESFloatArrays& arrs,GLsizei count,GLenum type,const GLvoid* indices);
virtual void convertArrs(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct) = 0;
void bindBuffer(GLenum target,GLuint buffer);
bool isBuffer(GLuint buffer);
bool isBindedBuffer(GLenum target);
@@ -72,43 +41,34 @@ public:
void getBufferUsage(GLenum target,GLint* param);
bool setBufferData(GLenum target,GLsizeiptr size,const GLvoid* data,GLenum usage);
bool setBufferSubData(GLenum target,GLintptr offset,GLsizeiptr size,const GLvoid* data);
void setShareGroup(ShareGroupPtr grp){m_shareGroup = grp;};
static GLDispatch& dispatcher();
static int getMaxLights(){return s_glSupport.maxLights;}
static int getMaxClipPlanes(){return s_glSupport.maxClipPlane;}
static int getMaxTexUnits(){return s_glSupport.maxTexUnits;}
static int getMaxTexSize(){return s_glSupport.maxTexSize;}
virtual ~GLEScontext();
static GLDispatch& dispatcher(){return s_glDispatch;};
protected:
void chooseConvertMethod(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id,unsigned int& index);
static android::Mutex s_lock;
static GLDispatch s_glDispatch;
bool m_initialized;
unsigned int m_activeTexture;
ArraysMap m_map;
~GLEScontext();
private:
virtual void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1) = 0 ;
GLuint getBuffer(GLenum target);
void sendArr(GLvoid* arr,GLenum arrayType,GLint size,GLsizei stride,int pointsIndex = -1);
void drawPoints(PointSizeIndices* points);
void drawPointsData(GLESFloatArrays& arrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices_in,bool isElemsDraw);
void chooseConvertMethod(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum type,const GLvoid* indices,bool direct,GLESpointer* p,GLenum array_id,unsigned int& index);
void convertDirect(GLESFloatArrays& fArrs,GLint first,GLsizei count,GLenum array_id,GLESpointer* p,unsigned int& index);
void convertDirectVBO(GLint first,GLsizei count,GLenum array_id,GLESpointer* p);
void convertIndirect(GLESFloatArrays& fArrs,GLsizei count,GLenum type,const GLvoid* indices,GLenum array_id,GLESpointer* p,unsigned int& index);
void convertIndirectVBO(GLsizei count,GLenum indices_type,const GLvoid* indices,GLenum array_id,GLESpointer* p);
static GLDispatch s_glDispatch;
static GLsupport s_glSupport;
static android::Mutex s_lock;
ArraysMap m_map;
GLESpointer* m_texCoords;
ShareGroupPtr m_shareGroup;
GLenum m_glError;
unsigned int m_activeTexture;
unsigned int m_tex2DBind[MAX_TEX_UNITS];
unsigned int m_arrayBuffer;
unsigned int m_elementBuffer;
int m_pointsIndex;
bool m_initialized;
ShareGroupPtr m_shareGroup;
};
#endif

View File

@@ -0,0 +1,61 @@
#ifndef GLES_MACROS_H
#define GLES_MACROS_H
#define GET_THREAD() \
ThreadInfo* thrd = NULL; \
if(s_eglIface) { \
thrd = s_eglIface->getThreadInfo(); \
} else { \
fprintf(stderr,"Context wasn't initialized yet \n"); \
}
#define GET_CTX() \
GET_THREAD(); \
if(!thrd) return; \
GLEScontext *ctx = static_cast<GLEScontext*>(thrd->glesContext); \
if(!ctx) return;
#define GET_CTX_CM() \
GET_THREAD(); \
if(!thrd) return; \
GLEScmContext *ctx = static_cast<GLEScmContext*>(thrd->glesContext); \
if(!ctx) return;
#define GET_CTX_V2() \
GET_THREAD(); \
if(!thrd) return; \
GLESv2Context *ctx = static_cast<GLESv2Context*>(thrd->glesContext); \
if(!ctx) return;
#define GET_CTX_RET(failure_ret) \
GET_THREAD(); \
if(!thrd) return failure_ret; \
GLEScontext *ctx = static_cast<GLEScontext*>(thrd->glesContext); \
if(!ctx) return failure_ret;
#define GET_CTX_CM_RET(failure_ret) \
GET_THREAD(); \
if(!thrd) return failure_ret; \
GLEScmContext *ctx = static_cast<GLEScmContext*>(thrd->glesContext); \
if(!ctx) return failure_ret;
#define GET_CTX_V2_RET(failure_ret) \
GET_THREAD(); \
if(!thrd) return failure_ret; \
GLESv2Context *ctx = static_cast<GLESv2Context*>(thrd->glesContext); \
if(!ctx) return failure_ret;
#define SET_ERROR_IF(condition,err) if((condition)) { \
ctx->setGLerror(err); \
return; \
}
#define RET_AND_SET_ERROR_IF(condition,err,ret) if((condition)) { \
ctx->setGLerror(err); \
return ret; \
}
#endif

View File

@@ -32,9 +32,10 @@ public:
unsigned int getBufferOffset() const;
void getBufferConversions(const RangeList& rl,RangeList& rlOut);
bool bufferNeedConversion(){ return !m_buffer->fullyConverted();}
void setArray (GLint size,GLenum type,GLsizei stride,const GLvoid* data);
void setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,int offset);
void setArray (GLint size,GLenum type,GLsizei stride,const GLvoid* data,bool normalize = false);
void setBuffer(GLint size,GLenum type,GLsizei stride,GLESbuffer* buf,int offset,bool normalize = false);
bool isEnable() const;
bool isNormalize() const;
void enable(bool b);
private:
@@ -42,6 +43,7 @@ private:
GLenum m_type;
GLsizei m_stride;
bool m_enabled;
bool m_normalize;
const GLvoid* m_data;
GLESbuffer* m_buffer;
unsigned int m_buffOffset;

View File

@@ -0,0 +1,33 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GLES_VALIDATE_H
#define GLES_VALIDATE_H
#include <GLES/gl.h>
struct GLESvalidate
{
static bool textureEnum(GLenum e,unsigned int maxTex);
static bool pixelType(GLenum type);
static bool pixelOp(GLenum format,GLenum type);
static bool pixelFrmt(GLenum format);
static bool bufferTarget(GLenum target);
static bool bufferParam(GLenum param);
static bool drawMode(GLenum mode);
static bool drawType(GLenum mode);
};
#endif

View File

@@ -16,6 +16,12 @@
#ifndef GL_UTILS_H
#define GL_UTILS_H
typedef enum{
GLES_1_1 = 1,
GLES_2_0 = 2,
MAX_GLES_VERSION //Must be last
}GLESVersion;
template <class T>
void swap(T& x,T& y) {
T temp;

View File

@@ -0,0 +1,30 @@
ifneq ($(HOST_OS),darwin)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
#
# This is built on linux host only !!!
#
PREBUILT := $(HOST_PREBUILT_TAG)
SDL_CONFIG ?= prebuilt/$(PREBUILT)/sdl/bin/sdl-config
SDL_CFLAGS := $(shell $(SDL_CONFIG) --cflags)
SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(SDL_CONFIG) --static-libs))
LOCAL_SRC_FILES:= \
triangleCM.cpp
LOCAL_SHARED_LIBRARIES := \
libGLcommon \
libEGL_translator \
libGLES_CM_translator
LOCAL_CFLAGS += $(SDL_CFLAGS) -g -O0
LOCAL_LDLIBS += $(SDL_LDLIBS)
LOCAL_MODULE:= triangleCM
LOCAL_MODULE_TAGS := debug
LOCAL_STATIC_LIBRARIES += libSDL libSDLmain
include $(BUILD_HOST_EXECUTABLE)
endif

View File

@@ -0,0 +1,385 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
//#define GL_API
//#define GL_APIENTRY
#undef ANDROID
#include <EGL/egl.h>
#include <GLES/gl.h>
#undef HAVE_MALLOC_H
#include <SDL.h>
#include <SDL_syswm.h>
#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
#define TEX_WIDTH 256
#define TEX_HEIGHT 256
#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \
(d) < -32768.65535 ? -32768 * 65536 + 65535 : \
((GLfixed) ((d) * 65536)))
#define X_to_F(x) ((float)(x))/65536.0f
static EGLint const attribute_list[] = {
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_NONE
};
unsigned char *genTexture(int width, int height, int comp)
{
unsigned char *img = new unsigned char[width * height * comp];
unsigned char *ptr = img;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
unsigned char col = ((i / 8 + j / 8) % 2) * 255 ;
for (int c = 0; c < comp; c++) {
*ptr = col; ptr++;
}
}
}
return img;
}
unsigned char *genRedTexture(int width, int height, int comp)
{
unsigned char *img = new unsigned char[width * height * comp];
memset(img,0,width*height*comp);
unsigned char *ptr = img;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
unsigned char col = ((i / 8 + j / 8) % 2) * 255 ;
*ptr = col;
ptr+=comp;
}
}
return img;
}
//mip 0;
unsigned char *genPalette4_rgb8(int width, int height,int color)
{
int size = width*height/2 + 16*3/*palette size*/;
unsigned char *img = new unsigned char[size];
memset(img,0,size);
img[0] = 255; img[1] = 0; img[2] = 0; // red
img[3] = 0; img[4] = 0; img[5] = 255; //blue
img[7] = 128; img[8] = 0; img[9] = 128; //fucsia
//rest of the palette is empty
unsigned char *ptr = img+(16*3);
for (int i = 0; i < (height*width/2); i++) {
ptr[i] = (i%2)?0x0|color:0x11|color;
}
return img;
}
void usage(const char *progname)
{
fprintf(stderr, "usage: %s [-n <nframes> -i -h]\n", progname);
fprintf(stderr, "\t-h: this message\n");
fprintf(stderr, "\t-i: immidate mode\n");
fprintf(stderr, "\t-n nframes: generate nframes\n");
fprintf(stderr, "\t-e: use index arrays\n");
fprintf(stderr, "\t-t: use texture\n");
fprintf(stderr, "\t-f: use fixed points\n");
fprintf(stderr, "\t-p: use point size OES extention\n");
}
#ifdef _WIN32
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
#else
int main(int argc, char **argv)
#endif
{
GLuint ui32Vbo = 0; // Vertex buffer object handle
GLuint ui32IndexVbo;
GLuint ui32Texture;
int nframes = 100;
bool immidateMode = true;
bool useIndices = false;
bool useTexture = false;
bool useCompTexture = false;
bool useFixed = false;
bool usePoints = true;
bool useCopy = false;
bool useSubCopy = false;
int c;
extern char *optarg;
#ifdef _WIN32
HWND windowId = NULL;
#else
Window windowId = NULL;
#endif
// // Inialize SDL window
//
if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) {
fprintf(stderr,"SDL init failed: %s\n", SDL_GetError());
return -1;
}
SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE);
if (surface == NULL) {
fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError());
return -1;
}
SDL_SysWMinfo wminfo;
memset(&wminfo, 0, sizeof(wminfo));
SDL_GetWMInfo(&wminfo);
#ifdef _WIN32
windowId = wminfo.window;
#else
windowId = wminfo.info.x11.window;
#endif
int major,minor,num_config;
EGLConfig configs[150];
EGLSurface egl_surface;
EGLContext ctx;
EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(d,&major,&minor);
printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor);
eglChooseConfig(d, attribute_list, configs, 150, &num_config);
printf("config returned %d\n",num_config);
egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL);
ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,NULL);
printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx);
if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){
printf("make current failed\n");
return false;
}
printf("after make current\n");
GLenum err = glGetError();
if(err != GL_NO_ERROR) {
printf("error before drawing ->>> %d \n",err);
} else {
printf("no error before drawing\n");
}
if (useTexture) {
glEnable(GL_TEXTURE_2D);
ui32Texture = 1;
glBindTexture(GL_TEXTURE_2D, ui32Texture);
GLenum err = glGetError();
unsigned char *pixels = NULL;
if(useCompTexture) {
pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,3);
glCompressedTexImage2D(GL_TEXTURE_2D,0,GL_PALETTE4_RGB8_OES,TEX_WIDTH,TEX_HEIGHT,0,3*16+TEX_WIDTH*TEX_HEIGHT/2,pixels);
} else {
pixels = genTexture(TEX_WIDTH, TEX_HEIGHT, 4);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
}
delete pixels;
err = glGetError();
if(err != GL_NO_ERROR)
printf("error %d after image \n",err);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
err = glGetError();
if(err != GL_NO_ERROR)
printf("error after min filter \n");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
err = glGetError();
if(err != GL_NO_ERROR)
printf("error after mag filter \n");
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
err = glGetError();
if(err != GL_NO_ERROR)
printf("error after env mode \n");
if(useCompTexture) {
pixels = genPalette4_rgb8(TEX_WIDTH,TEX_HEIGHT,1);
glCompressedTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_PALETTE4_RGB8_OES,3*16+(TEX_WIDTH*TEX_HEIGHT/128),pixels);
} else {
pixels = genRedTexture(TEX_WIDTH/8, TEX_HEIGHT/8, 4);
glTexSubImage2D(GL_TEXTURE_2D,0,TEX_WIDTH/4,TEX_HEIGHT/4,TEX_WIDTH/8,TEX_HEIGHT/8,GL_RGBA,GL_UNSIGNED_BYTE,pixels);
}
err = glGetError();
if(err != GL_NO_ERROR)
printf("error %d after subimage \n",err);
delete pixels;
}
glClearColor(0.6f, 0.8f, 1.0f, 1.0f); // clear blue
float afVertices[] = { -0.4f,-0.4f,0.0f, // Position
1.0f,0.0f,0.0f,1.0f, // Color
0.0f, 0.0f, // texture
12.f, //point size
0.4f,-0.4f,0.0f,
0.0f,1.0f,0.0f,1.0f,
1.0f, 0.0f,
47.0f,
0.0f,0.4f,0.0f,
0.0f,0.0f,1.0f,1.0f,
0.5f, 1.0f,
14.0f
};
GLfixed fixedVertices[] = { F_to_X(-0.4f),F_to_X(-0.4f),F_to_X(0.0f), // Position
F_to_X(1.0f),F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f), // Color
F_to_X(0.0f),F_to_X(0.0f), // texture
F_to_X(12.0f),//points size
F_to_X(0.4f),F_to_X(-0.4f),F_to_X(0.0f),
F_to_X(0.0f),F_to_X(1.0f),F_to_X(0.0f),F_to_X(1.0f),
F_to_X(1.0f),F_to_X( 0.0f),
F_to_X(30.0f),
F_to_X(0.0f),F_to_X(0.4f),F_to_X(0.0f),
F_to_X(0.0f),F_to_X(0.0f),F_to_X(1.0f),F_to_X(1.0f),
F_to_X(0.5f), F_to_X(1.0f),
F_to_X(30.0)
};
unsigned short indices[] = { 2, 1, 0 };
if (!immidateMode) {
glGenBuffers(1, &ui32Vbo);
ui32Vbo = 1;
printf("ui32Vbo = %d\n", ui32Vbo);
glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
unsigned int uiSize = 3 * (sizeof(float) * 10);
glBufferData(GL_ARRAY_BUFFER, uiSize, useFixed?(void *)fixedVertices:(void*)afVertices, GL_STATIC_DRAW);
ui32IndexVbo = 2;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
}
// Draws a triangle for 800 frames
float angle = 0.0;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLvoid* arr = NULL;
GLenum type;
GLenum drawType;
int size_of;
if(useFixed)
{
arr = fixedVertices;
type = GL_FIXED;
size_of = sizeof(GLfixed);
}
else
{
arr = afVertices;
type = GL_FLOAT;
size_of = sizeof(float);
}
if(usePoints)
{
drawType = GL_POINTS;
}
else
drawType = GL_TRIANGLES;
for (int i = 0; i < 10000; i++) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(angle, 0.0, 0.0, 1.0);
angle += 360.0 / nframes;
// Enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
if (immidateMode) {
glVertexPointer(3,type, size_of * 10, arr);
} else {
glVertexPointer(3,type, size_of * 10, 0);
}
// Set color data in the same way
glEnableClientState(GL_COLOR_ARRAY);
if (immidateMode) {
glColorPointer(4, type, size_of * 10, useFixed?(GLvoid*)(fixedVertices+3):(GLvoid*)(afVertices+3));
} else {
glColorPointer(4,type,size_of * 10, (GLvoid*) (size_of * 3) );
}
if (useTexture) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (immidateMode) {
glTexCoordPointer(2, type, size_of * 10, useFixed?(GLvoid*)(fixedVertices + 7):(GLvoid*)(afVertices+7));
} else {
glTexCoordPointer(2, type, size_of * 10, (GLvoid*)(size_of * 7));
}
}
if(usePoints)
{
glEnableClientState(GL_POINT_SIZE_ARRAY_OES);
if (immidateMode) {
glPointSizePointerOES(type,size_of * 10,useFixed?(GLvoid*)(fixedVertices + 9):(GLvoid*)(afVertices+9));
} else {
glPointSizePointerOES(type,size_of * 10,(GLvoid*)(size_of * 9));
}
}
if (useIndices) {
if (immidateMode) {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, indices);
} else {
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ui32IndexVbo);
glDrawElements(drawType, 3, GL_UNSIGNED_SHORT, 0);
}
} else {
glDrawArrays(drawType, 0, 3);
}
GLenum err = glGetError();
if(err != GL_NO_ERROR)
printf(" error %d has occured while drawing\n",err);
glPopMatrix();
eglSwapBuffers(d,egl_surface);
if(useTexture && useCopy)
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,0,0,256,256,0);
else if(useTexture && useSubCopy)
glCopyTexSubImage2D(GL_TEXTURE_2D,0,100,100,WINDOW_WIDTH/2,WINDOW_HEIGHT/2,50,50);
}
err = glGetError();
if(err != GL_NO_ERROR)
printf("error ->>> %d \n",err);
eglDestroySurface(d,egl_surface);
eglDestroyContext(d,ctx);
// Just wait until the window is closed
SDL_Event ev;
while( SDL_WaitEvent(&ev) ) {
if (ev.type == SDL_QUIT) {
break;
}
}
return 0;
}

View File

@@ -0,0 +1,29 @@
ifneq ($(HOST_OS),darwin)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
#
# This is built on linux host only !!!
#
PREBUILT := $(HOST_PREBUILT_TAG)
SDL_CONFIG ?= prebuilt/$(PREBUILT)/sdl/bin/sdl-config
SDL_CFLAGS := $(shell $(SDL_CONFIG) --cflags)
SDL_LDLIBS := $(filter-out %.a %.lib,$(shell $(SDL_CONFIG) --static-libs))
LOCAL_SRC_FILES:= \
triangleV2.cpp
LOCAL_SHARED_LIBRARIES := \
libGLcommon \
libEGL_translator \
libGLES_V2_translator
LOCAL_CFLAGS += $(SDL_CFLAGS) -g -O0
LOCAL_LDLIBS += $(SDL_LDLIBS)
LOCAL_MODULE:= triangleV2
LOCAL_MODULE_TAGS := debug
LOCAL_STATIC_LIBRARIES += libSDL libSDLmain
include $(BUILD_HOST_EXECUTABLE)
endif

View File

@@ -0,0 +1,315 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
//#define GL_API
//#define GL_APIENTRY
#undef ANDROID
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#undef HAVE_MALLOC_H
#include <SDL.h>
#include <SDL_syswm.h>
#define WINDOW_WIDTH 500
#define WINDOW_HEIGHT 500
#define TEX_WIDTH 256
#define TEX_HEIGHT 256
#define F_to_X(d) ((d) > 32767.65535 ? 32767 * 65536 + 65535 : \
(d) < -32768.65535 ? -32768 * 65536 + 65535 : \
((GLfixed) ((d) * 65536)))
#define X_to_F(x) ((float)(x))/65536.0f
//#define __FIXED__
static EGLint const attribute_list[] = {
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_NONE
};
unsigned char *genTexture(int width, int height, int comp)
{
unsigned char *img = new unsigned char[width * height * comp];
unsigned char *ptr = img;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
unsigned char col = ((i / 8 + j / 8) % 2) * 255 ;
for (int c = 0; c < comp; c++) {
*ptr = col; ptr++;
}
}
}
return img;
}
unsigned char *genRedTexture(int width, int height, int comp)
{
unsigned char *img = new unsigned char[width * height * comp];
memset(img,0,width*height*comp);
unsigned char *ptr = img;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
unsigned char col = ((i / 8 + j / 8) % 2) * 255 ;
*ptr = col;
ptr+=comp;
}
}
return img;
}
void usage(const char *progname)
{
fprintf(stderr, "usage: %s [-n <nframes> -i -h]\n", progname);
fprintf(stderr, "\t-h: this message\n");
fprintf(stderr, "\t-i: immidate mode\n");
fprintf(stderr, "\t-n nframes: generate nframes\n");
fprintf(stderr, "\t-e: use index arrays\n");
fprintf(stderr, "\t-t: use texture\n");
fprintf(stderr, "\t-f: use fixed points\n");
fprintf(stderr, "\t-p: use point size OES extention\n");
}
GLuint LoadShader(GLenum type,const char *shaderSrc)
{
GLuint shader;
GLint compiled;
// Create the shader object
shader = glCreateShader(type);
if(shader == 0)
return 0;
// Load the shader source
glShaderSource(shader, 1, &shaderSrc, NULL);
// Compile the shader
glCompileShader(shader);
// Check the compile status
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if(!compiled)
{
GLint infoLen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen > 1)
{
char* infoLog = (char*)malloc(sizeof(char) * infoLen);
glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
printf("Error compiling shader:\n%s\n", infoLog);
free(infoLog);
}
glDeleteShader(shader);
return 0;
}
return shader;
}
///
// Initialize the shader and program object
//
int Init()
{
char vShaderStr[] =
"attribute vec4 vPosition; \n"
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n"
"} \n";
char fShaderStr[] =
"precision mediump float; \n"
"void main() \n"
"{ \n"
#ifndef __FIXED__
" gl_FragColor = vec4(0.2, 0.5, 0.1, 1.0); \n"
#else
" gl_FragColor = vec4(0.4, 0.3, 0.7, 1.0); \n"
#endif
"} \n";
GLuint vertexShader;
GLuint fragmentShader;
GLuint programObject;
GLint linked;
// Load the vertex/fragment shaders
vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr);
fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fShaderStr);
// Create the program object
programObject = glCreateProgram();
if(programObject == 0)
return -1;
glAttachShader(programObject, vertexShader);
glAttachShader(programObject, fragmentShader);
// Bind vPosition to attribute 0
glBindAttribLocation(programObject, 0, "vPosition");
// Link the program
glLinkProgram(programObject);
// Check the link status
glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
if(!linked)
{
GLint infoLen = 0;
glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen > 1)
{
char* infoLog = (char*)malloc(sizeof(char) * infoLen);
glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
printf("Error linking program:\n%s\n", infoLog);
free(infoLog);
}
glDeleteProgram(programObject);
return -1;
}
// Store the program object
#ifndef __FIXED__
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
#else
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
#endif
return programObject;
}
///
// Draw a triangle using the shader pair created in Init()
//
void Draw(EGLDisplay display,EGLSurface surface,int width,int height,GLuint program)
{
#ifndef __FIXED__
GLfloat vVertices[] = {0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f};
#else
GLfixed vVertices[] = {F_to_X(0.0f), F_to_X(0.5f),F_to_X(0.0f),
F_to_X(-0.5f),F_to_X(-0.5f), F_to_X(0.0f),
F_to_X(0.5f),F_to_X(-0.5f),F_to_X(0.0f)};
#endif
// Set the viewport
glViewport(0, 0,width,height);
// Clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);
// Use the program object
glUseProgram(program);
// Load the vertex data
#ifndef __FIXED__
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vVertices);
#else
glVertexAttribPointer(0, 3, GL_FIXED, GL_FALSE, 0, vVertices);
#endif
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
eglSwapBuffers(display,surface);
}
#ifdef _WIN32
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
#else
int main(int argc, char **argv)
#endif
{
GLuint ui32Vbo = 0; // Vertex buffer object handle
GLuint ui32IndexVbo;
GLuint ui32Texture;
int nframes = 100;
bool immidateMode = false;
bool useIndices = false;
bool useTexture = true;
bool useCompTexture = false;
bool useFixed = true;
bool usePoints = false;
bool useCopy = false;
bool useSubCopy = false;
int c;
extern char *optarg;
#ifdef _WIN32
HWND windowId = NULL;
#else
Window windowId = NULL;
#endif
// // Inialize SDL window
//
if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO)) {
fprintf(stderr,"SDL init failed: %s\n", SDL_GetError());
return -1;
}
SDL_Surface *surface = SDL_SetVideoMode(WINDOW_WIDTH,WINDOW_HEIGHT, 32, SDL_HWSURFACE);
if (surface == NULL) {
fprintf(stderr,"Failed to set video mode: %s\n", SDL_GetError());
return -1;
}
SDL_SysWMinfo wminfo;
memset(&wminfo, 0, sizeof(wminfo));
SDL_GetWMInfo(&wminfo);
#ifdef _WIN32
windowId = wminfo.window;
#else
windowId = wminfo.info.x11.window;
#endif
int major,minor,num_config;
int attrib_list[] ={
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLConfig configs[150];
EGLSurface egl_surface;
EGLContext ctx;
EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(d,&major,&minor);
printf("DISPLAY == %p major =%d minor = %d\n",d,major,minor);
eglChooseConfig(d, attribute_list, configs, 150, &num_config);
printf("config returned %d\n",num_config);
egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL);
ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,attrib_list);
printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx);
if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){
printf("make current failed\n");
return false;
}
printf("after make current\n");
GLenum err = glGetError();
if(err != GL_NO_ERROR) {
printf("error before drawing ->>> %d \n",err);
} else {
printf("no error before drawing\n");
}
int program = Init();
if(program < 0){
printf("failed init shaders\n");
return false;
}
Draw(d,egl_surface,WINDOW_WIDTH,WINDOW_HEIGHT,program);
err = glGetError();
if(err != GL_NO_ERROR)
printf("error ->>> %d \n",err);
eglDestroySurface(d,egl_surface);
eglDestroyContext(d,ctx);
// Just wait until the window is closed
SDL_Event ev;
while( SDL_WaitEvent(&ev) ) {
if (ev.type == SDL_QUIT) {
break;
}
}
return 0;
}