diff options
author | Chien Yang <[email protected]> | 2006-10-27 04:45:39 +0000 |
---|---|---|
committer | Chien Yang <[email protected]> | 2006-10-27 04:45:39 +0000 |
commit | a667c6f38ae0916ef492c4d1bdbb9479db91c260 (patch) | |
tree | 87b76e92cd45cee3542b6b365d6b6268ddd43d98 /src/native | |
parent | 9b7f91292fcf0cbed1e80dfb4ff998b1a7352939 (diff) |
1) Implemented Raster support for d3d pipe.
2) Created a proper vertex data type for Background image.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@729 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/native')
-rw-r--r-- | src/native/d3d/Canvas3D.cpp | 131 | ||||
-rw-r--r-- | src/native/d3d/D3dCtx.hpp | 13 | ||||
-rw-r--r-- | src/native/d3d/D3dUtil.cpp | 55 |
3 files changed, 169 insertions, 30 deletions
diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp index b2336c7..dbe7042 100644 --- a/src/native/d3d/Canvas3D.cpp +++ b/src/native/d3d/Canvas3D.cpp @@ -360,7 +360,7 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground( D3DXMATRIX Ortho2D; D3DXMATRIX ptm, wtm, vtm; - D3DTLVERTEX verts[4]; + COORDTEXVERTEX verts[4]; D3DXMATRIX texMatrix; int tus; @@ -485,11 +485,10 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground( device->SetVertexShader(NULL); - device->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 | - D3DFVF_DIFFUSE | D3DFVF_TEXCOORDSIZE2(0)); + device->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0)); device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, - 2, verts, sizeof(D3DTLVERTEX)); + 2, verts, sizeof(COORDTEXVERTEX)); /* Restore renderstates */ @@ -529,11 +528,129 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillRaster(JNIEnv *env, jfloat mapZ, jfloat alpha) { + + DWORD cull, lighting; + D3DXMATRIX Ortho2D; + D3DXMATRIX ptm, wtm, vtm; + COORDCLRTEXVERTEX verts[4]; + D3DXMATRIX texMatrix; + int tus; + GetDevice(); - /* printf("Canvas3D.textureFillRaster()\n"); */ - /* TODO : Implement textureFillRaster() */ - printf("[TODO NEEDED] Canvas3D : *** textureFillRaster is not implemented yet.\n"); + device->GetRenderState(D3DRS_CULLMODE, &cull); + device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + + device->GetRenderState(D3DRS_LIGHTING, &lighting); + device->SetRenderState(D3DRS_LIGHTING, FALSE); + + tus = d3dCtx->texUnitStage; + + if (tus >= d3dCtx->bindTextureIdLen) { + if (debug) { + printf("Internal Error: texUnitState %d, bindTextureIDLen %d\n", + d3dCtx->texUnitStage, d3dCtx->bindTextureIdLen); + } + return; + } + + // TextureStage will be restore by caller. + device->SetTextureStageState(tus, D3DTSS_ALPHAOP, D3DTOP_MODULATE); + device->SetTextureStageState(tus, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); + device->SetTextureStageState(tus, D3DTSS_ALPHAARG2, D3DTA_CURRENT); + + device->GetTransform(D3DTS_PROJECTION, &ptm); + device->GetTransform(D3DTS_WORLD, &wtm); + device->GetTransform(D3DTS_VIEW, &vtm); + + Ortho2D._11 = 2.0; + Ortho2D._12 = 0.0; + Ortho2D._13 = 0.0; + Ortho2D._14 = 0.0; + + Ortho2D._21 = 0.0; + Ortho2D._22 = 2.0; + Ortho2D._23 = 0.0; + Ortho2D._24 = 0.0; + + Ortho2D._31 = 0.0; + Ortho2D._32 = 0.0; + Ortho2D._33 = -1.0; + Ortho2D._34 = 0.0; + + Ortho2D._41 = -1.0; + Ortho2D._42 = -1.0; + Ortho2D._43 = 0.0; + Ortho2D._44 = 1.0; + + /* + printf("Ortho2D matix : \n"); + printf("%f, %f, %f, %f\n", Ortho2D._11, Ortho2D._12, Ortho2D._13, Ortho2D._14); + printf("%f, %f, %f, %f\n", Ortho2D._21, Ortho2D._22, Ortho2D._23, Ortho2D._24); + printf("%f, %f, %f, %f\n", Ortho2D._31, Ortho2D._32, Ortho2D._33, Ortho2D._34); + printf("%f, %f, %f, %f\n", Ortho2D._41, Ortho2D._42, Ortho2D._43, Ortho2D._44); + */ + + device->SetTransform(D3DTS_WORLD, &identityMatrix); + device->SetTransform(D3DTS_VIEW, &identityMatrix); + device->SetTransform(D3DTS_PROJECTION, &Ortho2D); + + verts[0].tu = texMinU; /* tumin; */ + verts[0].tv = texMaxV; /* tvmax; */ + verts[1].tu = texMinU; /* tumin; */ + verts[1].tv = texMinV; /* tvmin; */ + verts[2].tu = texMaxU; /* tumax; */ + verts[2].tv = texMaxV; /* tvmax; */ + verts[3].tu = texMaxU; /* tumax; */ + verts[3].tv = texMinV; /* tvmin; */ + + D3DCOLOR alphaColor = 0xffffff | ((int)(alpha * 255.0f) << 24); + + verts[0].color = alphaColor; + verts[0].sx = mapMinX; + verts[0].sy = mapMaxY; + verts[0].sz = mapZ; + + verts[1].color = alphaColor; + verts[1].sx = mapMinX; + verts[1].sy = mapMinY; + verts[1].sz = mapZ; + + verts[2].color = alphaColor; + verts[2].sx = mapMaxX; + verts[2].sy = mapMaxY; + verts[2].sz = mapZ; + + verts[3].color = alphaColor; + verts[3].sx = mapMaxX; + verts[3].sy = mapMinY; + verts[3].sz = mapZ; + + /* + 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); + + printf("(mapZ) = (%3.2f)\n",mapZ); + */ + device->SetVertexShader(NULL); + + device->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 | + D3DFVF_DIFFUSE | D3DFVF_TEXCOORDSIZE2(0)); + + device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, + 2, verts, sizeof(COORDCLRTEXVERTEX)); + + + /* Restore renderstates */ + device->SetRenderState(D3DRS_CULLMODE, cull); + device->SetRenderState(D3DRS_LIGHTING, lighting); + + /* Restore texture Matrix transform */ + device->SetTransform(D3DTS_PROJECTION, &ptm); + device->SetTransform(D3DTS_WORLD, &wtm); + device->SetTransform(D3DTS_VIEW, &vtm); } diff --git a/src/native/d3d/D3dCtx.hpp b/src/native/d3d/D3dCtx.hpp index 2c3b8e2..f51925c 100644 --- a/src/native/d3d/D3dCtx.hpp +++ b/src/native/d3d/D3dCtx.hpp @@ -45,11 +45,24 @@ typedef struct _D3DVERTEX { float x, y, z; } D3DVERTEX; + typedef struct _D3DTLVERTEX { float sx, sy, sz, rhw; float tu, tv; } D3DTLVERTEX; +typedef struct _COORDTEXVERTEX { + float sx, sy, sz; + float tu, tv; +} COORDTEXVERTEX; + +typedef struct _COORDCLRTEXVERTEX { + float sx, sy, sz; + D3DCOLOR color; + float tu, tv; +} COORDCLRTEXVERTEX; + + typedef vector<LPDIRECT3DRESOURCE9> LPDIRECT3DRESOURCE9Vector; typedef vector<LPDIRECT3DVERTEXBUFFER9> LPDIRECT3DVERTEXBUFFER9Vector; //issue 135 iterator for vectors diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp index 0b9cd7c..6b5c1df 100644 --- a/src/native/d3d/D3dUtil.cpp +++ b/src/native/d3d/D3dUtil.cpp @@ -889,6 +889,7 @@ LPDIRECT3DVOLUMETEXTURE9 createVolumeTexture(D3dCtx *d3dCtx, // copy data from DirectDraw surface to memory +// and reverse the Y axis void copyDataFromSurface(jint imageFormat, jint xoffset, jint yoffset, jint subWidth, jint subHeight, @@ -900,8 +901,6 @@ void copyDataFromSurface(jint imageFormat, PIXELFORMAT ddpf; HRESULT hr; - printf("[Java 3D] copyDataFromSurface: not tested yet %d\n", imageFormat); - if (surf == NULL) { return; } @@ -940,6 +939,9 @@ void copyDataFromSurface(jint imageFormat, if ((imageFormat == IMAGE_FORMAT_INT_RGB) || (imageFormat == IMAGE_FORMAT_INT_ARGB)) { dstPitch = subWidth << 2; + destRow += (subHeight-1)*dstPitch; + + printf("[Java 3D] copyDataFromSurface: (1) %d\n", ddpf.dwRGBBitCount); if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -958,7 +960,7 @@ void copyDataFromSurface(jint imageFormat, *dst++ = (byte) 0xff; } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else { for (int i=yoffset; i < ylimit; i++) { @@ -971,7 +973,7 @@ void copyDataFromSurface(jint imageFormat, *dst++ = *src++; } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } } else { // handle less common format @@ -1006,7 +1008,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1023,7 +1025,7 @@ void copyDataFromSurface(jint imageFormat, *dst++ = (byte) ((mask >> 16) & 0xff); } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1039,7 +1041,7 @@ void copyDataFromSurface(jint imageFormat, *dst++ = (byte) ((mask >> 8) & 0xff); } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { printf("[Java 3D] copyDataFromSurface: Format on (8 bits or less surface) not support %d\n", imageFormat); @@ -1048,7 +1050,11 @@ void copyDataFromSurface(jint 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); + dstPitch = subWidth << 2; + destRow += (subHeight-1)*dstPitch; if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -1070,7 +1076,7 @@ void copyDataFromSurface(jint imageFormat, *dst++ = (byte) 0xff; } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else { for (int i=yoffset; i < ylimit; i++) { @@ -1086,7 +1092,7 @@ void copyDataFromSurface(jint imageFormat, *dst++ = *src++; } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } } else { // handle less common format @@ -1146,7 +1152,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1192,7 +1198,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1240,7 +1246,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { for (int i=yoffset; i < ylimit; i++) { @@ -1283,7 +1289,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } } @@ -1293,6 +1299,7 @@ void copyDataFromSurface(jint imageFormat, int ashift = firstBit(ddpf.dwRGBAlphaBitMask) + ucountBits(ddpf.dwRGBAlphaBitMask) - 8; dstPitch = subWidth << 1; + destRow += (subHeight-1)*dstPitch; if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -1315,7 +1322,8 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; + } } else { // handle less common format int gshift = firstBit(ddpf.dwGBitMask) + @@ -1352,7 +1360,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1384,7 +1392,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1415,7 +1423,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { for (int i=yoffset; i < ylimit; i++) { @@ -1443,7 +1451,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } } @@ -1452,6 +1460,7 @@ void copyDataFromSurface(jint imageFormat, int gshift = firstBit(ddpf.dwGBitMask) + ucountBits(ddpf.dwGBitMask) - 8; dstPitch = subWidth; + destRow += (subHeight-1)*dstPitch; if ((ddpf.dwRGBBitCount == 32) && (ddpf.dwRBitMask == 0xff0000) && @@ -1469,7 +1478,7 @@ void copyDataFromSurface(jint imageFormat, *src++; } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else { // handle less common format int gshift = firstBit(ddpf.dwGBitMask) + @@ -1495,7 +1504,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 24) && (ddpf.dwRGBBitCount > 16)) { @@ -1516,7 +1525,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if ((ddpf.dwRGBBitCount <= 16) && (ddpf.dwRGBBitCount > 8)) { @@ -1536,7 +1545,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } else if (ddpf.dwRGBBitCount <= 8) { for (int i=yoffset; i < ylimit; i++) { @@ -1553,7 +1562,7 @@ void copyDataFromSurface(jint imageFormat, } } srcRow += lockedRect.Pitch; - destRow += dstPitch; + destRow -= dstPitch; } } } |