diff options
author | Alessandro Borges <[email protected]> | 2005-12-21 21:58:21 +0000 |
---|---|---|
committer | Alessandro Borges <[email protected]> | 2005-12-21 21:58:21 +0000 |
commit | 13f19817dc36de51fe6fb55e8b01546d7862bb29 (patch) | |
tree | 8bb5e1242c41dc4fb5034d8f88a44babae07ad2b /src/native/d3d | |
parent | cac51fe3e2ad463dc97538a348715cbc14fd30fd (diff) |
Added support for Stencil.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@481 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/native/d3d')
-rw-r--r-- | src/native/d3d/Attributes.cpp | 24 | ||||
-rw-r--r-- | src/native/d3d/D3dCtx.cpp | 143 | ||||
-rw-r--r-- | src/native/d3d/D3dCtx.hpp | 19 | ||||
-rw-r--r-- | src/native/d3d/D3dDeviceInfo.cpp | 23 | ||||
-rw-r--r-- | src/native/d3d/D3dDeviceInfo.hpp | 6 | ||||
-rw-r--r-- | src/native/d3d/D3dDriverInfo.cpp | 40 | ||||
-rw-r--r-- | src/native/d3d/D3dDriverInfo.hpp | 1 | ||||
-rw-r--r-- | src/native/d3d/D3dUtil.cpp | 23 | ||||
-rw-r--r-- | src/native/d3d/GeometryArrayRetained.cpp | 155 | ||||
-rw-r--r-- | src/native/d3d/NativeConfigTemplate3D.cpp | 104 | ||||
-rw-r--r-- | src/native/d3d/StdAfx.h | 12 |
11 files changed, 359 insertions, 191 deletions
diff --git a/src/native/d3d/Attributes.cpp b/src/native/d3d/Attributes.cpp index c4fd82f..359ac22 100644 --- a/src/native/d3d/Attributes.cpp +++ b/src/native/d3d/Attributes.cpp @@ -345,7 +345,7 @@ void JNICALL Java_javax_media_j3d_Canvas3D_setLightEnables( #pragma warning(disable:4244) // loss of data from __int64 to int for (int i=nlights-1; i>=0; i--) { - device->LightEnable(i, enable_mask & (1<<i)); + device->LightEnable(i, enable_mask & (long)(1L<<i)); } } @@ -492,6 +492,28 @@ void JNICALL Java_javax_media_j3d_RenderingAttributesRetained_updateNative( break; } + if (userStencilAvailable == JNI_TRUE) + { + if (stencilEnable == JNI_TRUE) + { + /* + glEnable(GL_STENCIL_TEST); + + glStencilOp( getStencilOpValue(stencilFailOp), + getStencilOpValue(stencilZFailOp), + getStencilOpValue(stencilZPassOp)); + + glStencilFunc(getFunctionValue(stencilFunction), + stencilReferenceValue, stencilCompareMask); + glStencilMask(stencilWriteMask); + */ + + } else + { + // glDisable(GL_STENCIL_TEST); + } + } + } diff --git a/src/native/d3d/D3dCtx.cpp b/src/native/d3d/D3dCtx.cpp index 85c81b6..7bd4362 100644 --- a/src/native/d3d/D3dCtx.cpp +++ b/src/native/d3d/D3dCtx.cpp @@ -67,13 +67,19 @@ D3dCtx::D3dCtx(JNIEnv* env, jobject obj, HWND _hwnd, BOOL _offScreen, // this is the pixelFormat return from NativeConfigTemplate. minZDepth = vid & 0x3fffffff; - if (vid & 0x80000000) { - antialiasing = REQUIRED; - } else if (vid & 0x40000000) { - antialiasing = PREFERRED; - } else { - antialiasing = UNNECESSARY; - } + if (vid & 0x80000000) + { + antialiasing = REQUIRED; + } + else + if (vid & 0x40000000) + { + antialiasing = PREFERRED; + } + else + { + antialiasing = UNNECESSARY; + } setFullScreenFromProperty(env); @@ -385,7 +391,7 @@ BOOL D3dCtx::initialize(JNIEnv *env, jobject obj) // It is possible that last time Emulation mode is used. // If this is the case we will try Hardware mode first. - deviceInfo = setDeviceInfo(driverInfo, &bFullScreen, minZDepth); + deviceInfo = setDeviceInfo(driverInfo, &bFullScreen, minZDepth, minZDepthStencil); if ((pD3D == NULL) || (driverInfo == NULL)) { return false; @@ -512,7 +518,7 @@ else warning(CREATEDEVICEFAIL, hr); deviceInfo = driverInfo->d3dDeviceList[DEVICE_REF]; dwBehavior = findBehavior(); - deviceInfo->findDepthStencilFormat(minZDepth); + deviceInfo->findDepthStencilFormat(minZDepth,minZDepthStencil); d3dPresent.AutoDepthStencilFormat = deviceInfo->depthStencilFormat; if (deviceInfo->depthStencilFormat == D3DFMT_UNKNOWN) { @@ -833,7 +839,7 @@ INT D3dCtx::resetSurface(JNIEnv *env, jobject obj) HRESULT hr; - deviceInfo = setDeviceInfo(driverInfo, &bFullScreen, minZDepth); + deviceInfo = setDeviceInfo(driverInfo, &bFullScreen, minZDepth, minZDepthStencil); if (deviceInfo == NULL) { return NOCHANGE; @@ -984,54 +990,68 @@ DWORD D3dCtx::getHeight() } D3dDeviceInfo* D3dCtx::selectDevice(int deviceID, - D3dDriverInfo *driverInfo, - BOOL *bFullScreen, - int minZDepth) + D3dDriverInfo *driverInfo, + BOOL *bFullScreen, + int minZDepth, + int minZDepthStencil) { D3dDeviceInfo *pDevice; - for (int i=0; i < numDeviceTypes; i++) { + for (int i=0; i < numDeviceTypes; i++) + { pDevice = driverInfo->d3dDeviceList[i]; if ((((deviceID == DEVICE_HAL) || (deviceID == DEVICE_HAL_TnL)) && (pDevice->deviceType == D3DDEVTYPE_HAL)) || - (deviceID == DEVICE_REF) && - (pDevice->deviceType == D3DDEVTYPE_REF)) { + (deviceID == DEVICE_REF) && + (pDevice->deviceType == D3DDEVTYPE_REF)) + { if ((*bFullScreen && !pDevice->fullscreenCompatible) || - (!*bFullScreen && !pDevice->desktopCompatible)) { - if (pDevice->deviceType == D3DDEVTYPE_HAL) { - d3dError(HALDEVICENOTFOUND); - } else { - // should not happen, REF device always support - d3dError(DEVICENOTFOUND); - } - exit(1); + (!*bFullScreen && !pDevice->desktopCompatible)) + { + if (pDevice->deviceType == D3DDEVTYPE_HAL) + { + d3dError(HALDEVICENOTFOUND); + } + else + { + // should not happen, REF device always support + d3dError(DEVICENOTFOUND); + } + exit(1); } - if (pDevice->maxZBufferDepthSize == 0) { - if (pDevice->deviceType == D3DDEVTYPE_HAL) { - d3dError(HALNOTCOMPATIBLE); - } else { + if (pDevice->maxZBufferDepthSize == 0) + { + if (pDevice->deviceType == D3DDEVTYPE_HAL) + { + d3dError(HALNOTCOMPATIBLE); + } + else + { // should not happen, REF device always support d3dError(DEVICENOTFOUND); - } - exit(1); + } + exit(1); } - if (pDevice->deviceType == D3DDEVTYPE_HAL) { - if ((deviceID == DEVICE_HAL_TnL) && - !pDevice->isHardwareTnL) { + if (pDevice->deviceType == D3DDEVTYPE_HAL) + { + if ((deviceID == DEVICE_HAL_TnL) && + !pDevice->isHardwareTnL) + { d3dError(TNLHALDEVICENOTFOUND); exit(1); - } - } - pDevice->findDepthStencilFormat(minZDepth); - if (pDevice->depthStencilFormat == D3DFMT_UNKNOWN) { - d3dError(DEPTHSTENCILNOTFOUND); - exit(1); + } + } + + pDevice->findDepthStencilFormat(minZDepth, minZDepthStencil); + if (pDevice->depthStencilFormat == D3DFMT_UNKNOWN) + { + d3dError(DEPTHSTENCILNOTFOUND); + exit(1); } return pDevice; } } - // should not happen d3dError(DEVICENOTFOUND); exit(1); @@ -1040,19 +1060,25 @@ D3dDeviceInfo* D3dCtx::selectDevice(int deviceID, D3dDeviceInfo* D3dCtx::selectBestDevice(D3dDriverInfo *driverInfo, - BOOL *bFullScreen, int minZDepth) + BOOL *bFullScreen, + int minZDepth, + int minZDepthStencil) { D3dDeviceInfo *pDevice; D3dDeviceInfo *bestDevice = NULL; int i; - for (i=0; i < numDeviceTypes; i++) { + for (i=0; i < numDeviceTypes; i++) + { pDevice = driverInfo->d3dDeviceList[i]; - if (pDevice->maxZBufferDepthSize > 0) { - pDevice->findDepthStencilFormat(minZDepth); + if (pDevice->maxZBufferDepthSize > 0) + { + pDevice->findDepthStencilFormat(minZDepth, minZDepthStencil); - if (pDevice->depthStencilFormat == D3DFMT_UNKNOWN) { - if (pDevice->deviceType == D3DDEVTYPE_REF) { + if (pDevice->depthStencilFormat == D3DFMT_UNKNOWN) + { + if (pDevice->deviceType == D3DDEVTYPE_REF) + { d3dError(DEPTHSTENCILNOTFOUND); return NULL; } else { @@ -1640,14 +1666,23 @@ HMONITOR D3dCtx::findMonitor() D3dDeviceInfo* D3dCtx::setDeviceInfo(D3dDriverInfo *driverInfo, BOOL *bFullScreen, - int minZDepth) + int minZDepth, + int minZDepthStencil) { - if (requiredDeviceID >= 0) { - return selectDevice(requiredDeviceID, driverInfo, - bFullScreen, minZDepth); - } else { - return selectBestDevice(driverInfo, bFullScreen, - minZDepth); + if (requiredDeviceID >= 0) + { + return selectDevice(requiredDeviceID, + driverInfo, + bFullScreen, + minZDepth, + minZDepthStencil); + } + else + { + return selectBestDevice(driverInfo, + bFullScreen, + minZDepth, + minZDepthStencil); } } @@ -2037,6 +2072,8 @@ jboolean D3dCtx::getJavaBoolEnv(JNIEnv *env, char* envStr) + + /** // this routine is not safe using current D3D routines VOID D3dCtx::getDXVersion(CHAR* strResult) diff --git a/src/native/d3d/D3dCtx.hpp b/src/native/d3d/D3dCtx.hpp index 96a111a..746d459 100644 --- a/src/native/d3d/D3dCtx.hpp +++ b/src/native/d3d/D3dCtx.hpp @@ -97,10 +97,10 @@ public: BOOL inToggle; // in toggle fullscreen/window mode RECT screenRect; // coordinate of window relative to // the whole desktop in multiple monitor - RECT windowRect; // coordinate of window relative to - // the current monitor desktop only - INT minZDepth; // min Z depth set in NativeConfigTemplate - + RECT windowRect; // coordinate of window relative to + // the current monitor desktop only + INT minZDepth; // min Z depth set in NativeConfigTemplate + INT minZDepthStencil; // min Stencil depth set in NativeConfigTemplate DEVMODE devmode; // current display mode DWORD antialiasing; // PREFERRED, REQUIRED or UNNECESSARY @@ -124,6 +124,8 @@ public: DWORD softwareVertexProcessing; DWORD zWriteEnable; DWORD zEnable; + DWORD stencilWriteEnable; // new on 1.4 + DWORD stencilEnable; // new on 1.4 // Ambient material used when coloring Attributes D3DMATERIAL9 ambientMaterial; @@ -286,7 +288,8 @@ public: VOID setDriverInfo(); static D3dDeviceInfo* setDeviceInfo(D3dDriverInfo *driverInfo, BOOL *bFullScreen, - int minZDepth); + int minZDepth, + int minZDepthStencil); DWORD findBehavior(); VOID setPresentParams(); INT resetSurface(JNIEnv *env, jobject obj); @@ -304,10 +307,12 @@ public: static D3dDeviceInfo* selectDevice(int deviceID, D3dDriverInfo *driverInfo, BOOL *bFullScreen, - int minZDepth); + int minZDepth, + int minZDepthStencil); static D3dDeviceInfo* selectBestDevice(D3dDriverInfo *driverInfo, BOOL *bFullScreen, - int minZDepth); + int minZDepth, + int minZDepthStencil); static VOID setDeviceFromProperty(JNIEnv *env); static BOOL getSystemProperty(JNIEnv *env, char *strName, char *strValue); static VOID setDebugProperty(JNIEnv *env); diff --git a/src/native/d3d/D3dDeviceInfo.cpp b/src/native/d3d/D3dDeviceInfo.cpp index 7fffdf5..796889b 100644 --- a/src/native/d3d/D3dDeviceInfo.cpp +++ b/src/native/d3d/D3dDeviceInfo.cpp @@ -210,18 +210,25 @@ BOOL D3dDeviceInfo::supportAntialiasing() { } -void D3dDeviceInfo::findDepthStencilFormat(int minZDepth) +void D3dDeviceInfo::findDepthStencilFormat(int minZDepth, int minZDepthStencil) { depthStencilFormat = D3DFMT_UNKNOWN; - for (int i=0; i < D3DDEPTHFORMATSIZE; i++) { - if (depthFormatSupport[i]) { + for (int i=0; i < D3DDEPTHFORMATSIZE; i++) + { + //printf("\ndepthFormatSupport %s, %b",getPixelFormatName(d3dDepthFormat[i]), depthFormatSupport[i]); + if (depthFormatSupport[i]) + { // prefer one with stencil buffer, follow by D3DFMT_D16_LOCKABLE, - if (d3dDepthTable[i] >= minZDepth) { - depthStencilFormat = (D3DFORMAT) d3dDepthFormat[i]; - break; + // printf("\n ZDepth %d, Stencil %d ",d3dDepthTable[i],d3dStencilDepthTable[i]); + if (d3dDepthTable[i] >= minZDepth && d3dStencilDepthTable[i] >= minZDepthStencil ) + { + depthStencilFormat = (D3DFORMAT) d3dDepthFormat[i]; + break; } - } - } + }//if + }// for + // if none suitable found + } diff --git a/src/native/d3d/D3dDeviceInfo.hpp b/src/native/d3d/D3dDeviceInfo.hpp index ffb4587..1d63559 100644 --- a/src/native/d3d/D3dDeviceInfo.hpp +++ b/src/native/d3d/D3dDeviceInfo.hpp @@ -47,9 +47,13 @@ public: // max z buffer depth support UINT maxZBufferDepthSize; + // max stencil buffer depth support + UINT maxStencilDepthSize; // new on 1.4 + // Max vertex count support for each primitive DWORD maxVertexCount[GEO_TYPE_INDEXED_LINE_STRIP_SET+1]; + BOOL supportStencil; // new on 1.4 BOOL supportShaders11; BOOL isHardware; BOOL isHardwareTnL; @@ -87,7 +91,7 @@ public: BOOL supportAntialiasing(); D3DMULTISAMPLE_TYPE getBestMultiSampleType(); int getTextureFeaturesMask(); - void findDepthStencilFormat(int minZDepth); + void findDepthStencilFormat(int minZDepth, int minZDepthStencil); }; diff --git a/src/native/d3d/D3dDriverInfo.cpp b/src/native/d3d/D3dDriverInfo.cpp index a2d848f..30f2cc8 100644 --- a/src/native/d3d/D3dDriverInfo.cpp +++ b/src/native/d3d/D3dDriverInfo.cpp @@ -32,21 +32,25 @@ OSVERSIONINFO osvi; // When the index is greater than 65535, the nvidia driver will // consider it to be N % 65535. However it works fine in // hardware vertex processing mode. +//@TODO check this with Cap Bits UINT vertexBufferMaxVertexLimit = 65535; // True to disable setting D3DRS_MULTISAMPLEANTIALIAS // Rendering state. BOOL implicitMultisample; -D3DFORMAT d3dDepthFormat[D3DDEPTHFORMATSIZE] = {D3DFMT_D15S1, - D3DFMT_D24S8, - D3DFMT_D24X4S4, - D3DFMT_D16_LOCKABLE, - D3DFMT_D16, - D3DFMT_D32}; +D3DFORMAT d3dDepthFormat[D3DDEPTHFORMATSIZE] = { D3DFMT_D15S1, + D3DFMT_D24S8, + D3DFMT_D24X4S4, + D3DFMT_D16_LOCKABLE, + D3DFMT_D16, + D3DFMT_D32 + }; // This should match the depth bit in the above array -int d3dDepthTable[D3DDEPTHFORMATSIZE] = {15, 24, 24, 16, 16, 32}; +int d3dDepthTable[D3DDEPTHFORMATSIZE] = {15, 24, 24, 16, 16, 32}; +int d3dStencilDepthTable[D3DDEPTHFORMATSIZE]={ 1, 8, 4, 0, 0, 0}; + D3DLIGHT9 ambientLight; D3dDriverInfo::D3dDriverInfo() @@ -169,16 +173,19 @@ VOID buildDriverList(LPDIRECT3D9 pD3D) pDevice->deviceType = deviceTypes[j]; pD3D->GetDeviceCaps(i, deviceTypes[j], &d3dCaps); pDevice->setCaps(&d3dCaps); + pDevice->desktopCompatible = SUCCEEDED(pD3D->CheckDeviceType(i, deviceTypes[j], pDriver->desktopMode.Format, pDriver->desktopMode.Format, TRUE)); + pDevice->fullscreenCompatible = SUCCEEDED(pD3D->CheckDeviceType(i,deviceTypes[j], pDriver->desktopMode.Format, pDriver->desktopMode.Format, FALSE)); + pDevice->maxZBufferDepthSize = 0; if (pDevice->isHardwareTnL) { @@ -203,10 +210,21 @@ VOID buildDriverList(LPDIRECT3D9 pD3D) pDriver->desktopMode.Format, pDriver->desktopMode.Format, d3dDepthFormat[k])); - if (pDevice->depthFormatSupport[k]) { - if (d3dDepthTable[k] > pDevice->maxZBufferDepthSize) { - pDevice->maxZBufferDepthSize = d3dDepthTable[k]; - } + if (pDevice->depthFormatSupport[k]) + { + if (d3dDepthTable[k] > pDevice->maxZBufferDepthSize) + { + pDevice->maxZBufferDepthSize = d3dDepthTable[k]; + pDevice->maxStencilDepthSize = d3dStencilDepthTable[k]; + if (d3dStencilDepthTable[k]>0) + { + pDevice->supportStencil = true; + } + else + { + pDevice->supportStencil = false; + } + } } } diff --git a/src/native/d3d/D3dDriverInfo.hpp b/src/native/d3d/D3dDriverInfo.hpp index 5c5f0ca..d6fbcc2 100644 --- a/src/native/d3d/D3dDriverInfo.hpp +++ b/src/native/d3d/D3dDriverInfo.hpp @@ -22,6 +22,7 @@ extern D3DFORMAT d3dDepthFormat[D3DDEPTHFORMATSIZE]; extern int d3dDepthTable[D3DDEPTHFORMATSIZE]; +extern int d3dStencilDepthTable[D3DDEPTHFORMATSIZE]; class D3dDriverInfo { public: diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp index 81d2182..71c4e1d 100644 --- a/src/native/d3d/D3dUtil.cpp +++ b/src/native/d3d/D3dUtil.cpp @@ -202,7 +202,7 @@ typedef struct _PIXELFORMAT { DWORD dwRBitMask; DWORD dwGBitMask; DWORD dwBBitMask; - DWORD dwRGBAlphaBitMask; + DWORD dwRGBAlphaBitMask; BOOL noAlpha; } PIXELFORMAT; @@ -210,6 +210,8 @@ typedef struct _PIXELFORMAT { typedef struct _DEPTHPIXELFORMAT { DWORD dwZBufferBitDepth; DWORD dwZBitMask; + DWORD dwStencilBitDepth; + DWORD dwStencilBitMask; } DEPTHPIXELFORMAT; @@ -246,6 +248,7 @@ char* getPixelFormatName(D3DFORMAT f) // If there is a new D3DFORMAT, just add it here and // our copy procedures can handle any format specific // as bit mask. +//@TODO add floating point pixelFormats VOID computePixelFormat(PIXELFORMAT *ddpf, D3DFORMAT format) { switch (format) { @@ -388,20 +391,38 @@ VOID computeDepthPixelFormat(DEPTHPIXELFORMAT *ddpf, case D3DFMT_D16: ddpf->dwZBufferBitDepth = 16; ddpf->dwZBitMask = 0xffff; + ddpf->dwStencilBitDepth = 0; + ddpf->dwStencilBitMask = 0x0000; break; case D3DFMT_D15S1: ddpf->dwZBufferBitDepth = 16; ddpf->dwZBitMask = 0xfffe; + ddpf->dwStencilBitDepth = 1; + ddpf->dwStencilBitMask = 0x0001; break; case D3DFMT_D32: ddpf->dwZBufferBitDepth = 32; ddpf->dwZBitMask = 0xffffffff; + ddpf->dwStencilBitDepth = 0; + ddpf->dwStencilBitMask = 0x000000; break; case D3DFMT_D24S8: + ddpf->dwZBufferBitDepth = 32; + ddpf->dwZBitMask = 0xffffff00; + ddpf->dwStencilBitDepth = 8; + ddpf->dwStencilBitMask = 0x00000ff; + break; case D3DFMT_D24X8: + ddpf->dwZBufferBitDepth = 32; + ddpf->dwZBitMask = 0xffffff00; + ddpf->dwStencilBitDepth = 0; + ddpf->dwStencilBitMask = 0x0000000; + break; case D3DFMT_D24X4S4: ddpf->dwZBufferBitDepth = 32; ddpf->dwZBitMask = 0xffffff00; + ddpf->dwStencilBitDepth = 4; + ddpf->dwStencilBitMask = 0x000000f; break; default: printf("Unknown depth buffer format %d\n", format); diff --git a/src/native/d3d/GeometryArrayRetained.cpp b/src/native/d3d/GeometryArrayRetained.cpp index 681395c..d4f8b7c 100644 --- a/src/native/d3d/GeometryArrayRetained.cpp +++ b/src/native/d3d/GeometryArrayRetained.cpp @@ -2362,7 +2362,9 @@ void renderGeometry(JNIEnv *env, vb->isIndexPrimitive = true; renderTypeSet = true; // fall through - } else { // line mode + } + else + { // line mode // we don't want to see extra line appear in the // diagonal of quads if it splits into two // triangles. This is REALLY SLOW !!! @@ -2978,40 +2980,46 @@ void renderIndexGeometry(JNIEnv *env, vb->primitiveType = D3DPT_FORCE_DWORD; - for (i = 0; i < (indexCount >> 2); i++) { - if (d3dCtx->cullMode != D3DCULL_NONE) { - // Do back face culling here - idx0 = *idxPtr++; - idx1 = *idxPtr++; - idx2 = *idxPtr++; - idx3 = *idxPtr++; - if (strideData->fpositionPtr) { - fspt = strideData->fpositionPtr + posStride*idx0; - worldCoord[0].x = *fspt++; - worldCoord[0].y = *fspt++; - worldCoord[0].z = *fspt++; - fspt = strideData->fpositionPtr + posStride*idx1; - worldCoord[1].x = *fspt++; - worldCoord[1].y = *fspt++; - worldCoord[1].z = *fspt++; - fspt = strideData->fpositionPtr + posStride*idx2; - worldCoord[2].x = *fspt++; - worldCoord[2].y = *fspt++; - worldCoord[2].z = *fspt++; - } else { - dspt = strideData->dpositionPtr + posStride*idx0; - worldCoord[0].x = *dspt++; - worldCoord[0].y = *dspt++; - worldCoord[0].z = *dspt++; - dspt = strideData->dpositionPtr + posStride*idx1; - worldCoord[1].x = *dspt++; - worldCoord[1].y = *dspt++; - worldCoord[1].z = *dspt++; - dspt = strideData->dpositionPtr + posStride*idx2; - worldCoord[2].x = *dspt++; - worldCoord[2].y = *dspt++; - worldCoord[2].z = *dspt++; - } + for (i = 0; i < (indexCount >> 2); i++) + { + if (d3dCtx->cullMode != D3DCULL_NONE) + { + // Do back face culling here + idx0 = *idxPtr++; + idx1 = *idxPtr++; + idx2 = *idxPtr++; + idx3 = *idxPtr++; + + if (strideData->fpositionPtr) + { + fspt = strideData->fpositionPtr + posStride*idx0; + worldCoord[0].x = *fspt++; + worldCoord[0].y = *fspt++; + worldCoord[0].z = *fspt++; + fspt = strideData->fpositionPtr + posStride*idx1; + worldCoord[1].x = *fspt++; + worldCoord[1].y = *fspt++; + worldCoord[1].z = *fspt++; + fspt = strideData->fpositionPtr + posStride*idx2; + worldCoord[2].x = *fspt++; + worldCoord[2].y = *fspt++; + worldCoord[2].z = *fspt++; + } + else + { + dspt = strideData->dpositionPtr + posStride*idx0; + worldCoord[0].x = *dspt++; + worldCoord[0].y = *dspt++; + worldCoord[0].z = *dspt++; + dspt = strideData->dpositionPtr + posStride*idx1; + worldCoord[1].x = *dspt++; + worldCoord[1].y = *dspt++; + worldCoord[1].z = *dspt++; + dspt = strideData->dpositionPtr + posStride*idx2; + worldCoord[2].x = *dspt++; + worldCoord[2].y = *dspt++; + worldCoord[2].z = *dspt++; + } d3dCtx->transform(&worldCoord[0], &screenCoord[0]); d3dCtx->transform(&worldCoord[1], &screenCoord[1]); @@ -3020,46 +3028,56 @@ void renderIndexGeometry(JNIEnv *env, screenCoord[0].sy -= screenCoord[1].sy; screenCoord[2].sx -= screenCoord[1].sx; screenCoord[2].sy -= screenCoord[1].sy; - if (d3dCtx->cullMode == D3DCULL_CW) { - if ((screenCoord[0].sx*screenCoord[2].sy - - screenCoord[2].sx*screenCoord[0].sy) >= 0) { - DrawIndexPolygonLine(d3dCtx, - device, - vertexFormat, - strideData, - idx0, idx1, - idx2, idx3); - } - } else { // Clip front face - if ((screenCoord[0].sx*screenCoord[2].sy - - screenCoord[2].sx*screenCoord[0].sy) <= 0) { - DrawIndexPolygonLine(d3dCtx, - device, - vertexFormat, - strideData, - idx0, idx1, - idx2, idx3); - } + + if (d3dCtx->cullMode == D3DCULL_CW) + { + if ((screenCoord[0].sx*screenCoord[2].sy - + screenCoord[2].sx*screenCoord[0].sy) >= 0) + { + DrawIndexPolygonLine(d3dCtx, + device, + vertexFormat, + strideData, + idx0, idx1, + idx2, idx3); + } + } + else + { // Clip front face + if ((screenCoord[0].sx*screenCoord[2].sy - + screenCoord[2].sx*screenCoord[0].sy) <= 0) + { + DrawIndexPolygonLine(d3dCtx, + device, + vertexFormat, + strideData, + idx0, idx1, + idx2, idx3); + } } - } else { - // cullMode == D3DCULL_NONE - DrawIndexPolygonLine(d3dCtx, - device, - vertexFormat, - strideData, - idx0, idx1, - idx2, idx3); - } - } + } + else + { + // cullMode == D3DCULL_NONE + DrawIndexPolygonLine(d3dCtx, + device, + vertexFormat, + strideData, + idx0, idx1, + idx2, idx3); + } + }//for + if (((vertexFormat & D3DFVF_DIFFUSE) == 0) && - (!d3dCtx->isLightEnable)) { - d3dCtx->restoreDefaultLightMaterial(); + (!d3dCtx->isLightEnable)) + { + d3dCtx->restoreDefaultLightMaterial(); } // Don't call vb->Renderer() at the end return; } - //end Quad WireFrame + //end index Quad WireFrame // fall through case GEO_TYPE_INDEXED_TRI_SET: @@ -4491,6 +4509,7 @@ void executeIndexedGeometryArray(JNIEnv *env, env->ReleasePrimitiveArrayCritical(indexCoord, strideData.indexPtr, NULL); + } diff --git a/src/native/d3d/NativeConfigTemplate3D.cpp b/src/native/d3d/NativeConfigTemplate3D.cpp index c18134b..db2dace 100644 --- a/src/native/d3d/NativeConfigTemplate3D.cpp +++ b/src/native/d3d/NativeConfigTemplate3D.cpp @@ -20,7 +20,7 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isStereoAvailable( jlong pFormatInfo, jboolean offScreen) { - // DirectX 8.0 don't support stereo + // DirectX 9.0 don't support stereo return false; } @@ -47,20 +47,24 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing BOOL antialiasingSupport = false; lock(); - if (d3dDriverList == NULL) { + if (d3dDriverList == NULL) + { D3dDriverInfo::initialize(env); } - if (d3dDriverList != NULL) { - D3dDriverInfo *driverInfo = d3dDriverList[screen]; - for (int i=0; i < numDeviceTypes; i++) { + if (d3dDriverList != NULL) + { + D3dDriverInfo *driverInfo = d3dDriverList[screen]; + for (int i=0; i < numDeviceTypes; i++) + { D3dDeviceInfo *pDeviceInfo = driverInfo->d3dDeviceList[i]; if (pDeviceInfo->desktopCompatible && - pDeviceInfo->supportAntialiasing()) { - antialiasingSupport = true; - break; - } - } + pDeviceInfo->supportAntialiasing()) + { + antialiasingSupport = true; + break; + } + } } unlock(); return antialiasingSupport; @@ -74,6 +78,8 @@ jboolean JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasing return JNI_FALSE; } + + extern "C" JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( JNIEnv *env, @@ -84,6 +90,7 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( jlongArray offScreenPFArray) { int depth, red, green, blue; + int stencilDepth; int retValue = -1; jint *mx_ptr = (jint *) env->GetPrimitiveArrayCritical(attrList, NULL); @@ -91,43 +98,51 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( green = mx_ptr[GREEN_SIZE]; blue = mx_ptr[BLUE_SIZE]; depth = mx_ptr[DEPTH_SIZE]; + stencilDepth = mx_ptr[STENCIL_SIZE]; env->ReleasePrimitiveArrayCritical(attrList, mx_ptr, 0); - if (mx_ptr[STEREO] != REQUIRED) { - lock(); - - if (d3dDriverList == NULL) { - D3dDriverInfo::initialize(env); - } + if (mx_ptr[STEREO] != REQUIRED) + { + lock(); + if (d3dDriverList == NULL) + { + D3dDriverInfo::initialize(env); + } - if (d3dDriverList != NULL) { + if (d3dDriverList != NULL) + { BOOL bFullScreen; D3dDriverInfo *pDriver = d3dDriverList[screen]; - D3dDeviceInfo *deviceInfo = - D3dCtx::setDeviceInfo(pDriver, &bFullScreen, depth); - - if (deviceInfo != NULL) { - if ((depth <= deviceInfo->maxZBufferDepthSize) && - (red <= pDriver->redDepth) && - (green <= pDriver->greenDepth) && - (blue <= pDriver->blueDepth)) { - retValue = depth; - } + D3dDeviceInfo *deviceInfo = D3dCtx::setDeviceInfo(pDriver, &bFullScreen, depth, stencilDepth); + + if (deviceInfo != NULL) + { + if ((depth <= deviceInfo->maxZBufferDepthSize) && + (red <= pDriver->redDepth) && + (green <= pDriver->greenDepth) && + (blue <= pDriver->blueDepth)&& + (stencilDepth)<= deviceInfo->maxStencilDepthSize) + { + // first 0-7bits for depth,8-15 Stencil + retValue = depth |(stencilDepth <<8); + } } } unlock(); } - if (mx_ptr[ANTIALIASING] == REQUIRED) { - if (Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable(env, obj, 0, JNI_TRUE, screen) == JNI_TRUE) + if (mx_ptr[ANTIALIASING] == REQUIRED) + { + if (Java_javax_media_j3d_NativeConfigTemplate3D_isSceneAntialiasingMultisampleAvailable(env, obj, 0, JNI_TRUE, screen) == JNI_TRUE) { - retValue |= (1 << 31); - } else { - retValue = -1; - } + retValue |= (1 << 31); + } + else + { + retValue = -1; + } } - return retValue; } @@ -136,13 +151,22 @@ jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_choosePixelFormat( /* * Class: javax_media_j3d_NativeConfigTemplate3D * Method: getStencilSize - * Signature: (JZ)I - * @TODO: FIX THIS !!!!! + * Signature: (JZ)I * */ JNIEXPORT jint JNICALL Java_javax_media_j3d_NativeConfigTemplate3D_getStencilSize - (JNIEnv *, jobject, jlong, jboolean) + (JNIEnv *env, jobject obj, jlong pFormatInfo, jboolean offScreen) { - // dummy value - - return 8; + int stencilSize = (int)pFormatInfo; + + stencilSize = (stencilSize >> 8) & 0xff; + + /** // next version pFormatInfo will be a D3DFORMAT value or index for + D3DFORMAT fmt = d3dCtx->deviceInfo->depthStencilFormat; + if (fmt == D3DFMT_D15S1) stencilSize = 1; + else + if (fmt == D3DFMT_D24X4S4) stencilSize = 4; + else + if(fmt == D3DFMT_D24S8)stencilSize = 8; + */ + return stencilSize; } diff --git a/src/native/d3d/StdAfx.h b/src/native/d3d/StdAfx.h index d653594..4e86990 100644 --- a/src/native/d3d/StdAfx.h +++ b/src/native/d3d/StdAfx.h @@ -25,11 +25,20 @@ #pragma once #endif // _MSC_VER > 1000 +#ifndef _MT +#define _MT +#endif + // Exclude rarely-used stuff from Windows headers +#define VC_EXTRALEAN #define WIN32_LEAN_AND_MEAN + +//#undef _AFXDLL +//#undef _UNICODE + // Windows Header Files: -#include <afx.h> +#include <afx.h> #include <winbase.h> #include <windows.h> #include <multimon.h> @@ -46,6 +55,7 @@ #include <d3d9.h> #include <dxerr9.h> #include <d3dx9.h> +#include <d3dx9tex.h> #include <vector> #include <algorithm> using namespace std ; |