diff options
-rw-r--r-- | src/native/d3d/Canvas3D.cpp | 167 | ||||
-rw-r--r-- | src/native/d3d/D3dUtil.cpp | 180 | ||||
-rw-r--r-- | src/native/d3d/GraphicsContext3D.cpp | 114 | ||||
-rw-r--r-- | src/native/ogl/GraphicsContext3D.c | 154 |
4 files changed, 333 insertions, 282 deletions
diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp index 49d3493..57fbd0a 100644 --- a/src/native/d3d/Canvas3D.cpp +++ b/src/native/d3d/Canvas3D.cpp @@ -232,8 +232,6 @@ void JNICALL Java_javax_media_j3d_NativePipeline_texturemapping( Java_javax_media_j3d_NativePipeline_bindTexture2D( env, texture, ctx, objectId, TRUE); - // TODO --- Need to re-write. Chien - printf("[TODO NEEDED] Canvas3dD : *** texturemapping() ***\n"); Java_javax_media_j3d_NativePipeline_updateTexture2DSubImage( env, texture, ctx, 0, minX, minY, J3D_RGBA, format, minX, minY, rasWidth, maxX-minX, maxY-minY, IMAGE_DATA_TYPE_BYTE_ARRAY, @@ -357,9 +355,87 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground( jfloat mapMaxY) { GetDevice(); - /* printf("Canvas3D.textureFillBackground()\n"); */ + printf("[TODO NEEDED] Canvas3dD : *** textureFillBackground() ***\n"); + /* printf("Canvas3D.textureFillBackground()\n"); */ + +#if 0 + // Need D3D translation for the following ogl code : + /* Temporarily disable fragment and most 3D operations */ + glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_POLYGON_BIT); + + disableAttribFor2D(ctxProperties); + glDepthMask(GL_FALSE); + glEnable(GL_TEXTURE_2D); + + /* reset the polygon mode */ + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + /* loaded identity modelview and projection matrix */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glMatrixMode(GL_TEXTURE); + glPushMatrix(); + glLoadIdentity(); +#endif + + + + d3dCtx->rasterRect[0].tu = texMinU; /* tumin; */ + d3dCtx->rasterRect[0].tv = texMaxV; /* tvmax; */ + d3dCtx->rasterRect[1].tu = texMinU; /* tumin; */ + d3dCtx->rasterRect[1].tv = texMinV; /* tvmin; */ + d3dCtx->rasterRect[2].tu = texMaxU; /* tumax; */ + d3dCtx->rasterRect[2].tv = texMaxV; /* tvmax; */ + d3dCtx->rasterRect[3].tu = texMaxU; /* tumax; */ + d3dCtx->rasterRect[3].tv = texMinV; /* tvmin; */ + + d3dCtx->rasterRect[0].sx = mapMinX; + d3dCtx->rasterRect[0].sy = mapMaxY; + d3dCtx->rasterRect[0].sz = 0.999f; + d3dCtx->rasterRect[0].rhw = 1; + + d3dCtx->rasterRect[1].sx = mapMinX; + d3dCtx->rasterRect[1].sy = mapMinY; + d3dCtx->rasterRect[1].sz = 0.999f; + d3dCtx->rasterRect[1].rhw = 1; + + d3dCtx->rasterRect[2].sx = mapMaxX; + d3dCtx->rasterRect[2].sy = mapMaxY; + d3dCtx->rasterRect[2].sz = 0.999f; + d3dCtx->rasterRect[2].rhw = 1; + + d3dCtx->rasterRect[3].sx = mapMaxX; + d3dCtx->rasterRect[3].sy = mapMinY; + d3dCtx->rasterRect[3].sz = 0.999f; + d3dCtx->rasterRect[3].rhw = 1; + + /* + printf("(texMinU,texMinV,texMaxU,texMaxV) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", + texMinU,texMinV,texMaxU,texMaxV); + printf("(mapMinX,mapMinY,mapMaxX,mapMaxY) = (%3.2f,%3.2f,%3.2f,%3.2f)\n", + mapMinX,mapMinY,mapMaxX,mapMaxY); + */ + + /* TODO : Implement textureFillBackground() */ - printf("[TODO NEEDED] Canvas3D : *** textureFillBackground is not implemented yet.\n"); + /* drawTextureRect(d3dCtx, device, d3dImage->surf, + screenCoord, 0, 0, width, height, + scaleWidth, scaleHeight, texModeRepeat); + */ + +#if 0 + /* Restore texture Matrix transform */ + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + /* Restore attributes */ + glPopAttrib(); +#endif } @@ -403,11 +479,86 @@ void JNICALL Java_javax_media_j3d_NativePipeline_executeRasterDepth(JNIEnv *env, jint depthFormat, jobject depthData) { + void *depthObjPtr; + D3DVERTEX worldCoord; + D3DTLVERTEX screenCoord; + int endx = srcOffsetX + rasterWidth; + int endy = srcOffsetY + rasterHeight; + GetDevice(); - /* printf("Canvas3D.executeRasterDepth()\n"); */ - /* TODO : Implement executeRasterDepth() */ - printf("[TODO NEEDED] Canvas3D : *** : executeRasterDepth is not implemented yet.\n"); + /* printf("*** Canvas3D.executeRasterDepth() ***\n"); */ + + // clipping + if (srcOffsetX > depthWidth) { + srcOffsetX = depthWidth; + } else if (srcOffsetX < 0) { + srcOffsetX = 0; + } + if (srcOffsetY > depthHeight) { + srcOffsetY = depthHeight; + } else if (srcOffsetY < 0) { + srcOffsetY = 0; + } + + if (endx > depthWidth) { + endx = depthWidth; + } else if (endx < 0) { + endx = 0; + } + if (endy > depthHeight) { + endy = depthHeight; + } else if (endy < 0) { + endy = 0; + } + + int h = endy - srcOffsetY; + int w = endx - srcOffsetX; + + // raster position is upper left corner, default for Java3D + // ImageComponent currently has the data reverse in Y + if ((h > 0) && (w > 0)) { + worldCoord.x = posX; + worldCoord.y = posY; + worldCoord.z = posZ; + + d3dCtx->transform(&worldCoord, &screenCoord); + + if (d3dCtx->depthStencilSurface == NULL) { + HRESULT hr = + device->GetDepthStencilSurface(&d3dCtx->depthStencilSurface); + if (FAILED(hr)) { + if (debug) { + printf("[Java3D] Fail to get depth stencil surface %s\n", + DXGetErrorString9(hr)); + } + return; + } + } + + depthObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)depthData, NULL); + + if (depthFormat == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { + copyDepthToSurface(d3dCtx, + device, + (int)(screenCoord.sx), + (int)(screenCoord.sy), + srcOffsetX, srcOffsetY, + w, h, depthWidth, depthHeight, + (jint *)depthObjPtr, d3dCtx->depthStencilSurface); + + } else { // javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT + + copyDepthToSurface(d3dCtx, + device, + (int)(screenCoord.sx), + (int)(screenCoord.sy), + srcOffsetX, srcOffsetY, + w, h, depthWidth, depthHeight, + (jfloat *)depthObjPtr, d3dCtx->depthStencilSurface); + } + env->ReleasePrimitiveArrayCritical((jarray)depthData, depthObjPtr, 0); + } } extern "C" JNIEXPORT @@ -820,8 +971,6 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readOffScreenBuffer( imageObjPtr = (void *)env->GetDirectBufferAddress(data); } - /* TODO : Need to re-write --- Chien. */ - printf("[TODO NEEDED] Canvas3D : *** readOffScreenBuffer() ***\n"); copyDataFromSurface(format, 0, 0, width, height, (jbyte *)imageObjPtr, d3dCtx->backSurface); diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp index e14adc1..4c2ad9a 100644 --- a/src/native/d3d/D3dUtil.cpp +++ b/src/native/d3d/D3dUtil.cpp @@ -888,12 +888,8 @@ LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx, } -// TODO : No need to reverse the Y axis. -// Handle more format ------ Chien. - // copy data from DirectDraw surface to memory -// and reverse the Y axis -void copyDataFromSurface(jint internalFormat, +void copyDataFromSurface(jint imageFormat, jint xoffset, jint yoffset, jint subWidth, jint subHeight, jbyte *data, @@ -904,6 +900,8 @@ void copyDataFromSurface(jint internalFormat, PIXELFORMAT ddpf; HRESULT hr; + printf("[Java 3D] copyDataFromSurface: not tested yet %d\n", imageFormat); + if (surf == NULL) { return; } @@ -924,7 +922,7 @@ void copyDataFromSurface(jint internalFormat, D3DLOCK_READONLY); if (FAILED(hr)) { - printf("Fail to lock surface: %s\n", DXGetErrorString9(hr)); + printf("Fail to lock surface: %s\n", DXGetErrorString9(hr)); return; } @@ -939,12 +937,118 @@ void copyDataFromSurface(jint internalFormat, xoffset*((int) ceil((float) ddpf.dwRGBBitCount/8.0)) + (yoffset*lockedRect.Pitch); - - if ((internalFormat == IMAGE_FORMAT_BYTE_RGBA) || - (internalFormat == IMAGE_FORMAT_BYTE_RGB)) { + if ((imageFormat == IMAGE_FORMAT_INT_RGB) || + (imageFormat == IMAGE_FORMAT_INT_ARGB)) { dstPitch = subWidth << 2; - destRow += (subHeight-1)*dstPitch; + + if ((ddpf.dwRGBBitCount == 32) && + (ddpf.dwRBitMask == 0xff0000) && + (ddpf.dwGBitMask == 0xff00) && + (ddpf.dwBBitMask == 0xff)) { + // Optimize for the most common case + if (ddpf.noAlpha) { + for (int i=yoffset; i < ylimit; i++) { + src = srcRow; + dst = destRow; + for (int j=xoffset; j < xlimit; j++) { + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + *src++; + *dst++ = (byte) 0xff; + } + srcRow += lockedRect.Pitch; + destRow += dstPitch; + } + } else { + for (int i=yoffset; i < ylimit; i++) { + src = srcRow; + dst = destRow; + for (int j=xoffset; j < xlimit; j++) { + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + } + srcRow += lockedRect.Pitch; + destRow += dstPitch; + } + } + } else { // handle less common format + int rshift = firstBit(ddpf.dwRBitMask) + + ucountBits(ddpf.dwRBitMask) - 8; + int gshift = firstBit(ddpf.dwGBitMask) + + ucountBits(ddpf.dwGBitMask) - 8; + int bshift = firstBit(ddpf.dwBBitMask) + + ucountBits(ddpf.dwBBitMask) - 8; + int ashift = firstBit(ddpf.dwRGBAlphaBitMask) + + ucountBits(ddpf.dwRGBAlphaBitMask) - 8; + + if ((ddpf.dwRGBBitCount <= 32) && + (ddpf.dwRGBBitCount > 24)) { + + for (int i=yoffset; i < ylimit; i++) { + src = srcRow; + dst = destRow; + for (int j=xoffset; j < xlimit; j++) { + b1 = *src++; + b2 = *src++; + b3 = *src++; + b4 = *src++; + mask = ((b4 << 24) | (b3 << 16)| (b2 << 8) | b1); + *dst++ = (byte) (mask & 0xff); + *dst++ = (byte) ((mask >> 8) & 0xff); + *dst++ = (byte) ((mask >> 16) & 0xff); + if (ddpf.noAlpha) { + *dst++ = (byte) 0xff; + } else { + *dst++ = (byte) ((mask >> 24) & 0xff); + } + } + srcRow += lockedRect.Pitch; + destRow += dstPitch; + } + } else if ((ddpf.dwRGBBitCount <= 24) && + (ddpf.dwRGBBitCount > 16)) { + for (int i=yoffset; i < ylimit; i++) { + src = srcRow; + dst = destRow; + for (int j=xoffset; j < xlimit; j++) { + b1 = *src++; + b2 = *src++; + b3 = *src++; + mask = ((b3 << 16) | (b2 << 8) | b1); + *dst++ = (byte) (mask & 0xff); + *dst++ = (byte) ((mask >> 8) & 0xff); + *dst++ = (byte) ((mask >> 16) & 0xff); + } + srcRow += lockedRect.Pitch; + destRow += dstPitch; + } + } else if ((ddpf.dwRGBBitCount <= 16) && + (ddpf.dwRGBBitCount > 8)) { + for (int i=yoffset; i < ylimit; i++) { + src = srcRow; + dst = destRow; + for (int j=xoffset; j < xlimit; j++) { + b1 = *src++; + b2 = *src++; + *dst++ = (byte) (mask & 0xff); + *dst++ = (byte) ((mask >> 8) & 0xff); + } + srcRow += lockedRect.Pitch; + destRow += dstPitch; + } + } else if (ddpf.dwRGBBitCount <= 8) { + 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)) { + dstPitch = subWidth << 2; + if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && (ddpf.dwGBitMask == 0xff00) && @@ -965,7 +1069,7 @@ void copyDataFromSurface(jint internalFormat, *dst++ = (byte) 0xff; } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else { for (int i=yoffset; i < ylimit; i++) { @@ -981,22 +1085,22 @@ void copyDataFromSurface(jint internalFormat, *dst++ = *src++; } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } } else { // handle less common format int rshift = firstBit(ddpf.dwRBitMask) + - ucountBits(ddpf.dwRBitMask) - 8; + ucountBits(ddpf.dwRBitMask) - 8; int gshift = firstBit(ddpf.dwGBitMask) + - ucountBits(ddpf.dwGBitMask) - 8; + ucountBits(ddpf.dwGBitMask) - 8; int bshift = firstBit(ddpf.dwBBitMask) + - ucountBits(ddpf.dwBBitMask) - 8; + ucountBits(ddpf.dwBBitMask) - 8; int ashift = firstBit(ddpf.dwRGBAlphaBitMask) + - ucountBits(ddpf.dwRGBAlphaBitMask) - 8; - + ucountBits(ddpf.dwRGBAlphaBitMask) - 8; + if ((ddpf.dwRGBBitCount <= 32) && (ddpf.dwRGBBitCount > 24)) { - + for (int i=yoffset; i < ylimit; i++) { src = srcRow; dst = destRow; @@ -1041,7 +1145,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1087,7 +1191,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1135,7 +1239,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { for (int i=yoffset; i < ylimit; i++) { @@ -1178,17 +1282,16 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } } - } else if (internalFormat == IMAGE_FORMAT_BYTE_LA) { + } else if (imageFormat == IMAGE_FORMAT_BYTE_LA) { int gshift = firstBit(ddpf.dwGBitMask) + ucountBits(ddpf.dwGBitMask) - 8; int ashift = firstBit(ddpf.dwRGBAlphaBitMask) + ucountBits(ddpf.dwRGBAlphaBitMask) - 8; dstPitch = subWidth << 1; - destRow += (subHeight-1)*dstPitch; if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -1211,7 +1314,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else { // handle less common format int gshift = firstBit(ddpf.dwGBitMask) + @@ -1248,7 +1351,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1280,7 +1383,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1311,7 +1414,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { for (int i=yoffset; i < ylimit; i++) { @@ -1339,16 +1442,15 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } } - } else if (internalFormat == IMAGE_FORMAT_BYTE_GRAY) { + } else if (imageFormat == IMAGE_FORMAT_BYTE_GRAY) { int gshift = firstBit(ddpf.dwGBitMask) + ucountBits(ddpf.dwGBitMask) - 8; dstPitch = subWidth; - destRow += (subHeight-1)*dstPitch; if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -1366,7 +1468,7 @@ void copyDataFromSurface(jint internalFormat, *src++; } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else { // handle less common format int gshift = firstBit(ddpf.dwGBitMask) + @@ -1392,7 +1494,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1413,7 +1515,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1433,7 +1535,7 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { for (int i=yoffset; i < ylimit; i++) { @@ -1450,14 +1552,14 @@ void copyDataFromSurface(jint internalFormat, } } srcRow += lockedRect.Pitch; - destRow -= dstPitch; + destRow += dstPitch; } } } } else { // IMAGE_FORMAT_USHORT_GRAY - printf("[Java 3D] copyDataFromSurface: Format not support %d\n", internalFormat); + printf("[Java 3D] copyDataFromSurface: Format not support %d\n", imageFormat); } @@ -3319,8 +3421,6 @@ void copyDataToSurfaceRGBARev(jint internalFormat, } } - - void copyDataToSurfaceABGRRev(jint internalFormat, PIXELFORMAT *ddpf, unsigned char* pRect, @@ -11825,7 +11925,7 @@ int getPrimitiveNum(int primitive, int vcount) /* - * Note that tThe condition width == height always holds + * Note that the condition width == height always holds * when this function is invoked. */ LPDIRECT3DCUBETEXTURE9 createCubeMapTexture(D3dCtx *d3dCtx, diff --git a/src/native/d3d/GraphicsContext3D.cpp b/src/native/d3d/GraphicsContext3D.cpp index 22ead53..3b4f018 100644 --- a/src/native/d3d/GraphicsContext3D.cpp +++ b/src/native/d3d/GraphicsContext3D.cpp @@ -21,34 +21,14 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readRaster( jint imageFormat, jobject imageBuffer, jint depthFormat, jobject depthBuffer) { - printf("[Java3D] D3D : readRaster is not implemented yet.\n"); - -} - -#if 0 -extern "C" JNIEXPORT -void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( - JNIEnv *env, jobject obj, jlong ctx, - jint type, jint xOffset, jint yOffset, - jint wRaster, jint hRaster, jint hCanvas, jint format, - jobject image, jobject depth, jobject gc) -{ + void *imageObjPtr; + void *depthObjPtr; GetDevice(); - jclass gc_class = env->GetObjectClass(gc); - jfieldID id; - + printf("[GraphicsContext3D] readRaster ...\n"); + if ((type & javax_media_j3d_Raster_RASTER_COLOR) != 0) { - jclass image_class = env->GetObjectClass(image); - - if (image_class == NULL) { - return; - } - - id = env->GetFieldID(gc_class, "byteBuffer","[B"); - jarray byteData_array = (jarray) env->GetObjectField(gc, id); - jbyte *byteData; if ((d3dCtx->d3dPresent.SwapEffect == D3DSWAPEFFECT_DISCARD) // For offScreen rendering, swapBuffer never invoked @@ -60,43 +40,39 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( // it works. && ((d3dCtx->frontSurface != NULL) || (d3dCtx->frontSurface == NULL) && - d3dCtx->createFrontBuffer())) - { - + d3dCtx->createFrontBuffer())) { + HRESULT hr = device->GetFrontBufferData(0,d3dCtx->frontSurface);//iSwapChain as 0 - if (FAILED(hr)) - { - printf("GetFrontBuffer fail %s\n", DXGetErrorString9(hr)); - return; + if (FAILED(hr)) { + printf("GetFrontBuffer fail %s\n", DXGetErrorString9(hr)); + return; } - - byteData = (jbyte *) - env->GetPrimitiveArrayCritical(byteData_array, NULL); - - if (!d3dCtx->bFullScreen) - { + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)imageBuffer, NULL); + + if (!d3dCtx->bFullScreen) { // We need to invoke GetWindowRect() everytime // since message resize() will not receive // when Canvas3D inside browers. d3dCtx->getScreenRect(d3dCtx->hwnd, &d3dCtx->windowRect); - copyDataFromSurface(format, + copyDataFromSurface(imageFormat, xOffset + d3dCtx->windowRect.left, yOffset + d3dCtx->windowRect.top, wRaster, hRaster, - byteData, + (jbyte *) imageObjPtr, d3dCtx->frontSurface); } - else - { - copyDataFromSurface(format, xOffset, yOffset, - wRaster, hRaster, byteData, + else { + copyDataFromSurface(imageFormat, xOffset, yOffset, + wRaster, hRaster, (jbyte *) imageObjPtr, d3dCtx->frontSurface); } + + env->ReleasePrimitiveArrayCritical((jarray) imageBuffer, imageObjPtr, 0); + } - else - { + else { if (d3dCtx->backSurface == NULL) { HRESULT hr = device->GetBackBuffer(0,0, D3DBACKBUFFER_TYPE_MONO, //isSwapChain as 0 &d3dCtx->backSurface); @@ -105,26 +81,18 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( return; } } - byteData = (jbyte *)env->GetPrimitiveArrayCritical(byteData_array, NULL); + imageObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)imageBuffer, NULL); - copyDataFromSurface(format, xOffset, yOffset, wRaster, - hRaster, byteData, d3dCtx->backSurface); - } + copyDataFromSurface(imageFormat, xOffset, yOffset, wRaster, + hRaster, (jbyte *) imageObjPtr, d3dCtx->backSurface); - env->ReleasePrimitiveArrayCritical(byteData_array, byteData, 0); + env->ReleasePrimitiveArrayCritical((jarray)imageBuffer, imageObjPtr, 0); + + } + } if ((type & javax_media_j3d_Raster_RASTER_DEPTH) != 0) { - jclass depth_class = env->GetObjectClass(depth); - - if (depth_class == NULL) { - return; - } - - id = env->GetFieldID(depth_class, "width", "I"); - int wDepth = env->GetIntField(depth, id); - id = env->GetFieldID(depth_class, "type", "I"); - int depth_type = env->GetIntField(depth, id); if (d3dCtx->depthStencilSurface == NULL) { HRESULT hr = @@ -138,33 +106,21 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( } } - if (depth_type == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { - id = env->GetFieldID(gc_class, "intBuffer","[I"); - jarray intData_array = (jarray) env->GetObjectField(gc, id); - jint *intData = (jint *) - env->GetPrimitiveArrayCritical(intData_array, NULL); + depthObjPtr = (void *) env->GetPrimitiveArrayCritical((jarray)depthBuffer, NULL); - // yOffset is adjusted for OpenGL - Y upward + if (depthFormat == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { + // yOffset is adjusted for OpenGL - Y upward copyDepthFromSurface(xOffset, yOffset, wRaster, - hRaster, intData, d3dCtx->depthStencilSurface); - - env->ReleasePrimitiveArrayCritical(intData_array, intData, 0); + hRaster, (jint *) depthObjPtr, d3dCtx->depthStencilSurface); } else { // javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT - id = env->GetFieldID(gc_class, "floatBuffer","[F"); - jarray floatData_array = (jarray) env->GetObjectField(gc, id); - jfloat *floatData = (jfloat *) - env->GetPrimitiveArrayCritical(floatData_array, NULL); - + // yOffset is adjusted for OpenGL - Y upward copyDepthFromSurface(xOffset, yOffset, wRaster, - hRaster, floatData, d3dCtx->depthStencilSurface); - - env->ReleasePrimitiveArrayCritical(floatData_array, - floatData, 0); + hRaster, (jfloat *) depthObjPtr, d3dCtx->depthStencilSurface); } + env->ReleasePrimitiveArrayCritical((jarray)depthBuffer, depthObjPtr, 0); } } -#endif diff --git a/src/native/ogl/GraphicsContext3D.c b/src/native/ogl/GraphicsContext3D.c index 50f73bf..b785277 100644 --- a/src/native/ogl/GraphicsContext3D.c +++ b/src/native/ogl/GraphicsContext3D.c @@ -160,157 +160,3 @@ void JNICALL Java_javax_media_j3d_NativePipeline_readRaster( } - -JNIEXPORT -void JNICALL Java_javax_media_j3d_NativePipeline_readRasterNative( - JNIEnv *env, jobject obj, jlong ctx, - jint type, jint xOffset, jint yOffset, - jint wRaster, jint hRaster, jint hCanvas, - jint format, jobject image, jobject depth, jobject gc) -{ - JNIEnv table; - int yAdjusted; - jclass gc_class; - GLenum gltype; - - GraphicsContextPropertiesInfo *ctxProperties = (GraphicsContextPropertiesInfo *)ctx; - - table = *env; - - glPixelStorei(GL_PACK_ROW_LENGTH, wRaster); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - yAdjusted = hCanvas - hRaster - yOffset; - - gc_class = (jclass) (*(table->GetObjectClass))(env, gc); - - if ((type & javax_media_j3d_Raster_RASTER_COLOR) != 0) { - - jclass image_class; - - jfieldID byteData_field; - jarray byteData_array; - jbyte *byteData; - - byteData_field = (jfieldID)(*(table->GetFieldID))(env, - gc_class, "byteBuffer","[B"); - byteData_array = (jarray)(*(table->GetObjectField))(env, gc, - byteData_field); - - image_class = (jclass) (*(table->GetObjectClass))(env, image); - - if (image_class == NULL) { - return; - } - - switch (format) { - case IMAGE_FORMAT_BYTE_RGBA: - gltype = GL_RGBA; - break; - case IMAGE_FORMAT_BYTE_RGB: - gltype = GL_RGB; - break; - - case IMAGE_FORMAT_BYTE_ABGR: - if (ctxProperties->abgr_ext) { /* If its zero, should never come here! */ - gltype = GL_ABGR_EXT; - } - break; - - case IMAGE_FORMAT_BYTE_BGR: - gltype = GL_BGR; - break; - case IMAGE_FORMAT_BYTE_LA: - gltype = GL_LUMINANCE_ALPHA; - break; - - case IMAGE_FORMAT_BYTE_GRAY: - case IMAGE_FORMAT_USHORT_GRAY: - default: - throwAssert(env, "illegal format"); - break; - } - byteData = (jbyte *)(*(table->GetPrimitiveArrayCritical))(env, - byteData_array, NULL); - glReadPixels(xOffset, yAdjusted, wRaster, hRaster, - gltype, GL_UNSIGNED_BYTE, byteData); - - /* - { - int i, j , *intData; - fprintf(stderr, "format = %d, wRaster = %d, hRaster = %d\n\n", format, wRaster, hRaster); - intData = (int*)byteData; - for (i = 0; i < wRaster; i++) { - for (j = 0; j < hRaster; j++, intData++) { - fprintf(stderr, " 0x%x", *intData); - } - fprintf(stderr, "\n"); - } - } - */ - (*(table->ReleasePrimitiveArrayCritical))(env, byteData_array, - byteData, 0); - } - - - if ((type & javax_media_j3d_Raster_RASTER_DEPTH) != 0) { - - jclass depth_class; - jfieldID wDepth_field, depth_type_field; - jint depth_type, wDepth; - - depth_class = (jclass) (*(table->GetObjectClass))(env, depth); - - if (depth_class == NULL) { - return; - } - - wDepth_field = (jfieldID) (*(table->GetFieldID))(env, depth_class, - "width", "I"); - wDepth = (jint)(*(table->GetIntField))(env, depth, wDepth_field); - - depth_type_field = (jfieldID) (*(table->GetFieldID))(env, - depth_class, "type", "I"); - depth_type = (jint)(*(table->GetIntField))(env, depth, - depth_type_field); - - if (depth_type == javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_INT) { - jfieldID intData_field; - jarray intData_array; - jint *intData; - - intData_field = (jfieldID)(*(table->GetFieldID))(env, - gc_class, "intBuffer","[I"); - intData_array = (jarray)(*(table->GetObjectField))(env, gc, - intData_field); - - intData = (jint *)(*(table->GetPrimitiveArrayCritical))(env, - intData_array, NULL); - - /* yOffset is adjusted for OpenGL - Y upward */ - glReadPixels(xOffset, yAdjusted, wRaster, hRaster, - GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, intData); - - (*(table->ReleasePrimitiveArrayCritical))(env, intData_array, - intData, 0); - } else { /* javax_media_j3d_DepthComponentRetained_DEPTH_COMPONENT_TYPE_FLOAT */ - jfieldID floatData_field; - jarray floatData_array; - jfloat *floatData; - - floatData_field = (jfieldID)(*(table->GetFieldID))(env, - gc_class, "floatBuffer","[F"); - floatData_array = (jarray)(*(table->GetObjectField))(env, gc, - floatData_field); - floatData = (jfloat *)(*(table->GetPrimitiveArrayCritical))(env, - floatData_array, NULL); - - /* yOffset is adjusted for OpenGL - Y upward */ - glReadPixels(xOffset, yAdjusted, wRaster, hRaster, - GL_DEPTH_COMPONENT, GL_FLOAT, floatData); - - (*(table->ReleasePrimitiveArrayCritical))(env, floatData_array, - floatData, 0); - } - } -} - |