[DEV] updates

This commit is contained in:
Edouard DUPIN 2021-03-25 18:55:52 +01:00
parent da0e6810f6
commit 84fc01f773
27 changed files with 2155 additions and 2043 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> <fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="ewol" local="false"> <fileset name="all" enabled="true" check-config-name="Ewol" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/> <file-match-pattern match-pattern="." include-pattern="true"/>
</fileset> </fileset>
</fileset-config> </fileset-config>

View File

@ -5,6 +5,7 @@
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="resources"/>
<classpathentry including="**/*.java" kind="src" output="out/eclipse/classes-test" path="test/src"> <classpathentry including="**/*.java" kind="src" output="out/eclipse/classes-test" path="test/src">
<attributes> <attributes>
<attribute name="test" value="true"/> <attribute name="test" value="true"/>

16
gale.iml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="etk" exported="" />
<orderEntry type="library" exported="" name="lwjgl-stb-natives-linux" level="project" />
<orderEntry type="library" exported="" name="pngdecoder" level="project" />
<orderEntry type="library" exported="" name="lwjgl3-awt-0.1.7" level="project" />
<orderEntry type="library" scope="TEST" name="org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
</component>
</module>

View File

@ -0,0 +1,16 @@
#version 400 core
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
in vec4 io_color;
// output:
out vec4 out_Color;
void main(void) {
out_Color = io_color;
}

View File

@ -0,0 +1,21 @@
#version 400 core
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
// Input :
in vec3 in_position;
uniform vec4 in_colors;
uniform mat4 in_matrixTransformation;
uniform mat4 in_matrixProjection;
uniform mat4 in_matrixView;
// output :
out vec4 io_color;
void main(void) {
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
io_color = vec4(in_colors.xyz, 0.3);
}

View File

