Skip to content

Commit

Permalink
IIncluded Java+D3D-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ProggerFox committed Mar 11, 2019
1 parent 18e58fe commit 3556ec7
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,85 @@
package com.sun.javafx.sg.prism;

/**
* TODO: 3D - Need documentation
* The peer of the {@code PointLight} class. Holds the default values of {@code PointLight}'s
* properties and updates the visuals via {@link NGNode#visualsChanged} when one of the current
* values changes. The peer receives its changes by {@code PointLight.doUpdatePeer} calls.
*/
public class NGPointLight extends NGLightBase {

private static final double DEFAULT_C = 1;
private static final double DEFAULT_LC = 0;
private static final double DEFAULT_QC = 0;
private static final double DEFAULT_RANGE = Double.POSITIVE_INFINITY;
/** Constant attenuation factor default value */
private static final double DEFAULT_CA = 1;
/** Linear attenuation factor default value */
private static final double DEFAULT_LA = 0;
/** Quadratic attenuation factor default value */
private static final double DEFAULT_QA = 0;
/** Max range default value */
private static final double DEFAULT_MAX_RANGE = Double.POSITIVE_INFINITY;

public static double getDefaultC() {
return DEFAULT_C;
public NGPointLight() {
}

public static double getDefaultCa() {
return DEFAULT_CA;
}

public static double getDefaultLc() {
return DEFAULT_LC;
public static double getDefaultLa() {
return DEFAULT_LA;
}

public static double getDefaultQc() {
return DEFAULT_QC;
public static double getDefaultQa() {
return DEFAULT_QA;
}

public static double getDefaultRange() {
return DEFAULT_RANGE;
public static double getDefaultMaxRange() {
return DEFAULT_MAX_RANGE;
}

private double c = DEFAULT_C;

public double getC() {
return c;
private double ca = DEFAULT_CA;

public double getCa() {
return ca;
}

public void setC(double c) {
this.c = c;
public void setCa(double ca) {
this.ca = ca;
visualsChanged();
}


private double lc = DEFAULT_LC;
private double la = DEFAULT_LA;

public double getLc() {
return lc;
public double getLa() {
return la;
}

public void setLc(double lc) {
this.lc = lc;
public void setLa(double la) {
this.la = la;
visualsChanged();
}


private double qc = DEFAULT_QC;
private double qa = DEFAULT_QA;

public double getQc() {
return qc;
public double getQa() {
return qa;
}

public void setQc(double qc) {
this.qc = qc;
public void setQa(double qa) {
this.qa = qa;
visualsChanged();
}


private double range = DEFAULT_RANGE;
private double maxRange = DEFAULT_MAX_RANGE;

public double getRange() {
return range;
public double getMaxRange() {
return maxRange;
}

public void setRange(double range) {
this.range = range < 0 ? 0 : range;
public void setMaxRange(double maxRange) {
this.maxRange = maxRange < 0 ? 0 : maxRange;
visualsChanged();
}

public NGPointLight() {
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ private void renderMeshView(Graphics g) {
(float)cameraPos.y,
(float)cameraPos.z,
1.0f, 1.0f, 1.0f, 1.0f,
(float) NGPointLight.getDefaultC(),
(float) NGPointLight.getDefaultLc(),
(float) NGPointLight.getDefaultQc(),
(float) NGPointLight.getDefaultRange());
(float) NGPointLight.getDefaultCa(),
(float) NGPointLight.getDefaultLa(),
(float) NGPointLight.getDefaultQa(),
(float) NGPointLight.getDefaultMaxRange());
} else {
float ambientRed = 0.0f;
float ambientBlue = 0.0f;
Expand Down Expand Up @@ -160,10 +160,10 @@ private void renderMeshView(Graphics g) {
(float)lightWT.getMyt(),
(float)lightWT.getMzt(),
rL, gL, bL, 1.0f,
(float) light.getC(),
(float) light.getLc(),
(float) light.getQc(),
(float) light.getRange());
(float) light.getCa(),
(float) light.getLa(),
(float) light.getQa(),
(float) light.getMaxRange());
}
} else if (lightBase instanceof NGAmbientLight) {
// Accumulate ambient lights
Expand All @@ -183,8 +183,8 @@ private void renderMeshView(Graphics g) {
// Reset any previously set lights
meshView.setPointLight(pointLightIdx++,
0, 0, 0, // x y z
0, 0, 0, 0, // r g b
1, 0, 0, 0); // c lc qc range
0, 0, 0, 0, // r g b w
1, 0, 0, 0); // ca la qa maxRange
}

meshView.render(g);
Expand Down Expand Up @@ -228,4 +228,4 @@ public void release() {
// TODO: 3D - Need to release native resources
// material, mesh and meshview have native backing that need clean up.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface MeshView {
public void setPointLight(int index,
float x, float y, float z,
float r, float g, float b, float w,
float c, float cl, float cq, float range);
float ca, float la, float qa, float maxRange);

public void render(Graphics g);
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ protected State updateRenderTarget(RenderTarget target, NGCamera camera,

// Set projection view matrix
res = nSetProjViewMatrix(pContext, depthTest,
projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3),
projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7),
projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11),
projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15));
projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3),
projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7),
projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11),
projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15));
validate(res);

cameraPos = camera.getPositionInWorld(cameraPos);
Expand Down Expand Up @@ -293,17 +293,17 @@ protected void updateShaderTransform(Shader shader, BaseTransform xform) {
res = nResetTransform(pContext);
} else if (perspectiveTransform.isIdentity()) {
res = nSetTransform(pContext,
xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(),
xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(),
xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(),
0.0, 0.0, 0.0, 1.0);
xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(),
xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(),
xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(),
0.0, 0.0, 0.0, 1.0);
} else {
scratchTx.setIdentity().mul(xform).mul(perspectiveTransform);
res = nSetTransform(pContext,
scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3),
scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7),
scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11),
scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15));
scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3),
scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7),
scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11),
scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15));
}
validate(res);
}
Expand Down Expand Up @@ -374,73 +374,74 @@ D3DFrameStats getFrameStats(boolean reset, D3DFrameStats result) {
*/
private static native int nSetRenderTarget(long pContext, long pDest, boolean depthBuffer, boolean msaa);
private static native int nSetTexture(long pContext, long pTex, int texUnit,
boolean linear, int wrapMode);
boolean linear, int wrapMode);
private static native int nResetTransform(long pContext);
private static native int nSetTransform(long pContext,
double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33);
double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33);
private static native void nSetWorldTransformToIdentity(long pContext);
private static native void nSetWorldTransform(long pContext,
double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33);
double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33);
private static native int nSetCameraPosition(long pContext, double x, double y, double z);
private static native int nSetProjViewMatrix(long pContext, boolean isOrtho,
double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33);
double m00, double m01, double m02, double m03,
double m10, double m11, double m12, double m13,
double m20, double m21, double m22, double m23,
double m30, double m31, double m32, double m33);
private static native int nResetClipRect(long pContext);
private static native int nSetClipRect(long pContext,
int x1, int y1, int x2, int y2);
int x1, int y1, int x2, int y2);
private static native int nSetBlendEnabled(long pContext, int mode);
private static native int nSetDeviceParametersFor2D(long pContext);
private static native int nSetDeviceParametersFor3D(long pContext);

