Implement the GL11ExtensionPack APIs.

This commit is contained in:
Jack Palevich 2010-01-28 20:28:32 +08:00
parent 422cfc9c16
commit e44e45c454
5 changed files with 173 additions and 30 deletions

View File

@ -7,14 +7,14 @@ void glBlendFuncSeparate ( GLint srcRGB, GLint dstRGB, GLint srcAlpha, GLint dst
GLint glCheckFramebufferStatusOES ( GLint target ) GLint glCheckFramebufferStatusOES ( GLint target )
void glCompressedTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data ) void glCompressedTexImage2D ( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data )
void glCopyTexImage2D ( GLint target, GLint level, GLint internalformat, GLint x, GLint y, GLint width, GLint height, GLint border ) void glCopyTexImage2D ( GLint target, GLint level, GLint internalformat, GLint x, GLint y, GLint width, GLint height, GLint border )
void glDeleteFramebuffersOES ( GLint n, GLint *framebuffers ) void glDeleteFramebuffersOES ( GLint n, GLuint *framebuffers )
void glDeleteRenderbuffersOES ( GLint n, GLint *renderbuffers ) void glDeleteRenderbuffersOES ( GLint n, GLuint *renderbuffers )
void glEnable ( GLint cap ) void glEnable ( GLint cap )
void glFramebufferRenderbufferOES ( GLint target, GLint attachment, GLint renderbuffertarget, GLint renderbuffer ) void glFramebufferRenderbufferOES ( GLint target, GLint attachment, GLint renderbuffertarget, GLint renderbuffer )
void glFramebufferTexture2DOES ( GLint target, GLint attachment, GLint textarget, GLint texture, GLint level ) void glFramebufferTexture2DOES ( GLint target, GLint attachment, GLint textarget, GLint texture, GLint level )
void glGenerateMipmapOES ( GLint target ) void glGenerateMipmapOES ( GLint target )
void glGenFramebuffersOES ( GLint n, GLint *framebuffers ) void glGenFramebuffersOES ( GLint n, GLuint *framebuffers )
void glGenRenderbuffersOES ( GLint n, GLint *renderbuffers ) void glGenRenderbuffersOES ( GLint n, GLuint *renderbuffers )
void glGetFramebufferAttachmentParameterivOES ( GLint target, GLint attachment, GLint pname, GLint *params ) void glGetFramebufferAttachmentParameterivOES ( GLint target, GLint attachment, GLint pname, GLint *params )
void glGetIntegerv ( GLint pname, GLint *params ) void glGetIntegerv ( GLint pname, GLint *params )
void glGetRenderbufferParameterivOES ( GLint target, GLint pname, GLint *params ) void glGetRenderbufferParameterivOES ( GLint target, GLint pname, GLint *params )

View File