@ -1,19 +1,21 @@
/** Basic module interface. /**
* Basic module interface.
* *
* @author Edouard DUPIN */ * @author Edouard DUPIN
*/
open module org.atriasoft.gale { open module org.atriasoft.gale {
exports org.atriasoft.gale; exports org.atriasoft.gale;
exports org.atriasoft.gale.backend3d; exports org.atriasoft.gale.backend3d;
exports org.atriasoft.gale.context; exports org.atriasoft.gale.context;
//exports org.atriasoft.gale.context.JOGL; // exports org.atriasoft.gale.context.JOGL;
exports org.atriasoft.gale.context.LWJG_AWT; exports org.atriasoft.gale.context.LWJG_AWT;
exports org.atriasoft.gale.key; exports org.atriasoft.gale.key;
exports org.atriasoft.gale.resource; exports org.atriasoft.gale.resource;
requires transitive org.atriasoft.etk; requires transitive org.atriasoft.etk;
//requires transitive vecmath; // requires transitive vecmath;
requires transitive org.lwjgl; requires transitive org.lwjgl;
requires transitive org.lwjgl.natives; requires transitive org.lwjgl.natives;
requires transitive org.lwjgl.glfw; requires transitive org.lwjgl.glfw;
@ -25,12 +27,12 @@ open module org.atriasoft.gale {
requires transitive org.lwjgl.stb; requires transitive org.lwjgl.stb;
requires transitive org.lwjgl.stb.natives; requires transitive org.lwjgl.stb.natives;
requires transitive org.lwjgl.jawt; requires transitive org.lwjgl.jawt;
//requires transitive org.lwjgl.opengl.awt; // requires transitive org.lwjgl.opengl.awt;
requires transitive org.lwjgl.opengl; requires transitive org.lwjgl.opengl;
requires transitive org.lwjgl.opengl.natives; requires transitive org.lwjgl.opengl.natives;
//requires org.lwjgl.openvr; // requires org.lwjgl.openvr;
//requires transitive jogamp.fat; // requires transitive jogamp.fat;
requires transitive java.desktop; requires transitive java.desktop;
requires transitive pngdecoder; requires transitive pngdecoder;

View File

@ -15,231 +15,38 @@ public class Application {
public boolean canDraw = false; public boolean canDraw = false;
private boolean needRedraw = true; private boolean needRedraw = true;
private String title = "gale"; private String title = "gale";
private Uri iconName = new Uri(""); private Uri iconName = null;
private Cursor cursor = Cursor.arrow; private final Cursor cursor = Cursor.arrow;
private Orientation orientation = Orientation.screenAuto; private Orientation orientation = Orientation.screenAuto;
Vector2f windowsSize = new Vector2f(800,600); Vector2f windowsSize = new Vector2f(800, 600);
public Application() { public Application() {
Log.verbose("Constructor Gale Application"); Log.verbose("Constructor Gale Application");
} }
/**
* @brief The application is created.
* @param context Current gale context.
*/
public void onCreate(Context context) {
Log.verbose("Create Gale Application");
}
/**
* @brief The application is started.
* @param context Current gale context.
*/
public void onStart(Context context){
Log.verbose("Start Gale Application");
}
/**
* @brief The application is resumed (now visible).
* @param context Current gale context.
*/
public void onResume(Context context){
Log.verbose("Start Gale Application");
}
/**
* @brief call application to precalculate drawing.
* @param context Current gale context.
*/
public void onRegenerateDisplay(Context context) {
//Log.verbose("Regenerate Gale Application");
markDrawingIsNeeded();
}
/** /**
* @brief Real draw of the application * Exit the application (not availlable on IOs, ==> the user will not understand the comportement. He will think the application has crashed (Apple philosophie))
* @param context Current gale context.
*/
public void onDraw(Context context) {
Log.verbose("draw Gale Application");
}
/**
* @brief The application is Hide / not visible.
* @param context Current gale context.
*/
public void onPause(Context context) {
Log.verbose("Pause Gale Application");
}
/**
* @brief The application is stopped.
* @param context Current gale context.
*/
public void onStop(Context context) {
Log.verbose("Stop Gale Application");
}
/**
* @brief The application is removed (call destructor just adter it.).
* @param context Current gale context.
*/
public void onDestroy(Context context) {
Log.verbose("Destroy Gale Application");
}
/**
* @brief The user request application removing.
* @param context Current gale context.
*/
public void onKillDemand(Context context) {
Log.info("Gale request auto destroy ==> no applification specification");
System.exit(0);
}
/**
* @brief Exit the application (not availlable on IOs, ==> the user will not understand the comportement. He will think the application has crashed (Apple philosophie))
* @param value value to return on the program * @param value value to return on the program
*/ */
public void exit(int value) { public void exit(final int value) {
Log.verbose("Exit Requested " + value); Log.verbose("Exit Requested " + value);
Gale.getContext().stop(); Gale.getContext().stop();
} }
public void markDrawingIsNeeded() {
this.needRedraw = true;
}
public boolean isDrawingNeeded() {
boolean tmp = this.needRedraw;
this.needRedraw = false;
return tmp;
}
/**
* @brief Get touch/mouse/... event.
* @param type Type of pointer event
* @param pointerID Pointer id of the touch event.
* @param pos Position of the event (can be <0 if out of window).
* @param state Key state (up/down/move)
*/
public void onPointer(KeySpecial special,
KeyType type,
int pointerID,
Vector2f pos,
KeyStatus state) {
}
/**
* @brief Get keyborad value input.
* @param special Current special key status (ctrl/alt/shift ...).
* @param type Type of the event.
* @param value Unicode value of the char pushed (viable only if type==gale::key::keyboard::character).
* @param state State of the key (up/down/upRepeate/downRepeate)
*/
public void onKeyboard(KeySpecial special,
KeyKeyboard type,
Character value,
KeyStatus state) {
}
/**
* @brief Show the virtal keyboard (if possible : only on iOs/Android)
*/
public void keyboardShow() {
Context context = Gale.getContext();
if (context == null) {
return;
}
context.keyboardShow();
}
/**
* @brief Hide the virtal keyboard (if possible : only on iOs/Android)
*/
public void keyboardHide() {
Context context = Gale.getContext();
if (context == null) {
return;
}
context.keyboardHide();
}
/**
* @brief Event generated when user change the size of the window.
* @param size New size of the window.
*/
public void onResize(Vector2f size) {
if (size == null) {
Log.error("Try to set a null size ...");
return;
}
windowsSize = size;
}
/**
* @brief Set the size of the window (if possible: Android and Ios does not support it)
* @param size New size of the window.
* @return
*/
public void setSize(Vector2f size) {
windowsSize = size;
Context context = Gale.getContext();
if (context == null) {
return;
}
context.setSize(size);
}
/**
* @brief Get the size of the window.
* @return Current size of the window.
*/
public Vector2f getSize() {
return windowsSize;
}
public float getAspectRatio() { public float getAspectRatio() {
return windowsSize.x/windowsSize.y; return this.windowsSize.x() / this.windowsSize.y();
} }
/** /**
* @brief Event generated when user change the position of the window. * Get the cursor type.
* @param size New position of the window. * @return the current cursor.
*/ */
public void onMovePosition(Vector2f size) { public Cursor getCursor() {
return this.cursor;
}
/**
* @brief Set the position of the window (if possible: Android and Ios does not support it)
* @param size New position of the window.
*/
public void setPosition(Vector2f size) {
}
/**
* @brief Get the position of the window.
* @return Current position of the window.
*/
public Vector2f getPosition() {
return new Vector2f(0,0);
} }
/** /**
* @brief Set the title of the application * Get the current filename of the application.
* @param title New title to set at the application (if possible: Android and Ios does not support it)
*/
public void setTitle(String title) {
this.title = title;
Context context = Gale.getContext();
if (context == null) {
return;
}
context.setTitle(this.title);
}
/**
* @brief Get the current title of the application
* @return Current title
*/
public String getTitle() {
return this.title;
}
/**
* @brief set the Icon of the application.
* @param iconFile File name icon (.bmp/.png).
*/
public void setIcon(Uri iconFile) {
this.iconName = iconFile;
Gale.getContext().setIcon(this.iconName);
}
/**
* @brief Get the current filename of the application.
* @return Filename of the icon. * @return Filename of the icon.
*/ */
public Uri getIcon() { public Uri getIcon() {
@ -247,29 +54,7 @@ public class Application {
} }
/** /**
* @brief Set the cursor type. * get the screen orientation (if possible : only on iOs/Android)
* @param newCursor Selected cursor.
*/
public void setCursor(Cursor newCursor) {
Gale.getContext().setCursor(this.cursor);
}
/**
* @brief Get the cursor type.
* @return the current cursor.
*/
public Cursor getCursor() {
return this.cursor;
}
/**
* @brief set the screen orientation (if possible : only on iOs/Android)
* @param orientation New orientation.
*/
public void setOrientation(Orientation orientation) {
this.orientation = orientation;
Gale.getContext().forceOrientation(this.orientation);
}
/**
* @brief get the screen orientation (if possible : only on iOs/Android)
* @return Current orientation. * @return Current orientation.
*/ */
public Orientation getOrientation() { public Orientation getOrientation() {
@ -277,16 +62,249 @@ public class Application {
} }
/** /**
* @brief A clipboard data is back (apear after a request of a new clipboard). * Get the position of the window.
* @return Current position of the window.
*/
public Vector2f getPosition() {
return new Vector2f(0, 0);
}
/**
* Get the size of the window.
* @return Current size of the window.
*/
public Vector2f getSize() {
return this.windowsSize;
}
/**
* Get the current title of the application
* @return Current title
*/
public String getTitle() {
return this.title;
}
public boolean isDrawingNeeded() {
final boolean tmp = this.needRedraw;
this.needRedraw = false;
return tmp;
}
/**
* Hide the virtal keyboard (if possible : only on iOs/Android)
*/
public void keyboardHide() {
final Context context = Gale.getContext();
if (context == null) {
return;
}
context.keyboardHide();
}
/**
* Show the virtal keyboard (if possible : only on iOs/Android)
*/
public void keyboardShow() {
final Context context = Gale.getContext();
if (context == null) {
return;
}
context.keyboardShow();
}
public void markDrawingIsNeeded() {
this.needRedraw = true;
}
/**
* A clipboard data is back (apear after a request of a new clipboard).
* @param clipboardId Id of the clipboard. * @param clipboardId Id of the clipboard.
*/ */
public void onClipboardEvent(ClipboardList clipboardId) { public void onClipboardEvent(final ClipboardList clipboardId) {
} }
/** /**
* @brief Call every time a draw is called (not entirely periodic, but faster at we can ... * The application is created.
* @param context Current gale context.
*/
public void onCreate(final Context context) {
Log.verbose("Create Gale Application");
}
/**
* The application is removed (call destructor just adter it.).
* @param context Current gale context.
*/
public void onDestroy(final Context context) {
Log.verbose("Destroy Gale Application");
}
/**
* Real draw of the application
* @param context Current gale context.
*/
public void onDraw(final Context context) {
Log.verbose("draw Gale Application");
}
/**
* Get keyborad value input.
* @param special Current special key status (ctrl/alt/shift ...).
* @param type Type of the event.
* @param value Unicode value of the char pushed (viable only if type==gale::key::keyboard::character).
* @param state State of the key (up/down/upRepeate/downRepeate)
*/
public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
}
/**
* The user request application removing.
* @param context Current gale context.
*/
public void onKillDemand(final Context context) {
Log.info("Gale request auto destroy ==> no applification specification");
System.exit(0);
}
/**
* Event generated when user change the position of the window.
* @param size New position of the window.
*/
public void onMovePosition(final Vector2f size) {
}
/**
* The application is Hide / not visible.
* @param context Current gale context.
*/
public void onPause(final Context context) {
Log.verbose("Pause Gale Application");
}
/**
* Call every time a draw is called (not entirely periodic, but faster at we can ...
* @param time Current time of the call; * @param time Current time of the call;
*/ */
public void onPeriod(long time) {}; public void onPeriod(final long time) {}
/**
* Get touch/mouse/... event.
* @param type Type of pointer event
* @param pointerID Pointer id of the touch event.
* @param pos Position of the event (can be <0 if out of window).
* @param state Key state (up/down/move)
*/
public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
}
/**
* call application to precalculate drawing.
* @param context Current gale context.
*/
public void onRegenerateDisplay(final Context context) {
//Log.verbose("Regenerate Gale Application");
markDrawingIsNeeded();
}
/**
* Event generated when user change the size of the window.
* @param size New size of the window.
*/
public void onResize(final Vector2f size) {
if (size == null) {
Log.error("Try to set a null size ...");
return;
}
this.windowsSize = size;
}
/**
* The application is resumed (now visible).
* @param context Current gale context.
*/
public void onResume(final Context context) {
Log.verbose("Start Gale Application");
}
/**
* The application is started.
* @param context Current gale context.
*/
public void onStart(final Context context) {
Log.verbose("Start Gale Application");
}
/**
* The application is stopped.
* @param context Current gale context.
*/
public void onStop(final Context context) {
Log.verbose("Stop Gale Application");
}
/**
* Set the cursor type.
* @param newCursor Selected cursor.
*/
public void setCursor(final Cursor newCursor) {
Gale.getContext().setCursor(this.cursor);
}
/**
* set the Icon of the application.
* @param iconFile File name icon (.bmp/.png).
*/
public void setIcon(final Uri iconFile) {
this.iconName = iconFile;
Gale.getContext().setIcon(this.iconName);
}
/**
* set the screen orientation (if possible : only on iOs/Android)
* @param orientation New orientation.
*/
public void setOrientation(final Orientation orientation) {
this.orientation = orientation;
Gale.getContext().forceOrientation(this.orientation);
}
/**
* Set the position of the window (if possible: Android and Ios does not support it)
* @param size New position of the window.
*/
public void setPosition(final Vector2f size) {
}
/**
* Set the size of the window (if possible: Android and Ios does not support it)
* @param size New size of the window.
* @return
*/
public void setSize(final Vector2f size) {
this.windowsSize = size;
final Context context = Gale.getContext();
if (context == null) {
return;
}
context.setSize(size);
}
/**
* Set the title of the application
* @param title New title to set at the application (if possible: Android and Ios does not support it)
*/
public void setTitle(final String title) {
this.title = title;
final Context context = Gale.getContext();
if (context == null) {
return;
}
context.setTitle(this.title);
};
} }

View File

@ -6,340 +6,275 @@
package org.atriasoft.gale; package org.atriasoft.gale;
import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.gale.internal.Log; import org.atriasoft.gale.internal.Log;
/** /**
* @brief in the dimention class we store the data as the more usefull unit (pixel) * in the dimension 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 * but one case need to be dynamic the %, then when requested in % the register the % value
*/ */
public class Dimension { @SuppressWarnings("preview")
private final static Vector2f ratio = new Vector2f(9999999, 888888); public record Dimension(
private final static Vector2f invRatio = new Vector2f(1, 1); Vector2f size,
private final static Dimension windowsSize = new Dimension(new Vector2f(9999999, 888888), Distance.PIXEL); Distance type) {
public static final Dimension ZERO = new Dimension(Vector2f.ZERO, Distance.PIXEL);
private static Vector2f ratio = new Vector2f(9999999, 888888);
private static Vector2f invRatio = new Vector2f(1, 1);
private static Dimension windowsSize = new Dimension(Vector2f.MAX_VALUE, Distance.PIXEL);
public final static float INCH_TO_MILLIMETER = 1.0f / 25.4f; public static final float INCH_TO_MILLIMETER = 1.0f / 25.4f;
public final static float FOOT_TO_MILLIMETER = 1.0f / 304.8f; public static final float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
public final static float METER_TO_MILLIMETER = 1.0f / 1000.0f; public static final float METER_TO_MILLIMETER = 1.0f / 1000.0f;
public final static float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f; public static final float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f;
public final static float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f; public static final float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f;
public final static float MILLIMETER_TO_INCH = 25.4f; public static final float MILLIMETER_TO_INCH = 25.4f;
public final static float MILLIMETER_TO_FOOT = 304.8f; public static final float MILLIMETER_TO_FOOT = 304.8f;
public final static float MILLIMETER_TO_METER = 1000.0f; public static final float MILLIMETER_TO_METER = 1000.0f;
public final static float MILLIMETER_TO_CENTIMETER = 10.0f; public static final float MILLIMETER_TO_CENTIMETER = 10.0f;
public final static float MILLIMETER_TO_KILOMETER = 1000000.0f; public static final float MILLIMETER_TO_KILOMETER = 1000000.0f;
/** /**
* @brief basic init * basic init
*/ */
static { static {
final Dimension conversion = new Dimension(new Vector2f(72, 72), Distance.INCH); final Dimension conversion = new Dimension(new Vector2f(72, 72), Distance.INCH);
ratio.set(conversion.getMillimeter()); ratio = conversion.getMillimeter();
invRatio.setValue(1.0f / ratio.x, 1.0f / ratio.y); invRatio = new Vector2f(1.0f / ratio.x(), 1.0f / ratio.y());
windowsSize.set(new Vector2f(200, 200), Distance.PIXEL); windowsSize = new Dimension(new Vector2f(200, 200), Distance.PIXEL);
} }
/** /**
* @brief get the Windows diagonal size in the request unit * get the Windows diagonal size in the request unit
* @param[in] type Unit type requested. * @param type Unit type requested.
* @return the requested size * @return the requested size
*/ */
public static float getWindowsDiag(final Distance _type) { public static float getWindowsDiag(final Distance type) {
final Vector2f size = getWindowsSize(_type); final Vector2f size = getWindowsSize(type);
return size.length(); return size.length();
} }
/** /**
* @brief get the Windows size in the request unit * get the Windows size in the request unit
* @param[in] type Unit type requested. * @param type Unit type requested.
* @return the requested size * @return the requested size
*/ */
public static Vector2f getWindowsSize(final Distance _type) { public static Vector2f getWindowsSize(final Distance type) {
return windowsSize.get(_type); return windowsSize.get(type);
} }
/** /**
* @brief set the Milimeter ratio for calculation * set the Milimeter ratio for calculation
* @param[in] Ratio Milimeter ration for the screen calculation interpolation * @param ratio Milimeter ration for the screen calculation interpolation
* @param[in] type Unit type requested. * @param type Unit type requested.
* @note: same as @ref setPixelPerInch (internal manage convertion) * @note: same as @ref setPixelPerInch (internal manage convertion)
*/ */
public static void setPixelRatio(final Vector2f _ratio, final Distance _type) { public static void setPixelRatio(final Vector2f ratio, final Distance type) {
Log.info("Set a new screen ratio for the screen : ratio=" + _ratio + " type=" + _type); Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
final Dimension conversion = new Dimension(_ratio, _type); final Dimension conversion = new Dimension(ratio, type);
Log.info(" == > " + conversion); Log.info(" == > " + conversion);
ratio.set(conversion.getMillimeter()); Dimension.ratio = conversion.getMillimeter();
invRatio.setValue(1.0f / ratio.x, 1.0f / ratio.y); invRatio = new Vector2f(1.0f / Dimension.ratio.x(), 1.0f / Dimension.ratio.y());
Log.info("Set a new screen ratio for the screen : ratioMm=" + ratio); Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension.ratio);
} }
/** /**
* @brief set the current Windows size * set the current Windows size
* @param[in] size size of the current windows in pixel. * @param size size of the current windows in pixel.
*/ */
public static void setPixelWindowsSize(final Vector2f _size) { public static void setPixelWindowsSize(final Vector2f size) {
windowsSize.set(_size); windowsSize = new Dimension(size);
Log.verbose("Set a new Windows property size " + windowsSize + "px"); 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) * Constructor (default :0,0 mode pixel)
*/ */
public Dimension() { public Dimension() {
this(Vector2f.ZERO, Distance.PIXEL);
} }
/** /**
* @brief Constructor * Constructor
* @param[in] _config dimension configuration. * @param size Requested dimension
*/ */
public Dimension(final String _config) { public Dimension(final Vector2f size) {
set(_config); this(size, Distance.PIXEL);
}
public Dimension(final Vector2f size, final Distance type) {
this.size = size;
this.type = type;
} }
/** /**
* @brief Constructor * get the current dimension in requested type
* @param[in] _size Requested dimension * @param type Type of unit requested.
* @param[in] _type Unit of the Dimension * @return dimension requested.
*/ */
public Dimension(final Vector2f _size) { public Vector2f get(final Distance type) {
set(_size, Distance.PIXEL); return switch (type) {
} case POURCENT -> getPourcent();
case PIXEL -> getPixel();
public Dimension(final Vector2f _size, final Distance _type) { case METER -> getMeter();
set(_size, _type); case CENTIMETER -> getCentimeter();
} case MILLIMETER -> getMillimeter();
case KILOMETER -> getKilometer();
/***************************************************** case INCH -> getInch();
* isEqual case FOOT -> getFoot();
*****************************************************/ };
@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 * get the current dimension in Centimeter
* @param[in] _type Type of unit requested. * @return dimension in Centimeter
* @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() { public Vector2f getCentimeter() {
return getMillimeter().multiplyNew(MILLIMETER_TO_CENTIMETER); return getMillimeter().multiply(MILLIMETER_TO_CENTIMETER);
} }
/** /**
* @brief get the current dimention in Foot * get the current dimension in Foot
* @return dimention in Foot * @return dimension in Foot
*/ */
public Vector2f getFoot() { public Vector2f getFoot() {
return getMillimeter().multiplyNew(MILLIMETER_TO_FOOT); return getMillimeter().multiply(MILLIMETER_TO_FOOT);
} }
/** /**
* @brief get the current dimention in Inch * get the current dimension in Inch
* @return dimention in Inch * @return dimension in Inch
*/ */
public Vector2f getInch() { public Vector2f getInch() {
return getMillimeter().multiplyNew(MILLIMETER_TO_INCH); return getMillimeter().multiply(MILLIMETER_TO_INCH);
} }
/** /**
* @brief get the current dimention in Kilometer * get the current dimension in Kilometer
* @return dimention in Kilometer * @return dimension in Kilometer
*/ */
public Vector2f getKilometer() { public Vector2f getKilometer() {
return getMillimeter().multiplyNew(MILLIMETER_TO_KILOMETER); return getMillimeter().multiply(MILLIMETER_TO_KILOMETER);
} }
/** /**
* @brief get the current dimention in Meter * get the current dimension in Meter
* @return dimention in Meter * @return dimension in Meter
*/ */
public Vector2f getMeter() { public Vector2f getMeter() {
return getMillimeter().multiplyNew(MILLIMETER_TO_METER); return getMillimeter().multiply(MILLIMETER_TO_METER);
} }
/** /**
* @brief get the current dimention in Millimeter * get the current dimension in Millimeter
* @return dimention in Millimeter * @return dimension in Millimeter
*/ */
public Vector2f getMillimeter() { public Vector2f getMillimeter() {
return new Vector2f(getPixel().x * invRatio.x, getPixel().y * invRatio.y); return new Vector2f(getPixel().x() * invRatio.x(), getPixel().y() * invRatio.y());
} }
/** /**
* @brief get the current dimention in pixel * get the current dimension in pixel
* @return dimention in Pixel * @return dimension in Pixel
*/ */
public Vector2f getPixel() { public Vector2f getPixel() {
if (this.type != Distance.POURCENT) { if (this.type != Distance.POURCENT) {
return this.size; return this.size;
} else { }
final Vector2f windDim = windowsSize.getPixel(); final Vector2f windDim = windowsSize.getPixel();
final Vector2f res = new Vector2f(windDim.x * this.size.x, windDim.y * this.size.y); final Vector2f res = new Vector2f(windDim.x() * this.size.x(), windDim.y() * this.size.y());
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res); //GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res; return res;
} }
public Vector2i getPixeli() {
if (this.type != Distance.POURCENT) {
return new Vector2i((int) this.size.x(), (int) this.size.y());
}
final Vector2f windDim = windowsSize.getPixel();
final Vector2i res = new Vector2i((int) (windDim.x() * this.size.x()), (int) (windDim.y() * this.size.y()));
//GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
return res;
} }
/** /**
* @brief get the current dimention in Pourcent * get the current dimension in Pourcent
* @return dimention in Pourcent * @return dimension in Pourcent
*/ */
public Vector2f getPourcent() { public Vector2f getPourcent() {
if (this.type != Distance.POURCENT) { if (this.type != Distance.POURCENT) {
final Vector2f windDim = windowsSize.getPixel(); final Vector2f windDim = windowsSize.getPixel();
//GALE_DEBUG(" windows dimention : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ... //GALE_DEBUG(" windows dimension : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ...
//printf(" windows dimention : %f,%f", windDim.x(),windDim.y()); //printf(" windows dimension : %f,%f", windDim.x(),windDim.y());
//printf(" data : %f,%f", m_data.x(),m_data.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() / windDim.x()) * 100.0f, (this.size.y() / windDim.y()) * 100.0f);
} }
return new Vector2f(this.size.x * 100.0f, this.size.y * 100.0f); return new Vector2f(this.size.x() * 100.0f, this.size.y() * 100.0f);
}; };
/** /**
* @breif get the dimension type * get the dimension type
* @return the type * @return the type
*/ */
public Distance getType() { public Distance getType() {
return this.type; 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 * set the current dimension in requested type
* @param[in] _config dimension configuration. * @param config dimension configuration.
*/ */
private void set(String _config) { public static Dimension valueOf(String config) {
this.size.setValue(0, 0); final Vector2f size = Vector2f.ZERO;
this.type = Distance.PIXEL;
Distance type = Distance.PIXEL; Distance type = Distance.PIXEL;
if (_config.endsWith("%") == true) { if (config.endsWith("%")) {
type = Distance.POURCENT; type = Distance.POURCENT;
_config = _config.substring(0, _config.length() - 1); config = config.substring(0, config.length() - 1);
} else if (_config.endsWith("px") == true) { } else if (config.endsWith("px")) {
type = Distance.PIXEL; type = Distance.PIXEL;
_config = _config.substring(0, _config.length() - 2); config = config.substring(0, config.length() - 2);
} else if (_config.endsWith("ft") == true) { } else if (config.endsWith("ft")) {
type = Distance.FOOT; type = Distance.FOOT;
_config = _config.substring(0, _config.length() - 2); config = config.substring(0, config.length() - 2);
} else if (_config.endsWith("in") == true) { } else if (config.endsWith("in")) {
type = Distance.INCH; type = Distance.INCH;
_config = _config.substring(0, _config.length() - 2); config = config.substring(0, config.length() - 2);
} else if (_config.endsWith("km") == true) { } else if (config.endsWith("km")) {
type = Distance.KILOMETER; type = Distance.KILOMETER;
_config = _config.substring(0, _config.length() - 2); config = config.substring(0, config.length() - 2);
} else if (_config.endsWith("mm") == true) { } else if (config.endsWith("mm")) {
type = Distance.MILLIMETER; type = Distance.MILLIMETER;
_config = _config.substring(0, _config.length() - 2); config = config.substring(0, config.length() - 2);
} else if (_config.endsWith("cm") == true) { } else if (config.endsWith("cm")) {
type = Distance.CENTIMETER; type = Distance.CENTIMETER;
_config = _config.substring(0, _config.length() - 2); config = config.substring(0, config.length() - 2);
} else if (_config.endsWith("m") == true) { } else if (config.endsWith("m")) {
type = Distance.METER; type = Distance.METER;
_config = _config.substring(0, _config.length() - 1); config = config.substring(0, config.length() - 1);
} else { } else {
Log.critical("Can not parse dimention : '" + _config + "'"); Log.critical("Can not parse dimension : '" + config + "'");
return; return null;
} }
final Vector2f tmp = Vector2f.valueOf(_config); final Vector2f tmp = Vector2f.valueOf(config);
set(tmp, type); final Dimension ret = new Dimension(tmp, type);
Log.verbose(" config dimention : \"" + _config + "\" == > " + this); Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
} return ret;
public void set(final Vector2f _size) {
this.size = _size;
this.type = Distance.PIXEL;
} }
/** /**
* @brief set the current dimention in requested type * string cast :
* @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 @Override
public String toString() { public String toString() {
String str = get(getType()).toString(); String str = get(getType()).toString();
switch (getType()) { switch (getType()) {
case POURCENT: case POURCENT -> str += "%";
str += "%"; case PIXEL -> str += "px";
break; case METER -> str += "m";
case PIXEL: case CENTIMETER -> str += "cm";
str += "px"; case MILLIMETER -> str += "mm";
break; case KILOMETER -> str += "km";
case METER: case INCH -> str += "in";
str += "m"; case FOOT -> str += "ft";
break; default -> str += "";
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; return str;
} }

View File

@ -1,5 +1,6 @@
package org.atriasoft.gale; package org.atriasoft.gale;
import org.atriasoft.etk.Uri;
import org.atriasoft.gale.context.Context; import org.atriasoft.gale.context.Context;
//import org.atriasoft.gale.context.JOGL.ContextJOGL; //import org.atriasoft.gale.context.JOGL.ContextJOGL;
import org.atriasoft.gale.context.LWJG_AWT.ContextLWJGLAWT; import org.atriasoft.gale.context.LWJG_AWT.ContextLWJGLAWT;
@ -7,9 +8,25 @@ import org.atriasoft.gale.context.LWJG_AWT.ContextLWJGLAWT;
import org.atriasoft.gale.internal.Log; import org.atriasoft.gale.internal.Log;
public class Gale { public class Gale {
private Gale() {} public static Context getContext() {
// TODO Auto-generated method stub
return Context.getContext();
}
/** /**
* @brief This is the only one things the User might done in his main(); * get GALE version
* @return The string that describe gale version
*/
public static String getVersion() {
return "J-0.5";
}
public static void init() {
Uri.addLibrary("gale", Gale.class, "/resources/gale/");
}
/**
* This is the only one things the User might done in his main();
* @note To answare you before you ask the question, this is really simple: * @note To answare you before you ask the question, this is really simple:
* Due to the fect that the current system is multiple-platform, you "main" * Due to the fect that the current system is multiple-platform, you "main"
* Does not exist in the android platform, then gale call other start * Does not exist in the android platform, then gale call other start
@ -20,7 +37,8 @@ public class Gale {
* @param _argv Standard argv * @param _argv Standard argv
* @return normal error int for the application error management * @return normal error int for the application error management
*/ */
public static int run(Application application, String[] arg) { public static int run(final Application application, final String[] arg) {
init();
//etk::init(_argc, _argv); //etk::init(_argc, _argv);
Context context = null; Context context = null;
String request = ""; String request = "";
@ -35,16 +53,5 @@ public class Gale {
return context.run(); return context.run();
} }
/** private Gale() {}
* @brief get GALE version
* @return The string that describe gale version
*/
public static String getVersion() {
return "J-0.5";
}
public static Context getContext() {
// TODO Auto-generated method stub
return Context.getContext();
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -3,14 +3,14 @@ package org.atriasoft.gale.context;
public class ClipBoard { public class ClipBoard {
private ClipBoard() {} private ClipBoard() {}
/** /**
* @brief set the string data on a specific clipboard. The Gui system is notify that the clipboard "SELECTION" and "COPY" are change * set the string data on a specific clipboard. The Gui system is notify that the clipboard "SELECTION" and "COPY" are change
* @param _clipboardID Select the specific ID of the clipboard * @param _clipboardID Select the specific ID of the clipboard
* @param _data The string that might be send to the clipboard * @param _data The string that might be send to the clipboard
*/ */
public static void set(ClipboardList clipboardID, String data) { public static void set(ClipboardList clipboardID, String data) {
} }
/** /**
* @brief Call system to request the current clipboard. * Call system to request the current clipboard.
* @note Due to some system that manage the clipboard request asynchronous (like X11) and gale managing the system with only one thread, * @note Due to some system that manage the clipboard request asynchronous (like X11) and gale managing the system with only one thread,
* we need the call the system to send us the buffer, this is really ambigous, but the widget (who has focus) receive the * we need the call the system to send us the buffer, this is really ambigous, but the widget (who has focus) receive the
* notification of the arrival of this buffer id * notification of the arrival of this buffer id
@ -19,7 +19,7 @@ public class ClipBoard {
public static void request(ClipboardList clipboardID) { public static void request(ClipboardList clipboardID) {
} }
/** /**
* @brief set the gale internal buffer (no notification at the GUI). This fuction might be use by the * set the gale internal buffer (no notification at the GUI). This fuction might be use by the
* Gui abstraction to set the buffer we receive. The end user must not use it. * Gui abstraction to set the buffer we receive. The end user must not use it.
* @param _clipboardID selected clipboard ID * @param _clipboardID selected clipboard ID
* @param _data new buffer data * @param _data new buffer data
@ -27,7 +27,7 @@ public class ClipBoard {
public static void setSystem(ClipboardList clipboardID, String data) { public static void setSystem(ClipboardList clipboardID, String data) {
} }
/** /**
* @brief get the gale internal buffer of the curent clipboard. The end user can use it when he receive the event in * get the gale internal buffer of the curent clipboard. The end user can use it when he receive the event in
* the widget : @ref onEventClipboard == > we can nothe this function is the only one which permit it. * the widget : @ref onEventClipboard == > we can nothe this function is the only one which permit it.
* @note if we call this fuction withoutcallin @ref gale::context::clipBoard::Request, we only get the previous clipboard * @note if we call this fuction withoutcallin @ref gale::context::clipBoard::Request, we only get the previous clipboard
* @param _clipboardID selected clipboard ID * @param _clipboardID selected clipboard ID

View File

@ -28,7 +28,7 @@ public abstract class Context {
private static int countMemeCheck = 0; private static int countMemeCheck = 0;
/** /**
* @brief From everyware in the program, we can get the context inteface. * From everyware in the program, we can get the context inteface.
* @return current reference on the instance. * @return current reference on the instance.
*/ */
public static Context getContext() { public static Context getContext() {
@ -78,13 +78,13 @@ public abstract class Context {
// this.displayFps=true; // this.displayFps=true;
// } else if ( this.commandLine.get(iii) == "-h" // } else if ( this.commandLine.get(iii) == "-h"
// || this.commandLine.get(iii) == "--help" // || this.commandLine.get(iii) == "--help"
// || start_with(this.commandLine.get(iii), "--gale")) { // || startwith(this.commandLine.get(iii), "--gale")) {
// Log.print("gale - help : "); // Log.print("gale - help : ");
// Log.print(" --gale-fps"); // Log.print(" --gale-fps");
// Log.print(" Display the current fps of the display"); // Log.print(" Display the current fps of the display");
// Log.print(" -h/--help"); // Log.print(" -h/--help");
// Log.print(" Display this help"); // Log.print(" Display this help");
// if (start_with(this.commandLine.get(iii), "--gale")) { // if (startwith(this.commandLine.get(iii), "--gale")) {
// Log.error("gale unknow element in parameter: '" << this.commandLine.get(iii) << "'"); // Log.error("gale unknow element in parameter: '" << this.commandLine.get(iii) << "'");
// // remove parameter ... // // remove parameter ...
// } else { // } else {
@ -101,14 +101,14 @@ public abstract class Context {
Log.info("GALE v:" + Gale.getVersion()); Log.info("GALE v:" + Gale.getVersion());
forceOrientation(Orientation.screenAuto); forceOrientation(Orientation.screenAuto);
postAction((_context) -> { postAction((context) -> {
final Application appl = _context.getApplication(); final Application appl = context.getApplication();
if (appl == null) { if (appl == null) {
return; return;
} }
appl.onCreate(_context); appl.onCreate(context);
appl.onStart(_context); appl.onStart(context);
appl.onResume(_context); appl.onResume(context);
appl.canDraw = true; appl.canDraw = true;
}); });
@ -118,8 +118,8 @@ public abstract class Context {
} }
/** /**
* @brief Inform the Gui that we want to have a copy of the clipboard * Inform the Gui that we want to have a copy of the clipboard
* @param _clipboardID ID of the clipboard (STD/SELECTION) only apear here * @param clipboardID ID of the clipboard (STD/SELECTION) only apear here
*/ */
public void clipBoardGet(final ClipboardList clipboardID) { public void clipBoardGet(final ClipboardList clipboardID) {
// just transmit an event , we have the data in the system // just transmit an event , we have the data in the system
@ -127,21 +127,21 @@ public abstract class Context {
} }
/** /**
* @brief Inform the Gui that we are the new owner of the clipboard * Inform the Gui that we are the new owner of the clipboard
* @param _clipboardID ID of the clipboard (STD/SELECTION) only apear here * @param clipboardID ID of the clipboard (STD/SELECTION) only apear here
*/ */
public void clipBoardSet(final ClipboardList clipboardID) { public void clipBoardSet(final ClipboardList clipboardID) {
// nothing to do, data is already copyed in the GALE clipborad center // nothing to do, data is already copyed in the GALE clipborad center
} }
/** /**
* @brief force the screen orientation (availlable on portable elements ... * force the screen orientation (availlable on portable elements ...
* @param _orientation Selected orientation. * @param orientation Selected orientation.
*/ */
public void forceOrientation(final Orientation orientation) {} public void forceOrientation(final Orientation orientation) {}
/** /**
* @brief Redraw all the windows * Redraw all the windows
*/ */
public void forceRedrawAll() { public void forceRedrawAll() {
if (this.application == null) { if (this.application == null) {
@ -180,7 +180,7 @@ public abstract class Context {
} }
/** /**
* @brief The Application request the current position of the windows. * The Application request the current position of the windows.
* @return Turrent position of the Windows. * @return Turrent position of the Windows.
*/ */
public Vector2f getPos() { public Vector2f getPos() {
@ -192,7 +192,7 @@ public abstract class Context {
} }
/** /**
* @brief get the current windows size * get the current windows size
* @return the current size ... * @return the current size ...
*/ */
public Vector2f getSize() { public Vector2f getSize() {
@ -200,20 +200,20 @@ public abstract class Context {
} }
/** /**
* @brief get all Keyboard event from the X system (like many time use of META) * get all Keyboard event from the X system (like many time use of META)
* @param _status "true" if all the event will be get, false if we want only ours. * @param status "true" if all the event will be get, false if we want only ours.
*/ */
public void grabKeyboardEvents(final boolean status) {} public void grabKeyboardEvents(final boolean status) {}
/** /**
* @brief get all Mouse/Touch events from the X system * get all Mouse/Touch events from the X system
* @param _status "true" if all the event will be get, false if we want only ours. * @param status "true" if all the event will be get, false if we want only ours.
* @param _forcedPosition the position where the mouse might be reset at every events ... * @param forcedPosition the position where the mouse might be reset at every events ...
*/ */
public void grabPointerEvents(final boolean status, final Vector2f forcedPosition) {} public void grabPointerEvents(final boolean status, final Vector2f forcedPosition) {}
/** /**
* @brief The Application request that the Windows will be Hidden. * The Application request that the Windows will be Hidden.
*/ */
public void hide() { public void hide() {
Log.info("hide: NOT implemented ..."); Log.info("hide: NOT implemented ...");
@ -224,14 +224,14 @@ public abstract class Context {
} }
/** /**
* @brief Hide the virtal keyboard (for touch system only) * Hide the virtal keyboard (for touch system only)
*/ */
public void keyboardHide() { public void keyboardHide() {
Log.info("keyboardHide: NOT implemented ..."); Log.info("keyboardHide: NOT implemented ...");
} }
/** /**
* @brief display the virtal keyboard (for touch system only) * display the virtal keyboard (for touch system only)
*/ */
public void keyboardShow() { public void keyboardShow() {
Log.info("keyboardShow: NOT implemented ..."); Log.info("keyboardShow: NOT implemented ...");
@ -242,13 +242,13 @@ public abstract class Context {
} }
/** /**
* @brief Open an URL on an eternal brother. * Open an URL on an eternal brother.
* @param _url URL to open. * @param url URL to open.
*/ */
public void openURL(final String url) {} public void openURL(final String url) {}
/** /**
* @brief The current context is set in background (framerate is slowing down (max fps)/5 # 4fps) * The current context is set in background (framerate is slowing down (max fps)/5 # 4fps)
*/ */
public void operatingSystemBackground() { public void operatingSystemBackground() {
// set the current interface : // set the current interface :
@ -262,8 +262,8 @@ public abstract class Context {
} }
/** /**
* @brief Call by the OS when a clipboard arrive to US (previously requested by a widget) * Call by the OS when a clipboard arrive to US (previously requested by a widget)
* @param Id of the clipboard * @param clipboardID of the clipboard
*/ */
public void operatingSystemClipBoardArrive(final ClipboardList clipboardID) { public void operatingSystemClipBoardArrive(final ClipboardList clipboardID) {
postAction((context) -> { postAction((context) -> {
@ -297,7 +297,7 @@ public abstract class Context {
OpenGL.threadHasContext(); OpenGL.threadHasContext();
OpenGL.resetFlagState(); OpenGL.resetFlagState();
// process the events // process the events
if (this.displayFps == true) { if (this.displayFps) {
this.fpsSystemEvent.tic(); this.fpsSystemEvent.tic();
} }
boolean needRedraw = false; boolean needRedraw = false;
@ -333,52 +333,52 @@ public abstract class Context {
{ {
// Lock openGl context: // Lock openGl context:
OpenGL.lock(); OpenGL.lock();
if (this.displayFps == true) { if (this.displayFps) {
this.fpsSystemContext.tic(); this.fpsSystemContext.tic();
} }
if (needRedraw = true || displayEveryTime == true) { if (needRedraw || displayEveryTime) {
//Log.debug(" ==> real Draw"); //Log.debug(" ==> real Draw");
lockContext(); lockContext();
this.resourceManager.updateContext(); this.resourceManager.updateContext();
unLockContext(); unLockContext();
if (this.displayFps == true) { if (this.displayFps) {
this.fpsSystemContext.incrementCounter(); this.fpsSystemContext.incrementCounter();
} }
} }
if (this.displayFps == true) { if (this.displayFps) {
this.fpsSystemContext.toc(); this.fpsSystemContext.toc();
this.fpsSystem.tic(); this.fpsSystem.tic();
} }
if (this.application != null) { if (this.application != null) {
if (needRedraw == true || displayEveryTime == true) { if (needRedraw || displayEveryTime) {
this.fpsSystem.incrementCounter(); this.fpsSystem.incrementCounter();
// set the current interface : // set the current interface :
lockContext(); lockContext();
if (this.application.canDraw == true) { if (this.application.canDraw) {
this.application.onDraw(this); this.application.onDraw(this);
} }
unLockContext(); unLockContext();
hasDisplayDone = true; hasDisplayDone = true;
} }
} }
if (this.displayFps == true) { if (this.displayFps) {
this.fpsSystem.toc(); this.fpsSystem.toc();
this.fpsFlush.tic(); this.fpsFlush.tic();
} }
if (hasDisplayDone == true) { if (hasDisplayDone) {
//Log.info("lklklklklk " << _displayEveryTime); //Log.info("lklklklklk " << displayEveryTime);
if (this.displayFps == true) { if (this.displayFps) {
this.fpsFlush.incrementCounter(); this.fpsFlush.incrementCounter();
} }
OpenGL.flush(); OpenGL.flush();
} }
if (this.displayFps == true) { if (this.displayFps) {
this.fpsFlush.toc(); this.fpsFlush.toc();
} }
// release open GL Context // release open GL Context
OpenGL.unLock(); OpenGL.unLock();
} }
if (this.displayFps == true) { if (this.displayFps) {
this.fpsSystemEvent.draw(); this.fpsSystemEvent.draw();
this.fpsSystemContext.draw(); this.fpsSystemContext.draw();
this.fpsSystem.draw(); this.fpsSystem.draw();
@ -403,7 +403,7 @@ public abstract class Context {
}; };
/** /**
* @brief The current context is set in foreground (framerate is maximum speed) * The current context is set in foreground (framerate is maximum speed)
*/ */
public void operatingSystemForeground() { public void operatingSystemForeground() {
// set the current interface : // set the current interface :
@ -418,35 +418,35 @@ public abstract class Context {
} }
/** /**
* @brief The OS inform that the Windows is now Hidden. * The OS inform that the Windows is now Hidden.
*/ */
public void operatingSystemHide() { public void operatingSystemHide() {
postAction((context) -> { postAction((context) -> {
/* /*
Application> appl = _context.getApplication(); Application> appl = context.getApplication();
if (appl == null) { if (appl == null) {
return; return;
} }
appl.onKeyboard(_special, appl.onKeyboard(special,
_type, type,
_char, char,
_state); state);
*/ */
Log.todo("HIDE ... "); Log.todo("HIDE ... ");
}); });
}; };
/** /**
* @brief The OS inform that the current windows has change his position. * The OS inform that the current windows has change his position.
* @param _pos New position of the Windows. * @param pos New position of the Windows.
*/ */
public void operatingSystemMove(final Vector2f _pos) { public void operatingSystemMove(final Vector2f pos) {
if (this.windowsPos.isEqual(_pos)) { if (this.windowsPos.isEqual(pos)) {
return; return;
} }
postAction((context) -> { postAction((context) -> {
Log.debug("Receive MSG : THREAD_MOVE : " + context.windowsPos + " ==> " + _pos); Log.debug("Receive MSG : THREADMOVE : " + context.windowsPos + " ==> " + pos);
context.windowsPos = _pos; context.windowsPos = pos;
final Application appl = context.getApplication(); final Application appl = context.getApplication();
if (appl == null) { if (appl == null) {
return; return;
@ -456,26 +456,26 @@ public abstract class Context {
} }
/** /**
* @brief The OS inform that the openGL ext has been destroy == > use to automaticly reload the texture and other thinks ... * The OS inform that the openGL ext has been destroy == > use to automaticly reload the texture and other thinks ...
*/ */
public void operatingSystemOpenGlContextDestroy() { public void operatingSystemOpenGlContextDestroy() {
this.resourceManager.contextHasBeenDestroyed(); this.resourceManager.contextHasBeenDestroyed();
}; };
/** /**
* @brief The OS inform that the current windows has change his size. * The OS inform that the current windows has change his size.
* @param _size new size of the windows. * @param size new size of the windows.
*/ */
public void operatingSystemResize(final Vector2f _size) { public void operatingSystemResize(final Vector2f size) {
if (this.windowsSize == _size) { if (this.windowsSize == size) {
return; return;
} }
// TODO Better in the thread ... ==> but generate some init error ... // TODO Better in the thread ... ==> but generate some init error ...
//gale::Dimension::setPixelWindowsSize(_size); //gale::Dimension::setPixelWindowsSize(size);
postAction((context) -> { postAction((context) -> {
Log.debug("Receive MSG : THREAD_RESIZE : " + context.windowsSize + " ==> " + _size); Log.debug("Receive MSG : THREADRESIZE : " + context.windowsSize + " ==> " + size);
context.windowsSize = _size; context.windowsSize = size;
//gale::Dimension::setPixelWindowsSize(_context.windowsSize); //gale::Dimension::setPixelWindowsSize(context.windowsSize);
final Application tmpAppl = context.getApplication(); final Application tmpAppl = context.getApplication();
if (tmpAppl != null) { if (tmpAppl != null) {
tmpAppl.onResize(context.windowsSize); tmpAppl.onResize(context.windowsSize);
@ -486,7 +486,7 @@ public abstract class Context {
}; };
/** /**
* @brief The current context is resumed * The current context is resumed
*/ */
public void operatingSystemResume() { public void operatingSystemResume() {
// set the current interface : // set the current interface :
@ -517,11 +517,11 @@ public abstract class Context {
public void operatingSystemsetKeyboard(final KeySpecial special, final KeyKeyboard type, final KeyStatus state, final boolean isARepeateKey, final Character charValue) { public void operatingSystemsetKeyboard(final KeySpecial special, final KeyKeyboard type, final KeyStatus state, final boolean isARepeateKey, final Character charValue) {
KeyStatus tmpState = state; KeyStatus tmpState = state;
if (isARepeateKey == true) { if (isARepeateKey) {
if (tmpState == KeyStatus.down) { if (tmpState == KeyStatus.down) {
tmpState = KeyStatus.downRepeate; tmpState = KeyStatus.downRepeat;
} else { } else {
tmpState = KeyStatus.upRepeate; tmpState = KeyStatus.upRepeat;
} }
} }
operatingSystemsetKeyboard2(special, type, state, charValue); operatingSystemsetKeyboard2(special, type, state, charValue);
@ -538,26 +538,26 @@ public abstract class Context {
} }
/** /**
* @brief The OS inform that the Windows is now visible. * The OS inform that the Windows is now visible.
*/ */
public void operatingSystemShow() { public void operatingSystemShow() {
postAction((context) -> { postAction((context) -> {
/* /*
Application> appl = _context.getApplication(); Application> appl = context.getApplication();
if (appl == null) { if (appl == null) {
return; return;
} }
appl.onKeyboard(_special, appl.onKeyboard(special,
_type, type,
_char, char,
_state); state);
*/ */
Log.todo("SHOW ... "); Log.todo("SHOW ... ");
}); });
}; };
/** /**
* @brief The OS Inform that the Window has been killed * The OS Inform that the Window has been killed
*/ */
public void operatingSystemStop() { public void operatingSystemStop() {
// set the current interface : // set the current interface :
@ -573,7 +573,7 @@ public abstract class Context {
} }
/** /**
* @brief The current context is suspended * The current context is suspended
*/ */
public void operatingSystemSuspend() { public void operatingSystemSuspend() {
// set the current interface : // set the current interface :
@ -595,7 +595,7 @@ public abstract class Context {
} }
/** /**
* @brief Processing all the event arrived ... (commoly called in draw function) * Processing all the event arrived ... (commoly called in draw function)
*/ */
public void processEvents() { public void processEvents() {
int nbEvent = 0; int nbEvent = 0;
@ -648,63 +648,63 @@ public abstract class Context {
// } // }
public void requestUpdateSize() { public void requestUpdateSize() {
postAction((context) -> { postAction((context) -> {
//Log.debug("Receive MSG : THREAD_RESIZE"); //Log.debug("Receive MSG : THREADRESIZE");
context.forceRedrawAll(); context.forceRedrawAll();
}); });
} }
/** /**
* @brief reset event management for the IO like Input ou Mouse or keyborad * reset event management for the IO like Input ou Mouse or keyborad
*/ */
public void resetIOEvent() { public void resetIOEvent() {
// TODO this.input.newLayerSet(); // TODO this.input.newLayerSet();
} }
/** /**
* @brief Internal API to run the processing of the event loop ... * Internal API to run the processing of the event loop ...
* @return The Exit value of the program * @return The Exit value of the program
* @note INTERNAL API * @note INTERNAL API
*/ */
public abstract int run(); public abstract int run();
/** /**
* @brief set the cursor display type. * set the cursor display type.
* @param NewCursor selected new cursor. * @param newCursor selected new cursor.
*/ */
public void setCursor(final Cursor newCursor) {} public void setCursor(final Cursor newCursor) {}
/** /**
* @brief The application request a change of his current size force the fullscreen mode. * The application request a change of his current size force the fullscreen mode.
* @param _status status of the fullscreen mode. * @param status status of the fullscreen mode.
*/ */
public void setFullScreen(final boolean status) { public void setFullScreen(final boolean status) {
this.fullscreen = status; this.fullscreen = status;
} }
/** /**
* @brief set the Icon of the program * set the Icon of the program
* @param _inputFile new filename icon of the current program. * @param inputFile new filename icon of the current program.
*/ */
public void setIcon(final Uri inputFile) {}; public void setIcon(final Uri inputFile) {};
/** /**
* @brief The Application request that the current windows will change his position. * The Application request that the current windows will change his position.
* @param _pos New position of the Windows requested. * @param pos New position of the Windows requested.
*/ */
public void setPos(final Vector2f pos) { public void setPos(final Vector2f pos) {
Log.info("setPos: NOT implemented ..."); Log.info("setPos: NOT implemented ...");
}; };
/** /**
* @brief The application request a change of his current size. * The application request a change of his current size.
* @param _size new Requested size of the windows. * @param size new Requested size of the windows.
*/ */
public void setSize(final Vector2f size) { public void setSize(final Vector2f size) {
Log.info("setSize: NOT implemented ..."); Log.info("setSize: NOT implemented ...");
} }
/** /**
* @brief set the new title of the windows * set the new title of the windows
* @param title New desired title * @param title New desired title
*/ */
public void setTitle(final String title) { public void setTitle(final String title) {
@ -712,20 +712,20 @@ public abstract class Context {
}; };
/** /**
* @brief Enable or Disable the decoration on the Windows (availlable only on Desktop) * Enable or Disable the decoration on the Windows (availlable only on Desktop)
* @param _status "true" to enable decoration / false otherwise * @param status "true" to enable decoration / false otherwise
*/ */
public void setWindowsDecoration(final boolean status) {}; public void setWindowsDecoration(final boolean status) {};
/** /**
* @brief The Application request that the Windows will be visible. * The Application request that the Windows will be visible.
*/ */
public void show() { public void show() {
Log.info("show: NOT implemented ..."); Log.info("show: NOT implemented ...");
}; };
/** /**
* @brief StartProcessing (2nd thread). * StartProcessing (2nd thread).
* @note to call when all the Context is started * @note to call when all the Context is started
*/ */
public void start2ndThreadProcessing() { public void start2ndThreadProcessing() {
@ -743,7 +743,7 @@ public abstract class Context {
}; };
/** /**
* @brief The application request that the Window will be killed * The application request that the Window will be killed
*/ */
public void stop() { public void stop() {
Log.warning("stop: NOT implemented for this platform..."); Log.warning("stop: NOT implemented for this platform...");

File diff suppressed because it is too large Load Diff

View File

@ -13,209 +13,209 @@ public class KeySpecial {
private boolean valueNumLock = false; private boolean valueNumLock = false;
private boolean valueInsert = false; private boolean valueInsert = false;
/** /**
* @brief Main ructor * Main ructor
*/ */
public KeySpecial() { public KeySpecial() {
} }
/** /**
* @brief get the current CapLock Status * get the current CapLock Status
* @return The CapLock value * @return The CapLock value
*/ */
public boolean getCapsLock() { public boolean getCapsLock() {
return valueCapLock; return valueCapLock;
} }
/** /**
* @brief set the current CapLock Status * set the current CapLock Status
* @param value The new CapLock value * @param value The new CapLock value
*/ */
public void setCapsLock(boolean value) { public void setCapsLock(boolean value) {
valueCapLock = value; valueCapLock = value;
} }
/** /**
* @brief Get the current Shift key status * Get the current Shift key status
* @return The Shift value * @return The Shift value
*/ */
public boolean getShift() { public boolean getShift() {
return valueShiftLeft || valueShiftRight; return valueShiftLeft || valueShiftRight;
} }
/** /**
* @brief Get the current Shift left key status * Get the current Shift left key status
* @return The Shift value * @return The Shift value
*/ */
public boolean getShiftLeft() { public boolean getShiftLeft() {
return valueShiftLeft; return valueShiftLeft;
} }
/** /**
* @brief Get the current Shift right key status * Get the current Shift right key status
* @return The Shift value * @return The Shift value
*/ */
public boolean getShiftRight() { public boolean getShiftRight() {
return valueShiftRight; return valueShiftRight;
} }
/** /**
* @brief Set the current Shift left key status * Set the current Shift left key status
* @param value The new Shift value * @param value The new Shift value
*/ */
public void setShiftLeft(boolean value) { public void setShiftLeft(boolean value) {
valueShiftLeft = value; valueShiftLeft = value;
} }
/** /**
* @brief Set the current Shift right key status * Set the current Shift right key status
* @param value The new Shift value * @param value The new Shift value
*/ */
public void setShiftRight(boolean value) { public void setShiftRight(boolean value) {
valueShiftRight = value; valueShiftRight = value;
} }
/** /**
* @brief Get the Current Control key status * Get the Current Control key status
* @return The Control value * @return The Control value
*/ */
public boolean getCtrl() { public boolean getCtrl() {
return valueCtrlLeft || valueCtrlRight; return valueCtrlLeft || valueCtrlRight;
} }
/** /**
* @brief Get the Current Control left key status * Get the Current Control left key status
* @return The Control value * @return The Control value
*/ */
public boolean getCtrlLeft() { public boolean getCtrlLeft() {
return valueCtrlLeft; return valueCtrlLeft;
} }
/** /**
* @brief Get the Current Control right key status * Get the Current Control right key status
* @return The Control value * @return The Control value
*/ */
public boolean getCtrlRight() { public boolean getCtrlRight() {
return valueCtrlRight; return valueCtrlRight;
} }
/** /**
* @brief Set the Current Control left key status * Set the Current Control left key status
* @param value The new Control value * @param value The new Control value
*/ */
public void setCtrlLeft(boolean value){ public void setCtrlLeft(boolean value){
valueCtrlLeft = value; valueCtrlLeft = value;
} }
/** /**
* @brief Set the Current Control right key status * Set the Current Control right key status
* @param value The new Control value * @param value The new Control value
*/ */
public void setCtrlRight(boolean value) { public void setCtrlRight(boolean value) {
valueCtrlRight = value; valueCtrlRight = value;
} }
/** /**
* @brief Get the current Meta key status (also named windows or apple key) * Get the current Meta key status (also named windows or apple key)
* @return The Meta value (name Windows key, apple key, command key ...) * @return The Meta value (name Windows key, apple key, command key ...)
*/ */
public boolean getMeta() { public boolean getMeta() {
return valueMetaLeft || valueMetaRight; return valueMetaLeft || valueMetaRight;
} }
/** /**
* @brief Get the current Meta left key status (also named windows or apple key) * Get the current Meta left key status (also named windows or apple key)
* @return The Meta value (name Windows key, apple key, command key ...) * @return The Meta value (name Windows key, apple key, command key ...)
*/ */
public boolean getMetaLeft() { public boolean getMetaLeft() {
return valueMetaLeft; return valueMetaLeft;
} }
/** /**
* @brief Get the current Meta right key status (also named windows or apple key) * Get the current Meta right key status (also named windows or apple key)
* @return The Meta value (name Windows key, apple key, command key ...) * @return The Meta value (name Windows key, apple key, command key ...)
*/ */
public boolean getMetaRight() { public boolean getMetaRight() {
return valueMetaRight; return valueMetaRight;
} }
/** /**
* @brief Set the current Meta left key status (also named windows or apple key) * Set the current Meta left key status (also named windows or apple key)
* @param value The new Meta value (name Windows key, apple key, command key ...) * @param value The new Meta value (name Windows key, apple key, command key ...)
*/ */
public void setMetaLeft(boolean value) { public void setMetaLeft(boolean value) {
valueMetaLeft = value; valueMetaLeft = value;
} }
/** /**
* @brief Set the current Meta right key status (also named windows or apple key) * Set the current Meta right key status (also named windows or apple key)
* @param value The new Meta value (name Windows key, apple key, command key ...) * @param value The new Meta value (name Windows key, apple key, command key ...)
*/ */
public void setMetaRight(boolean value) { public void setMetaRight(boolean value) {
valueMetaRight = value; valueMetaRight = value;
} }
/** /**
* @brief Get the current Alt key status * Get the current Alt key status
* @return The Alt value * @return The Alt value
*/ */
public boolean getAlt() { public boolean getAlt() {
return valueAltLeft || valueAltRight; return valueAltLeft || valueAltRight;
} }
/** /**
* @brief Get the current Alt left key status * Get the current Alt left key status
* @return The Alt value * @return The Alt value
*/ */
public boolean getAltLeft() { public boolean getAltLeft() {
return valueAltLeft; return valueAltLeft;
} }
/** /**
* @brief Get the current Alt right key status (alt-gr) * Get the current Alt right key status (alt-gr)
* @return The Alt value * @return The Alt value
*/ */
public boolean getAltRight() { public boolean getAltRight() {
return valueAltRight; return valueAltRight;
} }
/** /**
* @brief Set the current Alt left key status * Set the current Alt left key status
* @param value The new Alt value * @param value The new Alt value
*/ */
public void setAltLeft(boolean value) { public void setAltLeft(boolean value) {
valueAltLeft = value; valueAltLeft = value;
} }
/** /**
* @brief Set the current Alt right key status (alt-gr) * Set the current Alt right key status (alt-gr)
* @param value The new Alt value * @param value The new Alt value
*/ */
public void setAltRight(boolean value) { public void setAltRight(boolean value) {
valueAltRight = value; valueAltRight = value;
} }
/** /**
* @brief Get the current Alt-Gr key status * Get the current Alt-Gr key status
* @return The Alt-gr value (does not exist on MacOs) * @return The Alt-gr value (does not exist on MacOs)
*/ */
public boolean getAltGr() { public boolean getAltGr() {
return getAltRight(); return getAltRight();
} }
/** /**
* @brief Set the current Alt-Gr key status * Set the current Alt-Gr key status
* @param value The new Alt-gr value (does not exist on MacOs) * @param value The new Alt-gr value (does not exist on MacOs)
*/ */
public void setAltGr(boolean value) { public void setAltGr(boolean value) {
setAltRight(value); setAltRight(value);
} }
/** /**
* @brief Get the current Ver-num key status * Get the current Ver-num key status
* @return The Numerical Lock value * @return The Numerical Lock value
*/ */
public boolean getNumLock() { public boolean getNumLock() {
return valueNumLock; return valueNumLock;
} }
/** /**
* @brief Set the current Ver-num key status * Set the current Ver-num key status
* @param value The new Numerical Lock value * @param value The new Numerical Lock value
*/ */
public void setNumLock(boolean value) { public void setNumLock(boolean value) {
valueNumLock = value; valueNumLock = value;
} }
/** /**
* @brief Get the current Intert key status * Get the current Intert key status
* @return The Insert value * @return The Insert value
*/ */
public boolean getInsert() { public boolean getInsert() {
return valueInsert; return valueInsert;
} }
/** /**
* @brief Set the current Intert key status * Set the current Intert key status
* @param value The new Insert value * @param value The new Insert value
*/ */
public void setInsert(boolean value) { public void setInsert(boolean value) {
valueInsert = value; valueInsert = value;
} }
/** /**
* @brief Update the internal value with the input moving key. * Update the internal value with the input moving key.
* @param move Moving key. * @param move Moving key.
* @param isDown The key is pressed or not. * @param isDown The key is pressed or not.
*/ */
@ -259,7 +259,7 @@ public class KeySpecial {
} }
} }
/** /**
* @brief Get the value with the input moving key. * Get the value with the input moving key.
* @param move Moving key. * @param move Moving key.
* @return true The key is pressed. * @return true The key is pressed.
* @return false The key is released. * @return false The key is released.

View File

@ -1,37 +1,32 @@
package org.atriasoft.gale.key; package org.atriasoft.gale.key;
public enum KeyStatus { public enum KeyStatus {
unknow, unknown,
down, // availlable on Keyboard too down, // available on Keyboard too
downRepeate, // availlable on Keyboard too: the down event us in repeate cycle downRepeat, // available on Keyboard too: the down event us in repeate cycle
move, move,
pressSingle, pressSingle,
pressDouble, pressDouble,
pressTriple, pressTriple,
pressQuad, pressQuad,
pressQuinte, pressQuint,
up, // availlable on Keyboard too up, // available on Keyboard too
upRepeate, // availlable on Keyboard too: the up event us in repeate cycle upRepeat, // available on Keyboard too: the up event us in repeate cycle
upAfter, // mouse input & finger input this appear after the single event (depending on some case...) upAfter, // mouse input & finger input this appear after the single event (depending on some case...)
enter, enter,
leave, leave,
abort, // Appeare when an event is tranfert betwwen widgets (the widget which receive this has lost the events) abort, // Appear 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) transfer // Appear 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) { public static KeyStatus pressCount(final int i) {
switch (i) { return switch (i) {
case 1: case 1 -> pressSingle;
return pressSingle; case 2 -> pressDouble;
case 2: case 3 -> pressTriple;
return pressDouble; case 4 -> pressQuad;
case 3: case 5 -> pressQuint;
return pressTriple; default -> unknown;
case 4: };
return pressQuad;
case 5:
return pressQuinte;
}
return unknow;
} }
} }

View File

@ -10,7 +10,7 @@ public abstract class Resource {
private static int idGenerated = 10; private static int idGenerated = 10;
/** /**
* @brief Get the current resource Manager * Get the current resource Manager
*/ */
protected static ResourceManager getManager() { protected static ResourceManager getManager() {
return Context.getContext().getResourcesManager(); return Context.getContext().getResourcesManager();
@ -22,7 +22,7 @@ public abstract class Resource {
protected String name = NO_NAME_RESOURCE; //!< name of the resource ... protected String name = NO_NAME_RESOURCE; //!< name of the resource ...
/** /**
* @brief generic protected contructor (use factory to create this class) * generic protected contructor (use factory to create this class)
*/ */
protected Resource() { protected Resource() {
this.uid = idGenerated++; this.uid = idGenerated++;
@ -50,7 +50,7 @@ public abstract class Resource {
} }
/** /**
* @brief get the resource name * get the resource name
* @return The requested name * @return The requested name
*/ */
public String getName() { public String getName() {
@ -58,7 +58,7 @@ public abstract class Resource {
} }
/** /**
* @brief Get the current resource level; * Get the current resource level;
* @return value in [0..5] * @return value in [0..5]
*/ */
public int getResourceLevel() { public int getResourceLevel() {
@ -77,21 +77,21 @@ public abstract class Resource {
} }
/** /**
* @brief User request the reload of all resources (usefull when the file depend on DATA:GUI:xxx ... * User request the reload of all resources (usefull when the file depend on DATA:GUI:xxx ...
*/ */
public void reload() { public void reload() {
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)"); Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)");
}; };
/** /**
* @brief The current OpenGl context is removing ==> remove yout own system data * The current OpenGl context is removing ==> remove yout own system data
*/ */
public void removeContext() { public void removeContext() {
Log.debug("Not set for : [" + getId() + "]" + getName() + " loaded ??? time(s)"); 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). * 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 * Just update your internal state
*/ */
public void removeContextToLate() { public void removeContextToLate() {
@ -99,7 +99,7 @@ public abstract class Resource {
} }
/** /**
* @brief get the resource name * get the resource name
* @param name The name to set. * @param name The name to set.
*/ */
public void setName(final String name) { public void setName(final String name) {
@ -107,7 +107,7 @@ public abstract class Resource {
} }
/** /**
* @brief Call when need to send data on the harware (openGL) * Call when need to send data on the harware (openGL)
* @note This is done asynchronously with the create of the Resource. * @note This is done asynchronously with the create of the Resource.
* @return true The context is updated * @return true The context is updated
* @return false The context is not updated * @return false The context is not updated

View File

@ -30,7 +30,7 @@ public class ResourceColored3DObject extends Resource {
super(); super();
// get the shader resource : // get the shader resource :
this.oGLPosition = 0; this.oGLPosition = 0;
this.program = ResourceProgram.create(new Uri("DATA_EGE", "simple3D.vert"), new Uri("DATA_EGE", "simple3D.frag")); this.program = ResourceProgram.create(new Uri("DATA", "simple3D.vert", "gale"), new Uri("DATA", "simple3D.frag", "gale"));
if (this.program != null) { if (this.program != null) {
this.oGLMatrixTransformation = this.program.getUniform("in_matrixTransformation"); this.oGLMatrixTransformation = this.program.getUniform("in_matrixTransformation");
this.oGLMatrixProjection = this.program.getUniform("in_matrixProjection"); this.oGLMatrixProjection = this.program.getUniform("in_matrixProjection");
@ -49,9 +49,9 @@ public class ResourceColored3DObject extends Resource {
private float[] convertInFloat(final List<Vector3f> data) { private float[] convertInFloat(final List<Vector3f> data) {
final float[] out = new float[data.size() * 3]; final float[] out = new float[data.size() * 3];
for (int iii = 0; iii < data.size(); iii++) { for (int iii = 0; iii < data.size(); iii++) {
out[iii * 3] = data.get(iii).x; out[iii * 3] = data.get(iii).x();
out[iii * 3 + 1] = data.get(iii).y; out[iii * 3 + 1] = data.get(iii).y();
out[iii * 3 + 2] = data.get(iii).z; out[iii * 3 + 2] = data.get(iii).z();
} }
return out; return out;
} }
@ -64,9 +64,9 @@ public class ResourceColored3DObject extends Resource {
Log.error("No shader ..."); Log.error("No shader ...");
return; return;
} }
if (true == depthtest) { if (depthtest) {
OpenGL.enable(OpenGL.Flag.flag_depthTest); OpenGL.enable(OpenGL.Flag.flag_depthTest);
if (false == updateDepthBuffer) { if (!updateDepthBuffer) {
OpenGL.setDeathMask(false); OpenGL.setDeathMask(false);
} }
} }
@ -74,7 +74,7 @@ public class ResourceColored3DObject extends Resource {
this.program.use(); this.program.use();
final Matrix4f projectionMatrix = OpenGL.getMatrix(); final Matrix4f projectionMatrix = OpenGL.getMatrix();
final Matrix4f viewMatrix = OpenGL.getCameraMatrix(); final Matrix4f viewMatrix = OpenGL.getCameraMatrix();
final Matrix4f transformationMatrix = Matrix4f.identity(); final Matrix4f transformationMatrix = Matrix4f.IDENTITY;
this.program.uniformMatrix(this.oGLMatrixView, viewMatrix); this.program.uniformMatrix(this.oGLMatrixView, viewMatrix);
this.program.uniformMatrix(this.oGLMatrixProjection, projectionMatrix); this.program.uniformMatrix(this.oGLMatrixProjection, projectionMatrix);
this.program.uniformMatrix(this.oGLMatrixTransformation, transformationMatrix); this.program.uniformMatrix(this.oGLMatrixTransformation, transformationMatrix);
@ -83,20 +83,20 @@ public class ResourceColored3DObject extends Resource {
// position : // position :
final FloatBuffer buffer = storeDataInFloatBuffer(convertInFloat(vertices)); final FloatBuffer buffer = storeDataInFloatBuffer(convertInFloat(vertices));
this.program.sendAttribute(this.oGLPosition, 3, buffer, 3); this.program.sendAttribute(this.oGLPosition, 3, buffer, 3);
if (color.a < 1.0f) { if (color.a() < 1.0f) {
OpenGL.enable(OpenGL.Flag.flag_blend); OpenGL.enable(OpenGL.Flag.flag_blend);
} }
// Request the draw of the elements: // Request the draw of the elements:
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size()); OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size());
if (color.a < 1.0f) { if (color.a() < 1.0f) {
OpenGL.disable(OpenGL.Flag.flag_blend); OpenGL.disable(OpenGL.Flag.flag_blend);
} }
this.program.unUse(); this.program.unUse();
// Request the draw od the elements: // Request the draw od the elements:
//glDrawArrays(oGLLINES, 0, vertices.size()); //glDrawArrays(oGLLINES, 0, vertices.size());
//this.oGLprogram.UnUse(); //this.oGLprogram.UnUse();
if (true == depthtest) { if (depthtest) {
if (false == updateDepthBuffer) { if (!updateDepthBuffer) {
OpenGL.setDeathMask(true); OpenGL.setDeathMask(true);
} }
OpenGL.disable(OpenGL.Flag.flag_depthTest); OpenGL.disable(OpenGL.Flag.flag_depthTest);
@ -111,9 +111,9 @@ public class ResourceColored3DObject extends Resource {
Log.error("No shader ..."); Log.error("No shader ...");
return; return;
} }
if (true == depthtest) { if (depthtest) {
OpenGL.enable(OpenGL.Flag.flag_depthTest); OpenGL.enable(OpenGL.Flag.flag_depthTest);
if (false == updateDepthBuffer) { if (!updateDepthBuffer) {
OpenGL.setDeathMask(false); OpenGL.setDeathMask(false);
} }
} }
@ -131,17 +131,17 @@ public class ResourceColored3DObject extends Resource {
// color : // color :
//Log.info("color= " + color + " " + this.oGLPosition); //Log.info("color= " + color + " " + this.oGLPosition);
this.program.uniformColor(this.oGLColor, color); this.program.uniformColor(this.oGLColor, color);
if (color.a < 1.0f) { if (color.a() < 1.0f) {
OpenGL.enable(OpenGL.Flag.flag_blend); OpenGL.enable(OpenGL.Flag.flag_blend);
} }
// Request the draw of the elements: // Request the draw of the elements:
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size()); OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size());
if (color.a < 1.0f) { if (color.a() < 1.0f) {
OpenGL.disable(OpenGL.Flag.flag_blend); OpenGL.disable(OpenGL.Flag.flag_blend);
} }
this.program.unUse(); this.program.unUse();
if (true == depthtest) { if (depthtest) {
if (false == updateDepthBuffer) { if (!updateDepthBuffer) {
OpenGL.setDeathMask(true); OpenGL.setDeathMask(true);
} }
OpenGL.disable(OpenGL.Flag.flag_depthTest); OpenGL.disable(OpenGL.Flag.flag_depthTest);
@ -286,41 +286,41 @@ 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) { 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<>(); final List<Vector3f> vertices = new ArrayList<>();
vertices.add(new Vector3f(min.x, min.y, min.z)); vertices.add(new Vector3f(min.x(), min.y(), min.z()));
vertices.add(new Vector3f(max.x, min.y, min.z)); vertices.add(new Vector3f(max.x(), min.y(), min.z()));
vertices.add(new Vector3f(max.x, min.y, min.z)); vertices.add(new Vector3f(max.x(), min.y(), min.z()));
vertices.add(new Vector3f(max.x, min.y, max.z)); vertices.add(new Vector3f(max.x(), min.y(), max.z()));
vertices.add(new Vector3f(max.x, min.y, max.z)); vertices.add(new Vector3f(max.x(), min.y(), max.z()));
vertices.add(new Vector3f(min.x, min.y, max.z)); vertices.add(new Vector3f(min.x(), min.y(), max.z()));
vertices.add(new Vector3f(min.x, min.y, max.z)); vertices.add(new Vector3f(min.x(), min.y(), max.z()));
vertices.add(new Vector3f(min.x, min.y, min.z)); vertices.add(new Vector3f(min.x(), min.y(), min.z()));
vertices.add(new Vector3f(min.x, max.y, min.z)); vertices.add(new Vector3f(min.x(), max.y(), min.z()));
vertices.add(new Vector3f(max.x, max.y, min.z)); vertices.add(new Vector3f(max.x(), max.y(), min.z()));
vertices.add(new Vector3f(max.x, max.y, min.z)); vertices.add(new Vector3f(max.x(), max.y(), min.z()));
vertices.add(new Vector3f(max.x, max.y, max.z)); vertices.add(new Vector3f(max.x(), max.y(), max.z()));
vertices.add(new Vector3f(max.x, max.y, max.z)); vertices.add(new Vector3f(max.x(), max.y(), max.z()));
vertices.add(new Vector3f(min.x, max.y, max.z)); vertices.add(new Vector3f(min.x(), max.y(), max.z()));
vertices.add(new Vector3f(min.x, max.y, max.z)); vertices.add(new Vector3f(min.x(), max.y(), max.z()));
vertices.add(new Vector3f(min.x, max.y, min.z)); vertices.add(new Vector3f(min.x(), max.y(), min.z()));
vertices.add(new Vector3f(min.x, min.y, min.z)); vertices.add(new Vector3f(min.x(), min.y(), min.z()));
vertices.add(new Vector3f(min.x, max.y, min.z)); vertices.add(new Vector3f(min.x(), max.y(), min.z()));
vertices.add(new Vector3f(max.x, min.y, min.z)); vertices.add(new Vector3f(max.x(), min.y(), min.z()));
vertices.add(new Vector3f(max.x, max.y, min.z)); vertices.add(new Vector3f(max.x(), max.y(), min.z()));
vertices.add(new Vector3f(max.x, min.y, max.z)); vertices.add(new Vector3f(max.x(), min.y(), max.z()));
vertices.add(new Vector3f(max.x, max.y, max.z)); vertices.add(new Vector3f(max.x(), max.y(), max.z()));
vertices.add(new Vector3f(min.x, min.y, max.z)); vertices.add(new Vector3f(min.x(), min.y(), max.z()));
vertices.add(new Vector3f(min.x, max.y, max.z)); vertices.add(new Vector3f(min.x(), max.y(), max.z()));
drawLine(vertices, color, transformationMatrix, updateDepthBuffer, depthtest); drawLine(vertices, color, transformationMatrix, updateDepthBuffer, depthtest);
} }
@ -402,9 +402,9 @@ public class ResourceColored3DObject extends Resource {
Log.error("No shader ..."); Log.error("No shader ...");
return; return;
} }
if (true == depthtest) { if (depthtest) {
OpenGL.enable(OpenGL.Flag.flag_depthTest); OpenGL.enable(OpenGL.Flag.flag_depthTest);
if (false == updateDepthBuffer) { if (!updateDepthBuffer) {
OpenGL.setDeathMask(false); OpenGL.setDeathMask(false);
} }
} }
@ -421,17 +421,17 @@ public class ResourceColored3DObject extends Resource {
this.program.sendAttribute(this.oGLPosition, 3, buffer, 3); this.program.sendAttribute(this.oGLPosition, 3, buffer, 3);
// color : // color :
this.program.uniformColor(this.oGLColor, color); this.program.uniformColor(this.oGLColor, color);
if (color.a < 1.0f) { if (color.a() < 1.0f) {
OpenGL.enable(OpenGL.Flag.flag_blend); OpenGL.enable(OpenGL.Flag.flag_blend);
} }
// Request the draw od the elements: // Request the draw od the elements:
OpenGL.drawArrays(OpenGL.RenderMode.line, 0, vertices.size()); OpenGL.drawArrays(OpenGL.RenderMode.line, 0, vertices.size());
if (color.a < 1.0f) { if (color.a() < 1.0f) {
OpenGL.disable(OpenGL.Flag.flag_blend); OpenGL.disable(OpenGL.Flag.flag_blend);
} }
this.program.unUse(); this.program.unUse();
if (true == depthtest) { if (depthtest) {
if (false == updateDepthBuffer) { if (!updateDepthBuffer) {
OpenGL.setDeathMask(true); OpenGL.setDeathMask(true);
} }
OpenGL.disable(OpenGL.Flag.flag_depthTest); OpenGL.disable(OpenGL.Flag.flag_depthTest);
@ -477,8 +477,9 @@ public class ResourceColored3DObject extends Resource {
public void drawSquare(final Vector3f size, final Matrix4f transformationMatrix, final Color tmpColor) { public void drawSquare(final Vector3f size, final Matrix4f transformationMatrix, final Color tmpColor) {
final List<Vector3f> tmpVertices = new ArrayList<>(); 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 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), 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()), 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()) };
tmpVertices.clear(); tmpVertices.clear();
for (int iii = 0; iii < 36; iii += 3) { for (int iii = 0; iii < 36; iii += 3) {
// normal calculation : // normal calculation :
@ -498,9 +499,9 @@ 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) { 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<>(); final List<Vector3f> tmpVertices = new ArrayList<>();
for (int iii = 0; iii < indice.size() / 3; ++iii) { 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 + 0)).add(offset));
tmpVertices.add(vertex.get(indice.get(iii * 3 + 1)).addNew(offset)); tmpVertices.add(vertex.get(indice.get(iii * 3 + 1)).add(offset));
tmpVertices.add(vertex.get(indice.get(iii * 3 + 2)).addNew(offset)); tmpVertices.add(vertex.get(indice.get(iii * 3 + 2)).add(offset));
//Log.info(" indices " << indice[iii*3 + 0] << " " << indice[iii*3 + 1] << " " << indice[iii*3 + 2]); //Log.info(" indices " << indice[iii*3 + 0] << " " << indice[iii*3 + 1] << " " << indice[iii*3 + 2]);
//Log.info(" triangle " << vertex[indice[iii*3 + 0]] << " " << vertex[indice[iii*3 + 1]] << " " << vertex[indice[iii*3 + 2]]); //Log.info(" triangle " << vertex[indice[iii*3 + 0]] << " " << vertex[indice[iii*3 + 1]] << " " << vertex[indice[iii*3 + 2]]);
} }

View File

@ -14,14 +14,14 @@ public class ResourceManager {
private boolean exiting = false; private boolean exiting = false;
/** /**
* @brief initialize the internal variable * initialize the internal variable
*/ */
public ResourceManager() { public ResourceManager() {
} }
/** /**
* @brief special end of application * special end of application
*/ */
public void applicationExiting() { public void applicationExiting() {
contextHasBeenDestroyed(); contextHasBeenDestroyed();
@ -41,7 +41,7 @@ public class ResourceManager {
} }
/** /**
* @brief This is to inform the resources manager that we have no more openGl context ... * This is to inform the resources manager that we have no more openGl context ...
*/ */
public void contextHasBeenDestroyed() { public void contextHasBeenDestroyed() {
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
@ -54,7 +54,7 @@ public class ResourceManager {
} }
/** /**
* @brief display in the log all the resources loaded ... * display in the log all the resources loaded ...
*/ */
public void display() { public void display() {
Log.info("Resources loaded : "); Log.info("Resources loaded : ");
@ -97,7 +97,7 @@ public class ResourceManager {
} }
/** /**
* @brief Reload all resources from files, and send there in openGL card if needed. * 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 * @note If file is reference at THEMEXXX:///filename if the Theme change the file will reload the newOne
*/ */
public void reLoadResources() { public void reLoadResources() {
@ -120,12 +120,12 @@ public class ResourceManager {
} }
/** /**
* @brief Uninitiamize the resource manager, free all resources previously requested * Uninitiamize the resource manager, free all resources previously requested
* @note when not free == > generate warning, because the segfault can appear after... * @note when not free == > generate warning, because the segfault can appear after...
*/ */
//public ~Manager(); //public ~Manager();
/** /**
* @brief remove all resources (un-init) out of the destructor (due to the system implementation) * remove all resources (un-init) out of the destructor (due to the system implementation)
*/ */
public void unInit() { public void unInit() {
display(); display();
@ -138,7 +138,7 @@ public class ResourceManager {
} }
/** /**
* @brief Call by the system to send all the needed data on the graphic card chen they change ... * 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 * @param object The resources that might be updated
*/ */
public void update(final Resource object) { public void update(final Resource object) {
@ -154,15 +154,15 @@ public class ResourceManager {
} }
/** /**
* @brief Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other .... * Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
*/ */
public void updateContext() { public void updateContext() {
if (this.exiting == true) { if (this.exiting) {
Log.error("Request update after application EXIT ..."); Log.error("Request update after application EXIT ...");
return; return;
} }
// TODO Check the number of call this ... Log.info("update open-gl context ... "); // TODO Check the number of call this ... Log.info("update open-gl context ... ");
if (this.contextHasBeenRemoved == true) { if (this.contextHasBeenRemoved) {
// need to update all ... // need to update all ...
this.contextHasBeenRemoved = false; this.contextHasBeenRemoved = false;
this.resourceListToUpdate.clear(); this.resourceListToUpdate.clear();
@ -173,7 +173,7 @@ public class ResourceManager {
for (final Resource it : this.resourceList) { for (final Resource it : this.resourceList) {
if (jjj == it.getResourceLevel()) { if (jjj == it.getResourceLevel()) {
//Log.debug("Update context named : " + lresourceList[iii].getName()); //Log.debug("Update context named : " + lresourceList[iii].getName());
if (it.updateContext() == false) { if (!it.updateContext()) {
// Lock error ==> postponned // Lock error ==> postponned
this.resourceListToUpdate.add(it); this.resourceListToUpdate.add(it);
} }
@ -193,7 +193,7 @@ public class ResourceManager {
Log.verbose(" updateContext level (U) : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1)); Log.verbose(" updateContext level (U) : " + jjj + "/" + (MAX_RESOURCE_LEVEL - 1));
for (final Resource it : resourceListToUpdate) { for (final Resource it : resourceListToUpdate) {
if (jjj == it.getResourceLevel()) { if (jjj == it.getResourceLevel()) {
if (it.updateContext() == false) { if (!it.updateContext()) {
// Lock error ==> postponned // Lock error ==> postponned
this.resourceListToUpdate.add(it); this.resourceListToUpdate.add(it);
} }

View File

@ -19,10 +19,10 @@ import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL40; import org.lwjgl.opengl.GL40;
class ProgAttributeElement { class ProgAttributeElement {
public String name; //!< Name of the element public String name; // !< Name of the element
public int elementId; //!< openGl Id if this element == > can not exist ==> @ref m_isLinked public int elementId; // !< openGl Id if this element == > can not exist ==> @ref m_isLinked
public boolean isAttribute; //!< true if it was an attribute element, otherwite it was an uniform public boolean isAttribute; // !< true if it was an attribute element, otherwite it was an uniform
public boolean isLinked; //!< if this element does not exist this is false public boolean isLinked; // !< if this element does not exist this is false
}; };
public class ResourceProgram extends Resource { public class ResourceProgram extends Resource {
@ -30,11 +30,8 @@ public class ResourceProgram extends Resource {
public static ResourceProgram create(final Uri uriVertexShader, final Uri uriFragmentShader) { public static ResourceProgram create(final Uri uriVertexShader, final Uri uriFragmentShader) {
ResourceProgram resource; ResourceProgram resource;
Resource resource2 = null;
final String name = uriVertexShader.getValue() + "<-->" + uriFragmentShader.getValue(); final String name = uriVertexShader.getValue() + "<-->" + uriFragmentShader.getValue();
if (name.isEmpty() == false && name != "---") { Resource resource2 = getManager().localKeep(name);
resource2 = getManager().localKeep(name);
}
if (resource2 != null) { if (resource2 != null) {
if (resource2 instanceof ResourceProgram) { if (resource2 instanceof ResourceProgram) {
resource2.keep(); resource2.keep();
@ -58,10 +55,10 @@ public class ResourceProgram extends Resource {
public static FloatBuffer storeDataInFloatBufferColor(final List<Color> data) { public static FloatBuffer storeDataInFloatBufferColor(final List<Color> data) {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size() * 4); final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size() * 4);
for (int iii = 0; iii < data.size(); iii++) { for (int iii = 0; iii < data.size(); iii++) {
buffer.put(iii * 3, data.get(iii).r); buffer.put(iii * 3, data.get(iii).r());
buffer.put(iii * 3 + 1, data.get(iii).g); buffer.put(iii * 3 + 1, data.get(iii).g());
buffer.put(iii * 3 + 2, data.get(iii).b); buffer.put(iii * 3 + 2, data.get(iii).b());
buffer.put(iii * 3 + 3, data.get(iii).a); buffer.put(iii * 3 + 3, data.get(iii).a());
} }
buffer.flip(); buffer.flip();
return buffer; return buffer;
@ -70,27 +67,32 @@ public class ResourceProgram extends Resource {
public static FloatBuffer storeDataInFloatBufferVector3f(final List<Vector3f> data) { public static FloatBuffer storeDataInFloatBufferVector3f(final List<Vector3f> data) {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size() * 3); final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size() * 3);
for (int iii = 0; iii < data.size(); iii++) { for (int iii = 0; iii < data.size(); iii++) {
buffer.put(iii * 3, data.get(iii).x); buffer.put(iii * 3, data.get(iii).x());
buffer.put(iii * 3 + 1, data.get(iii).y); buffer.put(iii * 3 + 1, data.get(iii).y());
buffer.put(iii * 3 + 2, data.get(iii).z); buffer.put(iii * 3 + 2, data.get(iii).z());
} }
buffer.flip(); buffer.flip();
return buffer; return buffer;
} }
private boolean exist = false; //!< the file existed private boolean exist = false; // !< the file existed
private int program = 0; //!< openGL id of the current program private int program = 0; // !< openGL id of the current program
private ResourceShader shaderVertex = null; private ResourceShader shaderVertex = null;
private ResourceShader shaderFragment = null; private ResourceShader shaderFragment = null;
private final List<ProgAttributeElement> elementList = new ArrayList<>(); //!< List of all the attribute requested by the user private final List<ProgAttributeElement> elementList = new ArrayList<>(); // !< List of all the attribute requested
private final List<Integer> listOfVBOUsed = new ArrayList<>(); //!< retain the list of VBO used to disable it when unuse program ... // by the user
// private boolean hasTexture = false; //!< A texture has been set to the current shader private final List<Integer> listOfVBOUsed = new ArrayList<>(); // !< retain the list of VBO used to disable it when
// private boolean hasTexture1 = false; //!< A texture has been set to the current shader // unuse program ...
private boolean hasTexture = false; // !< A texture has been set to the
// current shader
private boolean hasTexture1 = false; // !< A texture has been set to the
// current shader
/** /**
* @brief Contructor of an opengl Program. * Contructor of an opengl Program.
* @param uri Uri of the file * @param uriVertexShader Uri of the file
* @param uriFragmentShader Uri of the file
*/ */
protected ResourceProgram(final Uri uriVertexShader, final Uri uriFragmentShader) { protected ResourceProgram(final Uri uriVertexShader, final Uri uriFragmentShader) {
super(uriVertexShader.getValue() + "<-->" + uriFragmentShader.getValue()); super(uriVertexShader.getValue() + "<-->" + uriFragmentShader.getValue());
@ -110,7 +112,7 @@ public class ResourceProgram extends Resource {
} else { } else {
Log.debug("Add shader on program : " + uriFragmentShader + "frag"); Log.debug("Add shader on program : " + uriFragmentShader + "frag");
} }
if (OpenGL.hasContext() == true) { if (OpenGL.hasContext()) {
updateContext(); updateContext();
} else { } else {
getManager().update(this); getManager().update(this);
@ -118,14 +120,15 @@ public class ResourceProgram extends Resource {
} }
public void bindAttribute(final int attribute, final String variableName) { public void bindAttribute(final int attribute, final String variableName) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
OpenGL.programBindAttribute(this.program, attribute, variableName); OpenGL.programBindAttribute(this.program, attribute, variableName);
} }
/** /**
* @brief Check If an Id is valid in the shader or not (sometime the shader have not some attribute, then we need to display some error) * Check If an Id is valid in the shader or not (sometime the shader have
* not some attribute, then we need to display some error)
* @return idElem Id of the Attribute that might be sended. * @return idElem Id of the Attribute that might be sended.
* @return true The id is valid, false otherwise * @return true The id is valid, false otherwise
*/ */
@ -137,7 +140,7 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief Destructor, remove the current Program. * Destructor, remove the current Program.
*/ */
@Override @Override
public void cleanUp() { public void cleanUp() {
@ -151,35 +154,38 @@ public class ResourceProgram extends Resource {
this.shaderVertex = null; this.shaderVertex = null;
} }
this.elementList.clear(); this.elementList.clear();
// this.hasTexture = false; this.hasTexture = false;
// this.hasTexture1 = false; this.hasTexture1 = false;
} }
private float[] convertInFloat(final List<Vector3f> data) { private float[] convertInFloat(final List<Vector3f> data) {
final float[] out = new float[data.size() * 3]; final float[] out = new float[data.size() * 3];
for (int iii = 0; iii < data.size(); iii++) { for (int iii = 0; iii < data.size(); iii++) {
out[iii * 3] = data.get(iii).x; out[iii * 3] = data.get(iii).x();
out[iii * 3 + 1] = data.get(iii).y; out[iii * 3 + 1] = data.get(iii).y();
out[iii * 3 + 2] = data.get(iii).z; out[iii * 3 + 2] = data.get(iii).z();
} }
return out; return out;
} }
// private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) { // private void storeDataInAttributeList(int attributeNumber, int
// coordinateSize, float[] data) {
// int vboID = GL15.glGenBuffers(); // int vboID = GL15.glGenBuffers();
// vbos.add(vboID); // vbos.add(vboID);
// OpenGL.bindBuffer(vboID); // OpenGL.bindBuffer(vboID);
// FloatBuffer buffer = storeDataInFloatBuffer(data); // FloatBuffer buffer = storeDataInFloatBuffer(data);
// GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); // GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
// GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0); // GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT,
// false, 0, 0);
// GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// } // }
/** /**
* @brief User request an attribute on this program. * User request an attribute on this program.
* @note The attribute is send to the fragment shaders * @note The attribute is send to the fragment shaders
* @param elementName Name of the requested attribute. * @param elementName Name of the requested attribute.
* @return An abstract ID of the current attribute (this value is all time availlable, even if the program will be reloaded) * @return An abstract ID of the current attribute (this value is all time
* availlable, even if the program will be reloaded)
*/ */
public int getAttribute(final String elementName) { public int getAttribute(final String elementName) {
// check if it exist previously : // check if it exist previously :
@ -191,18 +197,20 @@ public class ResourceProgram extends Resource {
final ProgAttributeElement tmp = new ProgAttributeElement(); final ProgAttributeElement tmp = new ProgAttributeElement();
tmp.name = elementName; tmp.name = elementName;
tmp.isAttribute = true; tmp.isAttribute = true;
if (OpenGL.hasContext() == false) { if (!OpenGL.hasContext()) {
getManager().update(this); getManager().update(this);
tmp.elementId = -1; tmp.elementId = -1;
tmp.isLinked = false; tmp.isLinked = false;
} else if (this.exist == true) { } else if (this.exist) {
tmp.elementId = OpenGL.programGetAttributeLocation(this.program, tmp.name); tmp.elementId = OpenGL.programGetAttributeLocation(this.program, tmp.name);
tmp.isLinked = true; tmp.isLinked = true;
if (tmp.elementId < 0) { if (tmp.elementId < 0) {
Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\"" + tmp.name + "\") = " + tmp.elementId); Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\""
+ tmp.name + "\") = " + tmp.elementId);
tmp.isLinked = false; tmp.isLinked = false;
} else { } else {
Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\"" + tmp.name + "\") = " + tmp.elementId); Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetAttribLocation(\""
+ tmp.name + "\") = " + tmp.elementId);
} }
} else { } else {
// program is not loaded ==> just local reister ... // program is not loaded ==> just local reister ...
@ -220,10 +228,12 @@ public class ResourceProgram extends Resource {
// sendAttribute(idElem, 1, data[0]); // sendAttribute(idElem, 1, data[0]);
// } // }
/** /**
* @brief User request an Uniform on this program. * User request an Uniform on this program.
* @note uniform value is availlable for all the fragment shader in the program (only one value for all) * @note uniform value is availlable for all the fragment shader in the program
* (only one value for all)
* @param elementName Name of the requested uniform. * @param elementName Name of the requested uniform.
* @return An abstract ID of the current uniform (this value is all time availlable, even if the program will be reloaded) * @return An abstract ID of the current uniform (this value is all time
* availlable, even if the program will be reloaded)
*/ */
public int getUniform(final String elementName) { public int getUniform(final String elementName) {
// check if it exist previously : // check if it exist previously :
@ -235,18 +245,20 @@ public class ResourceProgram extends Resource {
final ProgAttributeElement tmp = new ProgAttributeElement(); final ProgAttributeElement tmp = new ProgAttributeElement();
tmp.name = elementName; tmp.name = elementName;
tmp.isAttribute = false; tmp.isAttribute = false;
if (OpenGL.hasContext() == false) { if (!OpenGL.hasContext()) {
getManager().update(this); getManager().update(this);
tmp.elementId = -1; tmp.elementId = -1;
tmp.isLinked = false; tmp.isLinked = false;
} else if (this.exist == true) { } else if (this.exist) {
tmp.elementId = OpenGL.programGetUniformLocation(this.program, tmp.name); tmp.elementId = OpenGL.programGetUniformLocation(this.program, tmp.name);
tmp.isLinked = true; tmp.isLinked = true;
if (tmp.elementId < 0) { if (tmp.elementId < 0) {
Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\"" + tmp.name + "\") = " + tmp.elementId); Log.warning(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\""
+ tmp.name + "\") = " + tmp.elementId);
tmp.isLinked = false; tmp.isLinked = false;
} else { } else {
Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\"" + tmp.name + "\") = " + tmp.elementId); Log.debug(" {" + this.program + "}[" + this.elementList.size() + "] glGetUniformLocation(\""
+ tmp.name + "\") = " + tmp.elementId);
} }
} else { } else {
// program is not loaded ==> just local reister ... // program is not loaded ==> just local reister ...
@ -258,43 +270,26 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief Relode the shader from the file. used when a request of resouces reload is done. * Relode the shader from the file. used when a request of resouces
* @note this is really usefull when we tested the new themes or shader developpements. * reload is done.
* @note this is really usefull when we tested the new themes or shader
* developpements.
*/ */
@Override @Override
public void reload() { public void reload() {
/* TODO ... /*
etk::file file(this.name, etk::FILETYPEDATA); * TODO ... etk::file file(this.name, etk::FILETYPEDATA); if (file.Exist() ==
if (file.Exist() == false) { * false) { Log.error("File does not Exist :"" + file + "\""); return; }
Log.error("File does not Exist :"" + file + "\""); *
return; * int fileSize = file.size(); if (fileSize == 0) {
} * Log.error("This file is empty : " + file); return; } if (file.fOpenRead() ==
* false) { Log.error("Can not open the file : " + file); return; } // remove
int fileSize = file.size(); * previous data ... if (this.fileData != null) { del ete[] this.fileData;
if (fileSize == 0) { * this.fileData = 0; } // allocate data this.fileData = ne w char[fileSize+5];
Log.error("This file is empty : " + file); * if (this.fileData == null) { Log.error("Error Memory allocation size=" +
return; * fileSize); return; } memset(this.fileData, 0, (fileSize+5)*sizeof(char)); //
} * load data from the file : file.fRead(this.fileData, 1, fileSize); // close
if (file.fOpenRead() == false) { * the file: file.fClose();
Log.error("Can not open the file : " + file);
return;
}
// remove previous data ...
if (this.fileData != null) {
del ete[] this.fileData;
this.fileData = 0;
}
// allocate data
this.fileData = ne w char[fileSize+5];
if (this.fileData == null) {
Log.error("Error Memory allocation size=" + fileSize);
return;
}
memset(this.fileData, 0, (fileSize+5)*sizeof(char));
// load data from the file :
file.fRead(this.fileData, 1, fileSize);
// close the file:
file.fClose();
*/ */
// now change the OGL context ... // now change the OGL context ...
removeContext(); removeContext();
@ -302,11 +297,11 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief remove the data from the opengl context. * remove the data from the opengl context.
*/ */
@Override @Override
public void removeContext() { public void removeContext() {
if (this.exist == true) { if (this.exist) {
OpenGL.programRemove(this.program); OpenGL.programRemove(this.program);
this.program = 0; this.program = 0;
this.exist = false; this.exist = false;
@ -318,7 +313,8 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief Special android spec! It inform us that all context is removed and after notify us... * Special android spec! It inform us that all context is removed and
* after notify us...
*/ */
@Override @Override
public void removeContextToLate() { public void removeContextToLate() {
@ -328,11 +324,14 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief Send attribute table to the specified ID attribute (not send if does not really exist in the openGL program). * Send attribute table to the specified ID attribute (not send if does
* not really exist in the openGL program).
* @param idElem Id of the Attribute that might be sent. * @param idElem Id of the Attribute that might be sent.
* @param nbElement Specifies the number of elements that are to be modified. * @param nbElement Specifies the number of elements that are to be
* @param pointer Pointer on the data that might be sent. * modified.
* @param jumpBetweenSample Number of byte to jump between 2 vertex (this permit to interlace informations) * @param data Pointer on the data that might be sent.
* @param jumpBetweenSample Number of byte to jump between 2 vertex (this permit
* to interlace informations)
*/ */
// public void sendAttribute3fv(int idElem, float[] data) { // public void sendAttribute3fv(int idElem, float[] data) {
// if (!this.exist) { // if (!this.exist) {
@ -340,7 +339,8 @@ public class ResourceProgram extends Resource {
// } // }
// if ( idElem < 0 // if ( idElem < 0
// || (long)idElem > this.elementList.size()) { // || (long)idElem > this.elementList.size()) {
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]"); // Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1)
// + "]");
// return; // return;
// } // }
// if (this.elementList.get(idElem).isLinked == false) { // if (this.elementList.get(idElem).isLinked == false) {
@ -348,7 +348,8 @@ public class ResourceProgram extends Resource {
// } // }
// FloatBuffer buffer = storeDataInFloatBuffer(data); // FloatBuffer buffer = storeDataInFloatBuffer(data);
// //GL40.glBindVertexArray(this.elementList.get(idElem).elementId); // //GL40.glBindVertexArray(this.elementList.get(idElem).elementId);
// Log.error("[" + this.elementList.get(idElem).name + "] send " + data.length + " element"); // Log.error("[" + this.elementList.get(idElem).name + "] send " + data.length +
// " element");
// GL40.glVertexAttribPointer( // GL40.glVertexAttribPointer(
// this.elementList.get(idElem).elementId, // this.elementList.get(idElem).elementId,
// data.length, // data.length,
@ -366,33 +367,35 @@ public class ResourceProgram extends Resource {
// public void sendAttribute(int idElem, List<Vector3f> data) { // public void sendAttribute(int idElem, List<Vector3f> data) {
// sendAttribute3fv(idElem, convertInFloat(data)); // sendAttribute3fv(idElem, convertInFloat(data));
// } // }
public void sendAttribute(final int idElem, final int nbElement, final FloatBuffer data, final int jumpBetweenSample) { public void sendAttribute(final int idElem, final int nbElement, final FloatBuffer data,
if (this.exist == false) { final int jumpBetweenSample) {
if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (this.elementList.get(idElem).isLinked == false) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
//GL40.glBindVertexArray(this.elementList.get(idElem).elementId); // GL40.glBindVertexArray(this.elementList.get(idElem).elementId);
//Log.error("[" + this.elementList.get(idElem).name + "] send " + 3 + " element"); // Log.error("[" + this.elementList.get(idElem).name + "] send " + 3 + "
GL40.glVertexAttribPointer(this.elementList.get(idElem).elementId, nbElement, GL40.GL_FLOAT, false, jumpBetweenSample * 4, /* 4 is the size of float in the generic system...*/ // element");
GL40.glVertexAttribPointer(this.elementList.get(idElem).elementId, nbElement, GL40.GL_FLOAT, false,
jumpBetweenSample * 4, /* 4 is the size of float in the generic system... */
data); data);
//checkGlError("glVertexAttribPointer", LINE, idElem); // checkGlError("glVertexAttribPointer", LINE, idElem);
GL40.glEnableVertexAttribArray(this.elementList.get(idElem).elementId); GL40.glEnableVertexAttribArray(this.elementList.get(idElem).elementId);
//checkGlError("glEnableVertexAttribArray", LINE, idElem); // checkGlError("glEnableVertexAttribArray", LINE, idElem);
} }
/** /**
* @brief Send attribute table to the spefified ID attribure (not send if does not really exist in the openGL program). * Send attribute table to the spefified ID attribure (not send if does
* not really exist in the openGL program).
* @param idElem Id of the Attribute that might be sended. * @param idElem Id of the Attribute that might be sended.
* @param vbo Reference on the buffer to send. * @param vbo Reference on the buffer to send.
* @param index Reference on the buffer to send. * @param index Reference on the buffer to send.
* @param jumpBetweenSample Number of byte to jump between 2 vertex (this permit to enterlace informations)
* @param offset offset of start the elements send.
*/ */
// public void sendAttributePointer(int idElem, // public void sendAttributePointer(int idElem,
// ResourceVirtualArrayObject vbo, // ResourceVirtualArrayObject vbo,
@ -405,7 +408,8 @@ public class ResourceProgram extends Resource {
// } // }
// if ( idElem < 0 // if ( idElem < 0
// || (long)idElem > this.elementList.size()) { // || (long)idElem > this.elementList.size()) {
// Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1) + "]"); // Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size()-1)
// + "]");
// return; // return;
// } // }
// if (this.elementList.get(idElem).isLinked == false) { // if (this.elementList.get(idElem).isLinked == false) {
@ -413,16 +417,20 @@ public class ResourceProgram extends Resource {
// } // }
// // check error of the VBO goog enought ... // // check error of the VBO goog enought ...
// if (vbo.getElementSize(index) <= 0) { // if (vbo.getElementSize(index) <= 0) {
// Log.error("Can not bind a VBO Buffer with an element size of : " + vbo.getElementSize(index) + " named=" + vbo.getName()); // Log.error("Can not bind a VBO Buffer with an element size of : " +
// vbo.getElementSize(index) + " named=" + vbo.getName());
// return; // return;
// } // }
// //
// Log.verbose("[" + this.elementList.get(idElem).name + "] send " + vbo.getElementSize(index) + " element on oglID=" + vbo.getGLID(index) + " VBOindex=" + index); // Log.verbose("[" + this.elementList.get(idElem).name + "] send " +
// vbo.getElementSize(index) + " element on oglID=" + vbo.getGLID(index) + "
// VBOindex=" + index);
// OpenGL.bindBuffer(vbo.getGLID(index)); // OpenGL.bindBuffer(vbo.getGLID(index));
// Log.verbose(" id=" + this.elementList.get(idElem).elementId); // Log.verbose(" id=" + this.elementList.get(idElem).elementId);
// Log.verbose(" eleme size=" + vbo.getElementSize(index)); // Log.verbose(" eleme size=" + vbo.getElementSize(index));
// OpenGL.bufferData(data, Usage.staticDraw); // OpenGL.bufferData(data, Usage.staticDraw);
// OpenGL.vertexAttribPointerFloat(this.elementList.get(idElem).elementId, vbo.getElementSize(index)); // Pointer on the buffer // OpenGL.vertexAttribPointerFloat(this.elementList.get(idElem).elementId,
// vbo.getElementSize(index)); // Pointer on the buffer
// OpenGL.unbindBuffer(); // OpenGL.unbindBuffer();
// //glEnableVertexAttribArray(this.elementList.get(idElem).elementId); // //glEnableVertexAttribArray(this.elementList.get(idElem).elementId);
// this.listOfVBOUsed.add(this.elementList.get(idElem).elementId); // this.listOfVBOUsed.add(this.elementList.get(idElem).elementId);
@ -437,13 +445,14 @@ public class ResourceProgram extends Resource {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (this.elementList.get(idElem).isLinked == false) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
Log.verbose("[" + this.elementList.get(idElem).name + "] send on oglID=" + vbo.getGL_ID(index) + " VBOindex=" + index); Log.verbose("[" + this.elementList.get(idElem).name + "] send on oglID=" + vbo.getOpenGlId(index) + " VBOindex="
GL20.glBindBuffer(GL20.GL_ARRAY_BUFFER, vbo.getGL_ID(index)); + index);
//checkGlError("glBindBuffer", __LINE__, _idElem); GL20.glBindBuffer(GL20.GL_ARRAY_BUFFER, vbo.getOpenGlId(index));
// checkGlError("glBindBuffer", __LINE__, _idElem);
Log.verbose(" id=" + this.elementList.get(idElem).elementId); Log.verbose(" id=" + this.elementList.get(idElem).elementId);
Log.verbose(" jump sample=" + jumpBetweenSample); Log.verbose(" jump sample=" + jumpBetweenSample);
Log.verbose(" offset=" + offset); Log.verbose(" offset=" + offset);
@ -453,68 +462,112 @@ public class ResourceProgram extends Resource {
false, // take our values as-is false, // take our values as-is
0, // no extra data between each position 0, // no extra data between each position
0); // Pointer on the buffer 0); // Pointer on the buffer
//checkGlError("glVertexAttribPointer", __LINE__, _idElem); // checkGlError("glVertexAttribPointer", __LINE__, _idElem);
GL20.glEnableVertexAttribArray(this.elementList.get(idElem).elementId); GL20.glEnableVertexAttribArray(this.elementList.get(idElem).elementId);
this.listOfVBOUsed.add(this.elementList.get(idElem).elementId); this.listOfVBOUsed.add(this.elementList.get(idElem).elementId);
//checkGlError("glEnableVertexAttribArray", __LINE__, _idElem); // checkGlError("glEnableVertexAttribArray", __LINE__, _idElem);
}
/**
* set the testure Id on the specify uniform element.
* @param idElem Id of the uniform that might be sended.
* @param textureOpenGlID Real openGL texture ID
*/
public void setTexture0(final int idElem, final int textureOpenGlID) {
if (!this.exist) {
return;
}
if (idElem < 0 || (long) idElem > this.elementList.size()) {
return;
}
if (!this.elementList.get(idElem).isLinked) {
return;
}
OpenGL.activeTexture(0);
// set the textureID
OpenGL.bindTexture2D(textureOpenGlID);
// set the texture on the uniform attribute
uniformInt(this.elementList.get(idElem).elementId, /* GLTEXTURE */0);
this.hasTexture = true;
}
public void setTexture1(final int idElem, final int textureOpenGlID) {
if (!this.exist) {
return;
}
if (idElem < 0 || (long) idElem > this.elementList.size()) {
return;
}
if (!this.elementList.get(idElem).isLinked) {
return;
}
OpenGL.activeTexture(1);
// set the textureID
OpenGL.bindTexture2D(textureOpenGlID);
// set the texture on the uniform attribute
uniformInt(this.elementList.get(idElem).elementId, /* GLTEXTURE */0);
this.hasTexture1 = true;
} }
public void uniformColor(final int idElem, final Color value) { public void uniformColor(final int idElem, final Color value) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformColor(this.elementList.get(idElem).elementId, value); OpenGL.programLoadUniformColor(this.elementList.get(idElem).elementId, value);
} }
/** /**
* @brief Send 1 float uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 1 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
*/ */
public void uniformFloat(final int idElem, final float value1) { public void uniformFloat(final int idElem, final float value1) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1); OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1);
} }
/** /**
* @brief Send 2 float uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 2 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
* @param value2 Value to send at the Uniform * @param value2 Value to send at the Uniform
*/ */
public void uniformFloat(final int idElem, final float value1, final float value2) { public void uniformFloat(final int idElem, final float value1, final float value2) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2); OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2);
} }
/** /**
* @brief Send 3 float uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 3 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
* @param value2 Value to send at the Uniform * @param value2 Value to send at the Uniform
@ -522,85 +575,90 @@ public class ResourceProgram extends Resource {
*/ */
public void uniformFloat(final int idElem, final float value1, final float value2, final float value3) { public void uniformFloat(final int idElem, final float value1, final float value2, final float value3) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2, value3); OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2, value3);
} }
/** /**
* @brief Send 4 float uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 4 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
* @param value2 Value to send at the Uniform * @param value2 Value to send at the Uniform
* @param value3 Value to send at the Uniform * @param value3 Value to send at the Uniform
* @param value4 Value to send at the Uniform * @param value4 Value to send at the Uniform
*/ */
public void uniformFloat(final int idElem, final float value1, final float value2, final float value3, final float value4) { public void uniformFloat(final int idElem, final float value1, final float value2, final float value3,
final float value4) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2, value3, value4); OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2, value3, value4);
} }
/** /**
* @brief Send 1 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 1 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
*/ */
public void uniformInt(final int idElem, final int value1) { public void uniformInt(final int idElem, final int value1) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1); OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1);
} }
/** /**
* @brief Send 2 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 2 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
* @param value2 Value to send at the Uniform * @param value2 Value to send at the Uniform
*/ */
public void uniformInt(final int idElem, final int value1, final int value2) { public void uniformInt(final int idElem, final int value1, final int value2) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2); OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2);
} }
/** /**
* @brief Send 3 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 3 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
* @param value2 Value to send at the Uniform * @param value2 Value to send at the Uniform
@ -608,21 +666,22 @@ public class ResourceProgram extends Resource {
*/ */
public void uniformInt(final int idElem, final int value1, final int value2, final int value3) { public void uniformInt(final int idElem, final int value1, final int value2, final int value3) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3); OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3);
} }
/** /**
* @brief Send 4 signed integer uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send 4 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param value1 Value to send at the Uniform * @param value1 Value to send at the Uniform
* @param value2 Value to send at the Uniform * @param value2 Value to send at the Uniform
@ -631,159 +690,118 @@ public class ResourceProgram extends Resource {
*/ */
public void uniformInt(final int idElem, final int value1, final int value2, final int value3, final int value4) { public void uniformInt(final int idElem, final int value1, final int value2, final int value3, final int value4) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3, value4); OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3, value4);
} }
/** /**
* @brief Send a uniform element to the spefified ID (not send if does not really exist in the openGL program) * Send a uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
* @param idElem Id of the uniform that might be sended. * @param idElem Id of the uniform that might be sended.
* @param matrix Matrix that might be sended. * @param matrix Matrix that might be sended.
* @param transpose Transpose the matrix (needed all the taime in the normal openGl access (only not done in the openGL-ES2 due to the fact we must done it ourself) * @param transpose Transpose the matrix (needed all the taime in the normal
* openGl access (only not done in the openGL-ES2 due to the
* fact we must done it ourself)
*/ */
public void uniformMatrix(final int idElem, final Matrix4f matrix) { public void uniformMatrix(final int idElem, final Matrix4f matrix) {
uniformMatrix(idElem, matrix, true); uniformMatrix(idElem, matrix, true);
} }
public void uniformMatrix(final int idElem, final Matrix4f matrix, final boolean transpose/*=true*/) { public void uniformMatrix(final int idElem, final Matrix4f matrix, final boolean transpose/* =true */) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
//Log.error("[" + this.elementList.get(idElem).name + "] send 1 matrix"); // Log.error("[" + this.elementList.get(idElem).name + "] send 1 matrix");
// note : Android des not supported the transposition of the matrix, then we will done it oursef: // note : Android des not supported the transposition of the matrix, then we
// will done it oursef:
/* /*
if (transpose == true) { * if (transpose == true) { Matrix4f tmp = matrix; tmp.transpose();
Matrix4f tmp = matrix; * programLoadUniformMatrix(this.elementList.get(idElem).elementId, tmp.mat); }
tmp.transpose(); * else { programLoadUniformMatrix(this.elementList.get(idElem).elementId,
programLoadUniformMatrix(this.elementList.get(idElem).elementId, tmp.mat); * matrix.mat); }
} else {
programLoadUniformMatrix(this.elementList.get(idElem).elementId, matrix.mat);
}
*/ */
OpenGL.programLoadUniformMatrix(this.elementList.get(idElem).elementId, matrix, transpose); OpenGL.programLoadUniformMatrix(this.elementList.get(idElem).elementId, matrix, transpose);
} }
public void uniformVector(final int idElem, final Vector2f value) { public void uniformVector(final int idElem, final Vector2f value) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value); OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
} }
public void uniformVector(final int idElem, final Vector2i value) { public void uniformVector(final int idElem, final Vector2i value) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value); OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
} }
public void uniformVector(final int idElem, final Vector3f value) { public void uniformVector(final int idElem, final Vector3f value) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value); OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
} }
public void uniformVector(final int idElem, final Vector3i value) { public void uniformVector(final int idElem, final Vector3i value) {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (idElem < 0 || (long) idElem > this.elementList.size()) { if (idElem < 0 || (long) idElem > this.elementList.size()) {
Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]"); Log.error("idElem = " + idElem + " not in [0.." + (this.elementList.size() - 1) + "]");
return; return;
} }
if (false == this.elementList.get(idElem).isLinked) { if (!this.elementList.get(idElem).isLinked) {
return; return;
} }
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value); OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
} }
// /**
// * @brief set the testure Id on the specify uniform element.
// * @param idElem Id of the uniform that might be sended.
// * @param textureOpenGlID Real openGL texture ID
// */
// public void setTexture0(int idElem, int textureOpenGlID){
//
// if (!this.exist) {
// return;
// }
// if ( idElem < 0
// || (long)idElem > this.elementList.size()) {
// return;
// }
// if (this.elementList.get(idElem).isLinked == false) {
// return;
// }
// OpenGL.activeTexture(GL13.GL_TEXTURE0);
// // set the textureID
// GL13.glBindTexture(GL13.GL_TEXTURE_2D, textureOpenGlID);
// // set the texture on the uniform attribute
// GL20.glUniform1i(this.elementList.get(idElem).elementId, /*GLTEXTURE*/0);
// this.hasTexture = true;
// }
// public void setTexture1(int idElem, int textureOpenGlID) {
// if (!this.exist) {
// return;
// }
// if ( idElem < 0
// || (long)idElem > this.elementList.size()) {
// return;
// }
// if (this.elementList.get(idElem).isLinked == false) {
// return;
// }
// OpenGL.activeTexture(GL13.GL_TEXTURE1);
// // set the textureID
// GL13.glBindTexture(GL13.GL_TEXTURE_2D, textureOpenGlID);
// // set the texture on the uniform attribute
// GL20.glUniform1i(this.elementList.get(idElem).elementId, /*GLTEXTURE*/1);
// this.hasTexture1 = true;
// }
/** /**
* @brief Stop the processing of this program * Stop the processing of this program
*/ */
public void unUse() { public void unUse() {
//Log.verbose("Will UN-use program : " + this.program); // Log.verbose("Will UN-use program : " + this.program);
if (this.exist == false) { if (!this.exist) {
return; return;
} }
for (final Integer it : this.listOfVBOUsed) { for (final Integer it : this.listOfVBOUsed) {
@ -795,11 +813,12 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief This load/reload the data in the opengl context, needed when removed previously. * This load/reload the data in the opengl context, needed when removed
* previously.
*/ */
@Override @Override
public boolean updateContext() { public boolean updateContext() {
if (this.exist == true) { if (this.exist) {
// Do nothing == > too dangerous ... // Do nothing == > too dangerous ...
} else { } else {
// create the Shader // create the Shader
@ -817,11 +836,12 @@ public class ResourceProgram extends Resource {
} }
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_POSITIONS, "in_position"); OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_POSITIONS, "in_position");
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_TEXTURE_COORDINATES, "tin_extureCoords"); OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_TEXTURE_COORDINATES,
"tin_extureCoords");
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_NORMALS, "in_normal"); OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_NORMALS, "in_normal");
OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_COLORS, "in_colors"); OpenGL.programBindAttribute(this.program, ResourceVirtualArrayObject.INDICE_VBO_COLORS, "in_colors");
if (OpenGL.programCompile(this.program) == false) { if (!OpenGL.programCompile(this.program)) {
Log.error("Could not compile'PROGRAM':'" + this.name + "'"); Log.error("Could not compile'PROGRAM':'" + this.name + "'");
OpenGL.programRemove(this.program); OpenGL.programRemove(this.program);
return true; return true;
@ -829,23 +849,27 @@ public class ResourceProgram extends Resource {
// now get the old attribute requested priviously ... // now get the old attribute requested priviously ...
long iii = 0; long iii = 0;
for (final ProgAttributeElement it : this.elementList) { for (final ProgAttributeElement it : this.elementList) {
if (it.isAttribute == true) { if (it.isAttribute) {
it.elementId = OpenGL.programGetAttributeLocation(this.program, it.name); it.elementId = OpenGL.programGetAttributeLocation(this.program, it.name);
it.isLinked = true; it.isLinked = true;
if (it.elementId < 0) { if (it.elementId < 0) {
Log.warning(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name + "\") = " + it.elementId); Log.warning(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name
+ "\") = " + it.elementId);
it.isLinked = false; it.isLinked = false;
} else { } else {
Log.debug(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name + "\") = " + it.elementId); Log.debug(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name
+ "\") = " + it.elementId);
} }
} else { } else {
it.elementId = OpenGL.programGetUniformLocation(this.program, it.name); it.elementId = OpenGL.programGetUniformLocation(this.program, it.name);
it.isLinked = true; it.isLinked = true;
if (it.elementId < 0) { if (it.elementId < 0) {
Log.warning(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name + "\") = " + it.elementId); Log.warning(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name
+ "\") = " + it.elementId);
it.isLinked = false; it.isLinked = false;
} else { } else {
Log.debug(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name + "\") = " + it.elementId); Log.debug(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name
+ "\") = " + it.elementId);
} }
} }
iii++; iii++;
@ -857,11 +881,12 @@ public class ResourceProgram extends Resource {
} }
/** /**
* @brief Request the processing of this program * Request the processing of this program
*/ */
public void use() { public void use() {
//Log.verbose("Will use program : " + this.program); // Log.verbose("Will use program : " + this.program);
// event if it was 0 == > set it to prevent other use of the previous shader display ... // event if it was 0 == > set it to prevent other use of the previous shader
// display ...
OpenGL.programUse(this.program); OpenGL.programUse(this.program);
} }

View File

@ -11,7 +11,7 @@ public class ResourceShader extends Resource {
ResourceShader resource; ResourceShader resource;
Resource resource2; Resource resource2;
final String name = uriShader.getValue(); final String name = uriShader.getValue();
if (name.isEmpty() == false && name != "---") { if (!name.isEmpty() && !name.equals("---")) {
resource2 = getManager().localKeep(name); resource2 = getManager().localKeep(name);
} else { } else {
Log.error("Can not create a shader without a filaname"); Log.error("Can not create a shader without a filaname");
@ -26,23 +26,18 @@ public class ResourceShader extends Resource {
return null; return null;
} }
resource = new ResourceShader(uriShader); resource = new ResourceShader(uriShader);
if (resource == null) {
Log.error("allocation error of a resource : " + name);
return null;
}
getManager().localAdd(resource); getManager().localAdd(resource);
return resource; return resource;
} }
private boolean exist = false; //!< The shader file existed and has been loaded private boolean exist = false; //!< The shader file existed and has been loaded
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 int shader = -1; //!< opengl id of this element
private final ShaderType type; //!< Type of the current shader(vertex/fragment) private final ShaderType type; //!< Type of the current shader(vertex/fragment)
private final Uri uri; private final Uri uri;
/** /**
* @brief Contructor of an opengl Shader * Constructor of an opengl Shader
* @param filename Standard file name format. see @ref etk::FSNode * @param uri Standard file name format. see @ref etk::FSNode
*/ */
protected ResourceShader(final Uri uri) { protected ResourceShader(final Uri uri) {
super(uri); super(uri);
@ -64,7 +59,7 @@ public class ResourceShader extends Resource {
} }
/** /**
* @brief Destructor, remove the current Shader * Destructor, remove the current Shader
*/ */
@Override @Override
public void cleanUp() { public void cleanUp() {
@ -73,7 +68,7 @@ public class ResourceShader extends Resource {
}; };
/** /**
* @brief get the opengl reference id of this shader. * get the opengl reference id of this shader.
* @return The opengl id. * @return The opengl id.
*/ */
public int getGLID() { public int getGLID() {
@ -81,7 +76,7 @@ public class ResourceShader extends Resource {
}; };
/** /**
* @brief get the opengl type of this shader. * get the opengl type of this shader.
* @return The type of this loaded shader. * @return The type of this loaded shader.
*/ */
public ShaderType getShaderType() { public ShaderType getShaderType() {
@ -89,14 +84,16 @@ public class ResourceShader extends Resource {
} }
/** /**
* @brief Relode the shader from the file. used when a request of resouces reload is done. * Reloaded the shader from the file. used when a request of resources reload is done.
* @note this is really usefull when we tested the new themes or shader developpements. * @note this is really useful when we tested the new themes or shader developments.
*/ */
@Override @Override
public void reload() { public void reload() {
Log.verbose("load shader:\n-----------------------------------------------------------------\n" + this.fileData + "\n-----------------------------------------------------------------"); //!< A copy of the data loaded from the file (useful only when opengl context is removed)
String fileData = "";
Log.verbose("load shader:\n-----------------------------------------------------------------\n" + fileData + "\n-----------------------------------------------------------------");
// now change the OGL context ... // now change the OGL context ...
if (OpenGL.hasContext() == true) { if (OpenGL.hasContext()) {
Log.debug("OGL : load SHADER '" + this.name + "' ==> call update context (direct)"); Log.debug("OGL : load SHADER '" + this.name + "' ==> call update context (direct)");
removeContext(); removeContext();
updateContext(); updateContext();
@ -110,11 +107,11 @@ public class ResourceShader extends Resource {
} }
/** /**
* @brief remove the data from the opengl context. * remove the data from the opengl context.
*/ */
@Override @Override
public void removeContext() { public void removeContext() {
if (true == this.exist) { if (this.exist) {
OpenGL.shaderRemove(this.shader); OpenGL.shaderRemove(this.shader);
this.shader = -1; this.shader = -1;
this.exist = false; this.exist = false;
@ -122,7 +119,7 @@ public class ResourceShader extends Resource {
} }
/** /**
* @brief Special android spec! It inform us that all context is removed and after notify us... * Special android spec! It inform us that all context is removed and after notify us...
*/ */
@Override @Override
public void removeContextToLate() { public void removeContextToLate() {
@ -131,14 +128,12 @@ public class ResourceShader extends Resource {
} }
/** /**
* @brief This load/reload the data in the opengl context, needed when removed previously. * This load/reload the data in the opengl context, needed when removed previously.
*/ */
@Override @Override
public boolean updateContext() { public boolean updateContext() {
if (this.exist == true) { if (!this.exist) {
// Do nothing == > too dangerous ... this.shader = OpenGL.shaderLoad(this.uri, this.type);
} else {
this.shader = OpenGL.shaderLoad(this.uri.get(), this.type);
// create the Shader // create the Shader
if (this.shader < 0) { if (this.shader < 0) {
return true; return true;

View File

@ -32,7 +32,7 @@ public class ResourceTexture extends Resource {
ResourceTexture resource; ResourceTexture resource;
Resource resource2; Resource resource2;
final String name = uriTexture.getValue(); final String name = uriTexture.getValue();
if (name.isEmpty() == false && name != "---") { if (!name.isEmpty() && !name.equals("---")) {
resource2 = getManager().localKeep(name); resource2 = getManager().localKeep(name);
} else { } else {
Log.error("Can not create a shader without a filaname"); Log.error("Can not create a shader without a filaname");
@ -48,14 +48,14 @@ public class ResourceTexture extends Resource {
} }
resource = new ResourceTexture(uriTexture, textureUnit); resource = new ResourceTexture(uriTexture, textureUnit);
final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture); final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
resource.setTexture(decodedData.getBuffer(), new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() == true ? TextureColorMode.rgba : TextureColorMode.rgb), resource.setTexture(decodedData.getBuffer(), new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() ? TextureColorMode.rgba : TextureColorMode.rgb),
textureUnit); textureUnit);
resource.flush(); resource.flush();
return resource; return resource;
} }
/** /**
* @brief get the next power 2 if the input * get the next power 2 if the input
* @param value Value that we want the next power of 2 * @param value Value that we want the next power of 2
* @return result value * @return result value
*/ */
@ -105,7 +105,7 @@ public class ResourceTexture extends Resource {
} }
public void bindForRendering(final int idTexture) { public void bindForRendering(final int idTexture) {
if (this.loaded == false) { if (!this.loaded) {
return; return;
} }
GL13.glActiveTexture(textureIdBinding[idTexture]); GL13.glActiveTexture(textureIdBinding[idTexture]);
@ -142,7 +142,7 @@ public class ResourceTexture extends Resource {
@Override @Override
public synchronized void removeContext() { public synchronized void removeContext() {
if (this.loaded == true) { if (this.loaded) {
// Request remove texture ... // Request remove texture ...
Log.info("TEXTURE: Rm [" + getId() + "] texId=" + this.texId); Log.info("TEXTURE: Rm [" + getId() + "] texId=" + this.texId);
// TODO Check if we are in the correct thread // TODO Check if we are in the correct thread
@ -161,14 +161,13 @@ public class ResourceTexture extends Resource {
this.data = data; this.data = data;
this.size = size; this.size = size;
this.textureUnit = textureUnit; this.textureUnit = textureUnit;
this.endPointSize.x = size.x; this.endPointSize = new Vector2f(size.x(), size.y());
this.endPointSize.y = size.y;
this.dataColorSpace = dataColorSpace; this.dataColorSpace = dataColorSpace;
flush(); flush();
} }
public void unBindForRendering() { public void unBindForRendering() {
if (this.loaded == false) { if (!this.loaded) {
return; return;
} }
if (this.dataColorSpace == TextureColorMode.rgb) { if (this.dataColorSpace == TextureColorMode.rgb) {
@ -180,7 +179,7 @@ public class ResourceTexture extends Resource {
// Gale internal API: // Gale internal API:
@Override @Override
public boolean updateContext() { public boolean updateContext() {
if (this.loaded == true) { if (this.loaded) {
return true; return true;
} }
// Request a new texture at openGl : // Request a new texture at openGl :
@ -192,9 +191,9 @@ public class ResourceTexture extends Resource {
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId); Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId);
if (this.dataColorSpace == TextureColorMode.rgb) { 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); 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 { } 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); 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 // generate multi-texture mapping
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);

View File

@ -76,10 +76,6 @@ public class ResourceVirtualArrayObject extends Resource {
int vertexCount = -1; int vertexCount = -1;
/**
* @brief ructor of this VBO.
* @param accesMode Acces mode : ???
*/
protected ResourceVirtualArrayObject(final float[] positions, final float[] colors, final float[] textureCoordinates, final float[] normals, final int[] indices, final int vertexCount) { protected ResourceVirtualArrayObject(final float[] positions, final float[] colors, final float[] textureCoordinates, final float[] normals, final int[] indices, final int vertexCount) {
super(); super();
this.resourceLevel = 3; this.resourceLevel = 3;
@ -93,7 +89,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
public void bindForRendering() { public void bindForRendering() {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
GL30.glBindVertexArray(this.vaoID); GL30.glBindVertexArray(this.vaoID);
@ -113,7 +109,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
private void bindIndicesBuffer(final int[] indices) { private void bindIndicesBuffer(final int[] indices) {
final int vboId = OpenGL.glGenBuffers(); final int vboId = OpenGL.genBuffers();
this.vbo.add(vboId); this.vbo.add(vboId);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboId); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboId);
final IntBuffer buffer = storeDataInIntBuffer(indices); final IntBuffer buffer = storeDataInIntBuffer(indices);
@ -121,7 +117,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief Destructor of this VBO. * Destructor of this VBO.
*/ */
@Override @Override
public void cleanUp() { public void cleanUp() {
@ -129,7 +125,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief clear buffers * clear buffers
*/ */
public void clear() { public void clear() {
//Log.verbose(" Clear: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.get(0).length + ")"); //Log.verbose(" Clear: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.get(0).length + ")");
@ -143,7 +139,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief Send the data to the graphic card. * Send the data to the graphic card.
*/ */
public void flush() { public void flush() {
// request to the manager to be call at the next update ... // request to the manager to be call at the next update ...
@ -152,7 +148,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief get the real openGL ID. * get the real openGL ID.
* @return the Ogl id reference of this VBO. * @return the Ogl id reference of this VBO.
*/ */
public int getGLID() { public int getGLID() {
@ -185,7 +181,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief Relode the shader from the file. used when a request of resouces reload is done. * 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. * @note this is really usefull when we tested the new themes or shader developpements.
*/ */
@Override @Override
@ -195,23 +191,21 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief remove the data from the opengl context. * remove the data from the opengl context.
*/ */
@Override @Override
public void removeContext() { public void removeContext() {
if (this.exist) {
if (this.exist == true) {
// OpenGL.deleteBuffers(this.vbo); // OpenGL.deleteBuffers(this.vbo);
this.exist = false; this.exist = false;
} }
} }
/** /**
* @brief Special android spec! It inform us that all context is removed and after notify us... * Special android spec! It inform us that all context is removed and after notify us...
*/ */
@Override @Override
public void removeContextToLate() { public void removeContextToLate() {
this.exist = false; this.exist = false;
// for (int iii=0; iii<this.vbo.length; iii++) { // for (int iii=0; iii<this.vbo.length; iii++) {
// this.vbo[iii] = 0; // this.vbo[iii] = 0;
@ -233,7 +227,7 @@ public class ResourceVirtualArrayObject extends Resource {
} }
public void unBindForRendering() { public void unBindForRendering() {
if (this.exist == false) { if (!this.exist) {
return; return;
} }
if (this.positions != null) { if (this.positions != null) {
@ -256,12 +250,12 @@ public class ResourceVirtualArrayObject extends Resource {
} }
/** /**
* @brief This load/reload the data in the opengl context, needed when removed previously. * This load/reload the data in the opengl context, needed when removed previously.
*/ */
@Override @Override
public boolean updateContext() { public boolean updateContext() {
//Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.indices.length + ") ********************************"); //Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.indices.length + ") ********************************");
if (this.exist == false) { if (!this.exist) {
Log.debug(" ==> ALLOCATE new handle"); Log.debug(" ==> ALLOCATE new handle");
// Allocate and assign a Vertex Array Object to our handle // Allocate and assign a Vertex Array Object to our handle
loadToVAO(); loadToVAO();

View File

@ -5,6 +5,8 @@
*/ */
package org.atriasoft.gale.resource; package org.atriasoft.gale.resource;
import java.util.Arrays;
import org.atriasoft.etk.Color; import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector3f; import org.atriasoft.etk.math.Vector3f;
@ -13,7 +15,7 @@ import org.atriasoft.gale.backend3d.OpenGL.Usage;
import org.atriasoft.gale.internal.Log; 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 * 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 class ResourceVirtualBufferObject extends Resource {
@ -26,14 +28,14 @@ public class ResourceVirtualBufferObject extends Resource {
private final Object[] buffer; //!< data that is availlable in the VBO system ... private final Object[] buffer; //!< data that is availlable in the VBO system ...
/** /**
* @brief Constructor of this VBO. * Constructor of this VBO.
* @param[in] accesMode Acces mode : ??? * @param accesMode Acces mode : ???
*/ */
protected ResourceVirtualBufferObject(final int _number) { protected ResourceVirtualBufferObject(final int number) {
super(); super();
this.vbo = new int[_number]; // 0 this.vbo = new int[number]; // 0
this.buffer = new Object[_number]; this.buffer = new Object[number];
Log.debug("OGL : load VBO count=\"" + _number + "\""); Log.debug("OGL : load VBO count=\"" + number + "\"");
this.resourceLevel = 3; this.resourceLevel = 3;
} }
@ -63,18 +65,16 @@ public class ResourceVirtualBufferObject extends Resource {
} }
/** /**
* @brief clear buffers * clear buffers
*/ */
public void clear() { public void clear() {
Log.verbose(" Clear: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")"); Log.verbose(" Clear: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
// DO not clear the this.vbo indexed in the graphic cards ... // DO not clear the this.vbo indexed in the graphic cards ...
for (int iii = 0; iii < this.buffer.length; iii++) { Arrays.fill(this.buffer, null);
this.buffer[iii] = null;
}
} }
/** /**
* @brief Send the data to the graphic card. * Send the data to the graphic card.
*/ */
public synchronized void flush() { public synchronized void flush() {
// request to the manager to be call at the next update ... // request to the manager to be call at the next update ...
@ -103,15 +103,15 @@ public class ResourceVirtualBufferObject extends Resource {
} }
/** /**
* @brief get the real openGL ID. * get the real openGL ID.
* @return the Ogl id reference of this VBO. * @return the Ogl id reference of this VBO.
*/ */
public int getGL_ID(final int _id) { public int getOpenGlId(final int id) {
return this.vbo[_id]; return this.vbo[id];
} }
/** /**
* @brief Relode the shader from the file. used when a request of resouces reload is done. * 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. * @note this is really usefull when we tested the new themes or shader developpements.
*/ */
@Override @Override
@ -121,29 +121,27 @@ public class ResourceVirtualBufferObject extends Resource {
} }
/** /**
* @brief remove the data from the opengl context. * remove the data from the opengl context.
*/ */
@Override @Override
public synchronized void removeContext() { public synchronized void removeContext() {
if (this.exist == true) { if (this.exist) {
OpenGL.deleteBuffers(this.vbo); OpenGL.deleteBuffers(this.vbo);
this.exist = false; this.exist = false;
} }
} }
/** /**
* @brief Special android spec! It inform us that all context is removed and after notify us... * Special android spec! It inform us that all context is removed and after notify us...
*/ */
@Override @Override
public synchronized void removeContextToLate() { public synchronized void removeContextToLate() {
this.exist = false; this.exist = false;
for (int iii = 0; iii < this.vbo.length; iii++) { Arrays.fill(this.vbo, 0);
this.vbo[iii] = 0;
}
} }
/** /**
* @brief get the data from the graphic card. * get the data from the graphic card.
*/ */
public void retreiveData() { public void retreiveData() {
Log.error("TODO ... "); Log.error("TODO ... ");
@ -170,7 +168,7 @@ public class ResourceVirtualBufferObject extends Resource {
} }
/** /**
* @brief This load/reload the data in the opengl context, needed when removed previously. * This load/reload the data in the opengl context, needed when removed previously.
*/ */
@Override @Override
public synchronized boolean updateContext() { public synchronized boolean updateContext() {
@ -182,7 +180,7 @@ public class ResourceVirtualBufferObject extends Resource {
return false; return false;
} }
*/ */
if (this.exist == false) { if (!this.exist) {
Log.debug(" ==> ALLOCATE new handle"); Log.debug(" ==> ALLOCATE new handle");
// Allocate and assign a Vertex Array Object to our handle // Allocate and assign a Vertex Array Object to our handle
OpenGL.genBuffers(this.vbo); OpenGL.genBuffers(this.vbo);

View File

@ -51,10 +51,6 @@ public class Sample1Application extends Application {
}; };
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer // this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, colors, indices); this.verticesVBO = ResourceVirtualArrayObject.create(vertices, colors, indices);
if (this.verticesVBO == null) {
Log.error("can not instanciate VBO ...");
return;
}
// TO facilitate some debugs we add a name of the VBO: // TO facilitate some debugs we add a name of the VBO:
this.verticesVBO.setName("[VBO] of basic SAMPLE"); this.verticesVBO.setName("[VBO] of basic SAMPLE");
// update all the VBO elements ... // update all the VBO elements ...
@ -69,7 +65,7 @@ public class Sample1Application extends Application {
// set the basic openGL view port: (position drawed in the windows) // set the basic openGL view port: (position drawed in the windows)
OpenGL.setViewPort(new Vector2f(0,0), size); OpenGL.setViewPort(new Vector2f(0,0), size);
// Clear all the stacked matrix ... // Clear all the stacked matrix ...
OpenGL.setBasicMatrix(Matrix4f.identity()); OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
// clear background // clear background
Color bgColor = new Color(0.0f, 1.0f, 1.0f, 0.75f); Color bgColor = new Color(0.0f, 1.0f, 1.0f, 0.75f);
OpenGL.clearColor(bgColor); OpenGL.clearColor(bgColor);

View File

@ -92,10 +92,6 @@ public class Sample2Application extends Application {
}; };
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer // this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, textureCoords, null, indices); this.verticesVBO = ResourceVirtualArrayObject.create(vertices, textureCoords, null, indices);
if (this.verticesVBO == null) {
Log.error("can not instanciate VBO ...");
return;
}
// TO facilitate some debugs we add a name of the VBO: // TO facilitate some debugs we add a name of the VBO:
this.verticesVBO.setName("[VBO] of basic SAMPLE"); this.verticesVBO.setName("[VBO] of basic SAMPLE");
// update all the VBO elements ... // update all the VBO elements ...
@ -119,7 +115,7 @@ public class Sample2Application extends Application {
// set the basic openGL view port: (position drawed in the windows) // set the basic openGL view port: (position drawed in the windows)
OpenGL.setViewPort(new Vector2f(0,0), size); OpenGL.setViewPort(new Vector2f(0,0), size);
// Clear all the stacked matrix ... // Clear all the stacked matrix ...
OpenGL.setBasicMatrix(Matrix4f.identity()); OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
// clear background // clear background
Color bgColor = new Color(0.0f, 1.0f, 1.0f, 0.75f); Color bgColor = new Color(0.0f, 1.0f, 1.0f, 0.75f);
OpenGL.enable(OpenGL.Flag.flag_depthTest); OpenGL.enable(OpenGL.Flag.flag_depthTest);
@ -143,12 +139,12 @@ public class Sample2Application extends Application {
// set Matrix : translation/positionMatrix // set Matrix : translation/positionMatrix
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix(); Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
Matrix4f transforamtionMatrix = Matrix4f.identity(); Matrix4f transforamtionMatrix = Matrix4f.IDENTITY;
transforamtionMatrix.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-1))); transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-1)));
transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(1,0,0),this.angleX)); transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(1,0,0),this.angleX));
transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,1,0),this.angleY)); transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,1,0),this.angleY));
transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,0,1),this.angleZ)); transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,0,1),this.angleZ));
Matrix4f viewMatrix = OpenGL.getCameraMatrix().multiplyNew(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-2))); Matrix4f viewMatrix = OpenGL.getCameraMatrix().multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-2)));
//Matrix4f tmpMatrix = projMatrix * camMatrix; //Matrix4f tmpMatrix = projMatrix * camMatrix;
this.verticesVBO.bindForRendering(); this.verticesVBO.bindForRendering();
this.oGLprogram.uniformMatrix(this.oGLMatrixView, viewMatrix); this.oGLprogram.uniformMatrix(this.oGLMatrixView, viewMatrix);

View File

@ -1,6 +1,5 @@
package org.atriasoft.gale.tools; package org.atriasoft.gale.tools;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -11,24 +10,22 @@ import de.matthiasmann.twl.utils.PNGDecoder;
import de.matthiasmann.twl.utils.PNGDecoder.Format; import de.matthiasmann.twl.utils.PNGDecoder.Format;
public class ImageLoader { public class ImageLoader {
private ImageLoader() {} public static ImageRawData decodePngFile(final Uri filename) {
public static ImageRawData decodePngFile(Uri filename) {
ByteBuffer buf = null; ByteBuffer buf = null;
int tWidth = 0; int tWidth = 0;
int tHeight = 0; int tHeight = 0;
boolean hasAlpha = false; boolean hasAlpha = false;
try { try {
// Open the PNG file as an InputStream // Open the PNG file as an InputStream
InputStream in = new FileInputStream(filename.get()); final InputStream in = Uri.getStream(filename);
// Link the PNG decoder to this stream // Link the PNG decoder to this stream
PNGDecoder decoder = new PNGDecoder(in); final PNGDecoder decoder = new PNGDecoder(in);
// Get the width and height of the texture // Get the width and height of the texture
tWidth = decoder.getWidth(); tWidth = decoder.getWidth();
tHeight = decoder.getHeight(); tHeight = decoder.getHeight();
hasAlpha = decoder.hasAlpha(); hasAlpha = decoder.hasAlpha();
// Decode the PNG file in a ByteBuffer // Decode the PNG file in a ByteBuffer
if (hasAlpha == true) { if (hasAlpha) {
buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
//decoder.decodeFlipped(buf, decoder.getWidth() * 4, Format.RGBA); //decoder.decodeFlipped(buf, decoder.getWidth() * 4, Format.RGBA);
decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA); decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
@ -39,11 +36,13 @@ public class ImageLoader {
} }
buf.flip(); buf.flip();
in.close(); in.close();
} catch (IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
System.err.println("try to load texture " + filename + ", didn't work"); System.err.println("try to load texture " + filename + ", didn't work");
System.exit(-1); System.exit(-1);
} }
return new ImageRawData(buf, tWidth, tHeight, hasAlpha); return new ImageRawData(buf, tWidth, tHeight, hasAlpha);
} }
private ImageLoader() {}
} }

View File

@ -13,10 +13,9 @@ import java.util.List;
import io.scenarium.logger.Logger; import io.scenarium.logger.Logger;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
//import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class) @TestMethodOrder(OrderAnnotation.class)