aboutsummaryrefslogtreecommitdiffstats
path: root/src/native/ogl
diff options
context:
space:
mode:
authorKevin Rushforth <[email protected]>2004-10-29 16:21:22 +0000
committerKevin Rushforth <[email protected]>2004-10-29 16:21:22 +0000
commita4461c4fe84cf7cfd29677b5073e8b9ea41c3a4a (patch)
tree30724a1d54d3d7045c10ecdb4ba6b479e3c0da43 /src/native/ogl
parent2ce93668c57e29a6d2ea992f8675afdd0719c820 (diff)
Submitted by: mikofclassx
Reviewed by: kcr Added new j3d.transparentOffScreen flag to allow transparent (alpha = 0) backgrounds for off-screen Canvas3D rendering. git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@64 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/native/ogl')
-rw-r--r--src/native/ogl/Canvas3D.c66
-rw-r--r--src/native/ogl/NativeConfigTemplate3D.c41
-rw-r--r--src/native/ogl/gldefs.h8
3 files changed, 76 insertions, 39 deletions
diff --git a/src/native/ogl/Canvas3D.c b/src/native/ogl/Canvas3D.c
index 24654ff..339fe63 100644
--- a/src/native/ogl/Canvas3D.c
+++ b/src/native/ogl/Canvas3D.c
@@ -38,18 +38,6 @@
#endif /* DEBUG */
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-
-#ifndef BOOL
-#define BOOL int
-#endif
-
static char *gl_VERSION;
static char *gl_VENDOR;
@@ -382,7 +370,8 @@ void checkTextureExtensions(
}
}
-BOOL getJavaBoolEnv(JNIEnv *env, char* envStr)
+jboolean
+getJavaBoolEnv(JNIEnv *env, char* envStr)
{
JNIEnv table = *env;
jclass cls;
@@ -392,31 +381,31 @@ BOOL getJavaBoolEnv(JNIEnv *env, char* envStr)
cls = (jclass) (*(table->FindClass))(env, "javax/media/j3d/VirtualUniverse");
if (cls == NULL) {
- return FALSE;
+ return JNI_FALSE;
}
fieldID = (jfieldID) (*(table->GetStaticFieldID))(env, cls, "mc",
"Ljavax/media/j3d/MasterControl;");
if (fieldID == NULL) {
- return FALSE;
+ return JNI_FALSE;
}
obj = (*(table->GetStaticObjectField))(env, cls, fieldID);
if (obj == NULL) {
- return FALSE;
+ return JNI_FALSE;
}
cls = (jclass) (*(table->FindClass))(env, "javax/media/j3d/MasterControl");
if (cls == NULL) {
- return FALSE;
+ return JNI_FALSE;
}
fieldID = (jfieldID) (*(table->GetFieldID))(env, cls, envStr, "Z");
if (fieldID == NULL ) {
- return FALSE;
+ return JNI_FALSE;
}
return (*(table->GetBooleanField))(env, obj, fieldID);
@@ -426,7 +415,8 @@ BOOL getJavaBoolEnv(JNIEnv *env, char* envStr)
/*
* get properties from current context
*/
-BOOL getPropertiesFromCurrentContext(
+static jboolean
+getPropertiesFromCurrentContext(
JNIEnv *env,
jobject obj,
GraphicsContextPropertiesInfo *ctxInfo,
@@ -456,7 +446,7 @@ BOOL getPropertiesFromCurrentContext(
glversion = (char *)glGetString(GL_VERSION);
if (glversion == NULL) {
fprintf(stderr, "glversion == null\n");
- return FALSE;
+ return JNI_FALSE;
}
gl_VERSION = glversion;
tmpVersionStr = strdup(glversion);
@@ -469,7 +459,7 @@ BOOL getPropertiesFromCurrentContext(
extensionStr = (char *)glGetString(GL_EXTENSIONS);
if (extensionStr == NULL) {
fprintf(stderr, "extensionStr == null\n");
- return FALSE;
+ return JNI_FALSE;
}
tmpExtensionStr = strdup(extensionStr);
@@ -988,7 +978,7 @@ BOOL getPropertiesFromCurrentContext(
/* clearing up the memory */
free(tmpExtensionStr);
free(tmpVersionStr);
- return TRUE;
+ return JNI_TRUE;
}
@@ -1723,7 +1713,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear(
#endif
if(!pa2d) {
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
else {
@@ -1813,7 +1803,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear(
if(xzoom > 1.0f || yzoom > 1.0f)
{
/* else don't need to clear the background with background color */
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
glPixelZoom(1.0, -1.0);
@@ -1823,7 +1813,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear(
break;
case javax_media_j3d_Background_SCALE_FIT_MIN:
if(xzoom != yzoom ) {
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
zoom = xzoom < yzoom? xzoom:yzoom;
@@ -1865,7 +1855,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_clear(
case javax_media_j3d_Background_SCALE_NONE_CENTER:
if(xzoom > 1.0f || yzoom > 1.0f){
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
if(xzoom >= 1.0f){
@@ -1957,7 +1947,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_textureclear(JNIEnv *env,
fprintf(stderr, "Canvas3D.textureclear()\n");
#endif
if(!pa2d){
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
/* glPushAttrib(GL_DEPTH_BUFFER_BIT); */
@@ -2092,7 +2082,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_textureclear(JNIEnv *env,
switch(imageScaleMode) {
case javax_media_j3d_Background_SCALE_NONE:
if(xzoom > 1.0f || yzoom > 1.0f){
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
texMinU = 0.0f;
@@ -2111,7 +2101,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_textureclear(JNIEnv *env,
break;
case javax_media_j3d_Background_SCALE_FIT_MIN:
if(xzoom != yzoom){
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
@@ -2174,7 +2164,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_textureclear(JNIEnv *env,
break;
case javax_media_j3d_Background_SCALE_NONE_CENTER:
if(xzoom > 1.0f || yzoom > 1.0f){
- glClearColor((float)r, (float)g, (float)b, 1.0f);
+ glClearColor((float)r, (float)g, (float)b, ctxProperties->alphaClearValue);
glClear(GL_COLOR_BUFFER_BIT);
}
if(xzoom >= 1.0f){
@@ -2899,7 +2889,16 @@ jint JNICALL Java_javax_media_j3d_Canvas3D_createOffScreenBuffer(
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
- bih.biBitCount = 24;
+
+
+ // by MIK OF CLASSX
+ if (getJavaBoolEnv(env, "transparentOffScreen")) {
+ bih.biBitCount = 32;
+ }
+ else {
+ bih.biBitCount = 24;
+ }
+
bih.biCompression = BI_RGB;
bitmapHdc = CreateCompatibleDC(hdc);
@@ -3128,6 +3127,9 @@ void initializeCtxInfo(JNIEnv *env , GraphicsContextPropertiesInfo* ctxInfo){
ctxInfo->multi_draw_arrays_ext = JNI_FALSE;
ctxInfo->implicit_multisample = getJavaBoolEnv(env, "implicitAntialiasing");
+
+ // by MIK OF CLASSX
+ ctxInfo->alphaClearValue = (getJavaBoolEnv(env, "transparentOffScreen") ? 0.0f : 1.0f);
/* ARB extensions */
ctxInfo->arb_transpose_matrix = JNI_FALSE;
@@ -3541,6 +3543,6 @@ jboolean JNICALL Java_javax_media_j3d_Canvas3D_validGraphicsMode(
#endif
#if defined(SOLARIS) || defined(__linux__)
- return TRUE;
+ return JNI_TRUE;
#endif
}
diff --git a/src/native/ogl/NativeConfigTemplate3D.c b/src/native/ogl/NativeConfigTemplate3D.c
index 8d147ff..7d85dd4 100644
--- a/src/native/ogl/NativeConfigTemplate3D.c
+++ b/src/native/ogl/NativeConfigTemplate3D.c
@@ -40,10 +40,13 @@
/* check if the extension is supported */
extern int isExtensionSupported(const char *allExtensions, const char *extension);
+/* by MIK OF CLASSX */
+extern jboolean getJavaBoolEnv(JNIEnv *env, char* envStr);
+
#if defined(SOLARIS) || defined(__linux__)
/* Fix for issue 20 */
-#define MAX_GLX_ATTRS_LENGTH 25
+#define MAX_GLX_ATTRS_LENGTH 100
GLXFBConfig *find_S_FBConfigs(jlong display,
jint screen,
@@ -315,6 +318,13 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_chooseOglVisual(
glxAttrs[index++] = mx_ptr[GREEN_SIZE];
glxAttrs[index++] = GLX_BLUE_SIZE;
glxAttrs[index++] = mx_ptr[BLUE_SIZE];
+
+ // by MIK OF CLASSX
+ if (getJavaBoolEnv(env, "transparentOffScreen")) {
+ glxAttrs[index++] = GLX_ALPHA_SIZE;
+ glxAttrs[index++] = 1;
+ }
+
glxAttrs[index++] = GLX_DEPTH_SIZE;
glxAttrs[index++] = mx_ptr[DEPTH_SIZE];
glxAttrs[index] = None;
@@ -1149,13 +1159,23 @@ int chooseSTDPixelFormat(
/* We are here b/c there is no support for Pbuffer on the HW.
This is a fallback path, we will hardcore the value. */
- pfd.cRedBits = 0;
- pfd.cGreenBits = 0;
- pfd.cBlueBits = 0;
- pfd.cDepthBits = 32;
-
+ // by MIK OF CLASSX
pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
+ if (getJavaBoolEnv(env, "transparentOffScreen")) {
+ pfd.cRedBits = 8;
+ pfd.cGreenBits = 8;
+ pfd.cBlueBits = 8;
+ pfd.cAlphaBits = 8;
+ pfd.cColorBits = 32;
+ }
+ else {
+ pfd.cRedBits = 8;
+ pfd.cGreenBits = 8;
+ pfd.cBlueBits = 8;
+ pfd.cAlphaBits = 0;
+ pfd.cColorBits = 24;
+ }
+ pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI;
@@ -1365,6 +1385,13 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat(
wglAttrs[index++] = mx_ptr[GREEN_SIZE];
wglAttrs[index++] = WGL_BLUE_BITS_ARB;
wglAttrs[index++] = mx_ptr[BLUE_SIZE];
+
+ // by MIK OF CLASSX
+ if (getJavaBoolEnv(env, "transparentOffScreen")) {
+ wglAttrs[index++] = WGL_ALPHA_BITS_ARB;
+ wglAttrs[index++] = 1;
+ }
+
wglAttrs[index++] = WGL_DEPTH_BITS_ARB;
wglAttrs[index++] = mx_ptr[DEPTH_SIZE];
diff --git a/src/native/ogl/gldefs.h b/src/native/ogl/gldefs.h
index b1fbe7d..7d5b70b 100644
--- a/src/native/ogl/gldefs.h
+++ b/src/native/ogl/gldefs.h
@@ -520,6 +520,14 @@ typedef struct {
multisampling API to enable/disable scene antialiasing.
*/
jboolean implicit_multisample;
+
+ // by MIK OF CLASSX
+ /*
+ Used by transparentOffScreen feature.
+ This is the value of the alpha channel
+ of the background.
+ */
+ GLfloat alphaClearValue;
/* GL_SGIS_sharpen_texture */
jboolean textureSharpenAvailable;