@ -29,28 +29,28 @@ glDrawTexfvOES check coords 5
glDrawTexivOES check coords 5 glDrawTexivOES check coords 5
glDrawTexsvOES check coords 5 glDrawTexsvOES check coords 5
glDrawTexxvOES check coords 5 glDrawTexxvOES check coords 5
glBindFramebufferOES unsupported glBindFramebufferOES requires OES_framebuffer_object
glBindRenderbufferOES unsupported glBindRenderbufferOES requires OES_framebuffer_object
glBlendEquation unsupported glBlendEquation requires OES_blend_subtract
glBlendEquationSeparate unsupported glBlendEquationSeparate requires OES_blend_equation_separate
glBlendFuncSeparate unsupported glBlendFuncSeparate requires OES_blend_equation_separate
glCheckFramebufferStatusOES unsupported return 0 glCheckFramebufferStatusOES requires OES_framebuffer_object return 0
glDeleteFramebuffersOES unsupported glDeleteFramebuffersOES requires OES_framebuffer_object check framebuffers n
glDeleteRenderbuffersOES unsupported glDeleteRenderbuffersOES requires OES_framebuffer_object check renderbuffers n
glFramebufferRenderbufferOES unsupported glFramebufferRenderbufferOES requires OES_framebuffer_object
glFramebufferStorageOES unsupported glFramebufferStorageOES requires OES_framebuffer_object
glFramebufferTexture2DOES unsupported glFramebufferTexture2DOES requires OES_framebuffer_object
glGenFramebuffersOES unsupported glGenFramebuffersOES requires OES_framebuffer_object check framebuffers n
glGenRenderbuffersOES unsupported glGenRenderbuffersOES requires OES_framebuffer_object check renderbuffers n
glGenerateMipmapOES unsupported glGenerateMipmapOES requires OES_framebuffer_object
glGetFramebufferAttachmentParameterivOES requires OES_framebuffer_object
glGetRenderbufferParameterivOES requires OES_framebuffer_object
glIsFramebufferOES requires OES_framebuffer_object return JNI_FALSE
glIsRenderbufferOES requires OES_framebuffer_object return JNI_FALSE
glRenderbufferStorageOES requires OES_framebuffer_object
glGetTexGen requires OES_texture_cube_map
glTexGen requires OES_texture_cube_map
glTexGenf requires OES_texture_cube_map
glTexGeni requires OES_texture_cube_map
glTexGenx requires OES_texture_cube_map
glGetBufferParameter unsupported glGetBufferParameter unsupported
glGetFramebufferAttachmentParameterivOES unsupported
glGetRenderbufferParameterivOES unsupported
glGetTexGen unsupported
glIsFramebufferOES unsupported return JNI_FALSE
glIsRenderbufferOES unsupported return JNI_FALSE
glRenderbufferStorageOES unsupported return false
glTexGen unsupported
glTexGenf unsupported
glTexGeni unsupported
glTexGenx unsupported

View File

