--- old/modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java 2015-05-06 16:28:07.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java 2015-05-06 16:28:07.000000000 -0700 @@ -112,7 +112,7 @@ // is a single point white point light at camera eye position. meshView.setAmbientLight(0.0f, 0.0f, 0.0f); Vec3d cameraPos = g.getCameraNoClone().getPositionInWorld(null); - meshView.setPointLight(pointLightIdx++, + meshView.setPointLight(pointLightIdx++, g.getPixelScaleFactor(), (float)cameraPos.x, (float)cameraPos.y, (float)cameraPos.z, @@ -151,7 +151,7 @@ NGPointLight light = (NGPointLight)lightBase; if (rL != 0.0f || gL != 0.0f || bL != 0.0f) { Affine3D lightWT = light.getWorldTransform(); - meshView.setPointLight(pointLightIdx++, + meshView.setPointLight(pointLightIdx++, g.getPixelScaleFactor(), (float)lightWT.getMxt(), (float)lightWT.getMyt(), (float)lightWT.getMzt(), @@ -173,7 +173,7 @@ // TODO: 3D Required for D3D implementation of lights, which is limited to 3 while (pointLightIdx < 3) { // Reset any previously set lights - meshView.setPointLight(pointLightIdx++, 0, 0, 0, 0, 0, 0, 0); + meshView.setPointLight(pointLightIdx++, 0, 0, 0, 0, 0, 0, 0, 0); } meshView.render(g); --- old/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/ViewPainter.java 2015-05-06 16:28:08.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/ViewPainter.java 2015-05-06 16:28:07.000000000 -0700 @@ -175,6 +175,9 @@ Graphics g = backBufferGraphics; // Take into account the pixel scale factor for retina displays final float pixelScale = getPixelScaleFactor(); + // Cache pixelScale in Graphics for use in 3D shaders such as camera and light positions. + g.setPixelScaleFactor(pixelScale); + // Initialize renderEverything based on various conditions that will cause us to render // the entire scene every time. boolean renderEverything = overlayRoot != null || --- old/modules/graphics/src/main/java/com/sun/prism/Graphics.java 2015-05-06 16:28:08.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/Graphics.java 2015-05-06 16:28:08.000000000 -0700 @@ -210,4 +210,6 @@ // TODO this is dangerous, must be called *after* setState3D is called, or it won't work public void setup3DRendering(); + public void setPixelScaleFactor(float pixelScale); + public float getPixelScaleFactor(); } --- old/modules/graphics/src/main/java/com/sun/prism/MeshView.java 2015-05-06 16:28:09.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/MeshView.java 2015-05-06 16:28:09.000000000 -0700 @@ -46,7 +46,7 @@ public void setAmbientLight(float r, float g, float b); - public void setPointLight(int index, + public void setPointLight(int index, float pixelScaleFactor, float x, float y, float z, float r, float g, float b, float w); --- old/modules/graphics/src/main/java/com/sun/prism/d3d/D3DContext.java 2015-05-06 16:28:10.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/d3d/D3DContext.java 2015-05-06 16:28:10.000000000 -0700 @@ -33,6 +33,7 @@ import com.sun.javafx.sg.prism.NGCamera; import com.sun.javafx.sg.prism.NGDefaultCamera; import com.sun.prism.CompositeMode; +import com.sun.prism.Graphics; import com.sun.prism.MeshView; import com.sun.prism.RTTexture; import com.sun.prism.RenderTarget; @@ -85,7 +86,7 @@ private final long pContext; - NGCamera camera = null; + private Vec3d cameraPos = new Vec3d(); private int targetWidth = 0, targetHeight = 0; private final D3DResourceFactory factory; @@ -215,7 +216,6 @@ resetLastClip(state); } - this.camera = camera; targetWidth = target.getPhysicalWidth(); targetHeight = target.getPhysicalHeight(); @@ -242,9 +242,9 @@ tempTx.get(12), tempTx.get(13), tempTx.get(14), tempTx.get(15)); validate(res); - tempVec3d = camera.getPositionInWorld(tempVec3d); -// System.err.println("Camera position in world = " + tempVec3d); - res = nSetCameraPosition(pContext, tempVec3d.x, tempVec3d.y, tempVec3d.z); + // update camera position; this will be uploaded to the shader + // when we switch to 3D state + cameraPos = camera.getPositionInWorld(cameraPos); return state; } @@ -544,8 +544,14 @@ nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w); } - void renderMeshView(long nativeMeshView, BaseTransform transformNoClone) { - updateWorldTransform(transformNoClone); + void renderMeshView(long nativeMeshView, Graphics g) { + updateWorldTransform(g.getTransformNoClone()); + float pixelScaleFactor = g.getPixelScaleFactor(); + int res = nSetCameraPosition(pContext, + cameraPos.x * pixelScaleFactor, + cameraPos.y * pixelScaleFactor, + cameraPos.z * pixelScaleFactor); + validate(res); nRenderMeshView(pContext, nativeMeshView); } --- old/modules/graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java 2015-05-06 16:28:11.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java 2015-05-06 16:28:10.000000000 -0700 @@ -81,9 +81,13 @@ } @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { + public void setPointLight(int index, float pixelScaleFactor, + float x, float y, float z, float r, float g, float b, float w) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { + x *= pixelScaleFactor; + y *= pixelScaleFactor; + z *= pixelScaleFactor; context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); } } @@ -91,7 +95,7 @@ @Override public void render(Graphics g) { material.lockTextureMaps(); - context.renderMeshView(nativeHandle, g.getTransformNoClone()); + context.renderMeshView(nativeHandle, g); material.unlockTextureMaps(); } --- old/modules/graphics/src/main/java/com/sun/prism/es2/ES2Context.java 2015-05-06 16:28:11.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/es2/ES2Context.java 2015-05-06 16:28:11.000000000 -0700 @@ -25,9 +25,7 @@ package com.sun.prism.es2; -import java.util.HashMap; import com.sun.glass.ui.Screen; -import com.sun.javafx.PlatformUtil; import com.sun.javafx.geom.Rectangle; import com.sun.javafx.geom.Vec3d; import com.sun.javafx.geom.transform.Affine2D; @@ -36,8 +34,8 @@ import com.sun.javafx.sg.prism.NGCamera; import com.sun.javafx.sg.prism.NGDefaultCamera; import com.sun.prism.CompositeMode; +import com.sun.prism.Graphics; import com.sun.prism.Material; -import com.sun.prism.PixelFormat; import com.sun.prism.RTTexture; import com.sun.prism.RenderTarget; import com.sun.prism.Texture; @@ -446,15 +444,19 @@ dstX0, dstY0, dstX1, dstY1); } - void renderMeshView(long nativeHandle, BaseTransform xform, ES2MeshView meshView) { + void renderMeshView(long nativeHandle, Graphics g, ES2MeshView meshView) { ES2Shader shader = (ES2Shader) getPhongShader(meshView); setShaderProgram(shader.getProgramObject()); + BaseTransform xform = g.getTransformNoClone(); + float pixelScaleFactor = g.getPixelScaleFactor(); updateRawMatrix(projViewTx); shader.setMatrix("viewProjectionMatrix", rawMatrix); - shader.setConstant("camPos", (float) cameraPos.x, - (float) cameraPos.y, (float)cameraPos.z); + shader.setConstant("camPos", + (float) cameraPos.x * pixelScaleFactor, + (float) cameraPos.y * pixelScaleFactor, + (float) cameraPos.z * pixelScaleFactor); updateWorldTransform(xform); updateRawMatrix(worldTx); --- old/modules/graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java 2015-05-06 16:28:12.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java 2015-05-06 16:28:12.000000000 -0700 @@ -101,9 +101,13 @@ } @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { + public void setPointLight(int index, float pixelScaleFactor, + float x, float y, float z, float r, float g, float b, float w) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { + x *= pixelScaleFactor; + y *= pixelScaleFactor; + z *= pixelScaleFactor; lights[index] = new ES2Light(x, y, z, r, g, b, w); context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); } @@ -116,7 +120,7 @@ @Override public void render(Graphics g) { material.lockTextureMaps(); - context.renderMeshView(nativeHandle, g.getTransformNoClone(), this); + context.renderMeshView(nativeHandle, g, this); material.unlockTextureMaps(); } --- old/modules/graphics/src/main/java/com/sun/prism/impl/ps/BaseShaderGraphics.java 2015-05-06 16:28:13.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/impl/ps/BaseShaderGraphics.java 2015-05-06 16:28:13.000000000 -0700 @@ -79,6 +79,7 @@ private final BaseShaderContext context; private Shader externalShader; private boolean isComplexPaint; + private float pixelScale = 1.0f; protected BaseShaderGraphics(BaseShaderContext context, RenderTarget renderTarget) @@ -2155,4 +2156,15 @@ public void setup3DRendering() { context.setRenderTarget(this); } + + @Override + public void setPixelScaleFactor(float pixelScale) { + this.pixelScale = pixelScale; + } + + @Override + public float getPixelScaleFactor() { + return pixelScale; + } + } --- old/modules/graphics/src/main/java/com/sun/prism/j2d/J2DPrismGraphics.java 2015-05-06 16:28:14.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/j2d/J2DPrismGraphics.java 2015-05-06 16:28:14.000000000 -0700 @@ -116,6 +116,7 @@ new java.awt.geom.AffineTransform(); private int clipRectIndex; private boolean hasPreCullingBits = false; + private float pixelScale = 1.0f; static java.awt.Color toJ2DColor(Color c) { return new java.awt.Color(c.getRed(), @@ -1382,6 +1383,16 @@ } @Override + public void setPixelScaleFactor(float pixelScale) { + this.pixelScale = pixelScale; + } + + @Override + public float getPixelScaleFactor() { + return pixelScale; + } + + @Override public void blit(RTTexture srcTex, RTTexture dstTex, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1) { --- old/modules/graphics/src/main/java/com/sun/prism/null3d/DummyGraphics.java 2015-05-06 16:28:14.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/null3d/DummyGraphics.java 2015-05-06 16:28:14.000000000 -0700 @@ -61,4 +61,16 @@ @Override public void setup3DRendering() { } + + private float pixelScale = 1.0f; + @Override + public void setPixelScaleFactor(float pixelScale) { + this.pixelScale = pixelScale; + } + + @Override + public float getPixelScaleFactor() { + return pixelScale; + } + } --- old/modules/graphics/src/main/java/com/sun/prism/sw/SWGraphics.java 2015-05-06 16:28:15.000000000 -0700 +++ new/modules/graphics/src/main/java/com/sun/prism/sw/SWGraphics.java 2015-05-06 16:28:15.000000000 -0700 @@ -91,6 +91,7 @@ private boolean antialiasedShape = true; private boolean hasPreCullingBits = false; + private float pixelScale = 1.0f; private NodePath renderRoot; @Override @@ -924,6 +925,16 @@ } @Override + public void setPixelScaleFactor(float pixelScale) { + this.pixelScale = pixelScale; + } + + @Override + public float getPixelScaleFactor() { + return pixelScale; + } + + @Override public void setLights(NGLightBase[] lights) { // Light are not supported by SW pipeline } --- old/modules/graphics/src/test/java/com/sun/javafx/sg/prism/TestGraphics.java 2015-05-06 16:28:16.000000000 -0700 +++ new/modules/graphics/src/test/java/com/sun/javafx/sg/prism/TestGraphics.java 2015-05-06 16:28:16.000000000 -0700 @@ -141,6 +141,17 @@ public void setup3DRendering() { } + private float pixelScale = 1.0f; + @Override + public void setPixelScaleFactor(float pixelScale) { + this.pixelScale = pixelScale; + } + + @Override + public float getPixelScaleFactor() { + return pixelScale; + } + public void blit(RTTexture srcTex, RTTexture dstTex, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1) { }