private static native long nCreateD3DMesh(long pContext);
private static native void nReleaseD3DMesh(long pContext, long nativeHandle);
private static native boolean nBuildNativeGeometryShort(long pContext, long nativeHandle,
float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength);
float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength);
private static native boolean nBuildNativeGeometryInt(long pContext, long nativeHandle,
float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength);
float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength);
private static native long nCreateD3DPhongMaterial(long pContext);
private static native void nReleaseD3DPhongMaterial(long pContext, long nativeHandle);
private static native void nSetDiffuseColor(long pContext, long nativePhongMaterial,
float r, float g, float b, float a);
float r, float g, float b, float a);
private static native void nSetSpecularColor(long pContext, long nativePhongMaterial,
boolean set, float r, float g, float b, float a);
boolean set, float r, float g, float b, float a);
private static native void nSetMap(long pContext, long nativePhongMaterial,
int mapType, long texID);
int mapType, long texID);
private static native long nCreateD3DMeshView(long pContext, long nativeMesh);
private static native void nReleaseD3DMeshView(long pContext, long nativeHandle);
private static native void nSetCullingMode(long pContext, long nativeMeshView,
int cullingMode);
int cullingMode);
private static native void nSetMaterial(long pContext, long nativeMeshView,
long nativePhongMaterialInfo);
long nativePhongMaterialInfo);
private static native void nSetWireframe(long pContext, long nativeMeshView,
boolean wireframe);
boolean wireframe);
private static native void nSetAmbientLight(long pContext, long nativeMeshView,
float r, float g, float b);
float r, float g, float b);
private static native void nSetPointLight(long pContext, long nativeMeshView,
int index, float x, float y, float z, float r, float g, float b, float w);
int index, float x, float y, float z, float r, float g, float b, float w,
float ca, float la, float qa, float maxRange);
private static native void nRenderMeshView(long pContext, long nativeMeshView);
private static native int nDrawIndexedQuads(long pContext,
float coords[], byte colors[], int numVertices);
float coords[], byte colors[], int numVertices);