@ -211,6 +211,8 @@ public class JniCodeEmitter {
index += 5; index += 5;
} else if (checks[index].equals("unsupported")) { } else if (checks[index].equals("unsupported")) {
index += 1; index += 1;
} else if (checks[index].equals("requires")) {
index += 2;
} else if (checks[index].equals("nullAllowed")) { } else if (checks[index].equals("nullAllowed")) {
return true; return true;
} else { } else {
@ -243,6 +245,8 @@ public class JniCodeEmitter {
index += 5; index += 5;
} else if (checks[index].equals("unsupported")) { } else if (checks[index].equals("unsupported")) {
index += 1; index += 1;
} else if (checks[index].equals("requires")) {
index += 2;
} else if (checks[index].equals("nullAllowed")) { } else if (checks[index].equals("nullAllowed")) {
index += 1; index += 1;
} else { } else {
@ -263,6 +267,8 @@ public class JniCodeEmitter {
while (index < checks.length) { while (index < checks.length) {
if (checks[index].equals("unsupported")) { if (checks[index].equals("unsupported")) {
return true; return true;
} else if (checks[index].equals("requires")) {
index += 2;
} else if (checks[index].equals("return")) { } else if (checks[index].equals("return")) {
index += 2; index += 2;
} else if (checks[index].startsWith("check")) { } else if (checks[index].startsWith("check")) {
@ -280,7 +286,34 @@ public class JniCodeEmitter {
} }
return false; return false;
} }
String isRequiresFunc(CFunc cfunc) {
String[] checks = mChecker.getChecks(cfunc.getName());
int index = 1;
if (checks != null) {
while (index < checks.length) {
if (checks[index].equals("unsupported")) {
index += 1;
} else if (checks[index].equals("requires")) {
return checks[index+1];
} else if (checks[index].equals("return")) {
index += 2;
} else if (checks[index].startsWith("check")) {
index += 3;
} else if (checks[index].equals("ifcheck")) {
index += 5;
} else if (checks[index].equals("nullAllowed")) {
index += 1;
} else {
System.out.println("Error: unknown keyword \"" +
checks[index] + "\"");
System.exit(0);
}
}
}
return null;
}
void emitNativeBoundsChecks(CFunc cfunc, String cname, PrintStream out, void emitNativeBoundsChecks(CFunc cfunc, String cname, PrintStream out,
boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) { boolean isBuffer, boolean emitExceptionCheck, String offset, String remaining, String iii) {
@ -365,6 +398,9 @@ public class JniCodeEmitter {
} else if (checks[index].equals("unsupported")) { } else if (checks[index].equals("unsupported")) {
// ignore // ignore
index += 1; index += 1;
} else if (checks[index].equals("requires")) {
// ignore
index += 2;
} else if (checks[index].equals("nullAllowed")) { } else if (checks[index].equals("nullAllowed")) {
// ignore // ignore
index += 1; index += 1;
@ -776,7 +812,23 @@ public class JniCodeEmitter {
out.println(); out.println();
return; return;
} }
String requiresExtension = isRequiresFunc(cfunc);
if (requiresExtension != null) {
out.println(indent +
"if (! supportsExtension(_env, _this, have_" + requiresExtension + "ID)) {");
out.println(indent + indent +
"_env->ThrowNew(UOEClass,");
out.println(indent + indent +
" \"" + cfunc.getName() + "\");");
if (isVoid) {
out.println(indent + indent + " return;");
} else {
String retval = getErrorReturnValue(cfunc);
out.println(indent + indent + " return " + retval + ";");
}
out.println(indent + "}");
}
if (mUseContextPointer) { if (mUseContextPointer) {
out.println(indent + out.println(indent +
"android::gl::ogles_context_t *ctx = getContext(_env, _this);"); "android::gl::ogles_context_t *ctx = getContext(_env, _this);");

View File

@ -23,6 +23,23 @@
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
// Work around differences between the generated name and the actual name.
#define glBlendEquation glBlendEquationOES
#define glBlendEquationSeparate glBlendEquationSeparateOES
#define glBlendFuncSeparate glBlendFuncSeparateOES
#define glGetTexGenfv glGetTexGenfvOES
#define glGetTexGeniv glGetTexGenivOES
#define glGetTexGenxv glGetTexGenxvOES
#define glTexGenf glTexGenfOES
#define glTexGenfv glTexGenfvOES
#define glTexGeni glTexGeniOES
#define glTexGeniv glTexGenivOES
#define glTexGenx glTexGenxOES
#define glTexGenxv glTexGenxvOES
/* special calls implemented in Android's GLES wrapper used to more /* special calls implemented in Android's GLES wrapper used to more
* efficiently bound-check passed arrays */ * efficiently bound-check passed arrays */
extern "C" { extern "C" {
@ -58,6 +75,11 @@ static jmethodID allowIndirectBuffersID;
static jfieldID positionID; static jfieldID positionID;
static jfieldID limitID; static jfieldID limitID;
static jfieldID elementSizeShiftID; static jfieldID elementSizeShiftID;
static jfieldID haveCheckedExtensionsID;
static jfieldID have_OES_blend_equation_separateID;
static jfieldID have_OES_blend_subtractID;
static jfieldID have_OES_framebuffer_objectID;
static jfieldID have_OES_texture_cube_mapID;
/* Cache method IDs each time the class is loaded. */ /* Cache method IDs each time the class is loaded. */
@ -72,6 +94,11 @@ nativeClassInitBuffer(JNIEnv *_env)
jclass g11impClassLocal = _env->FindClass("com/google/android/gles_jni/GLImpl"); jclass g11impClassLocal = _env->FindClass("com/google/android/gles_jni/GLImpl");
G11ImplClass = (jclass) _env->NewGlobalRef(g11impClassLocal); G11ImplClass = (jclass) _env->NewGlobalRef(g11impClassLocal);
haveCheckedExtensionsID = _env->GetFieldID(G11ImplClass, "haveCheckedExtensions", "Z");
have_OES_blend_equation_separateID = _env->GetFieldID(G11ImplClass, "have_OES_blend_equation_separate", "Z");
have_OES_blend_subtractID = _env->GetFieldID(G11ImplClass, "have_OES_blend_subtract", "Z");
have_OES_framebuffer_objectID = _env->GetFieldID(G11ImplClass, "have_OES_framebuffer_object", "Z");
have_OES_texture_cube_mapID = _env->GetFieldID(G11ImplClass, "have_OES_texture_cube_map", "Z");
getBasePointerID = _env->GetStaticMethodID(nioAccessClass, getBasePointerID = _env->GetStaticMethodID(nioAccessClass,
"getBasePointer", "(Ljava/nio/Buffer;)J"); "getBasePointer", "(Ljava/nio/Buffer;)J");
@ -193,5 +220,63 @@ getNumCompressedTextureFormats() {
return numCompressedTextureFormats; return numCompressedTextureFormats;
} }
// Check if the extension at the head of pExtensions is pExtension. Note that pExtensions is
// terminated by either 0 or space, while pExtension is terminated by 0.
static bool
extensionEqual(const GLubyte* pExtensions, const GLubyte* pExtension) {
while (true) {
char a = *pExtensions++;
char b = *pExtension++;
bool aEnd = a == '\0' || a == ' ';
bool bEnd = b == '\0';
if ( aEnd || bEnd) {
return aEnd == bEnd;
}
if ( a != b ) {
return false;
}
}
}
static const GLubyte*
nextExtension(const GLubyte* pExtensions) {
while (true) {
char a = *pExtensions++;
if ( a == '\0') {
return pExtensions-1;
} else if ( a == ' ') {
return pExtensions;
}
}
}
static bool
checkForExtension(const GLubyte* pExtensions, const GLubyte* pExtension) {
for (;*pExtensions != '\0'; pExtensions = nextExtension(pExtensions)) {
if (extensionEqual(pExtensions, pExtension)) {
return true;
}
}
return false;
}
static bool
supportsExtension(JNIEnv *_env, jobject impl, jfieldID fieldId) {
if (!_env->GetBooleanField(impl, haveCheckedExtensionsID)) {
_env->SetBooleanField(impl, haveCheckedExtensionsID, true);
const GLubyte* sExtensions = glGetString(GL_EXTENSIONS);
_env->SetBooleanField(impl, have_OES_blend_equation_separateID,
checkForExtension(sExtensions, (const GLubyte*) "GL_OES_blend_equation_separate"));
_env->SetBooleanField(impl, have_OES_blend_subtractID,
checkForExtension(sExtensions, (const GLubyte*) "GL_OES_blend_subtract"));
_env->SetBooleanField(impl, have_OES_framebuffer_objectID,
checkForExtension(sExtensions, (const GLubyte*) "GL_OES_framebuffer_object"));
_env->SetBooleanField(impl, have_OES_texture_cube_mapID,
checkForExtension(sExtensions, (const GLubyte*) "GL_OES_texture_cube_map"));
}
return _env->GetBooleanField(impl, fieldId);
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -47,6 +47,12 @@ public class GLImpl implements GL10, GL10Ext, GL11, GL11Ext, GL11ExtensionPack {
Buffer _pointSizePointerOES = null; Buffer _pointSizePointerOES = null;
Buffer _matrixIndexPointerOES = null; Buffer _matrixIndexPointerOES = null;
Buffer _weightPointerOES = null; Buffer _weightPointerOES = null;
private boolean haveCheckedExtensions;
private boolean have_OES_blend_equation_separate;
private boolean have_OES_blend_subtract;
private boolean have_OES_framebuffer_object;
private boolean have_OES_texture_cube_map;
public GLImpl() { public GLImpl() {
} }