From df863b1f8aa929ab70e6cb7d8f7861eb55af4bad Mon Sep 17 00:00:00 2001 From: Chien Yang Date: Thu, 19 Oct 2006 23:41:27 +0000 Subject: 1) Ported readRaster, executeRasterDepth, readOffScreenBuffer, and partially done on textureFillBackground. 2) Removed unuse code in ogl and d3d. git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@722 ba19aa83-45c5-6ac9-afd3-db810772062c --- src/native/d3d/GraphicsContext3D.cpp | 114 +++++++++++------------------------ 1 file changed, 35 insertions(+), 79 deletions(-) (limited to 'src/native/d3d/GraphicsContext3D.cpp') 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 -- cgit v1.2.3