minor formatting changes

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

@ -56,7 +56,7 @@ public class DefaultTechniqueDefLogic implements TechniqueDefLogic {
@Override
public Shader makeCurrent(AssetManager assetManager, RenderManager renderManager,
EnumSet<Caps> rendererCaps, DefineList defines) {
EnumSet<Caps> rendererCaps, DefineList defines) {
return techniqueDef.getShader(assetManager, rendererCaps, defines);
}
@ -66,13 +66,13 @@ public class DefaultTechniqueDefLogic implements TechniqueDefLogic {
if (geom instanceof InstancedGeometry) {
InstancedGeometry instGeom = (InstancedGeometry) geom;
renderer.renderMesh(mesh, lodLevel, instGeom.getActualNumInstances(),
instGeom.getAllInstanceData());
instGeom.getAllInstanceData());
} else {
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);
for (int j = 0; j < lightList.size(); j++) {
Light l = lightList.get(j);

@ -120,73 +120,72 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
int endIndex = numLights + startIndex;
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);
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++;
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);
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.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
lightDataIndex++;
//PADDING
lightData.setVector4InArray(0,0,0,0, lightDataIndex);
lightDataIndex++;
break;
case Point:
PointLight pl = (PointLight) l;
Vector3f pos = pl.getPosition();
float invRadius = pl.getInvRadius();
tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
//tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
lightDataIndex++;
//PADDING
lightData.setVector4InArray(0,0,0,0, lightDataIndex);
lightDataIndex++;
break;
case Spot:
SpotLight sl = (SpotLight) l;
Vector3f pos2 = sl.getPosition();
Vector3f dir2 = sl.getDirection();
float invRange = sl.getInvSpotRange();
float spotAngleCos = sl.getPackedAngleCos();
tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
// tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
lightDataIndex++;
//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
//the downside is that spotAngleCos decoding happens now in the frag shader.
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
tmpVec.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
lightDataIndex++;
break;
default:
throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
}
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
lightDataIndex++;
//PADDING
lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
lightDataIndex++;
break;
case Point:
PointLight pl = (PointLight) l;
Vector3f pos = pl.getPosition();
float invRadius = pl.getInvRadius();
tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
//tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
lightDataIndex++;
//PADDING
lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
lightDataIndex++;
break;
case Spot:
SpotLight sl = (SpotLight) l;
Vector3f pos2 = sl.getPosition();
Vector3f dir2 = sl.getDirection();
float invRange = sl.getInvSpotRange();
float spotAngleCos = sl.getPackedAngleCos();
tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
// tmpVec.divideLocal(tmpVec.w);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
lightDataIndex++;
//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
//the downside is that spotAngleCos decoding happens now in the frag shader.
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);
tmpVec.normalizeLocal();
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
lightDataIndex++;
break;
default:
throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
}
}
vars.release();
//Padding of unsued buffer space
@ -197,7 +196,6 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic {
return curIndex;
}
@Override
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights) {
int nbRenderedLights = 0;

@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.system.lwjgl;
import com.jme3.input.lwjgl.JInputJoyInput;
@ -82,18 +81,18 @@ public abstract class LwjglContext implements JmeContext {
protected Timer timer;
protected SystemListener listener;
public void setSystemListener(SystemListener listener){
public void setSystemListener(SystemListener listener) {
this.listener = listener;
}
protected void printContextInitInfo() {
logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n" +
" * Graphics Adapter: {2}\n" +
" * Driver Version: {3}\n" +
" * Scaling Factor: {4}",
new Object[]{ Sys.getVersion(), Thread.currentThread().getName(),
Display.getAdapter(), Display.getVersion(),
Display.getPixelScaleFactor() });
logger.log(Level.INFO, "LWJGL {0} context running on thread {1}\n"
+ " * Graphics Adapter: {2}\n"
+ " * Driver Version: {3}\n"
+ " * Scaling Factor: {4}",
new Object[]{Sys.getVersion(), Thread.currentThread().getName(),
Display.getAdapter(), Display.getVersion(),
Display.getPixelScaleFactor()});
}
protected ContextAttribs createContextAttribs() {
@ -162,6 +161,7 @@ public abstract class LwjglContext implements JmeContext {
}
}
}
protected void loadNatives() {
if (JmeSystem.isLowPermissions()) {
return;
@ -181,7 +181,7 @@ public abstract class LwjglContext implements JmeContext {
protected int getNumSamplesToUse() {
int samples = 0;
if (settings.getSamples() > 1){
if (settings.getSamples() > 1) {
samples = settings.getSamples();
int supportedSamples = determineMaxSamples(samples);
if (supportedSamples < samples) {
@ -196,14 +196,14 @@ public abstract class LwjglContext implements JmeContext {
return samples;
}
protected void initContextFirstTime(){
protected void initContextFirstTime() {
if (!GLContext.getCapabilities().OpenGL20) {
throw new RendererException("OpenGL 2.0 or higher is " +
"required for jMonkeyEngine");
throw new RendererException("OpenGL 2.0 or higher is "
+ "required for jMonkeyEngine");
}
if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2)
|| settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) {
|| settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)) {
GL gl = new LwjglGL();
GLExt glext = new LwjglGLExt();
GLFbo glfbo;
@ -215,20 +215,20 @@ public abstract class LwjglContext implements JmeContext {
}
if (settings.getBoolean("GraphicsDebug")) {
gl = new GLDebugDesktop(gl, glext, glfbo);
gl = new GLDebugDesktop(gl, glext, glfbo);
glext = (GLExt) gl;
glfbo = (GLFbo) gl;
}
if (settings.getBoolean("GraphicsTiming")) {
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);
glfbo = (GLFbo) GLTiming.createGLTiming(glfbo, timingState, GLFbo.class);
}
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);
glfbo = (GLFbo) GLTracer.createDesktopGlTracer(glfbo, GLFbo.class);
}
@ -260,42 +260,42 @@ public abstract class LwjglContext implements JmeContext {
}
}
public void internalDestroy(){
public void internalDestroy() {
renderer = null;
timer = null;
renderable.set(false);
synchronized (createdLock){
synchronized (createdLock) {
created.set(false);
createdLock.notifyAll();
}
}
public void internalCreate(){
public void internalCreate() {
timer = new LwjglTimer();
synchronized (createdLock){
synchronized (createdLock) {
created.set(true);
createdLock.notifyAll();
}
if (renderable.get()){
if (renderable.get()) {
initContextFirstTime();
}else{
} else {
assert getType() == Type.Canvas;
}
}
public void create(){
public void create() {
create(false);
}
public void destroy(){
public void destroy() {
destroy(false);
}
protected void waitFor(boolean createdVal){
synchronized (createdLock){
while (created.get() != createdVal){
protected void waitFor(boolean createdVal) {
synchronized (createdLock) {
while (created.get() != createdVal) {
try {
createdLock.wait();
} catch (InterruptedException ex) {
@ -304,11 +304,11 @@ public abstract class LwjglContext implements JmeContext {
}
}
public boolean isCreated(){
public boolean isCreated() {
return created.get();
}
public boolean isRenderable(){
public boolean isRenderable() {
return renderable.get();
}
@ -316,7 +316,7 @@ public abstract class LwjglContext implements JmeContext {
this.settings.copyFrom(settings);
}
public AppSettings getSettings(){
public AppSettings getSettings() {
return settings;
}

Loading…
Cancel
Save