From 273ebc2982d872de46efdcc3d19dc33af2a29271 Mon Sep 17 00:00:00 2001 From: Chien Yang Date: Sat, 28 Oct 2006 18:19:45 +0000 Subject: 1) Fixed Issue 349 : OffScreen Canvas3D needlessly forces power-of-two for its buffer 2) Fixed Issue 371 : Poor raster quality for systems that don't support NPOT textures 3) Minor clean up to native piples git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@731 ba19aa83-45c5-6ac9-afd3-db810772062c --- src/native/d3d/Canvas3D.cpp | 44 +++++++++++++++++++++++++------ src/native/d3d/D3dUtil.cpp | 6 ++--- src/native/d3d/GraphicsContext3D.cpp | 2 +- src/native/ogl/Canvas3D.c | 50 ++++++++++++++++++++++++++++-------- 4 files changed, 79 insertions(+), 23 deletions(-) (limited to 'src/native') diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp index dbe7042..ea84d95 100644 --- a/src/native/d3d/Canvas3D.cpp +++ b/src/native/d3d/Canvas3D.cpp @@ -352,7 +352,8 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground( jfloat mapMinX, jfloat mapMaxX, jfloat mapMinY, - jfloat mapMaxY) + jfloat mapMaxY, + jboolean useBilinearFilter) { DWORD alphaTest, alphaBlend, cull, zBuffer, @@ -398,12 +399,7 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground( d3dCtx->texUnitStage, d3dCtx->bindTextureIdLen); } return; - } - - device->SetTextureStageState(tus, - D3DTSS_TEXCOORDINDEX, - D3DTSS_TCI_PASSTHRU); - + } if (d3dCtx->texTransformSet[tus]) { device->GetTransform((D3DTRANSFORMSTATETYPE) @@ -415,6 +411,24 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground( &identityMatrix); } + // TextureStage will be restore by caller. + device->SetTextureStageState(tus, + D3DTSS_TEXCOORDINDEX, + D3DTSS_TCI_PASSTHRU); + + /* Setup filter mode if needed */ + if(useBilinearFilter) { + /* fprintf(stderr, "Background : use bilinear filter\n"); */ + device->SetSamplerState (tus, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + device->SetSamplerState (tus, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + device->SetSamplerState (tus, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + } + /* For debugging only + else { + fprintf(stderr, "Background : Not use bilinear filter\n"); + } + */ + device->GetTransform(D3DTS_PROJECTION, &ptm); device->GetTransform(D3DTS_WORLD, &wtm); device->GetTransform(D3DTS_VIEW, &vtm); @@ -526,7 +540,8 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, jfloat mapMinY, jfloat mapMaxY, jfloat mapZ, - jfloat alpha) + jfloat alpha, + jboolean useBilinearFilter) { DWORD cull, lighting; @@ -558,6 +573,19 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, device->SetTextureStageState(tus, D3DTSS_ALPHAOP, D3DTOP_MODULATE); device->SetTextureStageState(tus, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); device->SetTextureStageState(tus, D3DTSS_ALPHAARG2, D3DTA_CURRENT); + + /* Setup filter mode if needed */ + if(useBilinearFilter) { + /* fprintf(stderr, "Raster : use bilinear filter\n"); */ + device->SetSamplerState (tus, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); + device->SetSamplerState (tus, D3DSAMP_MIPFILTER, D3DTEXF_POINT); + device->SetSamplerState (tus, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); + } + /* For debugging only + else { + fprintf(stderr, "Raster : Not use bilinear filter\n"); + } + */ device->GetTransform(D3DTS_PROJECTION, &ptm); device->GetTransform(D3DTS_WORLD, &wtm); diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp index 6b5c1df..55e6ded 100644 --- a/src/native/d3d/D3dUtil.cpp +++ b/src/native/d3d/D3dUtil.cpp @@ -941,7 +941,7 @@ void copyDataFromSurface(jint imageFormat, dstPitch = subWidth << 2; destRow += (subHeight-1)*dstPitch; - printf("[Java 3D] copyDataFromSurface: (1) %d\n", ddpf.dwRGBBitCount); + /* printf("[Java 3D] copyDataFromSurface: (1) %d\n", ddpf.dwRGBBitCount); */ if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -1044,14 +1044,14 @@ void copyDataFromSurface(jint imageFormat, destRow -= dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { - printf("[Java 3D] copyDataFromSurface: Format on (8 bits or less surface) not support %d\n", imageFormat); + /* printf("[Java 3D] copyDataFromSurface: Format on (8 bits or less surface) not support %d\n", imageFormat); */ } } } else if ((imageFormat == IMAGE_FORMAT_BYTE_RGBA) || (imageFormat == IMAGE_FORMAT_BYTE_RGB) || (imageFormat == IMAGE_FORMAT_INT_BGR)) { - printf("[Java 3D] copyDataFromSurface: (2) %d\n", ddpf.dwRGBBitCount); + /* printf("[Java 3D] copyDataFromSurface: (2) %d\n", ddpf.dwRGBBitCount); */ dstPitch = subWidth << 2; destRow += (subHeight-1)*dstPitch; diff --git a/src/native/d3d/GraphicsContext3D.cpp b/src/native/d3d/GraphicsContext3D.cpp index 3b4f018..052e80e 100644 --- a/src/native/d3d/GraphicsContext3D.cpp +++ b/src/native/d3d/GraphicsContext3D.cpp @@ -26,7 +26,7 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readRaster( GetDevice(); - printf("[GraphicsContext3D] readRaster ...\n"); + /* printf("[GraphicsContext3D] readRaster ...\n"); */ if ((type & javax_media_j3d_Raster_RASTER_COLOR) != 0) { diff --git a/src/native/ogl/Canvas3D.c b/src/native/ogl/Canvas3D.c index c8a8db1..e1bcb83 100644 --- a/src/native/ogl/Canvas3D.c +++ b/src/native/ogl/Canvas3D.c @@ -378,7 +378,7 @@ checkTextureExtensions( ctxInfo->textureExtMask |= javax_media_j3d_Canvas3D_TEXTURE_LOD_OFFSET; } - + if (isExtensionSupported(tmpExtensionStr, "GL_ARB_texture_non_power_of_two")) { ctxInfo->textureNonPowerOfTwoAvailable = JNI_TRUE; @@ -386,6 +386,7 @@ checkTextureExtensions( javax_media_j3d_Canvas3D_TEXTURE_NON_POWER_OF_TWO; } + } jboolean @@ -650,7 +651,7 @@ getPropertiesFromCurrentContext( ctxInfo->texture_max_level_enum = GL_TEXTURE_MAX_LEVEL; - /* look for OpenGL 2.0 features */ + /* look for OpenGL 2.0 features */ if (ctxInfo->gl20) { ctxInfo->textureNonPowerOfTwoAvailable = JNI_TRUE; ctxInfo->textureExtMask |= @@ -1355,10 +1356,10 @@ void JNICALL Java_javax_media_j3d_NativePipeline_texturemapping( glDepthMask(GL_FALSE); glBindTexture(GL_TEXTURE_2D, objectId); /* set up texture parameter */ - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); #ifdef VERBOSE glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); @@ -1492,7 +1493,8 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground(JNIEnv *e jfloat mapMinX, jfloat mapMaxX, jfloat mapMinY, - jfloat mapMaxY) + jfloat mapMaxY, + jboolean useBilinearFilter ) { JNIEnv table; GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; @@ -1510,6 +1512,18 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground(JNIEnv *e glDepthMask(GL_FALSE); glEnable(GL_TEXTURE_2D); + /* Setup filter mode if needed */ + if(useBilinearFilter) { + /* fprintf(stderr, "Background : use bilinear filter\n"); */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + /* For debugging only + else { + fprintf(stderr, "Background : Not use bilinear filter\n"); + } + */ + /* reset the polygon mode */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); @@ -1564,7 +1578,8 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, jfloat mapMinY, jfloat mapMaxY, jfloat mapZ, - jfloat alpha) + jfloat alpha, + jboolean useBilinearFilter ) { JNIEnv table; GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctxInfo; @@ -1578,11 +1593,24 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, /* Temporarily disable fragment and most 3D operations */ glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT); - + disableAttribForRaster(ctxProperties); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glColor4f(1.0f, 1.0f, 1.0f, (float) alpha); + /* Setup filter mode if needed */ + if(useBilinearFilter) { + /* fprintf(stderr, "Raster : use bilinear filter\n"); */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + /* For debugging only + else { + fprintf(stderr, "Raster : Not use bilinear filter\n"); + } + */ + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glColor4f(1.0f, 1.0f, 1.0f, (float) alpha); + /* reset the polygon mode */ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); -- cgit v1.2.3