am 8e2dc32b: Merge "Add GLESv2 functionality to GLESv1/GLESv2 shared code"

* commit '8e2dc32b2d540f09a22dc447b53442070477498e':
  Add GLESv2 functionality to GLESv1/GLESv2 shared code
This commit is contained in:
David Turner
2011-05-03 12:53:07 -07:00
committed by Android Git Automerger
5 changed files with 122 additions and 13 deletions

View File

@@ -70,7 +70,7 @@ void GLClientState::enable(int location, int state)
m_states[location].enabled = state; m_states[location].enabled = state;
} }
void GLClientState::setState(int location, int size, GLenum type, GLsizei stride, void *data) void GLClientState::setState(int location, int size, GLenum type, GLboolean normalized, GLsizei stride, void *data)
{ {
if (!validLocation(location)) { if (!validLocation(location)) {
return; return;
@@ -81,6 +81,7 @@ void GLClientState::setState(int location, int size, GLenum type, GLsizei stride
m_states[location].data = data; m_states[location].data = data;
m_states[location].bufferObject = m_currentArrayVbo; m_states[location].bufferObject = m_currentArrayVbo;
m_states[location].elementSize = glSizeof(type) * size; m_states[location].elementSize = glSizeof(type) * size;
m_states[location].normalized = normalized;
} }
void GLClientState::setBufferObject(int location, GLuint id) void GLClientState::setBufferObject(int location, GLuint id)
@@ -210,7 +211,7 @@ int GLClientState::setPixelStore(GLenum param, GLint value)
size_t GLClientState::pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) size_t GLClientState::pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) const
{ {
int pixelsize = glUtilsPixelBitSize(format, type) >> 3; int pixelsize = glUtilsPixelBitSize(format, type) >> 3;

View File

@@ -24,8 +24,12 @@
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "ErrorLog.h"
class GLClientState { class GLClientState {
public: public:
@@ -57,6 +61,7 @@ public:
GLenum glConst; GLenum glConst;
unsigned int elementSize; unsigned int elementSize;
bool enableDirty; // true if any enable state has changed since last draw bool enableDirty; // true if any enable state has changed since last draw
bool normalized;
} VertexAttribState; } VertexAttribState;
typedef struct { typedef struct {
@@ -67,18 +72,20 @@ public:
public: public:
GLClientState(int nLocations = 32); GLClientState(int nLocations = 32);
~GLClientState(); ~GLClientState();
int nLocations() { return m_nLocations; }
const PixelStoreState *pixelStoreState() { return &m_pixelStore; } const PixelStoreState *pixelStoreState() { return &m_pixelStore; }
int setPixelStore(GLenum param, GLint value); int setPixelStore(GLenum param, GLint value);
GLuint currentArrayVbo() { return m_currentArrayVbo; } GLuint currentArrayVbo() { return m_currentArrayVbo; }
GLuint currentIndexVbo() { return m_currentIndexVbo; } GLuint currentIndexVbo() { return m_currentIndexVbo; }
void enable(int location, int state); void enable(int location, int state);
void setState(int location, int size, GLenum type, GLsizei stride, void *data); void setState(int location, int size, GLenum type, GLboolean normalized, GLsizei stride, void *data);
void setBufferObject(int location, GLuint id); void setBufferObject(int location, GLuint id);
const VertexAttribState *getState(int location); const VertexAttribState *getState(int location);
const VertexAttribState *getStateAndEnableDirty(int location, bool *enableChanged); const VertexAttribState *getStateAndEnableDirty(int location, bool *enableChanged);
int getLocation(GLenum loc); int getLocation(GLenum loc);
void setActiveTexture(int texUnit) {m_activeTexture = texUnit; }; void setActiveTexture(int texUnit) {m_activeTexture = texUnit; };
int getActiveTexture() const { return m_activeTexture; } int getActiveTexture() const { return m_activeTexture; }
int bindBuffer(GLenum target, GLuint id) int bindBuffer(GLenum target, GLuint id)
{ {
int err = 0; int err = 0;
@@ -94,6 +101,7 @@ public:
} }
return err; return err;
} }
int getBuffer(GLenum target) int getBuffer(GLenum target)
{ {
int ret=0; int ret=0;
@@ -109,7 +117,7 @@ public:
} }
return ret; return ret;
} }
size_t pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack); size_t pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack) const;
private: private:
PixelStoreState m_pixelStore; PixelStoreState m_pixelStore;
@@ -123,6 +131,46 @@ private:
bool validLocation(int location) { return (location >= 0 && location < m_nLocations); } bool validLocation(int location) { return (location >= 0 && location < m_nLocations); }
public: public:
void getClientStatePointer(GLenum pname, GLvoid** params); void getClientStatePointer(GLenum pname, GLvoid** params);
template <class T>
int getVertexAttribParameter(GLuint index, GLenum param, T *ptr)
{
bool handled = true;
const VertexAttribState *vertexAttrib = getState(index);
if (vertexAttrib == NULL) {
ERR("getVeterxAttriParameter for non existant index %d\n", index);
// set gl error;
return handled;
}
switch(param) {
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
*ptr = (T)(vertexAttrib->bufferObject);
break;
case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
*ptr = (T)(vertexAttrib->enabled);
break;
case GL_VERTEX_ATTRIB_ARRAY_SIZE:
*ptr = (T)(vertexAttrib->size);
break;
case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
*ptr = (T)(vertexAttrib->stride);
break;
case GL_VERTEX_ATTRIB_ARRAY_TYPE:
*ptr = (T)(vertexAttrib->type);
break;
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
*ptr = (T)(vertexAttrib->normalized);
break;
case GL_CURRENT_VERTEX_ATTRIB:
handled = false;
break;
default:
ERR("unknown vertex-attrib parameter param %d\n", param);
}
return handled;
}
template <class T> template <class T>
bool getClientStateParameter(GLenum param, T* ptr) bool getClientStateParameter(GLenum param, T* ptr)
{ {

View File

@@ -49,6 +49,7 @@ size_t glUtilsParamSize(GLenum param)
switch(param) switch(param)
{ {
case GL_DEPTH_FUNC:
case GL_DEPTH_BITS: case GL_DEPTH_BITS:
case GL_MAX_CLIP_PLANES: case GL_MAX_CLIP_PLANES:
case GL_GREEN_BITS: case GL_GREEN_BITS:
@@ -158,9 +159,16 @@ size_t glUtilsParamSize(GLenum param)
case GL_STENCIL_FUNC: case GL_STENCIL_FUNC:
case GL_STENCIL_TEST: case GL_STENCIL_TEST:
case GL_STENCIL_VALUE_MASK: case GL_STENCIL_VALUE_MASK:
case GL_SUBPIXEL_BITS: case GL_STENCIL_BACK_FUNC:
case GL_STENCIL_BACK_VALUE_MASK:
case GL_STENCIL_BACK_REF:
case GL_STENCIL_BACK_FAIL:
case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
case GL_STENCIL_BACK_PASS_DEPTH_PASS:
case GL_STENCIL_BACK_WRITEMASK:
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
case GL_TEXTURE_BINDING_2D: case GL_TEXTURE_BINDING_2D:
case GL_TEXTURE_BINDING_CUBE_MAP:
case GL_TEXTURE_COORD_ARRAY: case GL_TEXTURE_COORD_ARRAY:
case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING: case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
case GL_TEXTURE_COORD_ARRAY_SIZE: case GL_TEXTURE_COORD_ARRAY_SIZE:
@@ -178,6 +186,7 @@ size_t glUtilsParamSize(GLenum param)
case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T: case GL_TEXTURE_WRAP_T:
case GL_GENERATE_MIPMAP: case GL_GENERATE_MIPMAP:
case GL_GENERATE_MIPMAP_HINT:
case GL_RENDERBUFFER_WIDTH_OES: case GL_RENDERBUFFER_WIDTH_OES:
case GL_RENDERBUFFER_HEIGHT_OES: case GL_RENDERBUFFER_HEIGHT_OES:
case GL_RENDERBUFFER_INTERNAL_FORMAT_OES: case GL_RENDERBUFFER_INTERNAL_FORMAT_OES:
@@ -187,6 +196,8 @@ size_t glUtilsParamSize(GLenum param)
case GL_RENDERBUFFER_ALPHA_SIZE_OES: case GL_RENDERBUFFER_ALPHA_SIZE_OES:
case GL_RENDERBUFFER_DEPTH_SIZE_OES: case GL_RENDERBUFFER_DEPTH_SIZE_OES:
case GL_RENDERBUFFER_STENCIL_SIZE_OES: case GL_RENDERBUFFER_STENCIL_SIZE_OES:
case GL_RENDERBUFFER_BINDING:
case GL_FRAMEBUFFER_BINDING:
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES: case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_OES:
case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES: case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME_OES:
case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES: case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES:
@@ -210,6 +221,28 @@ size_t glUtilsParamSize(GLenum param)
case GL_BLEND_DST_ALPHA_OES: case GL_BLEND_DST_ALPHA_OES:
case GL_BLEND_SRC_ALPHA_OES: case GL_BLEND_SRC_ALPHA_OES:
case GL_MAX_LIGHTS: case GL_MAX_LIGHTS:
case GL_SHADER_TYPE:
case GL_DELETE_STATUS:
case GL_COMPILE_STATUS:
case GL_INFO_LOG_LENGTH:
case GL_SHADER_SOURCE_LENGTH:
case GL_CURRENT_PROGRAM:
case GL_LINK_STATUS:
case GL_VALIDATE_STATUS:
case GL_ATTACHED_SHADERS:
case GL_ACTIVE_UNIFORMS:
case GL_ACTIVE_ATTRIBUTES:
case GL_SUBPIXEL_BITS:
case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
case GL_NUM_SHADER_BINARY_FORMATS:
case GL_SHADER_COMPILER:
case GL_MAX_VERTEX_ATTRIBS:
case GL_MAX_VERTEX_UNIFORM_VECTORS:
case GL_MAX_VARYING_VECTORS:
case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
case GL_MAX_RENDERBUFFER_SIZE:
s = 1; s = 1;
break; break;
case GL_ALIASED_LINE_WIDTH_RANGE: case GL_ALIASED_LINE_WIDTH_RANGE:
@@ -225,6 +258,7 @@ size_t glUtilsParamSize(GLenum param)
case GL_CURRENT_NORMAL: case GL_CURRENT_NORMAL:
s = 3; s = 3;
break; break;
case GL_CURRENT_VERTEX_ATTRIB:
case GL_CURRENT_TEXTURE_COORDS: case GL_CURRENT_TEXTURE_COORDS:
case GL_CURRENT_COLOR: case GL_CURRENT_COLOR:
case GL_FOG_COLOR: case GL_FOG_COLOR:
@@ -328,3 +362,25 @@ int glUtilsPixelBitSize(GLenum format, GLenum type)
return pixelsize; return pixelsize;
} }
int glUtilsSumArrayValues(GLint *array, GLsizei count)
{
int sum = 0;
for (int i = 0; i < count; i++) {
sum += *array;
array++;
}
return sum;
}
void glUtilsPackStrings(void *ptr, char **strings, GLint *length, GLsizei count)
{
unsigned char *p = (unsigned char *)ptr;
for (int i = 0; i < count; i++) {
memcpy(p, *strings, *length);
p += *length;
strings++;
length++;
}
}

View File

@@ -39,6 +39,8 @@
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -50,6 +52,8 @@ extern "C" {
int size, GLenum type, unsigned int stride, int size, GLenum type, unsigned int stride,
unsigned int datalen); unsigned int datalen);
int glUtilsPixelBitSize(GLenum format, GLenum type); int glUtilsPixelBitSize(GLenum format, GLenum type);
int glUtilsSumArrayValues(GLint *array, GLsizei count);
void glUtilsPackStrings(void *ptr, char **strings, GLint *length, GLsizei count);
#ifdef __cplusplus #ifdef __cplusplus
}; };
#endif #endif

