minor formatting changes

experimental
Kirill Vainer 9 years ago
parent 961bf92734
commit f986043745
  1. 18
      jme3-core/src/main/java/com/jme3/material/DefaultTechniqueDefLogic.java
  2. 138
      jme3-core/src/main/java/com/jme3/material/SinglePassLightingLogic.java
  3. 100
      jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglContext.java

@ -49,14 +49,14 @@ import java.util.EnumSet;
public class DefaultTechniqueDefLogic implements TechniqueDefLogic { public class DefaultTechniqueDefLogic implements TechniqueDefLogic {
protected final TechniqueDef techniqueDef; protected final TechniqueDef techniqueDef;
public DefaultTechniqueDefLogic(TechniqueDef techniqueDef) { public DefaultTechniqueDefLogic(TechniqueDef techniqueDef) {
this.techniqueDef = techniqueDef; this.techniqueDef = techniqueDef;
} }
@Override @Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager, public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
EnumSet<Caps> rendererCaps, DefineList defines) { EnumSet<Caps> rendererCaps, DefineList defines) {
return techniqueDef.getShader(assetManager, rendererCaps, defines); return techniqueDef.getShader(assetManager, rendererCaps, defines);
} }
@ -65,14 +65,14 @@ public class DefaultTechniqueDefLogic implements TechniqueDefLogic {
int lodLevel = geom.getLodLevel(); int lodLevel = geom.getLodLevel();
if (geom instanceof InstancedGeometry) { if (geom instanceof InstancedGeometry) {
InstancedGeometry instGeom = (InstancedGeometry) geom; InstancedGeometry instGeom = (InstancedGeometry) geom;
renderer.renderMesh(mesh, lodLevel, instGeom.getActualNumInstances(), renderer.renderMesh(mesh, lodLevel, instGeom.getActualNumInstances(),
instGeom.getAllInstanceData()); instGeom.getAllInstanceData());
} else { } else {
renderer.renderMesh(mesh, lodLevel, 1, null); renderer.renderMesh(mesh, lodLevel, 1, null);
} }
} }
public static ColorRGBA getAmbientColor(LightList lightList, boolean removeLights, ColorRGBA ambientLightColor) { protected static ColorRGBA getAmbientColor(LightList lightList, boolean removeLights, ColorRGBA ambientLightColor) {
ambientLightColor.set(0, 0, 0, 1); ambientLightColor.set(0, 0, 0, 1);
for (int j = 0; j < lightList.size(); j++) { for (int j = 0; j < lightList.size(); j++) {
Light l = lightList.get(j); Light l = lightList.get(j);
@ -86,7 +86,7 @@ public class DefaultTechniqueDefLogic implements TechniqueDefLogic {
ambientLightColor.a = 1.0f; ambientLightColor.a = 1.0f;
return ambientLightColor; return ambientLightColor;
} }
@Override @Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights) { public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights) {
Renderer renderer = renderManager.getRenderer(); Renderer renderer = renderManager.getRenderer();

@ -57,14 +57,14 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
private static final String DEFINE_SINGLE_PASS_LIGHTING = "SINGLE_PASS_LIGHTING"; private static final String DEFINE_SINGLE_PASS_LIGHTING = "SINGLE_PASS_LIGHTING";
private static final String DEFINE_NB_LIGHTS = "NB_LIGHTS"; private static final String DEFINE_NB_LIGHTS = "NB_LIGHTS";
private static final RenderState ADDITIVE_LIGHT = new RenderState(); private static final RenderState ADDITIVE_LIGHT = new RenderState();
private final ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1); private final ColorRGBA ambientLightColor = new ColorRGBA(0, 0, 0, 1);
static { static {
ADDITIVE_LIGHT.setBlendMode(BlendMode.AlphaAdditive); ADDITIVE_LIGHT.setBlendMode(BlendMode.AlphaAdditive);
ADDITIVE_LIGHT.setDepthWrite(false); ADDITIVE_LIGHT.setDepthWrite(false);
} }
private final int singlePassLightingDefineId; private final int singlePassLightingDefineId;
private final int nbLightsDefineId; private final int nbLightsDefineId;
@ -73,7 +73,7 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
singlePassLightingDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_SINGLE_PASS_LIGHTING, VarType.Boolean); singlePassLightingDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_SINGLE_PASS_LIGHTING, VarType.Boolean);
nbLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NB_LIGHTS, VarType.Int); nbLightsDefineId = techniqueDef.addShaderUnmappedDefine(DEFINE_NB_LIGHTS, VarType.Int);
} }
@Override @Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager, public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
EnumSet<Caps> rendererCaps, DefineList defines) { EnumSet<Caps> rendererCaps, DefineList defines) {
@ -81,7 +81,7 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
defines.set(singlePassLightingDefineId, true); defines.set(singlePassLightingDefineId, true);
return super.makeCurrent(assetManager, renderManager, rendererCaps, defines); return super.makeCurrent(assetManager, renderManager, rendererCaps, defines);
} }
/** /**
* Uploads the lights in the light list as two uniform arrays.<br/><br/> * * Uploads the lights in the light list as two uniform arrays.<br/><br/> *
* <p> * <p>
@ -120,73 +120,72 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
int endIndex = numLights + startIndex; int endIndex = numLights + startIndex;
for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) { for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
Light l = lightList.get(curIndex);
if (l.getType() == Light.Type.Ambient) {
endIndex++;
continue;
}
ColorRGBA color = l.getColor();
//Color
lightData.setVector4InArray(color.getRed(),
color.getGreen(),
color.getBlue(),
l.getType().getId(),
lightDataIndex);
lightDataIndex++;
Light l = lightList.get(curIndex); switch (l.getType()) {
if(l.getType() == Light.Type.Ambient){ case Directional:
endIndex++; DirectionalLight dl = (DirectionalLight) l;
continue; Vector3f dir = dl.getDirection();
} //Data directly sent in view space to avoid a matrix mult for each pixel
ColorRGBA color = l.getColor(); tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
//Color rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
lightData.setVector4InArray(color.getRed(),
color.getGreen(),
color.getBlue(),
l.getType().getId(),
lightDataIndex);
lightDataIndex++;
switch (l.getType()) {
case Directional:
DirectionalLight dl = (DirectionalLight) l;
Vector3f dir = dl.getDirection();
//Data directly sent in view space to avoid a matrix mult for each pixel
tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
// tmpVec.divideLocal(tmpVec.w); // tmpVec.divideLocal(tmpVec.w);
// tmpVec.normalizeLocal(); // tmpVec.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
lightDataIndex++; lightDataIndex++;
//PADDING //PADDING
lightData.setVector4InArray(0,0,0,0, lightDataIndex); lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
lightDataIndex++; lightDataIndex++;
break; break;
case Point: case Point:
PointLight pl = (PointLight) l; PointLight pl = (PointLight) l;
Vector3f pos = pl.getPosition(); Vector3f pos = pl.getPosition();
float invRadius = pl.getInvRadius(); float invRadius = pl.getInvRadius();
tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f); tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
//tmpVec.divideLocal(tmpVec.w); //tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
lightDataIndex++; lightDataIndex++;
//PADDING //PADDING
lightData.setVector4InArray(0,0,0,0, lightDataIndex); lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
lightDataIndex++; lightDataIndex++;
break; break;
case Spot: case Spot:
SpotLight sl = (SpotLight) l; SpotLight sl = (SpotLight) l;
Vector3f pos2 = sl.getPosition(); Vector3f pos2 = sl.getPosition();
Vector3f dir2 = sl.getDirection(); Vector3f dir2 = sl.getDirection();
float invRange = sl.getInvSpotRange(); float invRange = sl.getInvSpotRange();
float spotAngleCos = sl.getPackedAngleCos(); float spotAngleCos = sl.getPackedAngleCos();
tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f); tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
// tmpVec.divideLocal(tmpVec.w); // tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
lightDataIndex++; lightDataIndex++;
//We transform the spot direction in view space here to save 5 varying later in the lighting shader //We transform the spot direction in view space here to save 5 varying later in the lighting shader
//one vec4 less and a vec4 that becomes a vec3 //one vec4 less and a vec4 that becomes a vec3
//the downside is that spotAngleCos decoding happens now in the frag shader. //the downside is that spotAngleCos decoding happens now in the frag shader.
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f); tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
tmpVec.normalizeLocal(); tmpVec.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex); lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
lightDataIndex++; lightDataIndex++;
break; break;
default: default:
throw new UnsupportedOperationException("Unknown type of light: " + l.getType()); throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
} }
} }
vars.release(); vars.release();
//Padding of unsued buffer space //Padding of unsued buffer space
@ -197,7 +196,6 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
return curIndex; return curIndex;
} }
@Override @Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights) { public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights) {
int nbRenderedLights = 0; int nbRenderedLights = 0;

@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jme3.system.lwjgl; package com.jme3.system.lwjgl;
import com.jme3.input.lwjgl.JInputJoyInput; import com.jme3.input.lwjgl.JInputJoyInput;
@ -69,7 +68,7 @@ public abstract class LwjglContext implements JmeContext {
private static final Logger logger = Logger.getLogger(LwjglContext.class.getName()); private static final Logger logger = Logger.getLogger(LwjglContext.class.getName());
protected static final String THREAD_NAME = "jME3 Main"; protected static final String THREAD_NAME = "jME3 Main";
protected AtomicBoolean created = new AtomicBoolean(false); protected AtomicBoolean created = new AtomicBoolean(false);
protected AtomicBoolean renderable = new AtomicBoolean(false); protected AtomicBoolean renderable = new AtomicBoolean(false);
protected final Object createdLock = new Object(); protected final Object createdLock = new Object();
@ -82,18 +81,18 @@ public abstract class LwjglContext implements JmeContext {
protected Timer timer; protected Timer timer;
protected SystemListener listener; protected SystemListener listener;
public void setSystemListener(SystemListener listener){ public void setSystemListener(SystemListener listener) {
this.listener = listener; this.listener = listener;
} }
protected void printContextInitInfo() { protected void printContextInitInfo() {
logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n" + logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n"
" * Graphics Adapter: {2}\n" + + " * Graphics Adapter: {2}\n"
" * Driver Version: {3}\n" + + " * Driver Version: {3}\n"
" * Scaling Factor: {4}", + " * Scaling Factor: {4}",
new Object[]{ Sys.getVersion(), Thread.currentThread().getName(), new Object[]{Sys.getVersion(), Thread.currentThread().getName(),
Display.getAdapter(), Display.getVersion(), Display.getAdapter(), Display.getVersion(),
Display.getPixelScaleFactor() }); Display.getPixelScaleFactor()});
} }
protected ContextAttribs createContextAttribs() { protected ContextAttribs createContextAttribs() {
@ -113,7 +112,7 @@ public abstract class LwjglContext implements JmeContext {
return null; return null;
} }
} }
protected int determineMaxSamples(int requestedSamples) { protected int determineMaxSamples(int requestedSamples) {
try { try {
// If we already have a valid context, determine samples using current // If we already have a valid context, determine samples using current
@ -131,13 +130,13 @@ public abstract class LwjglContext implements JmeContext {
} catch (LWJGLException ex) { } catch (LWJGLException ex) {
listener.handleError("Failed to check if display is current", ex); listener.handleError("Failed to check if display is current", ex);
} }
if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) { if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
// No pbuffer, assume everything is supported. // No pbuffer, assume everything is supported.
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} else { } else {
Pbuffer pb = null; Pbuffer pb = null;
// OpenGL2 method: Create pbuffer and query samples // OpenGL2 method: Create pbuffer and query samples
// from GL_ARB_framebuffer_object or GL_EXT_framebuffer_multisample. // from GL_ARB_framebuffer_object or GL_EXT_framebuffer_multisample.
try { try {
@ -155,13 +154,14 @@ public abstract class LwjglContext implements JmeContext {
} catch (LWJGLException ex) { } catch (LWJGLException ex) {
// Something else failed. // Something else failed.
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} finally { } finally {
if (pb != null) { if (pb != null) {
pb.destroy(); pb.destroy();
} }
} }
} }
} }
protected void loadNatives() { protected void loadNatives() {
if (JmeSystem.isLowPermissions()) { if (JmeSystem.isLowPermissions()) {
return; return;
@ -178,10 +178,10 @@ public abstract class LwjglContext implements JmeContext {
} }
NativeLibraryLoader.loadNativeLibrary("lwjgl", true); NativeLibraryLoader.loadNativeLibrary("lwjgl", true);
} }
protected int getNumSamplesToUse() { protected int getNumSamplesToUse() {
int samples = 0; int samples = 0;
if (settings.getSamples() > 1){ if (settings.getSamples() > 1) {
samples = settings.getSamples(); samples = settings.getSamples();
int supportedSamples = determineMaxSamples(samples); int supportedSamples = determineMaxSamples(samples);
if (supportedSamples < samples) { if (supportedSamples < samples) {
@ -189,60 +189,60 @@ public abstract class LwjglContext implements JmeContext {
"Couldn''t satisfy antialiasing samples requirement: x{0}. " "Couldn''t satisfy antialiasing samples requirement: x{0}. "
+ "Video hardware only supports: x{1}", + "Video hardware only supports: x{1}",
new Object[]{samples, supportedSamples}); new Object[]{samples, supportedSamples});
samples = supportedSamples; samples = supportedSamples;
} }
} }
return samples; return samples;
} }
protected void initContextFirstTime(){ protected void initContextFirstTime() {
if (!GLContext.getCapabilities().OpenGL20) { if (!GLContext.getCapabilities().OpenGL20) {
throw new RendererException("OpenGL 2.0 or higher is " + throw new RendererException("OpenGL 2.0 or higher is "
"required for jMonkeyEngine"); + "required for jMonkeyEngine");
} }
if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2) if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2)
|| settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) { || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) {
GL gl = new LwjglGL(); GL gl = new LwjglGL();
GLExt glext = new LwjglGLExt(); GLExt glext = new LwjglGLExt();
GLFbo glfbo; GLFbo glfbo;
if (GLContext.getCapabilities().OpenGL30) { if (GLContext.getCapabilities().OpenGL30) {
glfbo = new LwjglGLFboGL3(); glfbo = new LwjglGLFboGL3();
} else { } else {
glfbo = new LwjglGLFboEXT(); glfbo = new LwjglGLFboEXT();
} }
if (settings.getBoolean("GraphicsDebug")) { if (settings.getBoolean("GraphicsDebug")) {
gl = new GLDebugDesktop(gl, glext, glfbo); gl = new GLDebugDesktop(gl, glext, glfbo);
glext = (GLExt) gl; glext = (GLExt) gl;
glfbo = (GLFbo) gl; glfbo = (GLFbo) gl;
} }
if (settings.getBoolean("GraphicsTiming")) { if (settings.getBoolean("GraphicsTiming")) {
GLTimingState timingState = new GLTimingState(); GLTimingState timingState = new GLTimingState();
gl = (GL) GLTiming.createGLTiming(gl, timingState, GL.class, GL2.class, GL3.class, GL4.class); gl = (GL) GLTiming.createGLTiming(gl, timingState, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLTiming.createGLTiming(glext, timingState, GLExt.class); glext = (GLExt) GLTiming.createGLTiming(glext, timingState, GLExt.class);
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class); glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class);
} }
if (settings.getBoolean("GraphicsTrace")) { if (settings.getBoolean("GraphicsTrace")) {
gl = (GL) GLTracer.createDesktopGlTracer(gl, GL.class, GL2.class, GL3.class, GL4.class); gl = (GL) GLTracer.createDesktopGlTracer(gl, GL.class, GL2.class, GL3.class, GL4.class);
glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class); glext = (GLExt) GLTracer.createDesktopGlTracer(glext, GLExt.class);
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class); glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
} }
renderer = new GLRenderer(gl, glext, glfbo); renderer = new GLRenderer(gl, glext, glfbo);
renderer.initialize(); renderer.initialize();
} else { } else {
throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer()); throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
} }
if (GLContext.getCapabilities().GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) { if (GLContext.getCapabilities().GL_ARB_debug_output && settings.getBoolean("GraphicsDebug")) {
ARBDebugOutput.glDebugMessageCallbackARB(new ARBDebugOutputCallback(new LwjglGLDebugOutputHandler())); ARBDebugOutput.glDebugMessageCallbackARB(new ARBDebugOutputCallback(new LwjglGLDebugOutputHandler()));
} }
renderer.setMainFrameBufferSrgb(settings.getGammaCorrection()); renderer.setMainFrameBufferSrgb(settings.getGammaCorrection());
renderer.setLinearizeSrgbImages(settings.getGammaCorrection()); renderer.setLinearizeSrgbImages(settings.getGammaCorrection());
@ -260,42 +260,42 @@ public abstract class LwjglContext implements JmeContext {
} }
} }
public void internalDestroy(){ public void internalDestroy() {
renderer = null; renderer = null;
timer = null; timer = null;
renderable.set(false); renderable.set(false);
synchronized (createdLock){ synchronized (createdLock) {
created.set(false); created.set(false);
createdLock.notifyAll(); createdLock.notifyAll();
} }
} }
public void internalCreate(){ public void internalCreate() {
timer = new LwjglTimer(); timer = new LwjglTimer();
synchronized (createdLock){ synchronized (createdLock) {
created.set(true); created.set(true);
createdLock.notifyAll(); createdLock.notifyAll();
} }
if (renderable.get()){ if (renderable.get()) {
initContextFirstTime(); initContextFirstTime();
}else{ } else {
assert getType() == Type.Canvas; assert getType() == Type.Canvas;
} }
} }
public void create(){ public void create() {
create(false); create(false);
} }
public void destroy(){ public void destroy() {
destroy(false); destroy(false);
} }
protected void waitFor(boolean createdVal){ protected void waitFor(boolean createdVal) {
synchronized (createdLock){ synchronized (createdLock) {
while (created.get() != createdVal){ while (created.get() != createdVal) {
try { try {
createdLock.wait(); createdLock.wait();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
@ -304,11 +304,11 @@ public abstract class LwjglContext implements JmeContext {
} }
} }
public boolean isCreated(){ public boolean isCreated() {
return created.get(); return created.get();
} }
public boolean isRenderable(){ public boolean isRenderable() {
return renderable.get(); return renderable.get();
} }
@ -316,7 +316,7 @@ public abstract class LwjglContext implements JmeContext {
this.settings.copyFrom(settings); this.settings.copyFrom(settings);
} }
public AppSettings getSettings(){ public AppSettings getSettings() {
return settings; return settings;
} }

Loading…
Cancel
Save