aboutsummaryrefslogtreecommitdiffstats
path: root/src/native
diff options
context:
space:
mode:
authorChien Yang <[email protected]>2006-10-25 23:58:51 +0000
committerChien Yang <[email protected]>2006-10-25 23:58:51 +0000
commit5603761c3ee80f7c4f987e6d9cc95babea833ab3 (patch)
treecd05c404a39a9dd907986a75bfa38c775f4f00e7 /src/native
parentd073500495277164924b158e784a476d4e6c2777 (diff)
Implemented background texture support for D3D pipe.
git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@727 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/native')
-rw-r--r--src/native/d3d/Attributes.cpp35
-rw-r--r--src/native/d3d/Canvas3D.cpp214
-rw-r--r--src/native/d3d/D3dUtil.cpp1
3 files changed, 162 insertions, 88 deletions
diff --git a/src/native/d3d/Attributes.cpp b/src/native/d3d/Attributes.cpp
index dc21c80..ef4d3fe 100644
--- a/src/native/d3d/Attributes.cpp
+++ b/src/native/d3d/Attributes.cpp
@@ -505,31 +505,30 @@ void JNICALL Java_javax_media_j3d_NativePipeline_resetRenderingAttributes(
device->SetRenderState(D3DRS_ZWRITEENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
}
-
+
if (!db_enable_override) {
d3dCtx->zEnable = TRUE;
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
}
-
+
device->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_ALWAYS);
device->SetRenderState(D3DRS_ALPHAREF, 0);
- if(d3dCtx->stencilWriteEnable)
- {
- device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
- device->SetRenderState( D3DRS_STENCILREF, 0);
- device->SetRenderState( D3DRS_STENCILMASK, 0xFFFFFFFF);
- device->SetRenderState( D3DRS_STENCILWRITEMASK, 0xFFFFFFFF );
-
- // Always increment the stencil value
- device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
+ if(d3dCtx->stencilWriteEnable) {
+ device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
+ device->SetRenderState( D3DRS_STENCILREF, 0);
+ device->SetRenderState( D3DRS_STENCILMASK, 0xFFFFFFFF);
+ device->SetRenderState( D3DRS_STENCILWRITEMASK, 0xFFFFFFFF );
+
+ // Always increment the stencil value
+ device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
-
- device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
- d3dCtx->stencilWriteEnable = false;
- }
-
+
+ device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
+ d3dCtx->stencilWriteEnable = false;
+ }
+
/* setRasterOp(d3dCtx, R2_COPYPEN); */
}
@@ -543,13 +542,13 @@ void JNICALL Java_javax_media_j3d_NativePipeline_updateRenderingAttributes(
jboolean db_enable_override,
jboolean db_enable,
jboolean db_write_enable,
- jint db_func,
+ jint db_func,
jfloat at_value,
jint at_func,
jboolean ignoreVertexColors,
jboolean rasterOpEnable,
jint rasterOp,
- jboolean userStencilAvailable,
+ jboolean userStencilAvailable,
jboolean stencilEnable,
jint stencilFailOp,
jint stencilZFailOp,
diff --git a/src/native/d3d/Canvas3D.cpp b/src/native/d3d/Canvas3D.cpp
index 57fbd0a..b2336c7 100644
--- a/src/native/d3d/Canvas3D.cpp
+++ b/src/native/d3d/Canvas3D.cpp
@@ -354,65 +354,127 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground(
jfloat mapMinY,
jfloat mapMaxY)
{
+
+ DWORD alphaTest, alphaBlend, cull, zBuffer,
+ fog, lighting, stencil, specular;
+
+ D3DXMATRIX Ortho2D;
+ D3DXMATRIX ptm, wtm, vtm;
+ D3DTLVERTEX verts[4];
+ D3DXMATRIX texMatrix;
+ int tus;
+
GetDevice();
- 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;
+
+ device->GetRenderState(D3DRS_ALPHATESTENABLE, &alphaTest);
+ device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
+
+ device->GetRenderState(D3DRS_ALPHABLENDENABLE, &alphaBlend);
+ device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
+
+ device->GetRenderState(D3DRS_CULLMODE, &cull);
+ device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
+
+ device->GetRenderState(D3DRS_ZENABLE, &zBuffer);
+ device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
+
+ device->GetRenderState(D3DRS_FOGENABLE, &fog);
+ device->SetRenderState(D3DRS_FOGENABLE, FALSE);
+
+ device->GetRenderState(D3DRS_LIGHTING, &lighting);
+ device->SetRenderState(D3DRS_LIGHTING, FALSE);
+
+ device->GetRenderState(D3DRS_STENCILENABLE, &stencil);
+ device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
+
+ device->GetRenderState(D3DRS_SPECULARENABLE, &specular);
+ device->SetRenderState(D3DRS_SPECULARENABLE, FALSE);
+
+ tus = d3dCtx->texUnitStage;
+
+ if (tus >= d3dCtx->bindTextureIdLen) {
+ if (debug) {
+ printf("Internal Error: texUnitState %d, bindTextureIDLen %d\n",
+ d3dCtx->texUnitStage, d3dCtx->bindTextureIdLen);
+ }
+ return;
+ }
+
+ device->SetTextureStageState(tus,
+ D3DTSS_TEXCOORDINDEX,
+ D3DTSS_TCI_PASSTHRU);
+
+
+ if (d3dCtx->texTransformSet[tus]) {
+ device->GetTransform((D3DTRANSFORMSTATETYPE)
+ (D3DTS_TEXTURE0 + tus),
+ &texMatrix);
+
+ device->SetTransform((D3DTRANSFORMSTATETYPE)
+ (D3DTS_TEXTURE0 + tus),
+ &identityMatrix);
+ }
+
+ device->GetTransform(D3DTS_PROJECTION, &ptm);
+ device->GetTransform(D3DTS_WORLD, &wtm);
+ device->GetTransform(D3DTS_VIEW, &vtm);
+
+ Ortho2D._11 = 1.0;
+ Ortho2D._12 = 0.0;
+ Ortho2D._13 = 0.0;
+ Ortho2D._14 = 0.0;
+
+ Ortho2D._21 = 0.0;
+ Ortho2D._22 = 1.0;
+ Ortho2D._23 = 0.0;
+ Ortho2D._24 = 0.0;
+
+ Ortho2D._31 = 0.0;
+ Ortho2D._32 = 0.0;
+ Ortho2D._33 = 0.5;
+ Ortho2D._34 = 0.0;
+
+ Ortho2D._41 = 0.0;
+ Ortho2D._42 = 0.0;
+ Ortho2D._43 = 0.5;
+ 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_PROJECTION, &Ortho2D);
+ device->SetTransform(D3DTS_WORLD, &identityMatrix);
+ device->SetTransform(D3DTS_VIEW, &identityMatrix);
+
+ 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; */
+
+ verts[0].sx = mapMinX;
+ verts[0].sy = mapMaxY;
+ verts[0].sz = 0.999f;
+
+ verts[1].sx = mapMinX;
+ verts[1].sy = mapMinY;
+ verts[1].sz = 0.999f;
+
+ verts[2].sx = mapMaxX;
+ verts[2].sy = mapMaxY;
+ verts[2].sz = 0.999f;
+
+ verts[3].sx = mapMaxX;
+ verts[3].sy = mapMinY;
+ verts[3].sz = 0.999f;
/*
printf("(texMinU,texMinV,texMaxU,texMaxV) = (%3.2f,%3.2f,%3.2f,%3.2f)\n",
@@ -421,22 +483,34 @@ void JNICALL Java_javax_media_j3d_NativePipeline_textureFillBackground(
mapMinX,mapMinY,mapMaxX,mapMaxY);
*/
+ device->SetVertexShader(NULL);
- /* TODO : Implement textureFillBackground() */
- /* drawTextureRect(d3dCtx, device, d3dImage->surf,
- screenCoord, 0, 0, width, height,
- scaleWidth, scaleHeight, texModeRepeat);
- */
+ device->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1 |
+ D3DFVF_DIFFUSE | D3DFVF_TEXCOORDSIZE2(0));
-#if 0
- /* Restore texture Matrix transform */
- glPopMatrix();
+ device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,
+ 2, verts, sizeof(D3DTLVERTEX));
- glMatrixMode(GL_MODELVIEW);
- /* Restore attributes */
- glPopAttrib();
-#endif
+ /* Restore renderstates */
+ device->SetRenderState(D3DRS_ALPHATESTENABLE, alphaTest);
+ device->SetRenderState(D3DRS_CULLMODE, cull);
+ device->SetRenderState(D3DRS_ZENABLE, zBuffer);
+ device->SetRenderState(D3DRS_FOGENABLE, fog);
+ device->SetRenderState(D3DRS_LIGHTING, lighting);
+ device->SetRenderState(D3DRS_STENCILENABLE, stencil);
+ device->SetRenderState(D3DRS_SPECULARENABLE, specular);
+
+ /* Restore texture Matrix transform */
+ if (d3dCtx->texTransformSet[tus]) {
+ device->SetTransform((D3DTRANSFORMSTATETYPE)
+ (D3DTS_TEXTURE0 + tus),
+ &texMatrix);
+ }
+
+ device->SetTransform(D3DTS_PROJECTION, &ptm);
+ device->SetTransform(D3DTS_WORLD, &wtm);
+ device->SetTransform(D3DTS_VIEW, &vtm);
}
diff --git a/src/native/d3d/D3dUtil.cpp b/src/native/d3d/D3dUtil.cpp
index 4c2ad9a..0b9cd7c 100644
--- a/src/native/d3d/D3dUtil.cpp
+++ b/src/native/d3d/D3dUtil.cpp
@@ -1034,6 +1034,7 @@ void copyDataFromSurface(jint imageFormat,
for (int j=xoffset; j < xlimit; j++) {
b1 = *src++;
b2 = *src++;
+ mask = ((b2 << 8) | b1);
*dst++ = (byte) (mask & 0xff);
*dst++ = (byte) ((mask >> 8) & 0xff);
}