modules/graphics/src/main/java/com/sun/prism/d3d/D3DContext.java

Print this page




 535     }
 536 
 537     void setAmbientLight(long nativeMeshView, float r, float g, float b) {
 538         nSetAmbientLight(pContext, nativeMeshView, r, g, b);
 539     }
 540 
 541     void setPointLight(long nativeMeshView, int index, float x, float y, float z, float r, float g, float b, float w) {
 542         nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w);
 543     }
 544 
 545     @Override
 546     protected void renderQuads(float coordArray[], byte colorArray[], int numVertices) {
 547         int res = nDrawIndexedQuads(pContext, coordArray, colorArray, numVertices);
 548         D3DContext.validate(res);
 549     }
 550 
 551     void renderMeshView(long nativeMeshView, Graphics g) {
 552 
 553         // Support retina display by scaling the projViewTx and pass it to the shader.
 554         scratchTx = scratchTx.set(projViewTx);
 555         float pixelScaleFactor = g.getPixelScaleFactor();
 556         if (pixelScaleFactor != 1.0) {
 557             scratchTx.scale(pixelScaleFactor, pixelScaleFactor, 1.0);

 558         }
 559 
 560         // Set projection view matrix
 561         int res = nSetProjViewMatrix(pContext, g.isDepthTest(),
 562                 scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3),
 563                 scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7),
 564                 scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11),
 565                 scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15));
 566         validate(res);
 567 
 568         res = nSetCameraPosition(pContext, cameraPos.x, cameraPos.y, cameraPos.z);
 569         validate(res);
 570 
 571         // Undo the SwapChain scaling done in createGraphics() because 3D needs
 572         // this information in the shader (via projViewTx)
 573         BaseTransform xform = g.getTransformNoClone();
 574         if (pixelScaleFactor != 1.0) {
 575             float invPSF = 1 / pixelScaleFactor;
 576             scratchAffine3DTx.setToIdentity();
 577             scratchAffine3DTx.scale(invPSF, invPSF);
 578             scratchAffine3DTx.concatenate(xform);
 579             updateWorldTransform(scratchAffine3DTx);
 580         } else {
 581             updateWorldTransform(xform);
 582         }
 583 
 584         nRenderMeshView(pContext, nativeMeshView);
 585     }
 586 
 587     @Override
 588     public void blit(RTTexture srcRTT, RTTexture dstRTT,
 589                      int srcX0, int srcY0, int srcX1, int srcY1,
 590                      int dstX0, int dstY0, int dstX1, int dstY1) {
 591         long dstNativeHandle = dstRTT == null ? 0L : ((D3DTexture)dstRTT).getNativeSourceHandle();
 592         long srcNativeHandle = ((D3DTexture)srcRTT).getNativeSourceHandle();
 593         nBlit(pContext, srcNativeHandle, dstNativeHandle,
 594                           srcX0, srcY0, srcX1, srcY1,
 595                           dstX0, dstY0, dstX1, dstY1);
 596     }
 597 }


 535     }
 536 
 537     void setAmbientLight(long nativeMeshView, float r, float g, float b) {
 538         nSetAmbientLight(pContext, nativeMeshView, r, g, b);
 539     }
 540 
 541     void setPointLight(long nativeMeshView, int index, float x, float y, float z, float r, float g, float b, float w) {
 542         nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w);
 543     }
 544 
 545     @Override
 546     protected void renderQuads(float coordArray[], byte colorArray[], int numVertices) {
 547         int res = nDrawIndexedQuads(pContext, coordArray, colorArray, numVertices);
 548         D3DContext.validate(res);
 549     }
 550 
 551     void renderMeshView(long nativeMeshView, Graphics g) {
 552 
 553         // Support retina display by scaling the projViewTx and pass it to the shader.
 554         scratchTx = scratchTx.set(projViewTx);
 555         float pixelScaleFactorX = g.getPixelScaleFactorX();
 556         float pixelScaleFactorY = g.getPixelScaleFactorY();
 557         if (pixelScaleFactorX != 1.0 || pixelScaleFactorY != 1.0) {
 558             scratchTx.scale(pixelScaleFactorX, pixelScaleFactorY, 1.0);
 559         }
 560 
 561         // Set projection view matrix
 562         int res = nSetProjViewMatrix(pContext, g.isDepthTest(),
 563                 scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3),
 564                 scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7),
 565                 scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11),
 566                 scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15));
 567         validate(res);
 568 
 569         res = nSetCameraPosition(pContext, cameraPos.x, cameraPos.y, cameraPos.z);
 570         validate(res);
 571 
 572         // Undo the SwapChain scaling done in createGraphics() because 3D needs
 573         // this information in the shader (via projViewTx)
 574         BaseTransform xform = g.getTransformNoClone();
 575         if (pixelScaleFactorX != 1.0 || pixelScaleFactorY != 1.0) {

 576             scratchAffine3DTx.setToIdentity();
 577             scratchAffine3DTx.scale(1.0 / pixelScaleFactorX, 1.0 / pixelScaleFactorY);
 578             scratchAffine3DTx.concatenate(xform);
 579             updateWorldTransform(scratchAffine3DTx);
 580         } else {
 581             updateWorldTransform(xform);
 582         }
 583 
 584         nRenderMeshView(pContext, nativeMeshView);
 585     }
 586 
 587     @Override
 588     public void blit(RTTexture srcRTT, RTTexture dstRTT,
 589                      int srcX0, int srcY0, int srcX1, int srcY1,
 590                      int dstX0, int dstY0, int dstX1, int dstY1) {
 591         long dstNativeHandle = dstRTT == null ? 0L : ((D3DTexture)dstRTT).getNativeSourceHandle();
 592         long srcNativeHandle = ((D3DTexture)srcRTT).getNativeSourceHandle();
 593         nBlit(pContext, srcNativeHandle, dstNativeHandle,
 594                           srcX0, srcY0, srcX1, srcY1,
 595                           dstX0, dstY0, dstX1, dstY1);
 596     }
 597 }