View File

@@ -147,28 +147,28 @@ void GLEncoder::s_glVertexPointer(void *self, int size, GLenum type, GLsizei str
{ {
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
ctx->m_state->setState(GLClientState::VERTEX_LOCATION, size, type, stride, data); ctx->m_state->setState(GLClientState::VERTEX_LOCATION, size, type, false, stride, data);
} }
void GLEncoder::s_glNormalPointer(void *self, GLenum type, GLsizei stride, void *data) void GLEncoder::s_glNormalPointer(void *self, GLenum type, GLsizei stride, void *data)
{ {
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
ctx->m_state->setState(GLClientState::NORMAL_LOCATION, 3, type, stride, data); ctx->m_state->setState(GLClientState::NORMAL_LOCATION, 3, type, false, stride, data);
} }
void GLEncoder::s_glColorPointer(void *self, int size, GLenum type, GLsizei stride, void *data) void GLEncoder::s_glColorPointer(void *self, int size, GLenum type, GLsizei stride, void *data)
{ {
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
ctx->m_state->setState(GLClientState::COLOR_LOCATION, size, type, stride, data); ctx->m_state->setState(GLClientState::COLOR_LOCATION, size, type, false, stride, data);
} }
void GLEncoder::s_glPointsizePointer(void *self, GLenum type, GLsizei stride, void *data) void GLEncoder::s_glPointsizePointer(void *self, GLenum type, GLsizei stride, void *data)
{ {
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
ctx->m_state->setState(GLClientState::POINTSIZE_LOCATION, 1, type, stride, data); ctx->m_state->setState(GLClientState::POINTSIZE_LOCATION, 1, type, false, stride, data);
} }
void GLEncoder::s_glClientActiveTexture(void *self, GLenum texture) void GLEncoder::s_glClientActiveTexture(void *self, GLenum texture)
@@ -183,7 +183,7 @@ void GLEncoder::s_glTexcoordPointer(void *self, int size, GLenum type, GLsizei s
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
int loc = ctx->m_state->getLocation(GL_TEXTURE_COORD_ARRAY); int loc = ctx->m_state->getLocation(GL_TEXTURE_COORD_ARRAY);
ctx->m_state->setState(loc, size, type, stride, data); ctx->m_state->setState(loc, size, type, false, stride, data);
} }
void GLEncoder::s_glMatrixIndexPointerOES(void *self, int size, GLenum type, GLsizei stride, void * data) void GLEncoder::s_glMatrixIndexPointerOES(void *self, int size, GLenum type, GLsizei stride, void * data)
@@ -191,7 +191,7 @@ void GLEncoder::s_glMatrixIndexPointerOES(void *self, int size, GLenum type, GLs
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
int loc = ctx->m_state->getLocation(GL_MATRIX_INDEX_ARRAY_OES); int loc = ctx->m_state->getLocation(GL_MATRIX_INDEX_ARRAY_OES);
ctx->m_state->setState(loc, size, type, stride, data); ctx->m_state->setState(loc, size, type, false, stride, data);
} }
void GLEncoder::s_glWeightPointerOES(void * self, int size, GLenum type, GLsizei stride, void * data) void GLEncoder::s_glWeightPointerOES(void * self, int size, GLenum type, GLsizei stride, void * data)
@@ -199,7 +199,7 @@ void GLEncoder::s_glWeightPointerOES(void * self, int size, GLenum type, GLsizei
GLEncoder *ctx = (GLEncoder *)self; GLEncoder *ctx = (GLEncoder *)self;
assert(ctx->m_state != NULL); assert(ctx->m_state != NULL);
int loc = ctx->m_state->getLocation(GL_WEIGHT_ARRAY_OES); int loc = ctx->m_state->getLocation(GL_WEIGHT_ARRAY_OES);
ctx->m_state->setState(loc, size, type, stride, data); ctx->m_state->setState(loc, size, type, false, stride, data);
} }
void GLEncoder::s_glEnableClientState(void *self, GLenum state) void GLEncoder::s_glEnableClientState(void *self, GLenum state)