[DEV] continue rework
This commit is contained in:
parent
ea087ef912
commit
da0e6810f6
@ -91,10 +91,5 @@
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jReactPhysics3D">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="out/eclipse/classes"/>
|
||||
</classpath>
|
||||
|
@ -8,9 +8,9 @@ open module org.atriasoft.gale {
|
||||
exports org.atriasoft.gale.context;
|
||||
//exports org.atriasoft.gale.context.JOGL;
|
||||
exports org.atriasoft.gale.context.LWJG_AWT;
|
||||
exports org.atriasoft.gale.event;
|
||||
exports org.atriasoft.gale.key;
|
||||
exports org.atriasoft.gale.resource;
|
||||
|
||||
requires transitive org.atriasoft.etk;
|
||||
|
||||
//requires transitive vecmath;
|
||||
@ -20,8 +20,8 @@ open module org.atriasoft.gale {
|
||||
requires transitive org.lwjgl.glfw.natives;
|
||||
requires transitive org.lwjgl.assimp;
|
||||
requires transitive org.lwjgl.assimp.natives;
|
||||
// requires transitive org.lwjgl.openal;
|
||||
// requires transitive org.lwjgl.openal.natives;
|
||||
// requires transitive org.lwjgl.openal;
|
||||
// requires transitive org.lwjgl.openal.natives;
|
||||
requires transitive org.lwjgl.stb;
|
||||
requires transitive org.lwjgl.stb.natives;
|
||||
requires transitive org.lwjgl.jawt;
|
||||
|
347
src/org/atriasoft/gale/Dimension.java
Normal file
347
src/org/atriasoft/gale/Dimension.java
Normal file
@ -0,0 +1,347 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
package org.atriasoft.gale;
|
||||
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
|
||||
/**
|
||||
* @brief in the dimention class we store the data as the more usefull unit (pixel)
|
||||
* but one case need to be dynamic the %, then when requested in % the register the % value
|
||||
*/
|
||||
public class Dimension {
|
||||
private final static Vector2f ratio = new Vector2f(9999999, 888888);
|
||||
private final static Vector2f invRatio = new Vector2f(1, 1);
|
||||
private final static Dimension windowsSize = new Dimension(new Vector2f(9999999, 888888), Distance.PIXEL);
|
||||
|
||||
public final static float INCH_TO_MILLIMETER = 1.0f / 25.4f;
|
||||
public final static float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
|
||||
public final static float METER_TO_MILLIMETER = 1.0f / 1000.0f;
|
||||
public final static float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f;
|
||||
public final static float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f;
|
||||
public final static float MILLIMETER_TO_INCH = 25.4f;
|
||||
public final static float MILLIMETER_TO_FOOT = 304.8f;
|
||||
public final static float MILLIMETER_TO_METER = 1000.0f;
|
||||
public final static float MILLIMETER_TO_CENTIMETER = 10.0f;
|
||||
public final static float MILLIMETER_TO_KILOMETER = 1000000.0f;
|
||||
/**
|
||||
* @brief basic init
|
||||
*/
|
||||
static {
|
||||
final Dimension conversion = new Dimension(new Vector2f(72, 72), Distance.INCH);
|
||||
ratio.set(conversion.getMillimeter());
|
||||
invRatio.setValue(1.0f / ratio.x, 1.0f / ratio.y);
|
||||
windowsSize.set(new Vector2f(200, 200), Distance.PIXEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the Windows diagonal size in the request unit
|
||||
* @param[in] type Unit type requested.
|
||||
* @return the requested size
|
||||
*/
|
||||
public static float getWindowsDiag(final Distance _type) {
|
||||
final Vector2f size = getWindowsSize(_type);
|
||||
return size.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the Windows size in the request unit
|
||||
* @param[in] type Unit type requested.
|
||||
* @return the requested size
|
||||
*/
|
||||
public static Vector2f getWindowsSize(final Distance _type) {
|
||||
return windowsSize.get(_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the Milimeter ratio for calculation
|
||||
* @param[in] Ratio Milimeter ration for the screen calculation interpolation
|
||||
* @param[in] type Unit type requested.
|
||||
* @note: same as @ref setPixelPerInch (internal manage convertion)
|
||||
*/
|
||||
public static void setPixelRatio(final Vector2f _ratio, final Distance _type) {
|
||||
Log.info("Set a new screen ratio for the screen : ratio=" + _ratio + " type=" + _type);
|
||||
final Dimension conversion = new Dimension(_ratio, _type);
|
||||
Log.info(" == > " + conversion);
|
||||
ratio.set(conversion.getMillimeter());
|
||||
invRatio.setValue(1.0f / ratio.x, 1.0f / ratio.y);
|
||||
Log.info("Set a new screen ratio for the screen : ratioMm=" + ratio);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the current Windows size
|
||||
* @param[in] size size of the current windows in pixel.
|
||||
*/
|
||||
public static void setPixelWindowsSize(final Vector2f _size) {
|
||||
windowsSize.set(_size);
|
||||
Log.verbose("Set a new Windows property size " + windowsSize + "px");
|
||||
}
|
||||
|
||||
private Vector2f size = new Vector2f(0, 0);
|
||||
private Distance type = Distance.PIXEL;
|
||||
|
||||
/**
|
||||
* @brief Constructor (default :0,0 mode pixel)
|
||||
*/
|
||||
public Dimension() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _config dimension configuration.
|
||||
*/
|
||||
public Dimension(final String _config) {
|
||||
set(_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _size Requested dimension
|
||||
* @param[in] _type Unit of the Dimension
|
||||
*/
|
||||
public Dimension(final Vector2f _size) {
|
||||
set(_size, Distance.PIXEL);
|
||||
}
|
||||
|
||||
public Dimension(final Vector2f _size, final Distance _type) {
|
||||
set(_size, _type);
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* isEqual
|
||||
*****************************************************/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof Dimension)) {
|
||||
return false;
|
||||
}
|
||||
final Dimension other = (Dimension) obj;
|
||||
return this.size.equals(other.size) && this.type == other.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in requested type
|
||||
* @param[in] _type Type of unit requested.
|
||||
* @return dimention requested.
|
||||
*/
|
||||
public Vector2f get(final Distance _type) {
|
||||
switch (_type) {
|
||||
case POURCENT:
|
||||
return getPourcent();
|
||||
case PIXEL:
|
||||
return getPixel();
|
||||
case METER:
|
||||
return getMeter();
|
||||
case CENTIMETER:
|
||||
return getCentimeter();
|
||||
case MILLIMETER:
|
||||
return getMillimeter();
|
||||
case KILOMETER:
|
||||
return getKilometer();
|
||||
case INCH:
|
||||
return getInch();
|
||||
case FOOT:
|
||||
return getFoot();
|
||||
}
|
||||
return new Vector2f(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Centimeter
|
||||
* @return dimention in Centimeter
|
||||
*/
|
||||
public Vector2f getCentimeter() {
|
||||
return getMillimeter().multiplyNew(MILLIMETER_TO_CENTIMETER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Foot
|
||||
* @return dimention in Foot
|
||||
*/
|
||||
public Vector2f getFoot() {
|
||||
return getMillimeter().multiplyNew(MILLIMETER_TO_FOOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Inch
|
||||
* @return dimention in Inch
|
||||
*/
|
||||
public Vector2f getInch() {
|
||||
return getMillimeter().multiplyNew(MILLIMETER_TO_INCH);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Kilometer
|
||||
* @return dimention in Kilometer
|
||||
*/
|
||||
public Vector2f getKilometer() {
|
||||
return getMillimeter().multiplyNew(MILLIMETER_TO_KILOMETER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Meter
|
||||
* @return dimention in Meter
|
||||
*/
|
||||
public Vector2f getMeter() {
|
||||
return getMillimeter().multiplyNew(MILLIMETER_TO_METER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Millimeter
|
||||
* @return dimention in Millimeter
|
||||
*/
|
||||
public Vector2f getMillimeter() {
|
||||
return new Vector2f(getPixel().x * invRatio.x, getPixel().y * invRatio.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in pixel
|
||||
* @return dimention in Pixel
|
||||
*/
|
||||
public Vector2f getPixel() {
|
||||
if (this.type != Distance.POURCENT) {
|
||||
return this.size;
|
||||
} else {
|
||||
final Vector2f windDim = windowsSize.getPixel();
|
||||
final Vector2f res = new Vector2f(windDim.x * this.size.x, windDim.y * this.size.y);
|
||||
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current dimention in Pourcent
|
||||
* @return dimention in Pourcent
|
||||
*/
|
||||
public Vector2f getPourcent() {
|
||||
if (this.type != Distance.POURCENT) {
|
||||
final Vector2f windDim = windowsSize.getPixel();
|
||||
//GALE_DEBUG(" windows dimention : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ...
|
||||
//printf(" windows dimention : %f,%f", windDim.x(),windDim.y());
|
||||
//printf(" data : %f,%f", m_data.x(),m_data.y());
|
||||
return new Vector2f((this.size.x / windDim.x) * 100.0f, (this.size.y / windDim.y) * 100.0f);
|
||||
}
|
||||
return new Vector2f(this.size.x * 100.0f, this.size.y * 100.0f);
|
||||
};
|
||||
|
||||
/**
|
||||
* @breif get the dimension type
|
||||
* @return the type
|
||||
*/
|
||||
public Distance getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* assigment
|
||||
*****************************************************/
|
||||
public Dimension set(final Dimension _obj) {
|
||||
if (this != _obj) {
|
||||
this.size = _obj.size;
|
||||
this.type = _obj.type;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the current dimention in requested type
|
||||
* @param[in] _config dimension configuration.
|
||||
*/
|
||||
private void set(String _config) {
|
||||
this.size.setValue(0, 0);
|
||||
this.type = Distance.PIXEL;
|
||||
Distance type = Distance.PIXEL;
|
||||
if (_config.endsWith("%") == true) {
|
||||
type = Distance.POURCENT;
|
||||
_config = _config.substring(0, _config.length() - 1);
|
||||
} else if (_config.endsWith("px") == true) {
|
||||
type = Distance.PIXEL;
|
||||
_config = _config.substring(0, _config.length() - 2);
|
||||
} else if (_config.endsWith("ft") == true) {
|
||||
type = Distance.FOOT;
|
||||
_config = _config.substring(0, _config.length() - 2);
|
||||
} else if (_config.endsWith("in") == true) {
|
||||
type = Distance.INCH;
|
||||
_config = _config.substring(0, _config.length() - 2);
|
||||
} else if (_config.endsWith("km") == true) {
|
||||
type = Distance.KILOMETER;
|
||||
_config = _config.substring(0, _config.length() - 2);
|
||||
} else if (_config.endsWith("mm") == true) {
|
||||
type = Distance.MILLIMETER;
|
||||
_config = _config.substring(0, _config.length() - 2);
|
||||
} else if (_config.endsWith("cm") == true) {
|
||||
type = Distance.CENTIMETER;
|
||||
_config = _config.substring(0, _config.length() - 2);
|
||||
} else if (_config.endsWith("m") == true) {
|
||||
type = Distance.METER;
|
||||
_config = _config.substring(0, _config.length() - 1);
|
||||
} else {
|
||||
Log.critical("Can not parse dimention : '" + _config + "'");
|
||||
return;
|
||||
}
|
||||
final Vector2f tmp = Vector2f.valueOf(_config);
|
||||
set(tmp, type);
|
||||
Log.verbose(" config dimention : \"" + _config + "\" == > " + this);
|
||||
}
|
||||
|
||||
public void set(final Vector2f _size) {
|
||||
this.size = _size;
|
||||
this.type = Distance.PIXEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the current dimention in requested type
|
||||
* @param[in] _size Dimention to set
|
||||
* @param[in] _type Type of unit requested.
|
||||
*/
|
||||
public void set(final Vector2f _size, final Distance _type) {
|
||||
this.size = _size;
|
||||
this.type = _type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief string cast :
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String str = get(getType()).toString();
|
||||
switch (getType()) {
|
||||
case POURCENT:
|
||||
str += "%";
|
||||
break;
|
||||
case PIXEL:
|
||||
str += "px";
|
||||
break;
|
||||
case METER:
|
||||
str += "m";
|
||||
break;
|
||||
case CENTIMETER:
|
||||
str += "cm";
|
||||
break;
|
||||
case MILLIMETER:
|
||||
str += "mm";
|
||||
break;
|
||||
case KILOMETER:
|
||||
str += "km";
|
||||
break;
|
||||
case INCH:
|
||||
str += "in";
|
||||
break;
|
||||
case FOOT:
|
||||
str += "ft";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
}
|
12
src/org/atriasoft/gale/Distance.java
Normal file
12
src/org/atriasoft/gale/Distance.java
Normal file
@ -0,0 +1,12 @@
|
||||
package org.atriasoft.gale;
|
||||
|
||||
public enum Distance {
|
||||
POURCENT,
|
||||
PIXEL,
|
||||
METER,
|
||||
CENTIMETER,
|
||||
MILLIMETER,
|
||||
KILOMETER,
|
||||
INCH,
|
||||
FOOT;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,50 +0,0 @@
|
||||
package org.atriasoft.gale.event;
|
||||
|
||||
import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
|
||||
public class EventEntry {
|
||||
private KeySpecial specialKey; //!< input key status (prevent change in time..)
|
||||
private KeyKeyboard type; //!< type of hardware event
|
||||
private KeyStatus status; //!< status of hardware event
|
||||
private Character unicodeData; //!< Unicode data (in some case)
|
||||
public EventEntry(KeySpecial specialKey,
|
||||
KeyKeyboard type,
|
||||
KeyStatus status,
|
||||
Character charValue) {
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.specialKey = specialKey;
|
||||
this.unicodeData = charValue;
|
||||
}
|
||||
public void setType(KeyKeyboard type) {
|
||||
this.type = type;
|
||||
}
|
||||
public KeyKeyboard getType() {
|
||||
return this.type;
|
||||
}
|
||||
public void setStatus(KeyStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
public KeyStatus getStatus() {
|
||||
return this.status;
|
||||
};
|
||||
public void setSpecialKey(KeySpecial specialKey) {
|
||||
this.specialKey = specialKey;
|
||||
}
|
||||
public KeySpecial getSpecialKey() {
|
||||
return this.specialKey;
|
||||
}
|
||||
public void setChar(Character charValue) {
|
||||
this.unicodeData = charValue;
|
||||
}
|
||||
public Character getChar() {
|
||||
return this.unicodeData;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventEntry [type=" + type + ", status=" + status + ", unicodeData="
|
||||
+ unicodeData + ", specialKey=" + specialKey + "]";
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package org.atriasoft.gale.event;
|
||||
|
||||
import org.atriasoft.gale.key.KeyType;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
|
||||
public class EventInput {
|
||||
private KeyType type;
|
||||
private KeyStatus status;
|
||||
private int inputId;
|
||||
private Vector2f position;
|
||||
private KeySpecial specialKey; //!< input key status (prevent change in time..)
|
||||
public EventInput(KeyType type, KeyStatus status, int inputId, Vector2f position, KeySpecial specialKey) {
|
||||
this.type = type;
|
||||
this.status = status;
|
||||
this.inputId = inputId;
|
||||
this.position = position;
|
||||
this.specialKey = specialKey;
|
||||
}
|
||||
public KeyType getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(KeyType type) {
|
||||
this.type = type;
|
||||
}
|
||||
public KeyStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(KeyStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
public int getInputId() {
|
||||
return inputId;
|
||||
}
|
||||
public void setInputId(int inputId) {
|
||||
this.inputId = inputId;
|
||||
}
|
||||
public Vector2f getPosition() {
|
||||
return position;
|
||||
}
|
||||
public void setPosition(Vector2f position) {
|
||||
this.position = position;
|
||||
}
|
||||
public KeySpecial getSpecialKey() {
|
||||
return specialKey;
|
||||
}
|
||||
public void setSpecialKey(KeySpecial specialKey) {
|
||||
this.specialKey = specialKey;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventInput [type=" + type + ", status=" + status + ", inputId=" + inputId + ", position=" + position
|
||||
+ ", specialKey=" + specialKey + "]";
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package org.atriasoft.gale.event;
|
||||
|
||||
public class EventTime {
|
||||
private long timeSystem; //!< Current system time (micro-second)
|
||||
private long timeUpAppl; //!< Current application wake up-time (micro-second)
|
||||
private long timeDelta; //!< Time from the last cycle call of the system (main appl tick) (micro-second)
|
||||
private long timeDeltaCall; //!< Time from the last call (when we can manage periodic call with specifying periode) (micro-second)
|
||||
public EventTime(long timeSystem, long timeUpAppl, long timeDelta, long timeDeltaCall) {
|
||||
super();
|
||||
this.timeSystem = timeSystem;
|
||||
this.timeUpAppl = timeUpAppl;
|
||||
this.timeDelta = timeDelta;
|
||||
this.timeDeltaCall = timeDeltaCall;
|
||||
}
|
||||
public long getTimeSystem() {
|
||||
return timeSystem;
|
||||
}
|
||||
public void setTimeSystem(long timeSystem) {
|
||||
this.timeSystem = timeSystem;
|
||||
}
|
||||
public long getTimeUpAppl() {
|
||||
return timeUpAppl;
|
||||
}
|
||||
public void setTimeUpAppl(long timeUpAppl) {
|
||||
this.timeUpAppl = timeUpAppl;
|
||||
}
|
||||
public long getTimeDelta() {
|
||||
return timeDelta;
|
||||
}
|
||||
public float getTimeDeltaSecond() {
|
||||
return (float)timeDelta*0.0000001f;
|
||||
}
|
||||
public void setTimeDelta(long timeDelta) {
|
||||
this.timeDelta = timeDelta;
|
||||
}
|
||||
public long getTimeDeltaCall() {
|
||||
return timeDeltaCall;
|
||||
}
|
||||
public float getTimeDeltaCallSecond() {
|
||||
return (float)timeDeltaCall*0.0000001f;
|
||||
}
|
||||
public void setTimeDeltaCall(long timeDeltaCall) {
|
||||
this.timeDeltaCall = timeDeltaCall;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EventTime [timeSystem=" + timeSystem + "us, timeUpAppl=" + timeUpAppl + "us, timeDelta=" + timeDelta
|
||||
+ "us, timeDeltaCall=" + timeDeltaCall + "us]";
|
||||
}
|
||||
|
||||
}
|
@ -17,4 +17,21 @@ public enum KeyStatus {
|
||||
leave,
|
||||
abort, // Appeare when an event is tranfert betwwen widgets (the widget which receive this has lost the events)
|
||||
transfert // Appeare when an event is tranfert betwwen widgets (the widget which receive this has receive the transfert of the event)
|
||||
;
|
||||
|
||||
public static KeyStatus pressCount(final int i) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
return pressSingle;
|
||||
case 2:
|
||||
return pressDouble;
|
||||
case 3:
|
||||
return pressTriple;
|
||||
case 4:
|
||||
return pressQuad;
|
||||
case 5:
|
||||
return pressQuinte;
|
||||
}
|
||||
return unknow;
|
||||
}
|
||||
}
|
||||
|
@ -1,127 +1,111 @@
|
||||
package org.atriasoft.gale.resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
import org.atriasoft.gale.context.Context;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
|
||||
public abstract class Resource {
|
||||
protected static final String NO_NAME_RESOURCE = "---";
|
||||
protected static final int MAXRESOURCELEVEL = 5;
|
||||
private static int idGenerated = 10;
|
||||
|
||||
/**
|
||||
* @brief Get the current resource Manager
|
||||
*/
|
||||
protected static ResourceManager getManager() {
|
||||
return Context.getContext().getResourcesManager();
|
||||
}
|
||||
|
||||
protected long uid = -1; //!< unique ID definition
|
||||
protected int count = 1;
|
||||
protected int resourceLevel = MAXRESOURCELEVEL-1; //!< Level of the resource ==> for update priority [0..5] 0 must be update first.
|
||||
protected int resourceLevel = MAXRESOURCELEVEL - 1; //!< Level of the resource ==> for update priority [0..5] 0 must be update first.
|
||||
protected String name = NO_NAME_RESOURCE; //!< name of the resource ...
|
||||
protected boolean resourceHasBeenInit = false; //!< Know if the init function has bben called
|
||||
protected List<String> listType = new ArrayList<String>();
|
||||
|
||||
/**
|
||||
* @brief generic protected contructor (use factory to create this class)
|
||||
*/
|
||||
protected Resource() {
|
||||
this.uid = idGenerated++;
|
||||
this.addResourceType("gale::Resource");
|
||||
this.resourceHasBeenInit = true;
|
||||
getManager().localAdd(this);
|
||||
}
|
||||
protected Resource(String name) {
|
||||
this.resourceHasBeenInit = true;
|
||||
|
||||
protected Resource(final String name) {
|
||||
this.name = name;
|
||||
getManager().localAdd(this);
|
||||
}
|
||||
protected Resource( Uri uri) {
|
||||
this.resourceHasBeenInit = true;
|
||||
|
||||
protected Resource(final Uri uri) {
|
||||
this.name = uri.getValue();
|
||||
getManager().localAdd(this);
|
||||
}
|
||||
public void keep() {
|
||||
this.count++;
|
||||
}
|
||||
|
||||
public abstract void cleanUp();
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
public void release() {
|
||||
this.count--;
|
||||
if (this.count == 0) {
|
||||
|
||||
}
|
||||
}
|
||||
public abstract void cleanUp();
|
||||
public long getId() {
|
||||
return this.uid;
|
||||
}
|
||||
public boolean resourceHasBeenCorectlyInit() {
|
||||
return this.resourceHasBeenInit;
|
||||
}
|
||||
/**
|
||||
* @brief get the current type of the Resource
|
||||
* @return the last type name of the element
|
||||
*/
|
||||
public String getType() {
|
||||
if (this.listType.size() == 0) {
|
||||
return "gale::Resource";
|
||||
}
|
||||
return this.listType.get(this.listType.size()-1);
|
||||
}
|
||||
/**
|
||||
* @brief Get the herarchic of the Resource type.
|
||||
* @return descriptive string.
|
||||
*/
|
||||
public String getTypeDescription() {
|
||||
String ret = "gale::Resource";
|
||||
for(String element : this.listType) {
|
||||
ret += "|";
|
||||
ret += element;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* @brief check if the element herited from a specific type
|
||||
* @param type Type to check.
|
||||
* @return true if the element is compatible.
|
||||
*/
|
||||
public boolean isTypeCompatible( String type) {
|
||||
if (type == "gale::Resource") {
|
||||
return true;
|
||||
}
|
||||
for(String element : this.listType) {
|
||||
if (type == element) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* @brief Add a type of the list of Object.
|
||||
* @param type Type to add.
|
||||
*/
|
||||
protected void addResourceType(String type) {
|
||||
if (type == null) {
|
||||
Log.error(" try to add a type with no value...");
|
||||
return;
|
||||
}
|
||||
this.listType.add(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the resource name
|
||||
* @return The requested name
|
||||
*/
|
||||
public String getName() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
/**
|
||||
* @brief get the resource name
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName( String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current resource level;
|
||||
* @return value in [0..5]
|
||||
*/
|
||||
public int getResourceLevel() {
|
||||
return this.resourceLevel;
|
||||
}
|
||||
|
||||
public void keep() {
|
||||
this.count++;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.count--;
|
||||
if (this.count == 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief User request the reload of all resources (usefull when the file depend on DATA:GUI:xxx ...
|
||||
*/
|
||||
public void reload() {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The current OpenGl context is removing ==> remove yout own system data
|
||||
*/
|
||||
public void removeContext() {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The notification of the Context removing is too late, we have no more acces on the OpenGl context (thank you Android).
|
||||
* Just update your internal state
|
||||
*/
|
||||
public void removeContextToLate() {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the resource name
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call when need to send data on the harware (openGL)
|
||||
* @note This is done asynchronously with the create of the Resource.
|
||||
@ -132,30 +116,4 @@ public abstract class Resource {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The current OpenGl context is removing ==> remove yout own system data
|
||||
*/
|
||||
public void removeContext() {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
}
|
||||
/**
|
||||
* @brief The notification of the Context removing is too late, we have no more acces on the OpenGl context (thank you Android).
|
||||
* Juste update your internal state
|
||||
*/
|
||||
public void removeContextToLate() {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
}
|
||||
/**
|
||||
* @brief User request the reload of all resources (usefull when the file depend on DATA:GUI:xxx ...
|
||||
*/
|
||||
public void reload() {
|
||||
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
|
||||
}
|
||||
/**
|
||||
* @brief Get the current resource Manager
|
||||
*/
|
||||
protected static ResourceManager getManager() {
|
||||
return Context.getContext().getResourcesManager();
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,6 @@ import org.lwjgl.BufferUtils;
|
||||
public class ResourceColored3DObject extends Resource {
|
||||
public static ResourceColored3DObject create() {
|
||||
final ResourceColored3DObject resource = new ResourceColored3DObject();
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceColored3DObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
@ -31,7 +28,6 @@ public class ResourceColored3DObject extends Resource {
|
||||
|
||||
protected ResourceColored3DObject() {
|
||||
super();
|
||||
addResourceType("ResourceColored3DObject");
|
||||
// get the shader resource :
|
||||
this.oGLPosition = 0;
|
||||
this.program = ResourceProgram.create(new Uri("DATA_EGE", "simple3D.vert"), new Uri("DATA_EGE", "simple3D.frag"));
|
||||
@ -153,7 +149,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawCapsule(final float radius, final float size, int lats, final int longs, final Matrix4f transformationMatrix, final Color tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
lats = lats / 2 * 2;
|
||||
|
||||
// center to border (TOP)
|
||||
@ -249,7 +245,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawCone(final float radius, final float size, final int lats, final int longs, final Matrix4f transformationMatrix, final Color tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
// center to border (TOP)
|
||||
for (int jjj = 0; jjj < longs; ++jjj) {
|
||||
float lng = 2.0f * (float) Math.PI * (jjj - 1) / longs;
|
||||
@ -289,7 +285,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawCubeLine(final Vector3f min, final Vector3f max, final Color color, final Matrix4f transformationMatrix, final boolean updateDepthBuffer, final boolean depthtest) {
|
||||
final List<Vector3f> vertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> vertices = new ArrayList<>();
|
||||
vertices.add(new Vector3f(min.x, min.y, min.z));
|
||||
vertices.add(new Vector3f(max.x, min.y, min.z));
|
||||
|
||||
@ -329,7 +325,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawCylinder(final float radius, final float size, final int lats, final int longs, final Matrix4f transformationMatrix, final Color tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
// center to border (TOP)
|
||||
|
||||
// center to border (TOP)
|
||||
@ -443,7 +439,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawSphere(final float radius, final int lats, final int longs, final Matrix4f transformationMatrix, final Color tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
for (int iii = 0; iii <= lats; ++iii) {
|
||||
final float lat0 = (float) Math.PI * (-0.5f + (float) (iii - 1) / lats);
|
||||
final float z0 = radius * (float) Math.sin(lat0);
|
||||
@ -479,7 +475,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawSquare(final Vector3f size, final Matrix4f transformationMatrix, final Color tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
final int[] indices = { 0, 1, 2, 3, 2, 1, 4, 0, 6, 6, 0, 2, 5, 1, 4, 4, 1, 0, 7, 3, 1, 7, 1, 5, 5, 4, 7, 7, 4, 6, 7, 2, 3, 7, 6, 2 };
|
||||
final Vector3f[] vertices = { new Vector3f(size.x, size.y, size.z), new Vector3f(-size.x, size.y, size.z), new Vector3f(size.x, -size.y, size.z), new Vector3f(-size.x, -size.y, size.z),
|
||||
new Vector3f(size.x, size.y, -size.z), new Vector3f(-size.x, size.y, -size.z), new Vector3f(size.x, -size.y, -size.z), new Vector3f(-size.x, -size.y, -size.z) };
|
||||
@ -500,7 +496,7 @@ public class ResourceColored3DObject extends Resource {
|
||||
}
|
||||
|
||||
public void drawTriangles(final List<Vector3f> vertex, final List<Integer> indice, final Matrix4f transformationMatrix, final Color tmpColor, final Vector3f offset) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<Vector3f>();
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
for (int iii = 0; iii < indice.size() / 3; ++iii) {
|
||||
tmpVertices.add(vertex.get(indice.get(iii * 3 + 0)).addNew(offset));
|
||||
tmpVertices.add(vertex.get(indice.get(iii * 3 + 1)).addNew(offset));
|
||||
|
@ -3,146 +3,48 @@ package org.atriasoft.gale.resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
|
||||
public class ResourceManager {
|
||||
private List<Resource> resourceList = new ArrayList<Resource>();
|
||||
private List<Resource> resourceListToUpdate = new ArrayList<Resource>();
|
||||
private static final int MAX_RESOURCE_LEVEL = 9;
|
||||
private final List<Resource> resourceList = new ArrayList<>();
|
||||
private List<Resource> resourceListToUpdate = new ArrayList<>();
|
||||
private boolean contextHasBeenRemoved = true;
|
||||
private boolean exiting = false;
|
||||
private static final int MAX_RESOURCE_LEVEL = 9;
|
||||
|
||||
/**
|
||||
* @brief initialize the internal variable
|
||||
*/
|
||||
public ResourceManager() {
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief Uninitiamize the resource manager, free all resources previously requested
|
||||
* @note when not free == > generate warning, because the segfault can appear after...
|
||||
*/
|
||||
//public ~Manager();
|
||||
/**
|
||||
* @brief remove all resources (un-init) out of the destructor (due to the system implementation)
|
||||
*/
|
||||
public void unInit() {
|
||||
display();
|
||||
this.resourceListToUpdate.clear();
|
||||
// remove all resources ...
|
||||
for(Resource it : this.resourceList) {
|
||||
Log.warning("Find a resource that is not removed : [" + it.getId() + "]"
|
||||
+ "='" + it.getName() + "' "
|
||||
+ it.getCount() + " elements");
|
||||
}
|
||||
this.resourceList.clear();
|
||||
}
|
||||
/**
|
||||
* @brief display in the log all the resources loaded ...
|
||||
*/
|
||||
public void display(){
|
||||
Log.info("Resources loaded : ");
|
||||
// remove all resources ...
|
||||
for(Resource it : this.resourceList) {
|
||||
Log.info(" [" + it.getId() + "]"
|
||||
+ it.getType()
|
||||
+ "='" + it.getName() + "' "
|
||||
+ it.getCount() + " elements");
|
||||
}
|
||||
Log.info("Resources ---");
|
||||
}
|
||||
/**
|
||||
* @brief Reload all resources from files, and send there in openGL card if needed.
|
||||
* @note If file is reference at THEMEXXX:///filename if the Theme change the file will reload the newOne
|
||||
*/
|
||||
public void reLoadResources() {
|
||||
Log.info("------------- Resources re-loaded -------------");
|
||||
// remove all resources ...
|
||||
for (long jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
|
||||
Log.info(" Reload level : " + jjj + "/" + (MAX_RESOURCE_LEVEL-1));
|
||||
for(Resource it : this.resourceList) {
|
||||
if(jjj == it.getResourceLevel()) {
|
||||
if (it.getCount() > 0) {
|
||||
it.reload();
|
||||
Log.info(" [" + it.getId() + "]="+ it.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO UNderstand why it is set here ...
|
||||
//gale::requestUpdateSize();
|
||||
Log.info("------------- Resources -------------");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call by the system to send all the needed data on the graphic card chen they change ...
|
||||
* @param object The resources that might be updated
|
||||
* @brief special end of application
|
||||
*/
|
||||
public void update(Resource object) {
|
||||
// check if not added before
|
||||
for (Resource it : this.resourceListToUpdate) {
|
||||
if (it == object) {
|
||||
// just prevent some double add ...
|
||||
return;
|
||||
}
|
||||
}
|
||||
// add it ...
|
||||
this.resourceListToUpdate.add(object);
|
||||
public void applicationExiting() {
|
||||
contextHasBeenDestroyed();
|
||||
this.exiting = true;
|
||||
}
|
||||
/**
|
||||
* @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
|
||||
*/
|
||||
public void updateContext(){
|
||||
if (this.exiting == true) {
|
||||
Log.error("Request update after application EXIT ...");
|
||||
return;
|
||||
}
|
||||
// TODO Check the number of call this ... Log.info("update open-gl context ... ");
|
||||
if (this.contextHasBeenRemoved == true) {
|
||||
// need to update all ...
|
||||
this.contextHasBeenRemoved = false;
|
||||
this.resourceListToUpdate.clear();
|
||||
synchronized(this.resourceList) {
|
||||
if (this.resourceList.size() != 0) {
|
||||
for (long jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
|
||||
Log.verbose(" updateContext level (D) : " + jjj + "/" + (MAX_RESOURCE_LEVEL-1));
|
||||
for (Resource it : this.resourceList) {
|
||||
if(jjj == it.getResourceLevel()) {
|
||||
//Log.debug("Update context named : " + lresourceList[iii].getName());
|
||||
if (it.updateContext() == false) {
|
||||
// Lock error ==> postponned
|
||||
this.resourceListToUpdate.add(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Resource> resourceListToUpdate = null;
|
||||
synchronized(this.resourceListToUpdate) {
|
||||
resourceListToUpdate = this.resourceListToUpdate;
|
||||
this.resourceListToUpdate = new ArrayList<Resource>();
|
||||
}
|
||||
if (resourceListToUpdate.size() != 0) {
|
||||
for (long jjj=0; jjj<MAX_RESOURCE_LEVEL; jjj++) {
|
||||
Log.verbose(" updateContext level (U) : " + jjj + "/" + (MAX_RESOURCE_LEVEL-1));
|
||||
for (Resource it : resourceListToUpdate) {
|
||||
if (jjj == it.getResourceLevel()) {
|
||||
if (it.updateContext() == false) {
|
||||
// Lock error ==> postponned
|
||||
this.resourceListToUpdate.add(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cleanInternalRemoved() {
|
||||
//Log.info("remove object in Manager");
|
||||
updateContext();
|
||||
// TODO ...
|
||||
// for (auto it(this.resourceList.begin()); it!=this.resourceList.end(); ++it) {
|
||||
// if ((*it).expired() == true) {
|
||||
// this.resourceList.erase(it);
|
||||
// it = this.resourceList.begin();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is to inform the resources manager that we have no more openGl context ...
|
||||
*/
|
||||
public void contextHasBeenDestroyed() {
|
||||
for (Resource it : this.resourceList) {
|
||||
for (final Resource it : this.resourceList) {
|
||||
if (it.getCount() > 0) {
|
||||
it.removeContextToLate();
|
||||
}
|
||||
@ -150,17 +52,28 @@ public class ResourceManager {
|
||||
// no context preent ...
|
||||
this.contextHasBeenRemoved = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief special end of application
|
||||
* @brief display in the log all the resources loaded ...
|
||||
*/
|
||||
public void applicationExiting(){
|
||||
contextHasBeenDestroyed();
|
||||
this.exiting = true;
|
||||
public void display() {
|
||||
Log.info("Resources loaded : ");
|
||||
// remove all resources ...
|
||||
for (final Resource it : this.resourceList) {
|
||||
Log.info(" [" + it.getId() + "]" + it.getClass().getCanonicalName() + "='" + it.getName() + "' " + it.getCount() + " elements");
|
||||
}
|
||||
Log.info("Resources ---");
|
||||
}
|
||||
|
||||
public void localAdd(final Resource object) {
|
||||
// add at the end if no slot is free
|
||||
this.resourceList.add(object);
|
||||
}
|
||||
|
||||
// internal API to extent eResources in extern Soft
|
||||
public Resource localKeep(String filename) {
|
||||
public Resource localKeep(final String filename) {
|
||||
Log.verbose("KEEP (DEFAULT) : file : '" + filename + "' in " + this.resourceList.size() + " resources");
|
||||
for (Resource it : this.resourceList) {
|
||||
for (final Resource it : this.resourceList) {
|
||||
if (it == null) {
|
||||
continue;
|
||||
}
|
||||
@ -177,20 +90,118 @@ public class ResourceManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public void localAdd(Resource object) {
|
||||
// add at the end if no slot is free
|
||||
this.resourceList.add(object);
|
||||
|
||||
public Resource localKeep(final Uri uri) {
|
||||
// TODO Auto-generated method stub
|
||||
return localKeep(uri.toString());
|
||||
}
|
||||
public void cleanInternalRemoved() {
|
||||
//Log.info("remove object in Manager");
|
||||
updateContext();
|
||||
// TODO ...
|
||||
// for (auto it(this.resourceList.begin()); it!=this.resourceList.end(); ++it) {
|
||||
// if ((*it).expired() == true) {
|
||||
// this.resourceList.erase(it);
|
||||
// it = this.resourceList.begin();
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief Reload all resources from files, and send there in openGL card if needed.
|
||||
* @note If file is reference at THEMEXXX:///filename if the Theme change the file will reload the newOne
|
||||
*/
|
||||
public void reLoadResources() {
|
||||
Log.info("------------- Resources re-loaded -------------");
|
||||
// remove all resources ...
|
||||
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) {
|
||||
Log.info(" Reload level : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1));
|
||||
for (final Resource it : this.resourceList) {
|
||||
if (jjj == it.getResourceLevel()) {
|
||||
if (it.getCount() > 0) {
|
||||
it.reload();
|
||||
Log.info(" [" + it.getId() + "]=" + it.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO UNderstand why it is set here ...
|
||||
//gale::requestUpdateSize();
|
||||
Log.info("------------- Resources -------------");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Uninitiamize the resource manager, free all resources previously requested
|
||||
* @note when not free == > generate warning, because the segfault can appear after...
|
||||
*/
|
||||
//public ~Manager();
|
||||
/**
|
||||
* @brief remove all resources (un-init) out of the destructor (due to the system implementation)
|
||||
*/
|
||||
public void unInit() {
|
||||
display();
|
||||
this.resourceListToUpdate.clear();
|
||||
// remove all resources ...
|
||||
for (final Resource it : this.resourceList) {
|
||||
Log.warning("Find a resource that is not removed : [" + it.getId() + "]" + "='" + it.getName() + "' " + it.getCount() + " elements");
|
||||
}
|
||||
this.resourceList.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call by the system to send all the needed data on the graphic card chen they change ...
|
||||
* @param object The resources that might be updated
|
||||
*/
|
||||
public void update(final Resource object) {
|
||||
// check if not added before
|
||||
for (final Resource it : this.resourceListToUpdate) {
|
||||
if (it == object) {
|
||||
// just prevent some double add ...
|
||||
return;
|
||||
}
|
||||
}
|
||||
// add it ...
|
||||
this.resourceListToUpdate.add(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
|
||||
*/
|
||||
public void updateContext() {
|
||||
if (this.exiting == true) {
|
||||
Log.error("Request update after application EXIT ...");
|
||||
return;
|
||||
}
|
||||
// TODO Check the number of call this ... Log.info("update open-gl context ... ");
|
||||
if (this.contextHasBeenRemoved == true) {
|
||||
// need to update all ...
|
||||
this.contextHasBeenRemoved = false;
|
||||
this.resourceListToUpdate.clear();
|
||||
synchronized (this.resourceList) {
|
||||
if (this.resourceList.size() != 0) {
|
||||
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) {
|
||||
Log.verbose(" updateContext level (D) : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1));
|
||||
for (final Resource it : this.resourceList) {
|
||||
if (jjj == it.getResourceLevel()) {
|
||||
//Log.debug("Update context named : " + lresourceList[iii].getName());
|
||||
if (it.updateContext() == false) {
|
||||
// Lock error ==> postponned
|
||||
this.resourceListToUpdate.add(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Resource> resourceListToUpdate = null;
|
||||
synchronized (this.resourceListToUpdate) {
|
||||
resourceListToUpdate = this.resourceListToUpdate;
|
||||
this.resourceListToUpdate = new ArrayList<>();
|
||||
}
|
||||
if (resourceListToUpdate.size() != 0) {
|
||||
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) {
|
||||
Log.verbose(" updateContext level (U) : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1));
|
||||
for (final Resource it : resourceListToUpdate) {
|
||||
if (jjj == it.getResourceLevel()) {
|
||||
if (it.updateContext() == false) {
|
||||
// Lock error ==> postponned
|
||||
this.resourceListToUpdate.add(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +1,52 @@
|
||||
package org.atriasoft.gale.resource;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
import org.atriasoft.gale.backend3d.OpenGL;
|
||||
import org.atriasoft.gale.backend3d.OpenGL.ShaderType;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
|
||||
public class ResourceShader extends Resource {
|
||||
|
||||
public static ResourceShader create(final Uri uriShader) {
|
||||
ResourceShader resource;
|
||||
Resource resource2;
|
||||
final String name = uriShader.getValue();
|
||||
if (name.isEmpty() == false && name != "---") {
|
||||
resource2 = getManager().localKeep(name);
|
||||
} else {
|
||||
Log.error("Can not create a shader without a filaname");
|
||||
return null;
|
||||
}
|
||||
if (resource2 != null) {
|
||||
if (resource2 instanceof ResourceShader) {
|
||||
resource2.keep();
|
||||
return (ResourceShader) resource2;
|
||||
}
|
||||
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
||||
return null;
|
||||
}
|
||||
resource = new ResourceShader(uriShader);
|
||||
if (resource == null) {
|
||||
Log.error("allocation error of a resource : " + name);
|
||||
return null;
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private boolean exist = false; //!< The shader file existed and has been loaded
|
||||
private String fileData = ""; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
|
||||
private final String fileData = ""; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
|
||||
private int shader = -1; //!< opengl id of this element
|
||||
private final ShaderType type; //!< Type of the current shader(vertex/fragment)
|
||||
private final Uri uri;
|
||||
|
||||
/**
|
||||
* @brief Contructor of an opengl Shader
|
||||
* @param filename Standard file name format. see @ref etk::FSNode
|
||||
*/
|
||||
protected ResourceShader(Uri uri) {
|
||||
protected ResourceShader(final Uri uri) {
|
||||
super(uri);
|
||||
this.uri = uri;
|
||||
addResourceType("gale::Shader");
|
||||
this.resourceLevel = 0;
|
||||
Log.debug("OGL : load SHADER '" + uri + "'");
|
||||
// load data from file "all the time ..."
|
||||
@ -35,13 +62,16 @@ public class ResourceShader extends Resource {
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destructor, remove the current Shader
|
||||
*/
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
OpenGL.shaderRemove(this.shader);
|
||||
this.exist = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief get the opengl reference id of this shader.
|
||||
* @return The opengl id.
|
||||
@ -49,50 +79,20 @@ public class ResourceShader extends Resource {
|
||||
public int getGLID() {
|
||||
return this.shader;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief get the opengl type of this shader.
|
||||
* @return The type of this loaded shader.
|
||||
*/
|
||||
public ShaderType getShaderType() {
|
||||
return this.type;
|
||||
};
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
public boolean updateContext(){
|
||||
if (this.exist == true) {
|
||||
// Do nothing == > too dangerous ...
|
||||
} else {
|
||||
this.shader = OpenGL.shaderLoad(this.uri.get(), type);
|
||||
// create the Shader
|
||||
if (this.shader < 0) {
|
||||
return true;
|
||||
}
|
||||
this.exist = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
public void removeContext(){
|
||||
if (true == this.exist) {
|
||||
OpenGL.shaderRemove(this.shader);
|
||||
this.shader = -1;
|
||||
this.exist = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
public void removeContextToLate(){
|
||||
this.exist = false;
|
||||
this.shader = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
@Override
|
||||
public void reload() {
|
||||
Log.verbose("load shader:\n-----------------------------------------------------------------\n" + this.fileData + "\n-----------------------------------------------------------------");
|
||||
// now change the OGL context ...
|
||||
@ -108,34 +108,43 @@ public class ResourceShader extends Resource {
|
||||
getManager().update(this);
|
||||
}
|
||||
}
|
||||
public static ResourceShader create(Uri uriShader) {
|
||||
ResourceShader resource;
|
||||
Resource resource2;
|
||||
String name = uriShader.getValue();
|
||||
if (name.isEmpty() == false && name != "---") {
|
||||
resource2 = getManager().localKeep(name);
|
||||
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
@Override
|
||||
public void removeContext() {
|
||||
if (true == this.exist) {
|
||||
OpenGL.shaderRemove(this.shader);
|
||||
this.shader = -1;
|
||||
this.exist = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
@Override
|
||||
public void removeContextToLate() {
|
||||
this.exist = false;
|
||||
this.shader = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
@Override
|
||||
public boolean updateContext() {
|
||||
if (this.exist == true) {
|
||||
// Do nothing == > too dangerous ...
|
||||
} else {
|
||||
Log.error("Can not create a shader without a filaname");
|
||||
return null;
|
||||
}
|
||||
if (resource2 != null) {
|
||||
if (resource2 instanceof ResourceShader) {
|
||||
resource2.keep();
|
||||
return (ResourceShader)resource2;
|
||||
this.shader = OpenGL.shaderLoad(this.uri.get(), this.type);
|
||||
// create the Shader
|
||||
if (this.shader < 0) {
|
||||
return true;
|
||||
}
|
||||
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
||||
return null;
|
||||
this.exist = true;
|
||||
}
|
||||
resource = new ResourceShader(uriShader);
|
||||
if (resource == null) {
|
||||
Log.error("allocation error of a resource : " + name);
|
||||
return null;
|
||||
}
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init : ResourceProgram" );
|
||||
return null;
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import java.nio.ByteBuffer;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector2i;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
import org.atriasoft.gale.backend3d.OpenGL;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
import org.atriasoft.gale.tools.ImageLoader;
|
||||
import org.atriasoft.gale.tools.ImageRawData;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@ -14,189 +14,24 @@ import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
public class ResourceTexture extends Resource {
|
||||
private static int[] textureIdBinding = {
|
||||
GL13.GL_TEXTURE0,
|
||||
GL13.GL_TEXTURE1,
|
||||
GL13.GL_TEXTURE2,
|
||||
GL13.GL_TEXTURE3,
|
||||
GL13.GL_TEXTURE4,
|
||||
GL13.GL_TEXTURE5,
|
||||
GL13.GL_TEXTURE6,
|
||||
GL13.GL_TEXTURE7,
|
||||
GL13.GL_TEXTURE8,
|
||||
GL13.GL_TEXTURE9,
|
||||
GL13.GL_TEXTURE10,
|
||||
GL13.GL_TEXTURE11,
|
||||
GL13.GL_TEXTURE12,
|
||||
GL13.GL_TEXTURE13,
|
||||
GL13.GL_TEXTURE14,
|
||||
GL13.GL_TEXTURE15,
|
||||
GL13.GL_TEXTURE16,
|
||||
GL13.GL_TEXTURE17,
|
||||
GL13.GL_TEXTURE18,
|
||||
GL13.GL_TEXTURE19,
|
||||
GL13.GL_TEXTURE20,
|
||||
GL13.GL_TEXTURE21,
|
||||
GL13.GL_TEXTURE22,
|
||||
GL13.GL_TEXTURE23,
|
||||
GL13.GL_TEXTURE24,
|
||||
GL13.GL_TEXTURE25,
|
||||
GL13.GL_TEXTURE26,
|
||||
GL13.GL_TEXTURE27,
|
||||
GL13.GL_TEXTURE28,
|
||||
GL13.GL_TEXTURE29,
|
||||
GL13.GL_TEXTURE30,
|
||||
GL13.GL_TEXTURE31
|
||||
};
|
||||
public enum TextureColorMode {
|
||||
rgb, //!< red/green/blue data
|
||||
rgba //!< red/green/blue/alpha data
|
||||
};
|
||||
protected int texId = -1; //!< openGl textureID.
|
||||
protected Vector2f endPointSize = new Vector2f(-1, -1); //!< some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 . 1.0.
|
||||
protected boolean loaded = false; //!< internal state of the openGl system.
|
||||
// Image properties:
|
||||
private ByteBuffer data = null; //!< pointer on the image data.
|
||||
private Vector2i size = new Vector2i(-1,-1); //!< size of the image data.
|
||||
private TextureColorMode dataColorSpace = TextureColorMode.rgb; //!< Color space of the image.
|
||||
private int textureUnit = 0; // number of lines and colomns in the texture (multiple texturing in a single texture)
|
||||
private String filename = "";
|
||||
/**
|
||||
* @brief get the next power 2 if the input
|
||||
* @param value Value that we want the next power of 2
|
||||
* @return result value
|
||||
*/
|
||||
private static int nextP2(int value) {
|
||||
int val=1;
|
||||
for (int iii=1; iii<31; iii++) {
|
||||
if (value <= val) {
|
||||
return val;
|
||||
}
|
||||
val *=2;
|
||||
}
|
||||
Log.critical("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
// Public API:
|
||||
protected ResourceTexture(String filename, int textureUnit) {
|
||||
super(filename + "__" + textureUnit);
|
||||
this.filename = filename;
|
||||
this.textureUnit = textureUnit;
|
||||
addResourceType("gale::resource::Texture");
|
||||
}
|
||||
protected ResourceTexture(Uri filename, int textureUnit) {
|
||||
super(filename + "__" + textureUnit);
|
||||
this.filename = filename.get();
|
||||
this.textureUnit = textureUnit;
|
||||
addResourceType("gale::resource::Texture");
|
||||
}
|
||||
protected ResourceTexture() {
|
||||
super();
|
||||
addResourceType("gale::resource::Texture");
|
||||
}
|
||||
public void cleanUp() {
|
||||
removeContext();
|
||||
}
|
||||
// Gale internal API:
|
||||
@Override
|
||||
public boolean updateContext() {
|
||||
if (this.loaded == true) {
|
||||
return true;
|
||||
}
|
||||
// Request a new texture at openGl :
|
||||
texId = GL11.glGenTextures();
|
||||
GL13.glActiveTexture(textureUnit);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
|
||||
|
||||
// All RGB bytes are aligned to each other and each component is 1 byte
|
||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||
Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId);
|
||||
if (dataColorSpace == TextureColorMode.rgb) {
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x, this.size.y, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, data);
|
||||
} else {
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x, this.size.y, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, data);
|
||||
}
|
||||
// generate multi-texture mapping
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
|
||||
// Setup the ST coordinate system
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
|
||||
// Setup what to do when the texture has to be scaled
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
// now the data is loaded
|
||||
this.loaded = true;
|
||||
return true;
|
||||
}
|
||||
public void removeContext() {
|
||||
if (true == this.loaded) {
|
||||
// Request remove texture ...
|
||||
Log.info("TEXTURE: Rm [" + getId() + "] texId=" + this.texId);
|
||||
// TODO Check if we are in the correct thread
|
||||
GL11.glDeleteTextures(this.texId);
|
||||
this.loaded = false;
|
||||
}
|
||||
}
|
||||
public void removeContextToLate() {
|
||||
this.loaded = false;
|
||||
this.texId = -1;
|
||||
}
|
||||
public int getRendererId() {
|
||||
return this.texId;
|
||||
};
|
||||
public Vector2f getUsableSize() {
|
||||
return this.endPointSize;
|
||||
};
|
||||
public Vector2i getOpenGlSize() {
|
||||
return this.size;
|
||||
};
|
||||
// flush the data to send it at the openGl system
|
||||
public void flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(this);
|
||||
}
|
||||
public void setTexture(ByteBuffer data,
|
||||
Vector2i size,
|
||||
TextureColorMode dataColorSpace,
|
||||
int textureUnit) {
|
||||
this.data = data;
|
||||
this.size = size;
|
||||
this.textureUnit = textureUnit;
|
||||
this.endPointSize.x = (float)size.x;
|
||||
this.endPointSize.y = (float)size.y;
|
||||
this.dataColorSpace = dataColorSpace;
|
||||
flush();
|
||||
}
|
||||
public void bindForRendering(int idTexture) {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
}
|
||||
GL13.glActiveTexture(textureIdBinding[idTexture]);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texId);
|
||||
if (dataColorSpace == TextureColorMode.rgb) {
|
||||
OpenGL.enable(OpenGL.Flag.flag_cullFace);
|
||||
OpenGL.enable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
public void unBindForRendering() {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
}
|
||||
if (dataColorSpace == TextureColorMode.rgb) {
|
||||
OpenGL.disable(OpenGL.Flag.flag_cullFace);
|
||||
OpenGL.disable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResourceTexture createFromPng(Uri uriTexture) {
|
||||
private static int[] textureIdBinding = { GL13.GL_TEXTURE0, GL13.GL_TEXTURE1, GL13.GL_TEXTURE2, GL13.GL_TEXTURE3, GL13.GL_TEXTURE4, GL13.GL_TEXTURE5, GL13.GL_TEXTURE6, GL13.GL_TEXTURE7,
|
||||
GL13.GL_TEXTURE8, GL13.GL_TEXTURE9, GL13.GL_TEXTURE10, GL13.GL_TEXTURE11, GL13.GL_TEXTURE12, GL13.GL_TEXTURE13, GL13.GL_TEXTURE14, GL13.GL_TEXTURE15, GL13.GL_TEXTURE16, GL13.GL_TEXTURE17,
|
||||
GL13.GL_TEXTURE18, GL13.GL_TEXTURE19, GL13.GL_TEXTURE20, GL13.GL_TEXTURE21, GL13.GL_TEXTURE22, GL13.GL_TEXTURE23, GL13.GL_TEXTURE24, GL13.GL_TEXTURE25, GL13.GL_TEXTURE26,
|
||||
GL13.GL_TEXTURE27, GL13.GL_TEXTURE28, GL13.GL_TEXTURE29, GL13.GL_TEXTURE30, GL13.GL_TEXTURE31 };;
|
||||
|
||||
public static ResourceTexture createFromPng(final Uri uriTexture) {
|
||||
return createFromPng(uriTexture, 1);
|
||||
}
|
||||
public static ResourceTexture createFromPng(Uri uriTexture, int textureUnit) {
|
||||
|
||||
public static ResourceTexture createFromPng(final Uri uriTexture, final int textureUnit) {
|
||||
ResourceTexture resource;
|
||||
Resource resource2;
|
||||
String name = uriTexture.getValue();
|
||||
final String name = uriTexture.getValue();
|
||||
if (name.isEmpty() == false && name != "---") {
|
||||
resource2 = getManager().localKeep(name);
|
||||
} else {
|
||||
@ -206,23 +41,173 @@ public class ResourceTexture extends Resource {
|
||||
if (resource2 != null) {
|
||||
if (resource2 instanceof ResourceTexture) {
|
||||
resource2.keep();
|
||||
return (ResourceTexture)resource2;
|
||||
return (ResourceTexture) resource2;
|
||||
}
|
||||
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
||||
return null;
|
||||
}
|
||||
resource = new ResourceTexture(uriTexture, textureUnit);
|
||||
ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
|
||||
resource.setTexture(decodedData.getBuffer(),
|
||||
new Vector2i(decodedData.getWidth(), decodedData.getHeight()),
|
||||
(decodedData.isHasAlpha() == true?TextureColorMode.rgba:TextureColorMode.rgb),
|
||||
textureUnit);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init : ResourceProgram" );
|
||||
return null;
|
||||
}
|
||||
final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
|
||||
resource.setTexture(decodedData.getBuffer(), new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() == true ? TextureColorMode.rgba : TextureColorMode.rgb),
|
||||
textureUnit);
|
||||
resource.flush();
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the next power 2 if the input
|
||||
* @param value Value that we want the next power of 2
|
||||
* @return result value
|
||||
*/
|
||||
private static int nextP2(final int value) {
|
||||
int val = 1;
|
||||
for (int iii = 1; iii < 31; iii++) {
|
||||
if (value <= val) {
|
||||
return val;
|
||||
}
|
||||
val *= 2;
|
||||
}
|
||||
Log.critical("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
protected int texId = -1; //!< openGl textureID.
|
||||
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 . 1.0.
|
||||
protected Vector2f endPointSize = new Vector2f(-1, -1);
|
||||
// internal state of the openGl system.
|
||||
protected boolean loaded = false;
|
||||
// Image properties:
|
||||
// pointer on the image data.
|
||||
private ByteBuffer data = null;
|
||||
// size of the image data.
|
||||
private Vector2i size = new Vector2i(-1, -1);
|
||||
//!< Color space of the image.
|
||||
private TextureColorMode dataColorSpace = TextureColorMode.rgb;
|
||||
// number of lines and colomns in the texture (multiple texturing in a single texture)
|
||||
private int textureUnit = 0;
|
||||
private String filename = "";
|
||||
|
||||
protected ResourceTexture() {
|
||||
super();
|
||||
}
|
||||
|
||||
// Public API:
|
||||
protected ResourceTexture(final String filename, final int textureUnit) {
|
||||
super(filename + "__" + textureUnit);
|
||||
this.filename = filename;
|
||||
this.textureUnit = textureUnit;
|
||||
}
|
||||
|
||||
protected ResourceTexture(final Uri filename, final int textureUnit) {
|
||||
super(filename + "__" + textureUnit);
|
||||
this.filename = filename.get();
|
||||
this.textureUnit = textureUnit;
|
||||
}
|
||||
|
||||
public void bindForRendering(final int idTexture) {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
}
|
||||
GL13.glActiveTexture(textureIdBinding[idTexture]);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texId);
|
||||
if (this.dataColorSpace == TextureColorMode.rgb) {
|
||||
OpenGL.enable(OpenGL.Flag.flag_cullFace);
|
||||
OpenGL.enable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
removeContext();
|
||||
}
|
||||
|
||||
// Flush the data to send it at the openGl system
|
||||
public synchronized void flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
Log.verbose("Request UPDATE of Element");
|
||||
getManager().update(this);
|
||||
}
|
||||
|
||||
public Vector2i getOpenGlSize() {
|
||||
return this.size;
|
||||
};
|
||||
|
||||
public int getRendererId() {
|
||||
return this.texId;
|
||||
}
|
||||
|
||||
public Vector2f getUsableSize() {
|
||||
return this.endPointSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeContext() {
|
||||
if (this.loaded == true) {
|
||||
// Request remove texture ...
|
||||
Log.info("TEXTURE: Rm [" + getId() + "] texId=" + this.texId);
|
||||
// TODO Check if we are in the correct thread
|
||||
OpenGL.glDeleteTextures(this.texId);
|
||||
this.loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeContextToLate() {
|
||||
this.loaded = false;
|
||||
this.texId = -1;
|
||||
}
|
||||
|
||||
public void setTexture(final ByteBuffer data, final Vector2i size, final TextureColorMode dataColorSpace, final int textureUnit) {
|
||||
this.data = data;
|
||||
this.size = size;
|
||||
this.textureUnit = textureUnit;
|
||||
this.endPointSize.x = size.x;
|
||||
this.endPointSize.y = size.y;
|
||||
this.dataColorSpace = dataColorSpace;
|
||||
flush();
|
||||
}
|
||||
|
||||
public void unBindForRendering() {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
}
|
||||
if (this.dataColorSpace == TextureColorMode.rgb) {
|
||||
OpenGL.disable(OpenGL.Flag.flag_cullFace);
|
||||
OpenGL.disable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
|
||||
// Gale internal API:
|
||||
@Override
|
||||
public boolean updateContext() {
|
||||
if (this.loaded == true) {
|
||||
return true;
|
||||
}
|
||||
// Request a new texture at openGl :
|
||||
this.texId = GL11.glGenTextures();
|
||||
GL13.glActiveTexture(this.textureUnit);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texId);
|
||||
|
||||
// All RGB bytes are aligned to each other and each component is 1 byte
|
||||
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
|
||||
Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId);
|
||||
if (this.dataColorSpace == TextureColorMode.rgb) {
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x, this.size.y, 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, this.data);
|
||||
} else {
|
||||
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x, this.size.y, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.data);
|
||||
}
|
||||
// generate multi-texture mapping
|
||||
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
|
||||
|
||||
// Setup the ST coordinate system
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
|
||||
|
||||
// Setup what to do when the texture has to be scaled
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
|
||||
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
|
||||
// now the data is loaded
|
||||
this.loaded = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,10 @@ import java.nio.FloatBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
|
||||
import org.atriasoft.gale.backend3d.OpenGL;
|
||||
import org.atriasoft.gale.backend3d.OpenGL.RenderMode;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL15;
|
||||
@ -16,135 +17,71 @@ import org.lwjgl.opengl.GL30;
|
||||
//import models.RawModel;
|
||||
|
||||
public class ResourceVirtualArrayObject extends Resource {
|
||||
private int vaoID = -1;
|
||||
private boolean exist = false; //!< This data is availlable in the Graphic card
|
||||
private List<Integer> vbo = new ArrayList<Integer>();
|
||||
float[] positions = null;
|
||||
float[] colors = null;
|
||||
float[] textureCoordinates = null;
|
||||
float[] normals = null;
|
||||
int[] indices = null;
|
||||
int vertexCount = -1;
|
||||
public static final int INDICE_VBO_POSITIONS = 0;
|
||||
public static final int INDICE_VBO_TEXTURE_COORDINATES = 1;
|
||||
public static final int INDICE_VBO_NORMALS = 2;
|
||||
public static final int INDICE_VBO_COLORS = 3;
|
||||
|
||||
public void bindForRendering() {
|
||||
if (exist == false) {
|
||||
return;
|
||||
}
|
||||
GL30.glBindVertexArray(vaoID);
|
||||
if (positions != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_POSITIONS);
|
||||
//Log.info("unbind POSITION");
|
||||
}
|
||||
if (textureCoordinates != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_TEXTURE_COORDINATES);
|
||||
}
|
||||
if (normals != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_NORMALS);
|
||||
}
|
||||
if (colors != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_COLORS);
|
||||
}
|
||||
public static ResourceVirtualArrayObject create(final float[] positions, final float[] colors, final float[] textureCoordinates, final float[] normals, final int[] indices) {
|
||||
final ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, colors, textureCoordinates, normals, indices, indices.length);
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void unBindForRendering() {
|
||||
if (exist == false) {
|
||||
return;
|
||||
}
|
||||
if (positions != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_POSITIONS);
|
||||
}
|
||||
if (textureCoordinates != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_TEXTURE_COORDINATES);
|
||||
}
|
||||
if (normals != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_NORMALS);
|
||||
}
|
||||
if (colors != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_COLORS);
|
||||
}
|
||||
GL30.glBindVertexArray(0);
|
||||
public static ResourceVirtualArrayObject create(final float[] positions, final float[] textureCoordinates, final float[] normals, final int[] indices) {
|
||||
final ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, null, textureCoordinates, normals, indices, indices.length);
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void render(RenderMode mode) {
|
||||
OpenGL.drawElements(mode, vertexCount);
|
||||
public static ResourceVirtualArrayObject create(final float[] positions, final float[] colors, final int[] indices) {
|
||||
final ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, colors, null, null, indices, indices.length);
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static ResourceVirtualArrayObject create(final float[] positions, final int dimentions) {
|
||||
final ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, null, null, null, null, positions.length / dimentions);
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
private FloatBuffer storeDataInFloatBuffer(float[] data) {
|
||||
FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
|
||||
public static FloatBuffer storeDataInFloatBuffer(final float[] data) {
|
||||
final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
|
||||
buffer.put(data);
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private IntBuffer storeDataInIntBuffer(int[] data) {
|
||||
IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
|
||||
public static IntBuffer storeDataInIntBuffer(final int[] data) {
|
||||
final IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
|
||||
buffer.put(data);
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) {
|
||||
int vboID = GL15.glGenBuffers();
|
||||
vbo.add(vboID);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
|
||||
FloatBuffer buffer = storeDataInFloatBuffer(data);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
private int vaoID = -1;
|
||||
private boolean exist = false; //!< This data is availlable in the Graphic card
|
||||
private final List<Integer> vbo = new ArrayList<>();
|
||||
|
||||
private void bindIndicesBuffer(int[] indices) {
|
||||
int vboId = GL15.glGenBuffers();
|
||||
vbo.add(vboId);
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboId);
|
||||
IntBuffer buffer = storeDataInIntBuffer(indices);
|
||||
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
}
|
||||
float[] positions = null;
|
||||
|
||||
private void createVAO() {
|
||||
vaoID = GL30.glGenVertexArrays();
|
||||
GL30.glBindVertexArray(vaoID);
|
||||
}
|
||||
private void unbindVAO() {
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
float[] colors = null;
|
||||
|
||||
float[] textureCoordinates = null;
|
||||
|
||||
float[] normals = null;
|
||||
|
||||
int[] indices = null;
|
||||
|
||||
int vertexCount = -1;
|
||||
|
||||
public void loadToVAO() {
|
||||
createVAO();
|
||||
if (indices != null) {
|
||||
Log.info("Set indices");
|
||||
bindIndicesBuffer(indices);
|
||||
}
|
||||
if (positions != null) {
|
||||
Log.info("Set positions");
|
||||
storeDataInAttributeList(0, 3, positions);
|
||||
}
|
||||
if (textureCoordinates != null) {
|
||||
Log.info("Set textureCoordinates");
|
||||
storeDataInAttributeList(1, 2, textureCoordinates);
|
||||
}
|
||||
if (normals != null) {
|
||||
Log.info("Set normals");
|
||||
storeDataInAttributeList(2, 3, normals);
|
||||
}
|
||||
if (colors != null) {
|
||||
Log.info("Set colors");
|
||||
storeDataInAttributeList(3, 4, colors);
|
||||
}
|
||||
unbindVAO();
|
||||
}
|
||||
/**
|
||||
* @brief ructor of this VBO.
|
||||
* @param accesMode Acces mode : ???
|
||||
*/
|
||||
protected ResourceVirtualArrayObject(float[] positions, float[] colors, float[] textureCoordinates, float[] normals, int[] indices, int vertexCount) {
|
||||
protected ResourceVirtualArrayObject(final float[] positions, final float[] colors, final float[] textureCoordinates, final float[] normals, final int[] indices, final int vertexCount) {
|
||||
super();
|
||||
addResourceType("gale::VirtualBufferObject");
|
||||
this.resourceLevel = 3;
|
||||
this.positions = positions;
|
||||
this.colors = colors;
|
||||
@ -154,6 +91,35 @@ public class ResourceVirtualArrayObject extends Resource {
|
||||
this.vertexCount = vertexCount;
|
||||
Log.debug("OGL: load VBO count");
|
||||
}
|
||||
|
||||
public void bindForRendering() {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
GL30.glBindVertexArray(this.vaoID);
|
||||
if (this.positions != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_POSITIONS);
|
||||
//Log.info("unbind POSITION");
|
||||
}
|
||||
if (this.textureCoordinates != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_TEXTURE_COORDINATES);
|
||||
}
|
||||
if (this.normals != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_NORMALS);
|
||||
}
|
||||
if (this.colors != null) {
|
||||
GL20.glEnableVertexAttribArray(INDICE_VBO_COLORS);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindIndicesBuffer(final int[] indices) {
|
||||
final int vboId = OpenGL.glGenBuffers();
|
||||
this.vbo.add(vboId);
|
||||
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboId);
|
||||
final IntBuffer buffer = storeDataInIntBuffer(indices);
|
||||
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destructor of this VBO.
|
||||
*/
|
||||
@ -170,13 +136,11 @@ public class ResourceVirtualArrayObject extends Resource {
|
||||
// DO not clear the this.vbo indexed in the graphic cards ...
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief get the real openGL ID.
|
||||
* @return the Ogl id reference of this VBO.
|
||||
*/
|
||||
public int getGLID() {
|
||||
return this.vaoID;
|
||||
};
|
||||
|
||||
private void createVAO() {
|
||||
this.vaoID = GL30.glGenVertexArrays();
|
||||
GL30.glBindVertexArray(this.vaoID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send the data to the graphic card.
|
||||
@ -186,9 +150,115 @@ public class ResourceVirtualArrayObject extends Resource {
|
||||
getManager().update(this);
|
||||
Log.verbose("Request flush of VBO: [" + getId() + "] '" + getName() + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the real openGL ID.
|
||||
* @return the Ogl id reference of this VBO.
|
||||
*/
|
||||
public int getGLID() {
|
||||
return this.vaoID;
|
||||
};
|
||||
|
||||
public void loadToVAO() {
|
||||
createVAO();
|
||||
if (this.indices != null) {
|
||||
Log.info("Set indices");
|
||||
bindIndicesBuffer(this.indices);
|
||||
}
|
||||
if (this.positions != null) {
|
||||
Log.info("Set positions");
|
||||
storeDataInAttributeList(0, 3, this.positions);
|
||||
}
|
||||
if (this.textureCoordinates != null) {
|
||||
Log.info("Set textureCoordinates");
|
||||
storeDataInAttributeList(1, 2, this.textureCoordinates);
|
||||
}
|
||||
if (this.normals != null) {
|
||||
Log.info("Set normals");
|
||||
storeDataInAttributeList(2, 3, this.normals);
|
||||
}
|
||||
if (this.colors != null) {
|
||||
Log.info("Set colors");
|
||||
storeDataInAttributeList(3, 4, this.colors);
|
||||
}
|
||||
unbindVAO();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
@Override
|
||||
public void reload() {
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
@Override
|
||||
public void removeContext() {
|
||||
|
||||
if (this.exist == true) {
|
||||
// OpenGL.deleteBuffers(this.vbo);
|
||||
this.exist = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
@Override
|
||||
public void removeContextToLate() {
|
||||
|
||||
this.exist = false;
|
||||
// for (int iii=0; iii<this.vbo.length; iii++) {
|
||||
// this.vbo[iii] = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
public void render(final RenderMode mode) {
|
||||
OpenGL.drawElements(mode, this.vertexCount);
|
||||
}
|
||||
|
||||
private void storeDataInAttributeList(final int attributeNumber, final int coordinateSize, final float[] data) {
|
||||
final int vboID = GL15.glGenBuffers();
|
||||
this.vbo.add(vboID);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID);
|
||||
final FloatBuffer buffer = storeDataInFloatBuffer(data);
|
||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
|
||||
GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0);
|
||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
public void unBindForRendering() {
|
||||
if (this.exist == false) {
|
||||
return;
|
||||
}
|
||||
if (this.positions != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_POSITIONS);
|
||||
}
|
||||
if (this.textureCoordinates != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_TEXTURE_COORDINATES);
|
||||
}
|
||||
if (this.normals != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_NORMALS);
|
||||
}
|
||||
if (this.colors != null) {
|
||||
GL20.glDisableVertexAttribArray(INDICE_VBO_COLORS);
|
||||
}
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
private void unbindVAO() {
|
||||
GL30.glBindVertexArray(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
@Override
|
||||
public boolean updateContext() {
|
||||
//Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.indices.length + ") ********************************");
|
||||
if (this.exist == false) {
|
||||
@ -200,66 +270,5 @@ public class ResourceVirtualArrayObject extends Resource {
|
||||
Log.verbose(" Stop: [" + getId() + "] '" + getName() + "'");
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
public void removeContext() {
|
||||
|
||||
if (this.exist == true) {
|
||||
// OpenGL.deleteBuffers(this.vbo);
|
||||
this.exist = false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
public void removeContextToLate() {
|
||||
|
||||
this.exist = false;
|
||||
// for (int iii=0; iii<this.vbo.length; iii++) {
|
||||
// this.vbo[iii] = 0;
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
public void reload() {
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
public static ResourceVirtualArrayObject create(float[] positions, float[] colors, float[] textureCoordinates, float[] normals, int[] indices) {
|
||||
ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, colors, textureCoordinates, normals, indices, indices.length);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
public static ResourceVirtualArrayObject create(float[] positions, float[] colors, int[] indices) {
|
||||
ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, colors, null, null, indices, indices.length);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
public static ResourceVirtualArrayObject create(float[] positions, int dimentions) {
|
||||
ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, null, null, null, null, positions.length/dimentions);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
public static ResourceVirtualArrayObject create(float[] positions, float[] textureCoordinates, float[] normals, int[] indices) {
|
||||
ResourceVirtualArrayObject resource = new ResourceVirtualArrayObject(positions, null, textureCoordinates, normals, indices, indices.length);
|
||||
if (resource.resourceHasBeenCorectlyInit() == false) {
|
||||
Log.critical("resource Is not correctly init: ResourceVirtualBufferObject");
|
||||
}
|
||||
getManager().localAdd(resource);
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
|
216
src/org/atriasoft/gale/resource/ResourceVirtualBufferObject.java
Normal file
216
src/org/atriasoft/gale/resource/ResourceVirtualBufferObject.java
Normal file
@ -0,0 +1,216 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
package org.atriasoft.gale.resource;
|
||||
|
||||
import org.atriasoft.etk.Color;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.gale.backend3d.OpenGL;
|
||||
import org.atriasoft.gale.backend3d.OpenGL.Usage;
|
||||
import org.atriasoft.gale.internal.Log;
|
||||
|
||||
/**
|
||||
* @brief ResourceVirtualBufferObject is a specific resources for opengl, this load the data directly in the graphic card ad keep these inside
|
||||
*/
|
||||
public class ResourceVirtualBufferObject extends Resource {
|
||||
|
||||
public static ResourceVirtualBufferObject create(final int count) {
|
||||
return new ResourceVirtualBufferObject(count);
|
||||
}
|
||||
|
||||
private boolean exist = false; //!< This data is availlable in the Graphic card
|
||||
private final int[] vbo; //!< openGl ID of this VBO
|
||||
private final Object[] buffer; //!< data that is availlable in the VBO system ...
|
||||
|
||||
/**
|
||||
* @brief Constructor of this VBO.
|
||||
* @param[in] accesMode Acces mode : ???
|
||||
*/
|
||||
protected ResourceVirtualBufferObject(final int _number) {
|
||||
super();
|
||||
this.vbo = new int[_number]; // 0
|
||||
this.buffer = new Object[_number];
|
||||
Log.debug("OGL : load VBO count=\"" + _number + "\"");
|
||||
this.resourceLevel = 3;
|
||||
}
|
||||
|
||||
public int bufferSize(final int vboidcoord) {
|
||||
if (this.buffer[vboidcoord] != null) {
|
||||
// select the buffer to set data inside it ...
|
||||
if (this.buffer[vboidcoord] instanceof float[]) {
|
||||
return ((float[]) (this.buffer[vboidcoord])).length;
|
||||
} else if (this.buffer[vboidcoord] instanceof int[]) {
|
||||
return ((int[]) (this.buffer[vboidcoord])).length;
|
||||
} else if (this.buffer[vboidcoord] instanceof Vector2f[]) {
|
||||
return ((Vector2f[]) (this.buffer[vboidcoord])).length;
|
||||
} else if (this.buffer[vboidcoord] instanceof Vector3f[]) {
|
||||
return ((Vector3f[]) (this.buffer[vboidcoord])).length;
|
||||
} else if (this.buffer[vboidcoord] instanceof Color[]) {
|
||||
return ((Color[]) (this.buffer[vboidcoord])).length;
|
||||
} else {
|
||||
Log.error("Not managed VBO model : " + this.buffer[vboidcoord].getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief clear buffers
|
||||
*/
|
||||
public void clear() {
|
||||
Log.verbose(" Clear: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
|
||||
// DO not clear the this.vbo indexed in the graphic cards ...
|
||||
for (int iii = 0; iii < this.buffer.length; iii++) {
|
||||
this.buffer[iii] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send the data to the graphic card.
|
||||
*/
|
||||
public synchronized void flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
getManager().update(this);
|
||||
Log.verbose("Request flush of VBO: [" + getId() + "] '" + getName() + "'");
|
||||
}
|
||||
|
||||
public int getElementSize(final int index) {
|
||||
if (this.buffer[index] != null) {
|
||||
// select the buffer to set data inside it ...
|
||||
if (this.buffer[index] instanceof float[]) {
|
||||
return 1;
|
||||
} else if (this.buffer[index] instanceof int[]) {
|
||||
return 1;
|
||||
} else if (this.buffer[index] instanceof Vector2f[]) {
|
||||
return 2;
|
||||
} else if (this.buffer[index] instanceof Vector3f[]) {
|
||||
return 3;
|
||||
} else if (this.buffer[index] instanceof Color[]) {
|
||||
return 4;
|
||||
} else {
|
||||
Log.error("Not managed VBO model : " + this.buffer[index].getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the real openGL ID.
|
||||
* @return the Ogl id reference of this VBO.
|
||||
*/
|
||||
public int getGL_ID(final int _id) {
|
||||
return this.vbo[_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Relode the shader from the file. used when a request of resouces reload is done.
|
||||
* @note this is really usefull when we tested the new themes or shader developpements.
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
removeContext();
|
||||
updateContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief remove the data from the opengl context.
|
||||
*/
|
||||
@Override
|
||||
public synchronized void removeContext() {
|
||||
if (this.exist == true) {
|
||||
OpenGL.deleteBuffers(this.vbo);
|
||||
this.exist = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Special android spec! It inform us that all context is removed and after notify us...
|
||||
*/
|
||||
@Override
|
||||
public synchronized void removeContextToLate() {
|
||||
this.exist = false;
|
||||
for (int iii = 0; iii < this.vbo.length; iii++) {
|
||||
this.vbo[iii] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the data from the graphic card.
|
||||
*/
|
||||
public void retreiveData() {
|
||||
Log.error("TODO ... ");
|
||||
}
|
||||
|
||||
public void setVboData(final int vboId, final Color[] data) {
|
||||
this.buffer[vboId] = data;
|
||||
}
|
||||
|
||||
public void setVboData(final int vboId, final float[] data) {
|
||||
this.buffer[vboId] = data;
|
||||
}
|
||||
|
||||
public void setVboData(final int vboId, final int[] data) {
|
||||
this.buffer[vboId] = data;
|
||||
}
|
||||
|
||||
public void setVboData(final int vboId, final Vector2f[] data) {
|
||||
this.buffer[vboId] = data;
|
||||
}
|
||||
|
||||
public void setVboData(final int vboId, final Vector3f[] data) {
|
||||
this.buffer[vboId] = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This load/reload the data in the opengl context, needed when removed previously.
|
||||
*/
|
||||
@Override
|
||||
public synchronized boolean updateContext() {
|
||||
Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
|
||||
/*
|
||||
if (lock.tryLock() == false) {
|
||||
//Lock error ==> try later ...
|
||||
Log.warning(" ==> Lock error on VBO");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
if (this.exist == false) {
|
||||
Log.debug(" ==> ALLOCATE new handle");
|
||||
// Allocate and assign a Vertex Array Object to our handle
|
||||
OpenGL.genBuffers(this.vbo);
|
||||
}
|
||||
this.exist = true;
|
||||
for (int iii = 0; iii < this.vbo.length; iii++) {
|
||||
Log.verbose("VBO : add [" + getId() + "]=" + this.buffer[iii].getClass().getCanonicalName() + "*sizeof(float) OGl_Id=" + this.vbo[iii]);
|
||||
if (this.buffer[iii] != null) {
|
||||
OpenGL.bindBuffer(this.vbo[iii]);
|
||||
// select the buffer to set data inside it ...
|
||||
if (this.buffer[iii] instanceof float[]) {
|
||||
OpenGL.bufferData((float[]) (this.buffer[iii]), Usage.streamDraw);
|
||||
} else if (this.buffer[iii] instanceof int[]) {
|
||||
OpenGL.bufferData((int[]) (this.buffer[iii]), Usage.streamDraw);
|
||||
} else if (this.buffer[iii] instanceof Vector2f[]) {
|
||||
OpenGL.bufferData((Vector2f[]) (this.buffer[iii]), Usage.streamDraw);
|
||||
} else if (this.buffer[iii] instanceof Vector3f[]) {
|
||||
OpenGL.bufferData((Vector3f[]) (this.buffer[iii]), Usage.streamDraw);
|
||||
} else if (this.buffer[iii] instanceof Color[]) {
|
||||
OpenGL.bufferData((Color[]) (this.buffer[iii]), Usage.streamDraw);
|
||||
} else {
|
||||
Log.error("Not managed VBO model : " + this.buffer[iii].getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
}
|
||||
// un-bind it to permet to have no error in the next display ...
|
||||
OpenGL.unbindBuffer();
|
||||
Log.verbose(" Stop: [" + getId() + "] '" + getName() + "'");
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user