/*
* @param nSrcRTT must be valid native resource
* @param nDstRTT can be NULL if a valide render target is set
*/
private static native void nBlit(long pContext, long nSrcRTT, long nDstRTT,
int srcX0, int srcY0, int srcX1, int srcY1,
int dstX0, int dstY0, int dstX1, int dstY1);
int srcX0, int srcY0, int srcX1, int srcY1,
int dstX0, int dstY0, int dstX1, int dstY1);

private static native boolean nGetFrameStats(long pContext,
D3DFrameStats returnValue, boolean bReset);
D3DFrameStats returnValue, boolean bReset);

private static native boolean nIsRTTVolatile(long contextHandle);

Expand Down Expand Up @@ -483,13 +484,13 @@ void releaseD3DMesh(long nativeHandle) {
}

boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength,
short[] indexBuffer, int indexBufferLength) {
short[] indexBuffer, int indexBufferLength) {
return nBuildNativeGeometryShort(pContext, nativeHandle, vertexBuffer,
vertexBufferLength, indexBuffer, indexBufferLength);
}

boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength,
int[] indexBuffer, int indexBufferLength) {
int[] indexBuffer, int indexBufferLength) {
return nBuildNativeGeometryInt(pContext, nativeHandle, vertexBuffer,
vertexBufferLength, indexBuffer, indexBufferLength);
}
Expand Down Expand Up @@ -543,15 +544,16 @@ void setMaterial(long nativeMeshView, long nativePhongMaterial) {
}

void setWireframe(long nativeMeshView, boolean wireframe) {
nSetWireframe(pContext, nativeMeshView, wireframe);
nSetWireframe(pContext, nativeMeshView, wireframe);
}

void setAmbientLight(long nativeMeshView, float r, float g, float b) {
nSetAmbientLight(pContext, nativeMeshView, r, g, b);
}

void setPointLight(long nativeMeshView, int index, float x, float y, float z, float r, float g, float b, float w) {
nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w);
void setPointLight(long nativeMeshView, int index, float x, float y, float z,
float r, float g, float b, float w, float ca, float la, float qa, float maxRange) {
nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w, ca, la, qa, maxRange);
}

@Override
Expand Down Expand Up @@ -603,7 +605,7 @@ public void blit(RTTexture srcRTT, RTTexture dstRTT,
long dstNativeHandle = dstRTT == null ? 0L : ((D3DTexture)dstRTT).getNativeSourceHandle();
long srcNativeHandle = ((D3DTexture)srcRTT).getNativeSourceHandle();
nBlit(pContext, srcNativeHandle, dstNativeHandle,
srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1);
srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ public void setAmbientLight(float r, float g, float b) {
}

@Override
public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) {
public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w,
float ca, float la, float qa, float maxRange) {
// NOTE: We only support up to 3 point lights at the present
if (index >= 0 && index <= 2) {
context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w);
context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ca, la, qa, maxRange);
}
}

Expand Down Expand Up @@ -128,5 +129,4 @@ public void dispose() {
}
}
}

}
Loading

0 comments on commit 3556ec7

Please sign in to comment.