Fixed formatting thanks to EmpirePhoenix

experimental
michael 10 years ago
parent a59f017710
commit 99d69d1d01
  1. 2
      .gitignore
  2. 48
      jme3-core/src/main/java/com/jme3/asset/DesktopAssetManager.java
  3. 84
      jme3-core/src/main/java/com/jme3/asset/cache/WeakRefCloneAssetCache.java
  4. 4
      jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
  5. 1
      jme3-core/src/main/java/com/jme3/renderer/Caps.java
  6. 202
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  7. 321
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

2
.gitignore vendored

@ -131,5 +131,3 @@
!/jme3-bullet-native/libs/native/osx/x86_64/libbulletjme.dylib !/jme3-bullet-native/libs/native/osx/x86_64/libbulletjme.dylib
!/jme3-bullet-native/libs/native/linux/x86/libbulletjme.so !/jme3-bullet-native/libs/native/linux/x86/libbulletjme.so
!/jme3-bullet-native/libs/native/linux/x86_64/libbulletjme.so !/jme3-bullet-native/libs/native/linux/x86_64/libbulletjme.so
*.iml
/.idea/*

@ -68,12 +68,12 @@ public class DesktopAssetManager implements AssetManager {
private static final Logger logger = Logger.getLogger(AssetManager.class.getName()); private static final Logger logger = Logger.getLogger(AssetManager.class.getName());
private ShaderGenerator shaderGenerator; private ShaderGenerator shaderGenerator;
private final ImplHandler handler = new ImplHandler(this); private final ImplHandler handler = new ImplHandler(this);
private CopyOnWriteArrayList<AssetEventListener> eventListeners = private CopyOnWriteArrayList<AssetEventListener> eventListeners =
new CopyOnWriteArrayList<AssetEventListener>(); new CopyOnWriteArrayList<AssetEventListener>();
private List<ClassLoader> classLoaders = private List<ClassLoader> classLoaders =
Collections.synchronizedList(new ArrayList<ClassLoader>()); Collections.synchronizedList(new ArrayList<ClassLoader>());
@ -89,7 +89,7 @@ public class DesktopAssetManager implements AssetManager {
public DesktopAssetManager(URL configFile){ public DesktopAssetManager(URL configFile){
if (configFile != null){ if (configFile != null){
loadConfigFile(configFile); loadConfigFile(configFile);
} }
logger.fine("DesktopAssetManager created."); logger.fine("DesktopAssetManager created.");
} }
@ -109,11 +109,11 @@ public class DesktopAssetManager implements AssetManager {
} }
} }
} }
public void addClassLoader(ClassLoader loader) { public void addClassLoader(ClassLoader loader) {
classLoaders.add(loader); classLoaders.add(loader);
} }
public void removeClassLoader(ClassLoader loader) { public void removeClassLoader(ClassLoader loader) {
classLoaders.remove(loader); classLoaders.remove(loader);
} }
@ -121,7 +121,7 @@ public class DesktopAssetManager implements AssetManager {
public List<ClassLoader> getClassLoaders(){ public List<ClassLoader> getClassLoaders(){
return Collections.unmodifiableList(classLoaders); return Collections.unmodifiableList(classLoaders);
} }
public void addAssetEventListener(AssetEventListener listener) { public void addAssetEventListener(AssetEventListener listener) {
eventListeners.add(listener); eventListeners.add(listener);
} }
@ -133,7 +133,7 @@ public class DesktopAssetManager implements AssetManager {
public void clearAssetEventListeners() { public void clearAssetEventListeners() {
eventListeners.clear(); eventListeners.clear();
} }
public void setAssetEventListener(AssetEventListener listener){ public void setAssetEventListener(AssetEventListener listener){
eventListeners.clear(); eventListeners.clear();
eventListeners.add(listener); eventListeners.add(listener);
@ -160,7 +160,7 @@ public class DesktopAssetManager implements AssetManager {
registerLoader(clazz, extensions); registerLoader(clazz, extensions);
} }
} }
public void unregisterLoader(Class<? extends AssetLoader> loaderClass) { public void unregisterLoader(Class<? extends AssetLoader> loaderClass) {
handler.removeLoader(loaderClass); handler.removeLoader(loaderClass);
if (logger.isLoggable(Level.FINER)){ if (logger.isLoggable(Level.FINER)){
@ -190,7 +190,7 @@ public class DesktopAssetManager implements AssetManager {
registerLocator(rootPath, clazz); registerLocator(rootPath, clazz);
} }
} }
public void unregisterLocator(String rootPath, Class<? extends AssetLocator> clazz){ public void unregisterLocator(String rootPath, Class<? extends AssetLocator> clazz){
handler.removeLocator(clazz, rootPath); handler.removeLocator(clazz, rootPath);
if (logger.isLoggable(Level.FINER)){ if (logger.isLoggable(Level.FINER)){
@ -198,7 +198,7 @@ public class DesktopAssetManager implements AssetManager {
clazz.getSimpleName()); clazz.getSimpleName());
} }
} }
public AssetInfo locateAsset(AssetKey<?> key){ public AssetInfo locateAsset(AssetKey<?> key){
AssetInfo info = handler.tryLocate(key); AssetInfo info = handler.tryLocate(key);
if (info == null){ if (info == null){
@ -206,7 +206,7 @@ public class DesktopAssetManager implements AssetManager {
} }
return info; return info;
} }
public <T> T getFromCache(AssetKey<T> key) { public <T> T getFromCache(AssetKey<T> key) {
AssetCache cache = handler.getCache(key.getCacheType()); AssetCache cache = handler.getCache(key.getCacheType());
if (cache != null) { if (cache != null) {
@ -220,7 +220,7 @@ public class DesktopAssetManager implements AssetManager {
throw new IllegalArgumentException("Key " + key + " specifies no cache."); throw new IllegalArgumentException("Key " + key + " specifies no cache.");
} }
} }
public <T> void addToCache(AssetKey<T> key, T asset) { public <T> void addToCache(AssetKey<T> key, T asset) {
AssetCache cache = handler.getCache(key.getCacheType()); AssetCache cache = handler.getCache(key.getCacheType());
if (cache != null) { if (cache != null) {
@ -230,7 +230,7 @@ public class DesktopAssetManager implements AssetManager {
throw new IllegalArgumentException("Key " + key + " specifies no cache."); throw new IllegalArgumentException("Key " + key + " specifies no cache.");
} }
} }
public <T> boolean deleteFromCache(AssetKey<T> key) { public <T> boolean deleteFromCache(AssetKey<T> key) {
AssetCache cache = handler.getCache(key.getCacheType()); AssetCache cache = handler.getCache(key.getCacheType());
if (cache != null) { if (cache != null) {
@ -239,7 +239,7 @@ public class DesktopAssetManager implements AssetManager {
throw new IllegalArgumentException("Key " + key + " specifies no cache."); throw new IllegalArgumentException("Key " + key + " specifies no cache.");
} }
} }
public void clearCache(){ public void clearCache(){
handler.clearCache(); handler.clearCache();
if (logger.isLoggable(Level.FINER)){ if (logger.isLoggable(Level.FINER)){
@ -257,14 +257,14 @@ public class DesktopAssetManager implements AssetManager {
public <T> T loadAsset(AssetKey<T> key){ public <T> T loadAsset(AssetKey<T> key){
if (key == null) if (key == null)
throw new IllegalArgumentException("key cannot be null"); throw new IllegalArgumentException("key cannot be null");
for (AssetEventListener listener : eventListeners){ for (AssetEventListener listener : eventListeners){
listener.assetRequested(key); listener.assetRequested(key);
} }
AssetCache cache = handler.getCache(key.getCacheType()); AssetCache cache = handler.getCache(key.getCacheType());
AssetProcessor proc = handler.getProcessor(key.getProcessorType()); AssetProcessor proc = handler.getProcessor(key.getProcessorType());
Object obj = cache != null ? cache.getFromCache(key) : null; Object obj = cache != null ? cache.getFromCache(key) : null;
if (obj == null){ if (obj == null){
// Asset not in cache, load it from file system. // Asset not in cache, load it from file system.
@ -298,17 +298,17 @@ public class DesktopAssetManager implements AssetManager {
logger.log(Level.FINER, "Loaded {0} with {1}", logger.log(Level.FINER, "Loaded {0} with {1}",
new Object[]{key, loader.getClass().getSimpleName()}); new Object[]{key, loader.getClass().getSimpleName()});
} }
if (proc != null){ if (proc != null){
// do processing on asset before caching // do processing on asset before caching
obj = proc.postProcess(key, obj); obj = proc.postProcess(key, obj);
} }
if (cache != null){ if (cache != null){
// At this point, obj should be of type T // At this point, obj should be of type T
cache.addToCache(key, (T) obj); cache.addToCache(key, (T) obj);
} }
for (AssetEventListener listener : eventListeners){ for (AssetEventListener listener : eventListeners){
listener.assetLoaded(key); listener.assetLoaded(key);
} }
@ -334,7 +334,7 @@ public class DesktopAssetManager implements AssetManager {
} }
} }
} }
return clone; return clone;
} }
@ -342,7 +342,7 @@ public class DesktopAssetManager implements AssetManager {
return loadAsset(new AssetKey(name)); return loadAsset(new AssetKey(name));
} }
public Texture loadTexture(TextureKey key){ public Texture loadTexture(TextureKey key){
return (Texture) loadAsset(key); return (Texture) loadAsset(key);
} }
@ -438,5 +438,5 @@ public class DesktopAssetManager implements AssetManager {
this.shaderGenerator = shaderGenerator; this.shaderGenerator = shaderGenerator;
} }
} }

@ -33,7 +33,6 @@ package com.jme3.asset.cache;
import com.jme3.asset.AssetKey; import com.jme3.asset.AssetKey;
import com.jme3.asset.CloneableSmartAsset; import com.jme3.asset.CloneableSmartAsset;
import java.lang.ref.PhantomReference; import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue; import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -46,43 +45,43 @@ import java.util.logging.Logger;
* <codeWeakRefCloneAssetCache</code> caches cloneable assets in a weak-key * <codeWeakRefCloneAssetCache</code> caches cloneable assets in a weak-key
* cache, allowing them to be collected when memory is low. * cache, allowing them to be collected when memory is low.
* The cache stores weak references to the asset keys, so that * The cache stores weak references to the asset keys, so that
* when all clones of the original asset are collected, will cause the * when all clones of the original asset are collected, will cause the
* asset to be automatically removed from the cache. * asset to be automatically removed from the cache.
* *
* @author Kirill Vainer * @author Kirill Vainer
*/ */
public class WeakRefCloneAssetCache implements AssetCache { public class WeakRefCloneAssetCache implements AssetCache {
private static final Logger logger = Logger.getLogger(WeakRefAssetCache.class.getName()); private static final Logger logger = Logger.getLogger(WeakRefAssetCache.class.getName());
private final ReferenceQueue<AssetKey> refQueue = new ReferenceQueue<AssetKey>(); private final ReferenceQueue<AssetKey> refQueue = new ReferenceQueue<AssetKey>();
/** /**
* Maps cloned key to AssetRef which has a weak ref to the original * Maps cloned key to AssetRef which has a weak ref to the original
* key and a strong ref to the original asset. * key and a strong ref to the original asset.
*/ */
private final ConcurrentHashMap<AssetKey, AssetRef> smartCache private final ConcurrentHashMap<AssetKey, AssetRef> smartCache
= new ConcurrentHashMap<AssetKey, AssetRef>(); = new ConcurrentHashMap<AssetKey, AssetRef>();
/** /**
* Stored in the ReferenceQueue to find out when originalKey is collected * Stored in the ReferenceQueue to find out when originalKey is collected
* by GC. Once collected, the clonedKey is used to remove the asset * by GC. Once collected, the clonedKey is used to remove the asset
* from the cache. * from the cache.
*/ */
private static final class KeyRef extends PhantomReference<AssetKey> { private static final class KeyRef extends PhantomReference<AssetKey> {
AssetKey clonedKey; AssetKey clonedKey;
public KeyRef(AssetKey originalKey, ReferenceQueue<AssetKey> refQueue) { public KeyRef(AssetKey originalKey, ReferenceQueue<AssetKey> refQueue) {
super(originalKey, refQueue); super(originalKey, refQueue);
clonedKey = originalKey.clone(); clonedKey = originalKey.clone();
} }
} }
/** /**
* Stores the original key and original asset. * Stores the original key and original asset.
* The asset info contains a cloneable asset (e.g. the original, from * The asset info contains a cloneable asset (e.g. the original, from
* which all clones are made). Also a weak reference to the * which all clones are made). Also a weak reference to the
* original key which is used when the clones are produced. * original key which is used when the clones are produced.
*/ */
private static final class AssetRef extends WeakReference<AssetKey> { private static final class AssetRef extends WeakReference<AssetKey> {
@ -95,24 +94,24 @@ public class WeakRefCloneAssetCache implements AssetCache {
} }
} }
private final ThreadLocal<ArrayList<AssetKey>> assetLoadStack private final ThreadLocal<ArrayList<AssetKey>> assetLoadStack
= new ThreadLocal<ArrayList<AssetKey>>() { = new ThreadLocal<ArrayList<AssetKey>>() {
@Override @Override
protected ArrayList<AssetKey> initialValue() { protected ArrayList<AssetKey> initialValue() {
return new ArrayList<AssetKey>(); return new ArrayList<AssetKey>();
} }
}; };
private void removeCollectedAssets() { private void removeCollectedAssets(){
int removedAssets = 0; int removedAssets = 0;
for (KeyRef ref; (ref = (KeyRef) refQueue.poll()) != null; ) { for (KeyRef ref; (ref = (KeyRef)refQueue.poll()) != null;){
// (Cannot use ref.get() since it was just collected by GC!) // (Cannot use ref.get() since it was just collected by GC!)
AssetKey key = ref.clonedKey; AssetKey key = ref.clonedKey;
// Asset was collected, note that at this point the asset cache // Asset was collected, note that at this point the asset cache
// might not even have this asset anymore, it is OK. // might not even have this asset anymore, it is OK.
if (smartCache.remove(key) != null) { if (smartCache.remove(key) != null){
removedAssets++; removedAssets ++;
//System.out.println("WeakRefAssetCache: The asset " + ref.assetKey + " was purged from the cache"); //System.out.println("WeakRefAssetCache: The asset " + ref.assetKey + " was purged from the cache");
} }
} }
@ -120,24 +119,25 @@ public class WeakRefCloneAssetCache implements AssetCache {
logger.log(Level.FINE, "WeakRefAssetCache: {0} assets were purged from the cache.", removedAssets); logger.log(Level.FINE, "WeakRefAssetCache: {0} assets were purged from the cache.", removedAssets);
} }
} }
public <T> void addToCache(AssetKey<T> originalKey, T obj) { public <T> void addToCache(AssetKey<T> originalKey, T obj) {
// Make room for new asset // Make room for new asset
removeCollectedAssets(); removeCollectedAssets();
CloneableSmartAsset asset = (CloneableSmartAsset) obj; CloneableSmartAsset asset = (CloneableSmartAsset) obj;
// No circular references, since the original asset is // No circular references, since the original asset is
// strongly referenced, we don't want the key strongly referenced. // strongly referenced, we don't want the key strongly referenced.
asset.setKey(null); asset.setKey(null);
// Start tracking the collection of originalKey // Start tracking the collection of originalKey
// (this adds the KeyRef to the ReferenceQueue) // (this adds the KeyRef to the ReferenceQueue)
KeyRef ref = new KeyRef(originalKey, refQueue); KeyRef ref = new KeyRef(originalKey, refQueue);
// Place the asset in the cache, but use a clone of // Place the asset in the cache, but use a clone of
// the original key. // the original key.
smartCache.put(ref.clonedKey, new AssetRef(asset, originalKey)); smartCache.put(ref.clonedKey, new AssetRef(asset, originalKey));
// Push the original key used to load the asset // Push the original key used to load the asset
// so that it can be set on the clone later // so that it can be set on the clone later
ArrayList<AssetKey> loadStack = assetLoadStack.get(); ArrayList<AssetKey> loadStack = assetLoadStack.get();
@ -146,9 +146,9 @@ public class WeakRefCloneAssetCache implements AssetCache {
public <T> void registerAssetClone(AssetKey<T> key, T clone) { public <T> void registerAssetClone(AssetKey<T> key, T clone) {
ArrayList<AssetKey> loadStack = assetLoadStack.get(); ArrayList<AssetKey> loadStack = assetLoadStack.get();
((CloneableSmartAsset) clone).setKey(loadStack.remove(loadStack.size() - 1)); ((CloneableSmartAsset)clone).setKey(loadStack.remove(loadStack.size() - 1));
} }
public void notifyNoAssetClone() { public void notifyNoAssetClone() {
ArrayList<AssetKey> loadStack = assetLoadStack.get(); ArrayList<AssetKey> loadStack = assetLoadStack.get();
loadStack.remove(loadStack.size() - 1); loadStack.remove(loadStack.size() - 1);
@ -156,10 +156,10 @@ public class WeakRefCloneAssetCache implements AssetCache {
public <T> T getFromCache(AssetKey<T> key) { public <T> T getFromCache(AssetKey<T> key) {
AssetRef smartInfo; AssetRef smartInfo;
synchronized (smartCache) { synchronized (smartCache){
smartInfo = smartCache.get(key); smartInfo = smartCache.get(key);
} }
if (smartInfo == null) { if (smartInfo == null) {
return null; return null;
} else { } else {
@ -167,40 +167,40 @@ public class WeakRefCloneAssetCache implements AssetCache {
// can check this and determine that the asset clone // can check this and determine that the asset clone
// belongs to the asset retrieved here. // belongs to the asset retrieved here.
AssetKey keyForTheClone = smartInfo.get(); AssetKey keyForTheClone = smartInfo.get();
if (keyForTheClone == null) { if (keyForTheClone == null){
// The asset was JUST collected by GC // The asset was JUST collected by GC
// (between here and smartCache.get) // (between here and smartCache.get)
return null; return null;
} }
// Prevent original key from getting collected // Prevent original key from getting collected
// while an asset is loaded for it. // while an asset is loaded for it.
ArrayList<AssetKey> loadStack = assetLoadStack.get(); ArrayList<AssetKey> loadStack = assetLoadStack.get();
loadStack.add(keyForTheClone); loadStack.add(keyForTheClone);
return (T) smartInfo.asset; return (T) smartInfo.asset;
} }
} }
public boolean deleteFromCache(AssetKey key) { public boolean deleteFromCache(AssetKey key) {
ArrayList<AssetKey> loadStack = assetLoadStack.get(); ArrayList<AssetKey> loadStack = assetLoadStack.get();
if (!loadStack.isEmpty()) { if (!loadStack.isEmpty()){
throw new UnsupportedOperationException("Cache cannot be modified" throw new UnsupportedOperationException("Cache cannot be modified"
+ "while assets are being loaded"); + "while assets are being loaded");
} }
return smartCache.remove(key) != null; return smartCache.remove(key) != null;
} }
public void clearCache() { public void clearCache() {
ArrayList<AssetKey> loadStack = assetLoadStack.get(); ArrayList<AssetKey> loadStack = assetLoadStack.get();
if (!loadStack.isEmpty()) { if (!loadStack.isEmpty()){
throw new UnsupportedOperationException("Cache cannot be modified" throw new UnsupportedOperationException("Cache cannot be modified"
+ "while assets are being loaded"); + "while assets are being loaded");
} }
smartCache.clear(); smartCache.clear();
} }
} }

@ -49,9 +49,7 @@ public class TechniqueDef implements Savable {
* Version #1: Separate shader language for each shader source. * Version #1: Separate shader language for each shader source.
*/ */
public static final int SAVABLE_VERSION = 1; public static final int SAVABLE_VERSION = 1;
/** /**
* Describes light rendering mode. * Describes light rendering mode.
*/ */

@ -315,6 +315,7 @@ public enum Caps {
* Supports 32-bit index buffers. * Supports 32-bit index buffers.
*/ */
IntegerIndexBuffer, IntegerIndexBuffer,
/** /**
* Partial support for non-power-of-2 textures, typically found * Partial support for non-power-of-2 textures, typically found
* on OpenGL ES 2 devices. * on OpenGL ES 2 devices.

@ -71,7 +71,7 @@ public class GLRenderer implements Renderer {
private static final Logger logger = Logger.getLogger(GLRenderer.class.getName()); private static final Logger logger = Logger.getLogger(GLRenderer.class.getName());
private static final boolean VALIDATE_SHADER = false; private static final boolean VALIDATE_SHADER = false;
private static final Pattern GLVERSION_PATTERN = Pattern.compile(".*?(\\d+)\\.(\\d+).*"); private static final Pattern GLVERSION_PATTERN = Pattern.compile(".*?(\\d+)\\.(\\d+).*");
private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250); private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250);
private final StringBuilder stringBuf = new StringBuilder(250); private final StringBuilder stringBuf = new StringBuilder(250);
private final IntBuffer intBuf1 = BufferUtils.createIntBuffer(1); private final IntBuffer intBuf1 = BufferUtils.createIntBuffer(1);
@ -81,7 +81,7 @@ public class GLRenderer implements Renderer {
private final NativeObjectManager objManager = new NativeObjectManager(); private final NativeObjectManager objManager = new NativeObjectManager();
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class); private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
private final EnumMap<Limits, Integer> limits = new EnumMap<Limits, Integer>(Limits.class); private final EnumMap<Limits, Integer> limits = new EnumMap<Limits, Integer>(Limits.class);
// private int vertexTextureUnits; // private int vertexTextureUnits;
// private int fragTextureUnits; // private int fragTextureUnits;
// private int vertexUniforms; // private int vertexUniforms;
@ -111,7 +111,7 @@ public class GLRenderer implements Renderer {
private final GLExt glext; private final GLExt glext;
private final GLFbo glfbo; private final GLFbo glfbo;
private final TextureUtil texUtil; private final TextureUtil texUtil;
public GLRenderer(GL gl, GLFbo glfbo) { public GLRenderer(GL gl, GLFbo glfbo) {
this.gl = gl; this.gl = gl;
this.gl2 = gl instanceof GL2 ? (GL2)gl : null; this.gl2 = gl instanceof GL2 ? (GL2)gl : null;
@ -131,7 +131,7 @@ public class GLRenderer implements Renderer {
public EnumSet<Caps> getCaps() { public EnumSet<Caps> getCaps() {
return caps; return caps;
} }
// Not making public yet ... // Not making public yet ...
public EnumMap<Limits, Integer> getLimits() { public EnumMap<Limits, Integer> getLimits() {
return limits; return limits;
@ -144,7 +144,7 @@ public class GLRenderer implements Renderer {
} }
return extensionSet; return extensionSet;
} }
public static int extractVersion(String version) { public static int extractVersion(String version) {
Matcher m = GLVERSION_PATTERN.matcher(version); Matcher m = GLVERSION_PATTERN.matcher(version);
if (m.matches()) { if (m.matches()) {
@ -164,17 +164,17 @@ public class GLRenderer implements Renderer {
private boolean hasExtension(String extensionName) { private boolean hasExtension(String extensionName) {
return extensions.contains(extensionName); return extensions.contains(extensionName);
} }
private void loadCapabilitiesES() { private void loadCapabilitiesES() {
caps.add(Caps.GLSL100); caps.add(Caps.GLSL100);
caps.add(Caps.OpenGLES20); caps.add(Caps.OpenGLES20);
// Important: Do not add OpenGL20 - that's the desktop capability! // Important: Do not add OpenGL20 - that's the desktop capability!
} }
private void loadCapabilitiesGL2() { private void loadCapabilitiesGL2() {
int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION)); int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION));
if (oglVer >= 200) { if (oglVer >= 200) {
caps.add(Caps.OpenGL20); caps.add(Caps.OpenGL20);
if (oglVer >= 210) { if (oglVer >= 210) {
@ -196,9 +196,9 @@ public class GLRenderer implements Renderer {
} }
} }
} }
int glslVer = extractVersion(gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION)); int glslVer = extractVersion(gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION));
switch (glslVer) { switch (glslVer) {
default: default:
if (glslVer < 400) { if (glslVer < 400) {
@ -224,27 +224,27 @@ public class GLRenderer implements Renderer {
caps.add(Caps.GLSL100); caps.add(Caps.GLSL100);
break; break;
} }
// Workaround, always assume we support GLSL100 & GLSL110 // Workaround, always assume we support GLSL100 & GLSL110
// Supporting OpenGL 2.0 means supporting GLSL 1.10. // Supporting OpenGL 2.0 means supporting GLSL 1.10.
caps.add(Caps.GLSL110); caps.add(Caps.GLSL110);
caps.add(Caps.GLSL100); caps.add(Caps.GLSL100);
// Fix issue in TestRenderToMemory when GL.GL_FRONT is the main // Fix issue in TestRenderToMemory when GL.GL_FRONT is the main
// buffer being used. // buffer being used.
context.initialDrawBuf = getInteger(GL2.GL_DRAW_BUFFER); context.initialDrawBuf = getInteger(GL2.GL_DRAW_BUFFER);
context.initialReadBuf = getInteger(GL2.GL_READ_BUFFER); context.initialReadBuf = getInteger(GL2.GL_READ_BUFFER);
// XXX: This has to be GL.GL_BACK for canvas on Mac // XXX: This has to be GL.GL_BACK for canvas on Mac
// Since initialDrawBuf is GL.GL_FRONT for pbuffer, gotta // Since initialDrawBuf is GL.GL_FRONT for pbuffer, gotta
// change this value later on ... // change this value later on ...
// initialDrawBuf = GL.GL_BACK; // initialDrawBuf = GL.GL_BACK;
// initialReadBuf = GL.GL_BACK; // initialReadBuf = GL.GL_BACK;
} }
private void loadCapabilitiesCommon() { private void loadCapabilitiesCommon() {
extensions = loadExtensions(gl.glGetString(GL.GL_EXTENSIONS)); extensions = loadExtensions(gl.glGetString(GL.GL_EXTENSIONS));
limits.put(Limits.VertexTextureUnits, getInteger(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS)); limits.put(Limits.VertexTextureUnits, getInteger(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS));
if (limits.get(Limits.VertexTextureUnits) > 0) { if (limits.get(Limits.VertexTextureUnits) > 0) {
caps.add(Caps.VertexTextureFetch); caps.add(Caps.VertexTextureFetch);
@ -264,7 +264,7 @@ public class GLRenderer implements Renderer {
limits.put(Limits.TextureSize, getInteger(GL.GL_MAX_TEXTURE_SIZE)); limits.put(Limits.TextureSize, getInteger(GL.GL_MAX_TEXTURE_SIZE));
limits.put(Limits.CubemapSize, getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE)); limits.put(Limits.CubemapSize, getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE));
if (hasExtension("GL_ARB_draw_instanced") && if (hasExtension("GL_ARB_draw_instanced") &&
hasExtension("GL_ARB_instanced_arrays")) { hasExtension("GL_ARB_instanced_arrays")) {
caps.add(Caps.MeshInstancing); caps.add(Caps.MeshInstancing);
} }
@ -272,43 +272,43 @@ public class GLRenderer implements Renderer {
if (hasExtension("GL_OES_element_index_uint") || gl2 != null) { if (hasExtension("GL_OES_element_index_uint") || gl2 != null) {
caps.add(Caps.IntegerIndexBuffer); caps.add(Caps.IntegerIndexBuffer);
} }
if (hasExtension("GL_ARB_texture_buffer_object")) { if (hasExtension("GL_ARB_texture_buffer_object")) {
caps.add(Caps.TextureBuffer); caps.add(Caps.TextureBuffer);
} }
// == texture format extensions == // == texture format extensions ==
boolean hasFloatTexture = false; boolean hasFloatTexture = false;
hasFloatTexture = hasExtension("GL_OES_texture_half_float") && hasFloatTexture = hasExtension("GL_OES_texture_half_float") &&
hasExtension("GL_OES_texture_float"); hasExtension("GL_OES_texture_float");
if (!hasFloatTexture) { if (!hasFloatTexture) {
hasFloatTexture = hasExtension("GL_ARB_texture_float") && hasFloatTexture = hasExtension("GL_ARB_texture_float") &&
hasExtension("GL_ARB_half_float_pixel"); hasExtension("GL_ARB_half_float_pixel");
if (!hasFloatTexture) { if (!hasFloatTexture) {
hasFloatTexture = caps.contains(Caps.OpenGL30); hasFloatTexture = caps.contains(Caps.OpenGL30);
} }
} }
if (hasFloatTexture) { if (hasFloatTexture) {
caps.add(Caps.FloatTexture); caps.add(Caps.FloatTexture);
} }
if (hasExtension("GL_OES_depth_texture") || gl2 != null) { if (hasExtension("GL_OES_depth_texture") || gl2 != null) {
caps.add(Caps.DepthTexture); caps.add(Caps.DepthTexture);
// TODO: GL_OES_depth24 // TODO: GL_OES_depth24
} }
if (hasExtension("GL_OES_rgb8_rgba8") || if (hasExtension("GL_OES_rgb8_rgba8") ||
hasExtension("GL_ARM_rgba8") || hasExtension("GL_ARM_rgba8") ||
hasExtension("GL_EXT_texture_format_BGRA8888")) { hasExtension("GL_EXT_texture_format_BGRA8888")) {
caps.add(Caps.Rgba8); caps.add(Caps.Rgba8);
} }
if (caps.contains(Caps.OpenGL30) || hasExtension("GL_OES_packed_depth_stencil")) { if (caps.contains(Caps.OpenGL30) || hasExtension("GL_OES_packed_depth_stencil")) {
caps.add(Caps.PackedDepthStencilBuffer); caps.add(Caps.PackedDepthStencilBuffer);
} }
@ -323,35 +323,35 @@ public class GLRenderer implements Renderer {
caps.add(Caps.FloatDepthBuffer); caps.add(Caps.FloatDepthBuffer);
} }
if ((hasExtension("GL_EXT_packed_float") && hasFloatTexture) || if ((hasExtension("GL_EXT_packed_float") && hasFloatTexture) ||
caps.contains(Caps.OpenGL30)) { caps.contains(Caps.OpenGL30)) {
// Either OpenGL3 is available or both packed_float & half_float_pixel. // Either OpenGL3 is available or both packed_float & half_float_pixel.
caps.add(Caps.PackedFloatColorBuffer); caps.add(Caps.PackedFloatColorBuffer);
caps.add(Caps.PackedFloatTexture); caps.add(Caps.PackedFloatTexture);
} }
if (hasExtension("GL_EXT_texture_shared_exponent") || caps.contains(Caps.OpenGL30)) { if (hasExtension("GL_EXT_texture_shared_exponent") || caps.contains(Caps.OpenGL30)) {
caps.add(Caps.SharedExponentTexture); caps.add(Caps.SharedExponentTexture);
} }
if (hasExtension("GL_EXT_texture_compression_s3tc")) { if (hasExtension("GL_EXT_texture_compression_s3tc")) {
caps.add(Caps.TextureCompressionS3TC); caps.add(Caps.TextureCompressionS3TC);
} }
if (hasExtension("GL_ARB_ES3_compatibility")) { if (hasExtension("GL_ARB_ES3_compatibility")) {
caps.add(Caps.TextureCompressionETC2); caps.add(Caps.TextureCompressionETC2);
caps.add(Caps.TextureCompressionETC1); caps.add(Caps.TextureCompressionETC1);
} else if (hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) { } else if (hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) {
caps.add(Caps.TextureCompressionETC1); caps.add(Caps.TextureCompressionETC1);
} }
// == end texture format extensions == // == end texture format extensions ==
if (hasExtension("GL_ARB_vertex_array_object") || caps.contains(Caps.OpenGL30)) { if (hasExtension("GL_ARB_vertex_array_object") || caps.contains(Caps.OpenGL30)) {
caps.add(Caps.VertexBufferArray); caps.add(Caps.VertexBufferArray);
} }
if (hasExtension("GL_ARB_texture_non_power_of_two") || if (hasExtension("GL_ARB_texture_non_power_of_two") ||
hasExtension("GL_OES_texture_npot") || hasExtension("GL_OES_texture_npot") ||
hasExtension("GL_APPLE_texture_2D_limited_npot") || hasExtension("GL_APPLE_texture_2D_limited_npot") ||
caps.contains(Caps.OpenGL30)) { caps.contains(Caps.OpenGL30)) {
@ -361,7 +361,7 @@ public class GLRenderer implements Renderer {
+ "support non-power-of-2 textures. " + "support non-power-of-2 textures. "
+ "Some features might not work."); + "Some features might not work.");
} }
if (caps.contains(Caps.OpenGLES20)) { if (caps.contains(Caps.OpenGLES20)) {
// OpenGL ES 2 has some limited support for NPOT textures // OpenGL ES 2 has some limited support for NPOT textures
caps.add(Caps.PartialNonPowerOfTwoTextures); caps.add(Caps.PartialNonPowerOfTwoTextures);
@ -377,14 +377,14 @@ public class GLRenderer implements Renderer {
if (hasExtension("GL_EXT_framebuffer_object")) { if (hasExtension("GL_EXT_framebuffer_object")) {
caps.add(Caps.FrameBuffer); caps.add(Caps.FrameBuffer);
limits.put(Limits.RenderBufferSize, getInteger(GLExt.GL_MAX_RENDERBUFFER_SIZE_EXT)); limits.put(Limits.RenderBufferSize, getInteger(GLExt.GL_MAX_RENDERBUFFER_SIZE_EXT));
limits.put(Limits.FrameBufferAttachments, getInteger(GLExt.GL_MAX_COLOR_ATTACHMENTS_EXT)); limits.put(Limits.FrameBufferAttachments, getInteger(GLExt.GL_MAX_COLOR_ATTACHMENTS_EXT));
if (hasExtension("GL_EXT_framebuffer_blit")) { if (hasExtension("GL_EXT_framebuffer_blit")) {
caps.add(Caps.FrameBufferBlit); caps.add(Caps.FrameBufferBlit);
} }
if (hasExtension("GL_EXT_framebuffer_multisample")) { if (hasExtension("GL_EXT_framebuffer_multisample")) {
caps.add(Caps.FrameBufferMultisample); caps.add(Caps.FrameBufferMultisample);
limits.put(Limits.FrameBufferSamples, getInteger(GLExt.GL_MAX_SAMPLES_EXT)); limits.put(Limits.FrameBufferSamples, getInteger(GLExt.GL_MAX_SAMPLES_EXT));
@ -422,9 +422,9 @@ public class GLRenderer implements Renderer {
} }
caps.add(Caps.Multisample); caps.add(Caps.Multisample);
} }
// Supports sRGB pipeline. // Supports sRGB pipeline.
if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB")) if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB"))
|| caps.contains(Caps.OpenGL30) ) { || caps.contains(Caps.OpenGL30) ) {
caps.add(Caps.Srgb); caps.add(Caps.Srgb);
} }
@ -433,24 +433,24 @@ public class GLRenderer implements Renderer {
if (hasExtension("GL_ARB_seamless_cube_map") || caps.contains(Caps.OpenGL32)) { if (hasExtension("GL_ARB_seamless_cube_map") || caps.contains(Caps.OpenGL32)) {
caps.add(Caps.SeamlessCubemap); caps.add(Caps.SeamlessCubemap);
} }
// if (hasExtension("GL_ARB_get_program_binary")) { // if (hasExtension("GL_ARB_get_program_binary")) {
// int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS); // int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS);
// } // }
// Print context information // Print context information
logger.log(Level.INFO, "OpenGL Renderer Information\n" + logger.log(Level.INFO, "OpenGL Renderer Information\n" +
" * Vendor: {0}\n" + " * Vendor: {0}\n" +
" * Renderer: {1}\n" + " * Renderer: {1}\n" +
" * OpenGL Version: {2}\n" + " * OpenGL Version: {2}\n" +
" * GLSL Version: {3}", " * GLSL Version: {3}",
new Object[]{ new Object[]{
gl.glGetString(GL.GL_VENDOR), gl.glGetString(GL.GL_VENDOR),
gl.glGetString(GL.GL_RENDERER), gl.glGetString(GL.GL_RENDERER),
gl.glGetString(GL.GL_VERSION), gl.glGetString(GL.GL_VERSION),
gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION) gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION)
}); });
// Print capabilities (if fine logging is enabled) // Print capabilities (if fine logging is enabled)
if (logger.isLoggable(Level.FINE)) { if (logger.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -461,10 +461,10 @@ public class GLRenderer implements Renderer {
} }
logger.log(Level.FINE, sb.toString()); logger.log(Level.FINE, sb.toString());
} }
texUtil.initialize(caps); texUtil.initialize(caps);
} }
private void loadCapabilities() { private void loadCapabilities() {
if (gl2 != null) { if (gl2 != null) {
loadCapabilitiesGL2(); loadCapabilitiesGL2();
@ -473,22 +473,22 @@ public class GLRenderer implements Renderer {
} }
loadCapabilitiesCommon(); loadCapabilitiesCommon();
} }
private int getInteger(int en) { private int getInteger(int en) {
intBuf16.clear(); intBuf16.clear();
gl.glGetInteger(en, intBuf16); gl.glGetInteger(en, intBuf16);
return intBuf16.get(0); return intBuf16.get(0);
} }
private boolean getBoolean(int en) { private boolean getBoolean(int en) {
gl.glGetBoolean(en, nameBuf); gl.glGetBoolean(en, nameBuf);
return nameBuf.get(0) != (byte)0; return nameBuf.get(0) != (byte)0;
} }
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
public void initialize() { public void initialize() {
loadCapabilities(); loadCapabilities();
// Initialize default state.. // Initialize default state..
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
} }
@ -582,7 +582,7 @@ public class GLRenderer implements Renderer {
} }
if (state.isDepthTest() && !context.depthTestEnabled) { if (state.isDepthTest() && !context.depthTestEnabled) {
gl.glEnable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(convertTestFunction(context.depthFunc)); gl.glDepthFunc(convertTestFunction(context.depthFunc));
context.depthTestEnabled = true; context.depthTestEnabled = true;
} else if (!state.isDepthTest() && context.depthTestEnabled) { } else if (!state.isDepthTest() && context.depthTestEnabled) {
@ -721,7 +721,7 @@ public class GLRenderer implements Renderer {
break; break;
case Screen: case Screen:
gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_COLOR); gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_COLOR);
break; break;
case Exclusion: case Exclusion:
gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR); gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR);
break; break;
@ -1046,12 +1046,12 @@ public class GLRenderer implements Renderer {
boolean gles2 = caps.contains(Caps.OpenGLES20); boolean gles2 = caps.contains(Caps.OpenGLES20);
String language = source.getLanguage(); String language = source.getLanguage();
if (gles2 && !language.equals("GLSL100")) { if (gles2 && !language.equals("GLSL100")) {
throw new RendererException("This shader cannot run in OpenGL ES 2. " throw new RendererException("This shader cannot run in OpenGL ES 2. "
+ "Only GLSL 1.00 shaders are supported."); + "Only GLSL 1.00 shaders are supported.");
} }
// Upload shader source. // Upload shader source.
// Merge the defines and source code. // Merge the defines and source code.
stringBuf.setLength(0); stringBuf.setLength(0);
@ -1078,14 +1078,14 @@ public class GLRenderer implements Renderer {
} }
} }
} }
if (linearizeSrgbImages) { if (linearizeSrgbImages) {
stringBuf.append("#define SRGB 1\n"); stringBuf.append("#define SRGB 1\n");
} }
stringBuf.append(source.getDefines()); stringBuf.append(source.getDefines());
stringBuf.append(source.getSource()); stringBuf.append(source.getSource());
intBuf1.clear(); intBuf1.clear();
intBuf1.put(0, stringBuf.length()); intBuf1.put(0, stringBuf.length());
gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1); gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1);
@ -1143,7 +1143,7 @@ public class GLRenderer implements Renderer {
// If using GLSL 1.5, we bind the outputs for the user // If using GLSL 1.5, we bind the outputs for the user
// For versions 3.3 and up, user should use layout qualifiers instead. // For versions 3.3 and up, user should use layout qualifiers instead.
boolean bindFragDataRequired = false; boolean bindFragDataRequired = false;
for (ShaderSource source : shader.getSources()) { for (ShaderSource source : shader.getSources()) {
if (source.isUpdateNeeded()) { if (source.isUpdateNeeded()) {
updateShaderSourceData(source); updateShaderSourceData(source);
@ -1415,7 +1415,7 @@ public class GLRenderer implements Renderer {
} else if (attachmentSlot < 0 || attachmentSlot >= 16) { } else if (attachmentSlot < 0 || attachmentSlot >= 16) {
throw new UnsupportedOperationException("Invalid FBO attachment slot: " + attachmentSlot); throw new UnsupportedOperationException("Invalid FBO attachment slot: " + attachmentSlot);
} }
return GLExt.GL_COLOR_ATTACHMENT0_EXT + attachmentSlot; return GLExt.GL_COLOR_ATTACHMENT0_EXT + attachmentSlot;
} }
@ -1425,7 +1425,7 @@ public class GLRenderer implements Renderer {
if (image.isUpdateNeeded()) { if (image.isUpdateNeeded()) {
// Check NPOT requirements // Check NPOT requirements
checkNonPowerOfTwo(tex); checkNonPowerOfTwo(tex);
updateTexImageData(image, tex.getType(), 0); updateTexImageData(image, tex.getType(), 0);
// NOTE: For depth textures, sets nearest/no-mips mode // NOTE: For depth textures, sets nearest/no-mips mode
@ -1586,7 +1586,7 @@ public class GLRenderer implements Renderer {
// update viewport to reflect framebuffer's resolution // update viewport to reflect framebuffer's resolution
setViewPort(0, 0, fb.getWidth(), fb.getHeight()); setViewPort(0, 0, fb.getWidth(), fb.getHeight());
if (context.boundFBO != fb.getId()) { if (context.boundFBO != fb.getId()) {
glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, fb.getId()); glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, fb.getId());
statistics.onFrameBufferUse(fb, true); statistics.onFrameBufferUse(fb, true);
@ -1659,7 +1659,7 @@ public class GLRenderer implements Renderer {
public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) { public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
readFrameBufferWithGLFormat(fb, byteBuf, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); readFrameBufferWithGLFormat(fb, byteBuf, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE);
} }
private void readFrameBufferWithGLFormat(FrameBuffer fb, ByteBuffer byteBuf, int glFormat, int dataType) { private void readFrameBufferWithGLFormat(FrameBuffer fb, ByteBuffer byteBuf, int glFormat, int dataType) {
if (fb != null) { if (fb != null) {
RenderBuffer rb = fb.getColorBuffer(); RenderBuffer rb = fb.getColorBuffer();
@ -1681,8 +1681,8 @@ public class GLRenderer implements Renderer {
gl.glReadPixels(vpX, vpY, vpW, vpH, glFormat, dataType, byteBuf); gl.glReadPixels(vpX, vpY, vpW, vpH, glFormat, dataType, byteBuf);
} }
public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) {
GLImageFormat glFormat = texUtil.getImageFormatWithError(format, false); GLImageFormat glFormat = texUtil.getImageFormatWithError(format, false);
readFrameBufferWithGLFormat(fb, byteBuf, glFormat.format, glFormat.dataType); readFrameBufferWithGLFormat(fb, byteBuf, glFormat.format, glFormat.dataType);
} }
@ -1719,10 +1719,10 @@ public class GLRenderer implements Renderer {
\*********************************************************************/ \*********************************************************************/
private int convertTextureType(Texture.Type type, int samples, int face) { private int convertTextureType(Texture.Type type, int samples, int face) {
if (samples > 1 && !caps.contains(Caps.TextureMultisample)) { if (samples > 1 && !caps.contains(Caps.TextureMultisample)) {
throw new RendererException("Multisample textures are not supported" + throw new RendererException("Multisample textures are not supported" +
" by the video hardware."); " by the video hardware.");
} }
switch (type) { switch (type) {
case TwoDimensional: case TwoDimensional:
if (samples > 1) { if (samples > 1) {
@ -1742,7 +1742,7 @@ public class GLRenderer implements Renderer {
} }
case ThreeDimensional: case ThreeDimensional:
if (!caps.contains(Caps.OpenGL20)) { if (!caps.contains(Caps.OpenGL20)) {
throw new RendererException("3D textures are not supported" + throw new RendererException("3D textures are not supported" +
" by the video hardware."); " by the video hardware.");
} }
return GL2.GL_TEXTURE_3D; return GL2.GL_TEXTURE_3D;
@ -1826,11 +1826,11 @@ public class GLRenderer implements Renderer {
int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1, -1); int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1, -1);
boolean haveMips = true; boolean haveMips = true;
if (image != null) { if (image != null) {
haveMips = image.isGeneratedMipmapsRequired() || image.hasMipmaps(); haveMips = image.isGeneratedMipmapsRequired() || image.hasMipmaps();
} }
// filter things // filter things
if (image.getLastTextureState().magFilter != tex.getMagFilter()) { if (image.getLastTextureState().magFilter != tex.getMagFilter()) {
int magFilter = convertMagFilter(tex.getMagFilter()); int magFilter = convertMagFilter(tex.getMagFilter());
@ -1853,7 +1853,7 @@ public class GLRenderer implements Renderer {
context.seamlessCubemap = false; context.seamlessCubemap = false;
} }
} }
if (tex.getAnisotropicFilter() > 1) { if (tex.getAnisotropicFilter() > 1) {
if (caps.contains(Caps.TextureFilterAnisotropic)) { if (caps.contains(Caps.TextureFilterAnisotropic)) {
gl.glTexParameterf(target, gl.glTexParameterf(target,
@ -1865,7 +1865,7 @@ public class GLRenderer implements Renderer {
if (context.pointSprite) { if (context.pointSprite) {
return; // Attempt to fix glTexParameter crash for some ATI GPUs return; // Attempt to fix glTexParameter crash for some ATI GPUs
} }
// repeat modes // repeat modes
switch (tex.getType()) { switch (tex.getType()) {
case ThreeDimensional: case ThreeDimensional:
@ -1894,7 +1894,7 @@ public class GLRenderer implements Renderer {
// R to Texture compare mode // R to Texture compare mode
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) { if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE); gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE);
gl2.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY); gl2.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) { if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) {
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL); gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL);
} else { } else {
@ -1902,7 +1902,7 @@ public class GLRenderer implements Renderer {
} }
}else{ }else{
//restoring default value //restoring default value
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE); gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE);
} }
tex.compareModeUpdated(); tex.compareModeUpdated();
} }
@ -1911,10 +1911,10 @@ public class GLRenderer implements Renderer {
/** /**
* Validates if a potentially NPOT texture is supported by the hardware. * Validates if a potentially NPOT texture is supported by the hardware.
* <p> * <p>
* Textures with power-of-2 dimensions are supported on all hardware, however * Textures with power-of-2 dimensions are supported on all hardware, however
* non-power-of-2 textures may or may not be supported depending on which * non-power-of-2 textures may or may not be supported depending on which
* texturing features are used. * texturing features are used.
* *
* @param tex The texture to validate. * @param tex The texture to validate.
* @throws RendererException If the texture is not supported by the hardware * @throws RendererException If the texture is not supported by the hardware
*/ */
@ -1923,19 +1923,19 @@ public class GLRenderer implements Renderer {
// Texture is power-of-2, safe to use. // Texture is power-of-2, safe to use.
return; return;
} }
if (caps.contains(Caps.NonPowerOfTwoTextures)) { if (caps.contains(Caps.NonPowerOfTwoTextures)) {
// Texture is NPOT but it is supported by video hardware. // Texture is NPOT but it is supported by video hardware.
return; return;
} }
// Maybe we have some / partial support for NPOT? // Maybe we have some / partial support for NPOT?
if (!caps.contains(Caps.PartialNonPowerOfTwoTextures)) { if (!caps.contains(Caps.PartialNonPowerOfTwoTextures)) {
// Cannot use any type of NPOT texture (uncommon) // Cannot use any type of NPOT texture (uncommon)
throw new RendererException("non-power-of-2 textures are not " throw new RendererException("non-power-of-2 textures are not "
+ "supported by the video hardware"); + "supported by the video hardware");
} }
// Partial NPOT supported.. // Partial NPOT supported..
if (tex.getMinFilter().usesMipMapLevels()) { if (tex.getMinFilter().usesMipMapLevels()) {
throw new RendererException("non-power-of-2 textures with mip-maps " throw new RendererException("non-power-of-2 textures with mip-maps "
@ -1962,10 +1962,10 @@ public class GLRenderer implements Renderer {
throw new UnsupportedOperationException("unrecongized texture type"); throw new UnsupportedOperationException("unrecongized texture type");
} }
} }
/** /**
* Uploads the given image to the GL driver. * Uploads the given image to the GL driver.
* *
* @param img The image to upload * @param img The image to upload
* @param type How the data in the image argument should be interpreted. * @param type How the data in the image argument should be interpreted.
* @param unit The texture slot to be used to upload the image, not important * @param unit The texture slot to be used to upload the image, not important
@ -1989,7 +1989,7 @@ public class GLRenderer implements Renderer {
gl.glActiveTexture(GL.GL_TEXTURE0 + unit); gl.glActiveTexture(GL.GL_TEXTURE0 + unit);
context.boundTextureUnit = unit; context.boundTextureUnit = unit;
} }
gl.glBindTexture(target, texId); gl.glBindTexture(target, texId);
context.boundTextures[unit] = img; context.boundTextures[unit] = img;
@ -2032,12 +2032,12 @@ public class GLRenderer implements Renderer {
throw new RendererException("Multisample textures are not supported by the video hardware"); throw new RendererException("Multisample textures are not supported by the video hardware");
} }
} }
// Check if graphics card doesn't support depth textures // Check if graphics card doesn't support depth textures
if (img.getFormat().isDepthFormat() && !caps.contains(Caps.DepthTexture)) { if (img.getFormat().isDepthFormat() && !caps.contains(Caps.DepthTexture)) {
throw new RendererException("Depth textures are not supported by the video hardware"); throw new RendererException("Depth textures are not supported by the video hardware");
} }
if (target == GL.GL_TEXTURE_CUBE_MAP) { if (target == GL.GL_TEXTURE_CUBE_MAP) {
// Check max texture size before upload // Check max texture size before upload
int cubeSize = limits.get(Limits.CubemapSize); int cubeSize = limits.get(Limits.CubemapSize);
@ -2068,12 +2068,12 @@ public class GLRenderer implements Renderer {
if (!caps.contains(Caps.TextureArray)) { if (!caps.contains(Caps.TextureArray)) {
throw new RendererException("Texture arrays not supported by graphics hardware"); throw new RendererException("Texture arrays not supported by graphics hardware");
} }
List<ByteBuffer> data = img.getData(); List<ByteBuffer> data = img.getData();
// -1 index specifies prepare data for 2D Array // -1 index specifies prepare data for 2D Array
texUtil.uploadTexture(img, target, -1, linearizeSrgbImages); texUtil.uploadTexture(img, target, -1, linearizeSrgbImages);
for (int i = 0; i < data.size(); i++) { for (int i = 0; i < data.size(); i++) {
// upload each slice of 2D array in turn // upload each slice of 2D array in turn
// this time with the appropriate index // this time with the appropriate index
@ -2104,7 +2104,7 @@ public class GLRenderer implements Renderer {
if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) { if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
// Check NPOT requirements // Check NPOT requirements
checkNonPowerOfTwo(tex); checkNonPowerOfTwo(tex);
updateTexImageData(image, tex.getType(), unit); updateTexImageData(image, tex.getType(), unit);
} }
@ -2225,7 +2225,7 @@ public class GLRenderer implements Renderer {
//statistics.onVertexBufferUse(vb, false); //statistics.onVertexBufferUse(vb, false);
} }
} }
int usage = convertUsage(vb.getUsage()); int usage = convertUsage(vb.getUsage());
vb.getData().rewind(); vb.getData().rewind();
@ -2314,7 +2314,7 @@ public class GLRenderer implements Renderer {
if (context.boundShaderProgram <= 0) { if (context.boundShaderProgram <= 0) {
throw new IllegalStateException("Cannot render mesh without shader bound"); throw new IllegalStateException("Cannot render mesh without shader bound");
} }
Attribute attrib = context.boundShader.getAttribute(vb.getBufferType()); Attribute attrib = context.boundShader.getAttribute(vb.getBufferType());
int loc = attrib.getLocation(); int loc = attrib.getLocation();
if (loc == -1) { if (loc == -1) {
@ -2444,7 +2444,7 @@ public class GLRenderer implements Renderer {
// What is this? // What is this?
throw new RendererException("Unexpected format for index buffer: " + indexBuf.getFormat()); throw new RendererException("Unexpected format for index buffer: " + indexBuf.getFormat());
} }
if (indexBuf.isUpdateNeeded()) { if (indexBuf.isUpdateNeeded()) {
updateBufferData(indexBuf); updateBufferData(indexBuf);
} }
@ -2561,7 +2561,7 @@ public class GLRenderer implements Renderer {
if (interleavedData != null && interleavedData.isUpdateNeeded()) { if (interleavedData != null && interleavedData.isUpdateNeeded()) {
updateBufferData(interleavedData); updateBufferData(interleavedData);
} }
if (instanceData != null) { if (instanceData != null) {
setVertexAttrib(instanceData, null); setVertexAttrib(instanceData, null);
} }
@ -2611,11 +2611,11 @@ public class GLRenderer implements Renderer {
} }
private void renderMeshDefault(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) { private void renderMeshDefault(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) {
// Here while count is still passed in. Can be removed when/if // Here while count is still passed in. Can be removed when/if
// the method is collapsed again. -pspeed // the method is collapsed again. -pspeed
count = Math.max(mesh.getInstanceCount(), count); count = Math.max(mesh.getInstanceCount(), count);
VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
if (interleavedData != null && interleavedData.isUpdateNeeded()) { if (interleavedData != null && interleavedData.isUpdateNeeded()) {
updateBufferData(interleavedData); updateBufferData(interleavedData);
@ -2633,7 +2633,7 @@ public class GLRenderer implements Renderer {
setVertexAttrib(vb, null); setVertexAttrib(vb, null);
} }
} }
for (VertexBuffer vb : mesh.getBufferList().getArray()) { for (VertexBuffer vb : mesh.getBufferList().getArray()) {
if (vb.getBufferType() == Type.InterleavedData if (vb.getBufferType() == Type.InterleavedData
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
@ -2703,12 +2703,12 @@ public class GLRenderer implements Renderer {
// Gamma correction // Gamma correction
if (!caps.contains(Caps.Srgb)) { if (!caps.contains(Caps.Srgb)) {
// Not supported, sorry. // Not supported, sorry.
logger.warning("sRGB framebuffer is not supported " + logger.warning("sRGB framebuffer is not supported " +
"by video hardware, but was requested."); "by video hardware, but was requested.");
return; return;
} }
setFrameBuffer(null); setFrameBuffer(null);
if (enableSrgb) { if (enableSrgb) {

@ -60,10 +60,10 @@ import java.util.logging.Logger;
public class J3MLoader implements AssetLoader { public class J3MLoader implements AssetLoader {
private static final Logger logger = Logger.getLogger(J3MLoader.class.getName()); private static final Logger logger = Logger.getLogger(J3MLoader.class.getName());
// private ErrorLogger errors; // private ErrorLogger errors;
private ShaderNodeLoaderDelegate nodesLoaderDelegate; private ShaderNodeLoaderDelegate nodesLoaderDelegate;
boolean isUseNodes = false; boolean isUseNodes = false;
private AssetManager assetManager; private AssetManager assetManager;
private AssetKey key; private AssetKey key;
@ -107,9 +107,9 @@ public class J3MLoader implements AssetLoader {
} }
// LightMode <MODE> // LightMode <MODE>
private void readLightMode(String statement) throws IOException { private void readLightMode(String statement) throws IOException{
String[] split = statement.split(whitespacePattern); String[] split = statement.split(whitespacePattern);
if (split.length != 2) { if (split.length != 2){
throw new IOException("LightMode statement syntax incorrect"); throw new IOException("LightMode statement syntax incorrect");
} }
LightMode lm = LightMode.valueOf(split[1]); LightMode lm = LightMode.valueOf(split[1]);
@ -117,29 +117,29 @@ public class J3MLoader implements AssetLoader {
} }
// ShadowMode <MODE> // ShadowMode <MODE>
private void readShadowMode(String statement) throws IOException { private void readShadowMode(String statement) throws IOException{
String[] split = statement.split(whitespacePattern); String[] split = statement.split(whitespacePattern);
if (split.length != 2) { if (split.length != 2){
throw new IOException("ShadowMode statement syntax incorrect"); throw new IOException("ShadowMode statement syntax incorrect");
} }
ShadowMode sm = ShadowMode.valueOf(split[1]); ShadowMode sm = ShadowMode.valueOf(split[1]);
technique.setShadowMode(sm); technique.setShadowMode(sm);
} }
private Object readValue(VarType type, String value) throws IOException { private Object readValue(VarType type, String value) throws IOException{
if (type.isTextureType()) { if (type.isTextureType()){
// String texturePath = readString("[\n;(//)(\\})]"); // String texturePath = readString("[\n;(//)(\\})]");
String texturePath = value.trim(); String texturePath = value.trim();
boolean flipY = false; boolean flipY = false;
boolean repeat = false; boolean repeat = false;
if (texturePath.startsWith("Flip Repeat ")) { if (texturePath.startsWith("Flip Repeat ")){
texturePath = texturePath.substring(12).trim(); texturePath = texturePath.substring(12).trim();
flipY = true; flipY = true;
repeat = true; repeat = true;
} else if (texturePath.startsWith("Flip ")) { }else if (texturePath.startsWith("Flip ")){
texturePath = texturePath.substring(5).trim(); texturePath = texturePath.substring(5).trim();
flipY = true; flipY = true;
} else if (texturePath.startsWith("Repeat ")) { }else if (texturePath.startsWith("Repeat ")){
texturePath = texturePath.substring(7).trim(); texturePath = texturePath.substring(7).trim();
repeat = true; repeat = true;
} }
@ -161,269 +161,270 @@ public class J3MLoader implements AssetLoader {
Texture tex; Texture tex;
try { try {
tex = assetManager.loadTexture(texKey); tex = assetManager.loadTexture(texKey);
} catch (AssetNotFoundException ex) { } catch (AssetNotFoundException ex){
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[]{texKey, key}); logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[]{texKey, key});
tex = null; tex = null;
} }
if (tex != null) { if (tex != null){
if (repeat) { if (repeat){
tex.setWrap(WrapMode.Repeat); tex.setWrap(WrapMode.Repeat);
} }
} else { }else{
tex = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager)); tex = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
if (repeat) { if (repeat){
tex.setWrap(WrapMode.Repeat); tex.setWrap(WrapMode.Repeat);
} }
tex.setKey(texKey); tex.setKey(texKey);
} }
return tex; return tex;
} else { }else{
String[] split = value.trim().split(whitespacePattern); String[] split = value.trim().split(whitespacePattern);
switch (type) { switch (type){
case Float: case Float:
if (split.length != 1) { if (split.length != 1){
throw new IOException("Float value parameter must have 1 entry: " + value); throw new IOException("Float value parameter must have 1 entry: " + value);
} }
return Float.parseFloat(split[0]); return Float.parseFloat(split[0]);
case Vector2: case Vector2:
if (split.length != 2) { if (split.length != 2){
throw new IOException("Vector2 value parameter must have 2 entries: " + value); throw new IOException("Vector2 value parameter must have 2 entries: " + value);
} }
return new Vector2f(Float.parseFloat(split[0]), return new Vector2f(Float.parseFloat(split[0]),
Float.parseFloat(split[1])); Float.parseFloat(split[1]));
case Vector3: case Vector3:
if (split.length != 3) { if (split.length != 3){
throw new IOException("Vector3 value parameter must have 3 entries: " + value); throw new IOException("Vector3 value parameter must have 3 entries: " + value);
} }
return new Vector3f(Float.parseFloat(split[0]), return new Vector3f(Float.parseFloat(split[0]),
Float.parseFloat(split[1]), Float.parseFloat(split[1]),
Float.parseFloat(split[2])); Float.parseFloat(split[2]));
case Vector4: case Vector4:
if (split.length != 4) { if (split.length != 4){
throw new IOException("Vector4 value parameter must have 4 entries: " + value); throw new IOException("Vector4 value parameter must have 4 entries: " + value);
} }
return new ColorRGBA(Float.parseFloat(split[0]), return new ColorRGBA(Float.parseFloat(split[0]),
Float.parseFloat(split[1]), Float.parseFloat(split[1]),
Float.parseFloat(split[2]), Float.parseFloat(split[2]),
Float.parseFloat(split[3])); Float.parseFloat(split[3]));
case Int: case Int:
if (split.length != 1) { if (split.length != 1){
throw new IOException("Int value parameter must have 1 entry: " + value); throw new IOException("Int value parameter must have 1 entry: " + value);
} }
return Integer.parseInt(split[0]); return Integer.parseInt(split[0]);
case Boolean: case Boolean:
if (split.length != 1) { if (split.length != 1){
throw new IOException("Boolean value parameter must have 1 entry: " + value); throw new IOException("Boolean value parameter must have 1 entry: " + value);
} }
return Boolean.parseBoolean(split[0]); return Boolean.parseBoolean(split[0]);
default: default:
throw new UnsupportedOperationException("Unknown type: " + type); throw new UnsupportedOperationException("Unknown type: "+type);
} }
} }
} }
// <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [ ":" <DEFAULTVAL> ] [-LINEAR] // <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [-LINEAR] [ ":" <DEFAULTVAL> ]
private void readParam(String statement) throws IOException { private void readParam(String statement) throws IOException{
String name; String name;
String defaultVal = null; String defaultVal = null;
ColorSpace colorSpace = null; ColorSpace colorSpace = null;
String[] split = statement.split(":"); String[] split = statement.split(":");
// Parse default val // Parse default val
if (split.length == 1) { if (split.length == 1){
// Doesn't contain default value // Doesn't contain default value
} else { }else{
if (split.length != 2) { if (split.length != 2){
throw new IOException("Parameter statement syntax incorrect"); throw new IOException("Parameter statement syntax incorrect");
} }
statement = split[0].trim(); statement = split[0].trim();
defaultVal = split[1].trim(); defaultVal = split[1].trim();
} }
if (statement.endsWith("-LINEAR")) { if (statement.endsWith("-LINEAR")) {
colorSpace = ColorSpace.Linear; colorSpace = ColorSpace.Linear;
statement = statement.substring(0, statement.length() - "-LINEAR".length()); statement = statement.substring(0, statement.length() - "-LINEAR".length());
} }
// Parse ffbinding // Parse ffbinding
int startParen = statement.indexOf("("); int startParen = statement.indexOf("(");
if (startParen != -1) { if (startParen != -1){
// get content inside parentheses // get content inside parentheses
int endParen = statement.indexOf(")", startParen); int endParen = statement.indexOf(")", startParen);
String bindingStr = statement.substring(startParen + 1, endParen).trim(); String bindingStr = statement.substring(startParen+1, endParen).trim();
// don't care about bindingStr // don't care about bindingStr
statement = statement.substring(0, startParen); statement = statement.substring(0, startParen);
} }
// Parse type + name // Parse type + name
split = statement.split(whitespacePattern); split = statement.split(whitespacePattern);
if (split.length != 2) { if (split.length != 2){
throw new IOException("Parameter statement syntax incorrect"); throw new IOException("Parameter statement syntax incorrect");
} }
VarType type; VarType type;
if (split[0].equals("Color")) { if (split[0].equals("Color")){
type = VarType.Vector4; type = VarType.Vector4;
} else { }else{
type = VarType.valueOf(split[0]); type = VarType.valueOf(split[0]);
} }
name = split[1]; name = split[1];
Object defaultValObj = null; Object defaultValObj = null;
if (defaultVal != null) { if (defaultVal != null){
defaultValObj = readValue(type, defaultVal); defaultValObj = readValue(type, defaultVal);
} }
if (type.isTextureType()) { if(type.isTextureType()){
materialDef.addMaterialParamTexture(type, name, colorSpace); materialDef.addMaterialParamTexture(type, name, colorSpace);
} else { }else{
materialDef.addMaterialParam(type, name, defaultValObj); materialDef.addMaterialParam(type, name, defaultValObj);
} }
} }
private void readValueParam(String statement) throws IOException { private void readValueParam(String statement) throws IOException{
// Use limit=1 incase filename contains colons // Use limit=1 incase filename contains colons
String[] split = statement.split(":", 2); String[] split = statement.split(":", 2);
if (split.length != 2) { if (split.length != 2){
throw new IOException("Value parameter statement syntax incorrect"); throw new IOException("Value parameter statement syntax incorrect");
} }
String name = split[0].trim(); String name = split[0].trim();
// parse value // parse value
MatParam p = material.getMaterialDef().getMaterialParam(name); MatParam p = material.getMaterialDef().getMaterialParam(name);
if (p == null) { if (p == null){
throw new IOException("The material parameter: " + name + " is undefined."); throw new IOException("The material parameter: "+name+" is undefined.");
} }
Object valueObj = readValue(p.getVarType(), split[1]); Object valueObj = readValue(p.getVarType(), split[1]);
if (p.getVarType().isTextureType()) { if (p.getVarType().isTextureType()){
material.setTextureParam(name, p.getVarType(), (Texture) valueObj); material.setTextureParam(name, p.getVarType(), (Texture) valueObj);
} else { }else{
material.setParam(name, p.getVarType(), valueObj); material.setParam(name, p.getVarType(), valueObj);
} }
} }
private void readMaterialParams(List<Statement> paramsList) throws IOException { private void readMaterialParams(List<Statement> paramsList) throws IOException{
for (Statement statement : paramsList) { for (Statement statement : paramsList){
readParam(statement.getLine()); readParam(statement.getLine());
} }
} }
private void readExtendingMaterialParams(List<Statement> paramsList) throws IOException { private void readExtendingMaterialParams(List<Statement> paramsList) throws IOException{
for (Statement statement : paramsList) { for (Statement statement : paramsList){
readValueParam(statement.getLine()); readValueParam(statement.getLine());
} }
} }
private void readWorldParams(List<Statement> worldParams) throws IOException { private void readWorldParams(List<Statement> worldParams) throws IOException{
for (Statement statement : worldParams) { for (Statement statement : worldParams){
technique.addWorldParam(statement.getLine()); technique.addWorldParam(statement.getLine());
} }
} }
private boolean parseBoolean(String word) { private boolean parseBoolean(String word){
return word != null && word.equals("On"); return word != null && word.equals("On");
} }
private void readRenderStateStatement(Statement statement) throws IOException { private void readRenderStateStatement(Statement statement) throws IOException{
String[] split = statement.getLine().split(whitespacePattern); String[] split = statement.getLine().split(whitespacePattern);
if (split[0].equals("Wireframe")) { if (split[0].equals("Wireframe")){
renderState.setWireframe(parseBoolean(split[1])); renderState.setWireframe(parseBoolean(split[1]));
} else if (split[0].equals("FaceCull")) { }else if (split[0].equals("FaceCull")){
renderState.setFaceCullMode(FaceCullMode.valueOf(split[1])); renderState.setFaceCullMode(FaceCullMode.valueOf(split[1]));
} else if (split[0].equals("DepthWrite")) { }else if (split[0].equals("DepthWrite")){
renderState.setDepthWrite(parseBoolean(split[1])); renderState.setDepthWrite(parseBoolean(split[1]));
} else if (split[0].equals("DepthTest")) { }else if (split[0].equals("DepthTest")){
renderState.setDepthTest(parseBoolean(split[1])); renderState.setDepthTest(parseBoolean(split[1]));
} else if (split[0].equals("Blend")) { }else if (split[0].equals("Blend")){
renderState.setBlendMode(BlendMode.valueOf(split[1])); renderState.setBlendMode(BlendMode.valueOf(split[1]));
} else if (split[0].equals("AlphaTestFalloff")) { }else if (split[0].equals("AlphaTestFalloff")){
renderState.setAlphaTest(true); renderState.setAlphaTest(true);
renderState.setAlphaFallOff(Float.parseFloat(split[1])); renderState.setAlphaFallOff(Float.parseFloat(split[1]));
} else if (split[0].equals("PolyOffset")) { }else if (split[0].equals("PolyOffset")){
float factor = Float.parseFloat(split[1]); float factor = Float.parseFloat(split[1]);
float units = Float.parseFloat(split[2]); float units = Float.parseFloat(split[2]);
renderState.setPolyOffset(factor, units); renderState.setPolyOffset(factor, units);
} else if (split[0].equals("ColorWrite")) { }else if (split[0].equals("ColorWrite")){
renderState.setColorWrite(parseBoolean(split[1])); renderState.setColorWrite(parseBoolean(split[1]));
} else if (split[0].equals("PointSprite")) { }else if (split[0].equals("PointSprite")){
renderState.setPointSprite(parseBoolean(split[1])); renderState.setPointSprite(parseBoolean(split[1]));
} else if (split[0].equals("DepthFunc")) { }else if (split[0].equals("DepthFunc")){
renderState.setDepthFunc(RenderState.TestFunction.valueOf(split[1])); renderState.setDepthFunc(RenderState.TestFunction.valueOf(split[1]));
} else if (split[0].equals("AlphaFunc")) { }else if (split[0].equals("AlphaFunc")){
renderState.setAlphaFunc(RenderState.TestFunction.valueOf(split[1])); renderState.setAlphaFunc(RenderState.TestFunction.valueOf(split[1]));
} else { } else {
throw new MatParseException(null, split[0], statement); throw new MatParseException(null, split[0], statement);
} }
} }
private void readAdditionalRenderState(List<Statement> renderStates) throws IOException { private void readAdditionalRenderState(List<Statement> renderStates) throws IOException{
renderState = material.getAdditionalRenderState(); renderState = material.getAdditionalRenderState();
for (Statement statement : renderStates) { for (Statement statement : renderStates){
readRenderStateStatement(statement); readRenderStateStatement(statement);
} }
renderState = null; renderState = null;
} }
private void readRenderState(List<Statement> renderStates) throws IOException { private void readRenderState(List<Statement> renderStates) throws IOException{
renderState = new RenderState(); renderState = new RenderState();
for (Statement statement : renderStates) { for (Statement statement : renderStates){
readRenderStateStatement(statement); readRenderStateStatement(statement);
} }
technique.setRenderState(renderState); technique.setRenderState(renderState);
renderState = null; renderState = null;
} }
private void readForcedRenderState(List<Statement> renderStates) throws IOException { private void readForcedRenderState(List<Statement> renderStates) throws IOException{
renderState = new RenderState(); renderState = new RenderState();
for (Statement statement : renderStates) { for (Statement statement : renderStates){
readRenderStateStatement(statement); readRenderStateStatement(statement);
} }
technique.setForcedRenderState(renderState); technique.setForcedRenderState(renderState);
renderState = null; renderState = null;
} }
// <DEFINENAME> [ ":" <PARAMNAME> ] // <DEFINENAME> [ ":" <PARAMNAME> ]
private void readDefine(String statement) throws IOException { private void readDefine(String statement) throws IOException{
String[] split = statement.split(":"); String[] split = statement.split(":");
if (split.length == 1) { if (split.length == 1){
// add preset define // add preset define
technique.addShaderPresetDefine(split[0].trim(), VarType.Boolean, true); technique.addShaderPresetDefine(split[0].trim(), VarType.Boolean, true);
} else if (split.length == 2) { }else if (split.length == 2){
technique.addShaderParamDefine(split[1].trim(), split[0].trim()); technique.addShaderParamDefine(split[1].trim(), split[0].trim());
} else { }else{
throw new IOException("Define syntax incorrect"); throw new IOException("Define syntax incorrect");
} }
} }
private void readDefines(List<Statement> defineList) throws IOException { private void readDefines(List<Statement> defineList) throws IOException{
for (Statement statement : defineList) { for (Statement statement : defineList){
readDefine(statement.getLine()); readDefine(statement.getLine());
} }
} }
private void readTechniqueStatement(Statement statement) throws IOException { private void readTechniqueStatement(Statement statement) throws IOException{
String[] split = statement.getLine().split("[ \\{]"); String[] split = statement.getLine().split("[ \\{]");
if (split[0].equals("VertexShader") || if (split[0].equals("VertexShader") ||
split[0].equals("FragmentShader") || split[0].equals("FragmentShader") ||
split[0].equals("GeometryShader") || split[0].equals("GeometryShader") ||
split[0].equals("TessellationControlShader") || split[0].equals("TessellationControlShader") ||
split[0].equals("TessellationEvaluationShader")) { split[0].equals("TessellationEvaluationShader")) {
readShaderStatement(statement.getLine()); readShaderStatement(statement.getLine());
} else if (split[0].equals("LightMode")) { }else if (split[0].equals("LightMode")){
readLightMode(statement.getLine()); readLightMode(statement.getLine());
} else if (split[0].equals("ShadowMode")) { }else if (split[0].equals("ShadowMode")){
readShadowMode(statement.getLine()); readShadowMode(statement.getLine());
} else if (split[0].equals("WorldParameters")) { }else if (split[0].equals("WorldParameters")){
readWorldParams(statement.getContents()); readWorldParams(statement.getContents());
} else if (split[0].equals("RenderState")) { }else if (split[0].equals("RenderState")){
readRenderState(statement.getContents()); readRenderState(statement.getContents());
} else if (split[0].equals("ForcedRenderState")) { }else if (split[0].equals("ForcedRenderState")){
readForcedRenderState(statement.getContents()); readForcedRenderState(statement.getContents());
} else if (split[0].equals("Defines")) { }else if (split[0].equals("Defines")){
readDefines(statement.getContents()); readDefines(statement.getContents());
} else if (split[0].equals("ShaderNodesDefinitions")) { } else if (split[0].equals("ShaderNodesDefinitions")) {
initNodesLoader(); initNodesLoader();
if (isUseNodes) { if (isUseNodes) {
@ -436,23 +437,23 @@ public class J3MLoader implements AssetLoader {
} }
} else if (split[0].equals("FragmentShaderNodes")) { } else if (split[0].equals("FragmentShaderNodes")) {
initNodesLoader(); initNodesLoader();
if (isUseNodes) { if (isUseNodes) {
nodesLoaderDelegate.readFragmentShaderNodes(statement.getContents()); nodesLoaderDelegate.readFragmentShaderNodes(statement.getContents());
} }
} else { } else {
throw new MatParseException(null, split[0], statement); throw new MatParseException(null, split[0], statement);
} }
} }
private void readTransparentStatement(String statement) throws IOException { private void readTransparentStatement(String statement) throws IOException{
String[] split = statement.split(whitespacePattern); String[] split = statement.split(whitespacePattern);
if (split.length != 2) { if (split.length != 2){
throw new IOException("Transparent statement syntax incorrect"); throw new IOException("Transparent statement syntax incorrect");
} }
material.setTransparent(parseBoolean(split[1])); material.setTransparent(parseBoolean(split[1]));
} }
private void readTechnique(Statement techStat) throws IOException { private void readTechnique(Statement techStat) throws IOException{
isUseNodes = false; isUseNodes = false;
String[] split = techStat.getLine().split(whitespacePattern); String[] split = techStat.getLine().split(whitespacePattern);
if (split.length == 1) { if (split.length == 1) {
@ -463,12 +464,12 @@ public class J3MLoader implements AssetLoader {
} else { } else {
throw new IOException("Technique statement syntax incorrect"); throw new IOException("Technique statement syntax incorrect");
} }
for (Statement statement : techStat.getContents()) { for (Statement statement : techStat.getContents()){
readTechniqueStatement(statement); readTechniqueStatement(statement);
} }
if (isUseNodes) { if(isUseNodes){
nodesLoaderDelegate.computeConditions(); nodesLoaderDelegate.computeConditions();
//used for caching later, the shader here is not a file. //used for caching later, the shader here is not a file.
technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100"); technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
@ -477,48 +478,48 @@ public class J3MLoader implements AssetLoader {
if (shaderName.containsKey(Shader.ShaderType.Vertex) && shaderName.containsKey(Shader.ShaderType.Fragment)) { if (shaderName.containsKey(Shader.ShaderType.Vertex) && shaderName.containsKey(Shader.ShaderType.Fragment)) {
technique.setShaderFile(shaderName, shaderLanguage); technique.setShaderFile(shaderName, shaderLanguage);
} }
materialDef.addTechniqueDef(technique); materialDef.addTechniqueDef(technique);
technique = null; technique = null;
shaderLanguage.clear(); shaderLanguage.clear();
shaderName.clear(); shaderName.clear();
} }
private void loadFromRoot(List<Statement> roots) throws IOException { private void loadFromRoot(List<Statement> roots) throws IOException{
if (roots.size() == 2) { if (roots.size() == 2){
Statement exception = roots.get(0); Statement exception = roots.get(0);
String line = exception.getLine(); String line = exception.getLine();
if (line.startsWith("Exception")) { if (line.startsWith("Exception")){
throw new AssetLoadException(line.substring("Exception ".length())); throw new AssetLoadException(line.substring("Exception ".length()));
} else { }else{
throw new IOException("In multiroot material, expected first statement to be 'Exception'"); throw new IOException("In multiroot material, expected first statement to be 'Exception'");
} }
} else if (roots.size() != 1) { }else if (roots.size() != 1){
throw new IOException("Too many roots in J3M/J3MD file"); throw new IOException("Too many roots in J3M/J3MD file");
} }
boolean extending = false; boolean extending = false;
Statement materialStat = roots.get(0); Statement materialStat = roots.get(0);
String materialName = materialStat.getLine(); String materialName = materialStat.getLine();
if (materialName.startsWith("MaterialDef")) { if (materialName.startsWith("MaterialDef")){
materialName = materialName.substring("MaterialDef ".length()).trim(); materialName = materialName.substring("MaterialDef ".length()).trim();
extending = false; extending = false;
} else if (materialName.startsWith("Material")) { }else if (materialName.startsWith("Material")){
materialName = materialName.substring("Material ".length()).trim(); materialName = materialName.substring("Material ".length()).trim();
extending = true; extending = true;
} else { }else{
throw new IOException("Specified file is not a Material file"); throw new IOException("Specified file is not a Material file");
} }
String[] split = materialName.split(":", 2); String[] split = materialName.split(":", 2);
if (materialName.equals("")) { if (materialName.equals("")){
throw new MatParseException("Material name cannot be empty", materialStat); throw new MatParseException("Material name cannot be empty", materialStat);
} }
if (split.length == 2) { if (split.length == 2){
if (!extending) { if (!extending){
throw new MatParseException("Must use 'Material' when extending.", materialStat); throw new MatParseException("Must use 'Material' when extending.", materialStat);
} }
String extendedMat = split[1].trim(); String extendedMat = split[1].trim();
@ -531,65 +532,65 @@ public class J3MLoader implements AssetLoader {
material = new Material(def); material = new Material(def);
material.setKey(key); material.setKey(key);
// material.setAssetName(fileName); // material.setAssetName(fileName);
} else if (split.length == 1) { }else if (split.length == 1){
if (extending) { if (extending){
throw new MatParseException("Expected ':', got '{'", materialStat); throw new MatParseException("Expected ':', got '{'", materialStat);
} }
materialDef = new MaterialDef(assetManager, materialName); materialDef = new MaterialDef(assetManager, materialName);
// NOTE: pass file name for defs so they can be loaded later // NOTE: pass file name for defs so they can be loaded later
materialDef.setAssetName(key.getName()); materialDef.setAssetName(key.getName());
} else { }else{
throw new MatParseException("Cannot use colon in material name/path", materialStat); throw new MatParseException("Cannot use colon in material name/path", materialStat);
} }
for (Statement statement : materialStat.getContents()) { for (Statement statement : materialStat.getContents()){
split = statement.getLine().split("[ \\{]"); split = statement.getLine().split("[ \\{]");
String statType = split[0]; String statType = split[0];
if (extending) { if (extending){
if (statType.equals("MaterialParameters")) { if (statType.equals("MaterialParameters")){
readExtendingMaterialParams(statement.getContents()); readExtendingMaterialParams(statement.getContents());
} else if (statType.equals("AdditionalRenderState")) { }else if (statType.equals("AdditionalRenderState")){
readAdditionalRenderState(statement.getContents()); readAdditionalRenderState(statement.getContents());
} else if (statType.equals("Transparent")) { }else if (statType.equals("Transparent")){
readTransparentStatement(statement.getLine()); readTransparentStatement(statement.getLine());
} }
} else { }else{
if (statType.equals("Technique")) { if (statType.equals("Technique")){
readTechnique(statement); readTechnique(statement);
} else if (statType.equals("MaterialParameters")) { }else if (statType.equals("MaterialParameters")){
readMaterialParams(statement.getContents()); readMaterialParams(statement.getContents());
} else { }else{
throw new MatParseException("Expected material statement, got '" + statType + "'", statement); throw new MatParseException("Expected material statement, got '"+statType+"'", statement);
} }
} }
} }
} }
public Object load(AssetInfo info) throws IOException { public Object load(AssetInfo info) throws IOException {
this.assetManager = info.getManager(); this.assetManager = info.getManager();
InputStream in = info.openStream(); InputStream in = info.openStream();
try { try {
key = info.getKey(); key = info.getKey();
loadFromRoot(BlockLanguageParser.parse(in)); loadFromRoot(BlockLanguageParser.parse(in));
} finally { } finally {
if (in != null) { if (in != null){
in.close(); in.close();
} }
} }
if (material != null) { if (material != null){
if (!(info.getKey() instanceof MaterialKey)) { if (!(info.getKey() instanceof MaterialKey)){
throw new IOException("Material instances must be loaded via MaterialKey"); throw new IOException("Material instances must be loaded via MaterialKey");
} }
// material implementation // material implementation
return material; return material;
} else { }else{
// material definition // material definition
return materialDef; return materialDef;
} }
} }
public MaterialDef loadMaterialDef(List<Statement> roots, AssetManager manager, AssetKey key) throws IOException { public MaterialDef loadMaterialDef(List<Statement> roots, AssetManager manager, AssetKey key) throws IOException {
this.key = key; this.key = key;
this.assetManager = manager; this.assetManager = manager;
@ -603,7 +604,7 @@ public class J3MLoader implements AssetLoader {
if (isUseNodes) { if (isUseNodes) {
if (nodesLoaderDelegate == null) { if (nodesLoaderDelegate == null) {
nodesLoaderDelegate = new ShaderNodeLoaderDelegate(); nodesLoaderDelegate = new ShaderNodeLoaderDelegate();
} else { }else{
nodesLoaderDelegate.clear(); nodesLoaderDelegate.clear();
} }
nodesLoaderDelegate.setTechniqueDef(technique); nodesLoaderDelegate.setTechniqueDef(technique);
@ -611,6 +612,6 @@ public class J3MLoader implements AssetLoader {
nodesLoaderDelegate.setAssetManager(assetManager); nodesLoaderDelegate.setAssetManager(assetManager);
} }
} }
} }
} }

Loading…
Cancel
Save