diff --git a/.classpath b/.classpath
index a1b8fa1..5d35e48 100644
--- a/.classpath
+++ b/.classpath
@@ -87,7 +87,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/module-info.java b/src/module-info.java
index d960b4e..874336a 100644
--- a/src/module-info.java
+++ b/src/module-info.java
@@ -12,29 +12,24 @@ open module org.atriasoft.gale {
exports org.atriasoft.gale.context.LWJG_AWT;
exports org.atriasoft.gale.key;
exports org.atriasoft.gale.resource;
-
+
requires transitive org.atriasoft.etk;
-
- // requires transitive vecmath;
+ requires transitive org.atriasoft.egami;
+
requires transitive org.lwjgl;
requires transitive org.lwjgl.natives;
requires transitive org.lwjgl.glfw;
requires transitive org.lwjgl.glfw.natives;
requires transitive org.lwjgl.assimp;
requires transitive org.lwjgl.assimp.natives;
- // requires transitive org.lwjgl.openal;
- // requires transitive org.lwjgl.openal.natives;
requires transitive org.lwjgl.stb;
requires transitive org.lwjgl.stb.natives;
requires transitive org.lwjgl.jawt;
- // requires transitive org.lwjgl.opengl.awt;
requires transitive org.lwjgl.opengl;
requires transitive org.lwjgl.opengl.natives;
- // requires org.lwjgl.openvr;
-
- // requires transitive jogamp.fat;
-
+
requires transitive java.desktop;
requires transitive pngdecoder;
requires transitive lwjgl3.awt;
+ requires io.scenarium.logger;
}
diff --git a/src/org/atriasoft/gale/Application.java b/src/org/atriasoft/gale/Application.java
index ba421ea..bb3ec91 100644
--- a/src/org/atriasoft/gale/Application.java
+++ b/src/org/atriasoft/gale/Application.java
@@ -17,7 +17,7 @@ public class Application {
private Uri iconName = null;
private final Cursor cursor = Cursor.arrow;
private Orientation orientation = Orientation.screenAuto;
- Vector2f windowsSize = new Vector2f(800, 600);
+ private Vector2f windowsSize = new Vector2f(800, 600);
public Application() {
Log.verbose("Constructor Gale Application");
@@ -286,6 +286,9 @@ public class Application {
* @return
*/
public void setSize(final Vector2f size) {
+ if (size.x() <= 0 || size.y() <= 0) {
+ Log.error("Wrong windows size: " + size);
+ }
this.windowsSize = size;
final Context context = Gale.getContext();
if (context == null) {
diff --git a/src/org/atriasoft/gale/Dimension.java b/src/org/atriasoft/gale/Dimension.java
deleted file mode 100644
index 43123b2..0000000
--- a/src/org/atriasoft/gale/Dimension.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/** @file
- * @author Edouard DUPIN
- * @copyright 2011, Edouard DUPIN, all right reserved
- * @license MPL v2.0 (see license file)
- */
-package org.atriasoft.gale;
-
-import org.atriasoft.etk.math.Vector2f;
-import org.atriasoft.etk.math.Vector2i;
-import org.atriasoft.gale.internal.Log;
-
-/**
- * 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
- */
-@SuppressWarnings("preview")
-public record Dimension(
- Vector2f size,
- 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 static final float INCH_TO_MILLIMETER = 1.0f / 25.4f;
- public static final float FOOT_TO_MILLIMETER = 1.0f / 304.8f;
- public static final float METER_TO_MILLIMETER = 1.0f / 1000.0f;
- public static final float CENTIMETER_TO_MILLIMETER = 1.0f / 10.0f;
- public static final float KILOMETER_TO_MILLIMETER = 1.0f / 1000000.0f;
- public static final float MILLIMETER_TO_INCH = 25.4f;
- public static final float MILLIMETER_TO_FOOT = 304.8f;
- public static final float MILLIMETER_TO_METER = 1000.0f;
- public static final float MILLIMETER_TO_CENTIMETER = 10.0f;
- public static final float MILLIMETER_TO_KILOMETER = 1000000.0f;
- /**
- * basic init
- */
- static {
- final Dimension conversion = new Dimension(new Vector2f(72, 72), Distance.INCH);
- ratio = conversion.getMillimeter();
- invRatio = new Vector2f(1.0f / ratio.x(), 1.0f / ratio.y());
- windowsSize = new Dimension(new Vector2f(200, 200), Distance.PIXEL);
- }
-
- /**
- * get the Windows diagonal size in the request unit
- * @param type Unit type requested.
- * @return the requested size
- */
- public static float getWindowsDiag(final Distance type) {
- final Vector2f size = getWindowsSize(type);
- return size.length();
- }
-
- /**
- * get the Windows size in the request unit
- * @param type Unit type requested.
- * @return the requested size
- */
- public static Vector2f getWindowsSize(final Distance type) {
- return windowsSize.get(type);
- }
-
- /**
- * set the Milimeter ratio for calculation
- * @param ratio Milimeter ration for the screen calculation interpolation
- * @param type Unit type requested.
- * @note: same as @ref setPixelPerInch (internal manage convertion)
- */
- public static void setPixelRatio(final Vector2f ratio, final Distance type) {
- Log.info("Set a new screen ratio for the screen : ratio=" + ratio + " type=" + type);
- final Dimension conversion = new Dimension(ratio, type);
- Log.info(" == > " + conversion);
- Dimension.ratio = conversion.getMillimeter();
- invRatio = new Vector2f(1.0f / Dimension.ratio.x(), 1.0f / Dimension.ratio.y());
- Log.info("Set a new screen ratio for the screen : ratioMm=" + Dimension.ratio);
- }
-
- /**
- * set the current Windows size
- * @param size size of the current windows in pixel.
- */
- public static void setPixelWindowsSize(final Vector2f size) {
- windowsSize = new Dimension(size);
- Log.verbose("Set a new Windows property size " + windowsSize + "px");
- }
-
- /**
- * Constructor (default :0,0 mode pixel)
- */
- public Dimension() {
- this(Vector2f.ZERO, Distance.PIXEL);
- }
-
- /**
- * Constructor
- * @param size Requested dimension
- */
- public Dimension(final Vector2f size) {
- this(size, Distance.PIXEL);
- }
-
- public Dimension(final Vector2f size, final Distance type) {
- this.size = size;
- this.type = type;
- }
-
- /**
- * get the current dimension in requested type
- * @param type Type of unit requested.
- * @return dimension requested.
- */
- public Vector2f get(final Distance type) {
- return switch (type) {
- case POURCENT -> getPourcent();
- case PIXEL -> getPixel();
- case METER -> getMeter();
- case CENTIMETER -> getCentimeter();
- case MILLIMETER -> getMillimeter();
- case KILOMETER -> getKilometer();
- case INCH -> getInch();
- case FOOT -> getFoot();
- };
- }
-
- /**
- * get the current dimension in Centimeter
- * @return dimension in Centimeter
- */
- public Vector2f getCentimeter() {
- return getMillimeter().multiply(MILLIMETER_TO_CENTIMETER);
- }
-
- /**
- * get the current dimension in Foot
- * @return dimension in Foot
- */
- public Vector2f getFoot() {
- return getMillimeter().multiply(MILLIMETER_TO_FOOT);
- }
-
- /**
- * get the current dimension in Inch
- * @return dimension in Inch
- */
- public Vector2f getInch() {
- return getMillimeter().multiply(MILLIMETER_TO_INCH);
- }
-
- /**
- * get the current dimension in Kilometer
- * @return dimension in Kilometer
- */
- public Vector2f getKilometer() {
- return getMillimeter().multiply(MILLIMETER_TO_KILOMETER);
- }
-
- /**
- * get the current dimension in Meter
- * @return dimension in Meter
- */
- public Vector2f getMeter() {
- return getMillimeter().multiply(MILLIMETER_TO_METER);
- }
-
- /**
- * get the current dimension in Millimeter
- * @return dimension in Millimeter
- */
- public Vector2f getMillimeter() {
- return new Vector2f(getPixel().x() * invRatio.x(), getPixel().y() * invRatio.y());
- }
-
- /**
- * get the current dimension in pixel
- * @return dimension in Pixel
- */
- public Vector2f getPixel() {
- if (this.type != Distance.POURCENT) {
- return this.size;
- }
- final Vector2f windDim = windowsSize.getPixel();
- final Vector2f res = new Vector2f(windDim.x() * this.size.x(), windDim.y() * this.size.y());
- //GALE_DEBUG("Get % : " + m_data + " / " + windDim + " == > " + res);
- return res;
- }
-
- 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;
- }
-
- /**
- * get the current dimension in Pourcent
- * @return dimension in Pourcent
- */
- public Vector2f getPourcent() {
- if (this.type != Distance.POURCENT) {
- final Vector2f windDim = windowsSize.getPixel();
- //GALE_DEBUG(" windows dimension : " /*+ windowsSize*/ + " == > " + windDim + "px"); // ==> infinite loop ...
- //printf(" windows dimension : %f,%f", windDim.x(),windDim.y());
- //printf(" data : %f,%f", m_data.x(),m_data.y());
- return new Vector2f((this.size.x() / windDim.x()) * 100.0f, (this.size.y() / windDim.y()) * 100.0f);
- }
- return new Vector2f(this.size.x() * 100.0f, this.size.y() * 100.0f);
- };
-
- /**
- * get the dimension type
- * @return the type
- */
- public Distance getType() {
- return this.type;
- }
-
- /**
- * set the current dimension in requested type
- * @param config dimension configuration.
- */
- public static Dimension valueOf(String config) {
- final Vector2f size = Vector2f.ZERO;
- Distance type = Distance.PIXEL;
- if (config.endsWith("%")) {
- type = Distance.POURCENT;
- config = config.substring(0, config.length() - 1);
- } else if (config.endsWith("px")) {
- type = Distance.PIXEL;
- config = config.substring(0, config.length() - 2);
- } else if (config.endsWith("ft")) {
- type = Distance.FOOT;
- config = config.substring(0, config.length() - 2);
- } else if (config.endsWith("in")) {
- type = Distance.INCH;
- config = config.substring(0, config.length() - 2);
- } else if (config.endsWith("km")) {
- type = Distance.KILOMETER;
- config = config.substring(0, config.length() - 2);
- } else if (config.endsWith("mm")) {
- type = Distance.MILLIMETER;
- config = config.substring(0, config.length() - 2);
- } else if (config.endsWith("cm")) {
- type = Distance.CENTIMETER;
- config = config.substring(0, config.length() - 2);
- } else if (config.endsWith("m")) {
- type = Distance.METER;
- config = config.substring(0, config.length() - 1);
- } else {
- Log.critical("Can not parse dimension : '" + config + "'");
- return null;
- }
- final Vector2f tmp = Vector2f.valueOf(config);
- final Dimension ret = new Dimension(tmp, type);
- Log.verbose(" config dimension : '" + config + "' == > " + ret.toString());
- return ret;
- }
-
- /**
- * string cast :
- */
- @Override
- public String toString() {
- String str = get(getType()).toString();
- switch (getType()) {
- case POURCENT -> str += "%";
- case PIXEL -> str += "px";
- case METER -> str += "m";
- case CENTIMETER -> str += "cm";
- case MILLIMETER -> str += "mm";
- case KILOMETER -> str += "km";
- case INCH -> str += "in";
- case FOOT -> str += "ft";
- default -> str += "";
- }
- return str;
- }
-
-}
diff --git a/src/org/atriasoft/gale/Distance.java b/src/org/atriasoft/gale/Distance.java
deleted file mode 100644
index 265de8d..0000000
--- a/src/org/atriasoft/gale/Distance.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package org.atriasoft.gale;
-
-public enum Distance {
- POURCENT,
- PIXEL,
- METER,
- CENTIMETER,
- MILLIMETER,
- KILOMETER,
- INCH,
- FOOT;
-}
diff --git a/src/org/atriasoft/gale/backend3d/OpenGL.java b/src/org/atriasoft/gale/backend3d/OpenGL.java
index 9b2f79f..b455e82 100644
--- a/src/org/atriasoft/gale/backend3d/OpenGL.java
+++ b/src/org/atriasoft/gale/backend3d/OpenGL.java
@@ -41,9 +41,7 @@ public class OpenGL {
// We map all the flag, but not all is supported by all platform...
public static enum Flag {
- flag_blend, // !< If enabled, blend the computed fragment color values with the values in
- // the color buffers.
- // See glBlendFunc.
+ flag_blend, // !< If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc.
flag_clipDistanceI, // !< If enabled, clip geometry against user-defined half space i.
flag_colorLogigOP, // !< If enabled, apply the currently selected logical operation to the computed
// fragment color and color buffer values. See glLogicOp.
@@ -62,10 +60,8 @@ public class OpenGL {
// glDepthRange.
flag_depthTest, // !< If enabled, do depth comparisons and update the depth buffer. Note that
// even if the depth buffer exists and the depth mask is non-zero, the depth
- // buffer is not updated if the depth test is disabled. See glDepthFunc and
- // glDepthRange.
- flag_dither, // !< If enabled, dither color components or indices before they are written to
- // the color buffer.
+ // buffer is not updated if the depth test is disabled. See glDepthFunc and glDepthRange.
+ flag_dither, // !< If enabled, dither color components or indices before they are written to the color buffer.
flag_framebufferSRGB, // !< If enabled and the value of GLFRAMEBUFFERATTACHMENTCOLORENCODING for the
// framebuffer attachment corresponding to the destination buffer is GLSRGB, the
// R, G, and B destination color values (after conversion from fixed-point to
@@ -438,6 +434,10 @@ public class OpenGL {
GL11.glDrawElements(CONVERT_RENDER_MODE.get(mode), vertexCount, GL11.GL_UNSIGNED_INT, 0);
}
+ public static void drawTriangleRed(final Vector3f aaa, final Vector3f bbb, final Vector3f ccc) {
+ GL11.glFinish();
+ }
+
/**
* enable a flag on the system
* @param flagID The flag requested
@@ -526,7 +526,11 @@ public class OpenGL {
}
public static void glTexImage2D(final int level, final int internalFormat, final int width, final int height, final int border, final int format, final int sizeObject, final byte[] data) {
- final ByteBuffer dataBuffer = ByteBuffer.wrap(data);
+ final ByteBuffer dataBuffer = ByteBuffer.allocateDirect(data.length);
+ for (int iii = 0; iii < data.length; iii++) {
+ dataBuffer.put(data[iii]);
+ }
+ dataBuffer.flip();
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, level, internalFormat, width, height, border, format, sizeObject, dataBuffer);
}
@@ -535,7 +539,11 @@ public class OpenGL {
}
public static void glTexSubImage2D(final int level, final int xOffset, final int yOffset, final int width, final int height, final int format, final int sizeObject, final byte[] data) {
- final ByteBuffer dataBuffer = ByteBuffer.wrap(data);
+ final ByteBuffer dataBuffer = ByteBuffer.allocateDirect(data.length);
+ for (int iii = 0; iii < data.length; iii++) {
+ dataBuffer.put(data[iii]);
+ }
+ dataBuffer.flip();
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, level, xOffset, yOffset, width, height, format, sizeObject, dataBuffer);
}
diff --git a/src/org/atriasoft/gale/context/Context.java b/src/org/atriasoft/gale/context/Context.java
index 843fa42..12c4a92 100644
--- a/src/org/atriasoft/gale/context/Context.java
+++ b/src/org/atriasoft/gale/context/Context.java
@@ -57,7 +57,7 @@ public abstract class Context {
private final Fps fpsSystemContext = new Fps("SystemContext", this.displayFps);
private final Fps fpsSystem = new Fps("System", this.displayFps);
private final Fps fpsFlush = new Fps("Flush", this.displayFps);
- protected Vector2f windowsSize = new Vector2f(0, 0); //!< current size of the system
+ protected Vector2f windowsSize = Vector2f.ZERO; //!< current size of the system
protected boolean fullscreen = false;
protected Vector2f windowsPos; //!< current size of the system
@@ -155,6 +155,9 @@ public abstract class Context {
if (this.application == null) {
return;
}
+ if (this.windowsSize == Vector2f.ZERO) {
+ return;
+ }
this.application.onResize(this.windowsSize);
}
@@ -615,16 +618,20 @@ public abstract class Context {
* Processing all the event arrived ... (commoly called in draw function)
*/
public void processEvents() {
- int nbEvent = 0;
- //Log.debug(" ******** Event " << this.msgSystem.count());
- while (this.msgSystem.size() > 0) {
- nbEvent++;
- //Log.verbose(" [" << nbEvent << "] event ...");
- final ActionToDoInAsyncLoop func = getAction();
- if (func == null) {
- continue;
+ try {
+ int nbEvent = 0;
+ //Log.debug(" ******** Event " << this.msgSystem.count());
+ while (this.msgSystem.size() > 0) {
+ nbEvent++;
+ //Log.verbose(" [" << nbEvent << "] event ...");
+ final ActionToDoInAsyncLoop func = getAction();
+ if (func == null) {
+ continue;
+ }
+ func.run(this);
}
- func.run(this);
+ } catch (Exception e) {
+ Log.critical("Catch exception in main event Loop ...", e);
}
}
diff --git a/src/org/atriasoft/gale/context/LWJG_AWT/ContextLWJGLAWT.java b/src/org/atriasoft/gale/context/LWJG_AWT/ContextLWJGLAWT.java
index fc8b963..429f1c8 100644
--- a/src/org/atriasoft/gale/context/LWJG_AWT/ContextLWJGLAWT.java
+++ b/src/org/atriasoft/gale/context/LWJG_AWT/ContextLWJGLAWT.java
@@ -26,6 +26,8 @@ import java.util.List;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
+import io.scenarium.logger.Logger;
+
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.gale.Application;
@@ -173,6 +175,9 @@ public class ContextLWJGLAWT extends Context implements MouseListener, MouseMoti
}
operatingSystemDraw(true);
swapBuffers();
+ if (Logger.isCriticalOccured()) {
+ ContextLWJGLAWT.this.frame.dispose();
+ }
}
}, BorderLayout.CENTER);
this.frame.pack();
diff --git a/src/org/atriasoft/gale/internal/Log.java b/src/org/atriasoft/gale/internal/Log.java
index bc4ae50..32d8b4e 100644
--- a/src/org/atriasoft/gale/internal/Log.java
+++ b/src/org/atriasoft/gale/internal/Log.java
@@ -14,47 +14,62 @@ public class Log {
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
-
- private Log() {}
-
- public static void print(String data) {
- if (PRINT_PRINT)
- Logger.print(LIB_NAME_DRAW, data);
- }
-
- public static void todo(String data) {
- if (PRINT_TODO)
- Logger.todo(LIB_NAME_DRAW, data);
- }
-
- public static void critical(String data) {
- if (PRINT_CRITICAL)
+
+ public static void critical(final String data) {
+ if (PRINT_CRITICAL) {
Logger.critical(LIB_NAME_DRAW, data);
+ }
}
-
- public static void error(String data) {
- if (PRINT_ERROR)
- Logger.error(LIB_NAME_DRAW, data);
+
+ public static void critical(final String data, final Exception e) {
+ e.printStackTrace();
+ if (PRINT_CRITICAL) {
+ Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
+ }
}
-
- public static void warning(String data) {
- if (PRINT_WARNING)
- Logger.warning(LIB_NAME_DRAW, data);
- }
-
- public static void info(String data) {
- if (PRINT_INFO)
- Logger.info(LIB_NAME_DRAW, data);
- }
-
- public static void debug(String data) {
- if (PRINT_DEBUG)
+
+ public static void debug(final String data) {
+ if (PRINT_DEBUG) {
Logger.debug(LIB_NAME_DRAW, data);
+ }
}
-
- public static void verbose(String data) {
- if (PRINT_VERBOSE)
+
+ public static void error(final String data) {
+ if (PRINT_ERROR) {
+ Logger.error(LIB_NAME_DRAW, data);
+ }
+ }
+
+ public static void info(final String data) {
+ if (PRINT_INFO) {
+ Logger.info(LIB_NAME_DRAW, data);
+ }
+ }
+
+ public static void print(final String data) {
+ if (PRINT_PRINT) {
+ Logger.print(LIB_NAME_DRAW, data);
+ }
+ }
+
+ public static void todo(final String data) {
+ if (PRINT_TODO) {
+ Logger.todo(LIB_NAME_DRAW, data);
+ }
+ }
+
+ public static void verbose(final String data) {
+ if (PRINT_VERBOSE) {
Logger.verbose(LIB_NAME_DRAW, data);
+ }
}
-
+
+ public static void warning(final String data) {
+ if (PRINT_WARNING) {
+ Logger.warning(LIB_NAME_DRAW, data);
+ }
+ }
+
+ private Log() {}
+
}
diff --git a/src/org/atriasoft/gale/resource/ResourceManager.java b/src/org/atriasoft/gale/resource/ResourceManager.java
index f612b2d..a3ff133 100644
--- a/src/org/atriasoft/gale/resource/ResourceManager.java
+++ b/src/org/atriasoft/gale/resource/ResourceManager.java
@@ -141,22 +141,24 @@ public class ResourceManager {
* Call by the system to send all the needed data on the graphic card chen they change ...
* @param object The resources that might be updated
*/
- public synchronized void update(final Resource object) {
- // check if not added before
- for (final Resource it : this.resourceListToUpdate) {
- if (it == object) {
- // just prevent some double add ...
- return;
+ public void update(final Resource object) {
+ synchronized (this.resourceListToUpdate) {
+ // check if not added before
+ for (final Resource it : this.resourceListToUpdate) {
+ if (it == object) {
+ // just prevent some double add ...
+ return;
+ }
}
+ // add it ...
+ this.resourceListToUpdate.add(object);
}
- // add it ...
- this.resourceListToUpdate.add(object);
}
/**
* Call by the system chen the openGL Context has been unexpectially removed == > This reload all the texture, VBO and other ....
*/
- public synchronized void updateContext() {
+ public void updateContext() {
if (this.exiting) {
Log.error("Request update after application EXIT ...");
return;
@@ -165,7 +167,9 @@ public class ResourceManager {
if (this.contextHasBeenRemoved) {
// need to update all ...
this.contextHasBeenRemoved = false;
- this.resourceListToUpdate.clear();
+ synchronized (this.resourceListToUpdate) {
+ this.resourceListToUpdate.clear();
+ }
synchronized (this.resourceList) {
if (this.resourceList.size() != 0) {
for (long jjj = 0; jjj < MAX_RESOURCE_LEVEL; jjj++) {
@@ -175,7 +179,9 @@ public class ResourceManager {
//Log.debug("Update context named : " + lresourceList[iii].getName());
if (!it.updateContext()) {
// Lock error ==> postponned
- this.resourceListToUpdate.add(it);
+ synchronized (this.resourceListToUpdate) {
+ this.resourceListToUpdate.add(it);
+ }
}
}
}
diff --git a/src/org/atriasoft/gale/resource/ResourceProgram.java b/src/org/atriasoft/gale/resource/ResourceProgram.java
index f470c4a..68fa2bb 100644
--- a/src/org/atriasoft/gale/resource/ResourceProgram.java
+++ b/src/org/atriasoft/gale/resource/ResourceProgram.java
@@ -27,7 +27,7 @@ class ProgAttributeElement {
public class ResourceProgram extends Resource {
static final boolean DEBUG = false; // TODO externalize this ...
-
+
public static ResourceProgram create(final Uri uriVertexShader, final Uri uriFragmentShader) {
ResourceProgram resource;
final String name = uriVertexShader.getValue() + "<-->" + uriFragmentShader.getValue();
@@ -44,14 +44,14 @@ public class ResourceProgram extends Resource {
getManager().localAdd(resource);
return resource;
}
-
+
public static FloatBuffer storeDataInFloatBuffer(final float[] data) {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
buffer.put(data);
buffer.flip();
return buffer;
}
-
+
public static FloatBuffer storeDataInFloatBufferColor(final List data) {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size() * 4);
for (int iii = 0; iii < data.size(); iii++) {
@@ -63,7 +63,7 @@ public class ResourceProgram extends Resource {
buffer.flip();
return buffer;
}
-
+
public static FloatBuffer storeDataInFloatBufferVector3f(final List data) {
final FloatBuffer buffer = BufferUtils.createFloatBuffer(data.size() * 3);
for (int iii = 0; iii < data.size(); iii++) {
@@ -74,12 +74,12 @@ public class ResourceProgram extends Resource {
buffer.flip();
return buffer;
}
-
+
private boolean exist = false; // !< the file existed
private int program = 0; // !< openGL id of the current program
private ResourceShader shaderVertex = null;
private ResourceShader shaderFragment = null;
-
+
private final List elementList = new ArrayList<>(); // !< List of all the attribute requested
// by the user
private final List listOfVBOUsed = new ArrayList<>(); // !< retain the list of VBO used to disable it when
@@ -88,7 +88,7 @@ public class ResourceProgram extends Resource {
// current shader
private boolean hasTexture1 = false; // !< A texture has been set to the
// current shader
-
+
/**
* Contructor of an opengl Program.
* @param uriVertexShader Uri of the file
@@ -118,14 +118,14 @@ public class ResourceProgram extends Resource {
getManager().update(this);
}
}
-
+
public void bindAttribute(final int attribute, final String variableName) {
if (!this.exist) {
return;
}
OpenGL.programBindAttribute(this.program, attribute, variableName);
}
-
+
/**
* 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)
@@ -138,7 +138,7 @@ public class ResourceProgram extends Resource {
}
return this.elementList.get(idElem).isLinked;
}
-
+
/**
* Destructor, remove the current Program.
*/
@@ -157,7 +157,7 @@ public class ResourceProgram extends Resource {
this.hasTexture = false;
this.hasTexture1 = false;
}
-
+
private float[] convertInFloat(final List data) {
final float[] out = new float[data.size() * 3];
for (int iii = 0; iii < data.size(); iii++) {
@@ -167,7 +167,7 @@ public class ResourceProgram extends Resource {
}
return out;
}
-
+
// private void storeDataInAttributeList(int attributeNumber, int
// coordinateSize, float[] data) {
// int vboID = GL15.glGenBuffers();
@@ -179,7 +179,7 @@ public class ResourceProgram extends Resource {
// false, 0, 0);
// GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
// }
-
+
/**
* User request an attribute on this program.
* @note The attribute is send to the fragment shaders
@@ -205,12 +205,10 @@ public class ResourceProgram extends Resource {
tmp.elementId = OpenGL.programGetAttributeLocation(this.program, tmp.name);
tmp.isLinked = true;
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;
} 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 {
// program is not loaded ==> just local reister ...
@@ -220,7 +218,7 @@ public class ResourceProgram extends Resource {
this.elementList.add(tmp);
return this.elementList.size() - 1;
}
-
+
// public void sendAttribute(int idElem, etk::Vector> data) {
// sendAttribute(idElem, 4/*r,g,b,a*/, data[0]);
// }
@@ -253,12 +251,10 @@ public class ResourceProgram extends Resource {
tmp.elementId = OpenGL.programGetUniformLocation(this.program, tmp.name);
tmp.isLinked = true;
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;
} 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 {
// program is not loaded ==> just local reister ...
@@ -268,7 +264,7 @@ public class ResourceProgram extends Resource {
this.elementList.add(tmp);
return this.elementList.size() - 1;
}
-
+
/**
* Relode the shader from the file. used when a request of resouces
* reload is done.
@@ -295,7 +291,7 @@ public class ResourceProgram extends Resource {
removeContext();
updateContext();
}
-
+
/**
* remove the data from the opengl context.
*/
@@ -311,18 +307,18 @@ public class ResourceProgram extends Resource {
}
}
}
-
+
/**
* Special android spec! It inform us that all context is removed and
* after notify us...
*/
@Override
public void removeContextToLate() {
-
+
this.exist = false;
this.program = 0;
}
-
+
/**
* Send attribute table to the specified ID attribute (not send if does
* not really exist in the openGL program).
@@ -367,8 +363,7 @@ public class ResourceProgram extends Resource {
// public void sendAttribute(int idElem, List 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, final int jumpBetweenSample) {
if (!this.exist) {
return;
}
@@ -382,14 +377,13 @@ public class ResourceProgram extends Resource {
// GL40.glBindVertexArray(this.elementList.get(idElem).elementId);
// Log.error("[" + this.elementList.get(idElem).name + "] send " + 3 + "
// 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... */
+ 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);
// checkGlError("glVertexAttribPointer", LINE, idElem);
GL40.glEnableVertexAttribArray(this.elementList.get(idElem).elementId);
// checkGlError("glEnableVertexAttribArray", LINE, idElem);
}
-
+
/**
* Send attribute table to the spefified ID attribure (not send if does
* not really exist in the openGL program).
@@ -448,9 +442,8 @@ public class ResourceProgram extends Resource {
if (!this.elementList.get(idElem).isLinked) {
return;
}
-
- Log.verbose("[" + this.elementList.get(idElem).name + "] send on oglID=" + vbo.getOpenGlId(index) + " VBOindex="
- + index);
+
+ Log.verbose("[" + this.elementList.get(idElem).name + "] send on oglID=" + vbo.getOpenGlId(index) + " VBOindex=" + index);
GL20.glBindBuffer(GL20.GL_ARRAY_BUFFER, vbo.getOpenGlId(index));
// checkGlError("glBindBuffer", __LINE__, _idElem);
Log.verbose(" id=" + this.elementList.get(idElem).elementId);
@@ -467,7 +460,7 @@ public class ResourceProgram extends Resource {
this.listOfVBOUsed.add(this.elementList.get(idElem).elementId);
// checkGlError("glEnableVertexAttribArray", __LINE__, _idElem);
}
-
+
/**
* set the testure Id on the specify uniform element.
* @param idElem Id of the uniform that might be sended.
@@ -490,7 +483,7 @@ public class ResourceProgram extends Resource {
uniformInt(this.elementList.get(idElem).elementId, /* GLTEXTURE */0);
this.hasTexture = true;
}
-
+
public void setTexture1(final int idElem, final int textureOpenGlID) {
if (!this.exist) {
return;
@@ -508,7 +501,7 @@ public class ResourceProgram extends Resource {
uniformInt(this.elementList.get(idElem).elementId, /* GLTEXTURE */0);
this.hasTexture1 = true;
}
-
+
public void uniformColor(final int idElem, final Color value) {
if (!this.exist) {
return;
@@ -522,7 +515,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformColor(this.elementList.get(idElem).elementId, value);
}
-
+
/**
* Send 1 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
@@ -542,7 +535,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1);
}
-
+
/**
* Send 2 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
@@ -551,7 +544,7 @@ public class ResourceProgram extends Resource {
* @param value2 Value to send at the Uniform
*/
public void uniformFloat(final int idElem, final float value1, final float value2) {
-
+
if (!this.exist) {
return;
}
@@ -564,7 +557,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2);
}
-
+
/**
* Send 3 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
@@ -574,7 +567,7 @@ public class ResourceProgram extends Resource {
* @param value3 Value to send at the Uniform
*/
public void uniformFloat(final int idElem, final float value1, final float value2, final float value3) {
-
+
if (!this.exist) {
return;
}
@@ -587,7 +580,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2, value3);
}
-
+
/**
* Send 4 float uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
@@ -597,9 +590,8 @@ public class ResourceProgram extends Resource {
* @param value3 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) {
return;
}
@@ -612,7 +604,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformFloat(this.elementList.get(idElem).elementId, value1, value2, value3, value4);
}
-
+
/**
* Send 1 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
@@ -620,7 +612,7 @@ public class ResourceProgram extends Resource {
* @param value1 Value to send at the Uniform
*/
public void uniformInt(final int idElem, final int value1) {
-
+
if (!this.exist) {
return;
}
@@ -633,7 +625,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1);
}
-
+
/**
* Send 2 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
@@ -642,7 +634,7 @@ public class ResourceProgram extends Resource {
* @param value2 Value to send at the Uniform
*/
public void uniformInt(final int idElem, final int value1, final int value2) {
-
+
if (!this.exist) {
return;
}
@@ -655,7 +647,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2);
}
-
+
/**
* Send 3 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
@@ -665,7 +657,7 @@ public class ResourceProgram extends Resource {
* @param value3 Value to send at the Uniform
*/
public void uniformInt(final int idElem, final int value1, final int value2, final int value3) {
-
+
if (!this.exist) {
return;
}
@@ -678,7 +670,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3);
}
-
+
/**
* Send 4 signed integer uniform element to the spefified ID (not send if
* does not really exist in the openGL program)
@@ -689,7 +681,7 @@ public class ResourceProgram extends Resource {
* @param value4 Value to send at the Uniform
*/
public void uniformInt(final int idElem, final int value1, final int value2, final int value3, final int value4) {
-
+
if (!this.exist) {
return;
}
@@ -702,7 +694,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformInt(this.elementList.get(idElem).elementId, value1, value2, value3, value4);
}
-
+
/**
* Send a uniform element to the spefified ID (not send if does not
* really exist in the openGL program)
@@ -715,7 +707,7 @@ public class ResourceProgram extends Resource {
public void uniformMatrix(final int idElem, final Matrix4f matrix) {
uniformMatrix(idElem, matrix, true);
}
-
+
public void uniformMatrix(final int idElem, final Matrix4f matrix, final boolean transpose/* =true */) {
if (!this.exist) {
return;
@@ -738,7 +730,7 @@ public class ResourceProgram extends Resource {
*/
OpenGL.programLoadUniformMatrix(this.elementList.get(idElem).elementId, matrix, transpose);
}
-
+
public void uniformVector(final int idElem, final Vector2f value) {
if (!this.exist) {
return;
@@ -752,7 +744,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
}
-
+
public void uniformVector(final int idElem, final Vector2i value) {
if (!this.exist) {
return;
@@ -766,7 +758,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
}
-
+
public void uniformVector(final int idElem, final Vector3f value) {
if (!this.exist) {
return;
@@ -780,7 +772,7 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
}
-
+
public void uniformVector(final int idElem, final Vector3i value) {
if (!this.exist) {
return;
@@ -794,13 +786,13 @@ public class ResourceProgram extends Resource {
}
OpenGL.programLoadUniformVector(this.elementList.get(idElem).elementId, value);
}
-
+
/**
* Stop the processing of this program
*/
public void unUse() {
// Log.verbose("Will UN-use program : " + this.program);
-
+
if (!this.exist) {
return;
}
@@ -811,7 +803,7 @@ public class ResourceProgram extends Resource {
// no need to disable program == > this only generate perturbation on speed ...
OpenGL.programUse(-1);
}
-
+
/**
* This load/reload the data in the opengl context, needed when removed
* previously.
@@ -834,13 +826,12 @@ public class ResourceProgram extends Resource {
if (this.shaderFragment != null) {
OpenGL.programAttach(this.program, this.shaderFragment.getGLID());
}
-
+
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_COLORS, "in_colors");
-
+
if (!OpenGL.programCompile(this.program)) {
Log.error("Could not compile'PROGRAM':'" + this.name + "'");
OpenGL.programRemove(this.program);
@@ -853,23 +844,19 @@ public class ResourceProgram extends Resource {
it.elementId = OpenGL.programGetAttributeLocation(this.program, it.name);
it.isLinked = true;
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;
} else {
- Log.debug(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name
- + "\") = " + it.elementId);
+ Log.debug(" {" + this.program + "}[" + iii + "] openGL::getAttributeLocation(\"" + it.name + "\") = " + it.elementId);
}
} else {
it.elementId = OpenGL.programGetUniformLocation(this.program, it.name);
it.isLinked = true;
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;
} else {
- Log.debug(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name
- + "\") = " + it.elementId);
+ Log.debug(" {" + this.program + "}[" + iii + "] openGL::getUniformLocation(\"" + it.name + "\") = " + it.elementId);
}
}
iii++;
@@ -879,7 +866,7 @@ public class ResourceProgram extends Resource {
}
return true;
}
-
+
/**
* Request the processing of this program
*/
@@ -889,5 +876,5 @@ public class ResourceProgram extends Resource {
// display ...
OpenGL.programUse(this.program);
}
-
+
}
diff --git a/src/org/atriasoft/gale/resource/ResourceTexture.java b/src/org/atriasoft/gale/resource/ResourceTexture.java
index 8166dd7..da9bfc6 100644
--- a/src/org/atriasoft/gale/resource/ResourceTexture.java
+++ b/src/org/atriasoft/gale/resource/ResourceTexture.java
@@ -2,8 +2,8 @@ package org.atriasoft.gale.resource;
import java.nio.ByteBuffer;
+import org.atriasoft.egami.Image;
import org.atriasoft.etk.Uri;
-import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.internal.Log;
@@ -48,8 +48,30 @@ public class ResourceTexture extends Resource {
}
resource = new ResourceTexture(uriTexture, textureUnit);
final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
- resource.setTexture(decodedData.getBuffer(), new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() ? TextureColorMode.rgba : TextureColorMode.rgb),
- textureUnit);
+ Image img = new Image(decodedData.getWidth(), decodedData.getHeight());
+ ByteBuffer mlklmklm = decodedData.getBuffer();
+ byte[] elemData = new byte[mlklmklm.remaining()];
+ mlklmklm.get(elemData);
+ if (decodedData.isHasAlpha()) {
+ for (int yyy = 0; yyy < decodedData.getHeight(); yyy++) {
+ for (int xxx = 0; xxx < decodedData.getWidth(); xxx++) {
+ img.setR(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 0]);
+ img.setG(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 1]);
+ img.setB(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 2]);
+ img.setA(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 4 + 3]);
+ }
+ }
+ } else {
+ for (int yyy = 0; yyy < decodedData.getHeight(); yyy++) {
+ for (int xxx = 0; xxx < decodedData.getWidth(); xxx++) {
+ img.setA(xxx, yyy, 0xFF);
+ img.setR(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 3 + 0]);
+ img.setG(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 3 + 1]);
+ img.setB(xxx, yyy, elemData[(yyy * decodedData.getWidth() + xxx) * 3 + 2]);
+ }
+ }
+ }
+ resource.setTexture(img, new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() ? TextureColorMode.rgba : TextureColorMode.rgb), textureUnit);
resource.flush();
return resource;
}
@@ -73,34 +95,26 @@ public class ResourceTexture extends Resource {
protected int texId = -1; //!< openGl textureID.
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 . 1.0.
- protected Vector2f endPointSize = new Vector2f(-1, -1);
+ protected Vector2i endPointSize = new Vector2i(-1, -1);
// internal state of the openGl system.
protected boolean loaded = false;
// Image properties:
// pointer on the image data.
- private ByteBuffer data = null;
+ //private ByteBuffer data = null;
+ protected Image data = new Image(32, 32);
// size of the image data.
private Vector2i size = new Vector2i(-1, -1);
//!< Color space of the image.
private TextureColorMode dataColorSpace = TextureColorMode.rgb;
// number of lines and colomns in the texture (multiple texturing in a single texture)
private int textureUnit = 0;
- private String filename = "";
protected ResourceTexture() {
super();
}
- // Public API:
- protected ResourceTexture(final String filename, final int textureUnit) {
- super(filename + "__" + textureUnit);
- this.filename = filename;
- this.textureUnit = textureUnit;
- }
-
protected ResourceTexture(final Uri filename, final int textureUnit) {
- super(filename + "__" + textureUnit);
- this.filename = filename.get();
+ super(filename.toString() + "__" + textureUnit);
this.textureUnit = textureUnit;
}
@@ -136,7 +150,7 @@ public class ResourceTexture extends Resource {
return this.texId;
}
- public Vector2f getUsableSize() {
+ public Vector2i getUsableSize() {
return this.endPointSize;
}
@@ -157,11 +171,11 @@ public class ResourceTexture extends Resource {
this.texId = -1;
}
- public void setTexture(final ByteBuffer data, final Vector2i size, final TextureColorMode dataColorSpace, final int textureUnit) {
+ public void setTexture(final Image data, final Vector2i size, final TextureColorMode dataColorSpace, final int textureUnit) {
this.data = data;
this.size = size;
this.textureUnit = textureUnit;
- this.endPointSize = new Vector2f(size.x(), size.y());
+ this.endPointSize = new Vector2i(size.x(), size.y());
this.dataColorSpace = dataColorSpace;
flush();
}
@@ -191,9 +205,11 @@ public class ResourceTexture extends Resource {
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
Log.info("TEXTURE: add [" + getId() + "]=" + this.size + " OGlId=" + this.texId);
if (this.dataColorSpace == TextureColorMode.rgb) {
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, this.data);
+ OpenGL.glTexImage2D(0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.data.getRaw());
+ //The local image has not RGB but only RGBA data ...
+ //OpenGL.glTexImage2D(0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, this.data.getRaw());
} 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);
+ OpenGL.glTexImage2D(0, GL11.GL_RGBA, this.size.x(), this.size.y(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.data.getRaw());
}
// generate multi-texture mapping
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
diff --git a/src/org/atriasoft/gale/resource/ResourceVirtualBufferObject.java b/src/org/atriasoft/gale/resource/ResourceVirtualBufferObject.java
index bbd5373..5cf6d21 100644
--- a/src/org/atriasoft/gale/resource/ResourceVirtualBufferObject.java
+++ b/src/org/atriasoft/gale/resource/ResourceVirtualBufferObject.java
@@ -172,7 +172,7 @@ public class ResourceVirtualBufferObject extends Resource {
*/
@Override
public synchronized boolean updateContext() {
- Log.verbose(" Start: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
+ Log.warning("updateContext (VBO Start: [" + getId() + "] '" + getName() + "' (size=" + this.buffer.length + ")");
/*
if (lock.tryLock() == false) {
//Lock error ==> try later ...
@@ -187,8 +187,8 @@ public class ResourceVirtualBufferObject extends Resource {
}
this.exist = true;
for (int iii = 0; iii < this.vbo.length; iii++) {
- Log.verbose("VBO : add [" + getId() + "]=" + this.buffer[iii].getClass().getCanonicalName() + "*sizeof(float) OGl_Id=" + this.vbo[iii]);
if (this.buffer[iii] != null) {
+ Log.verbose("VBO : add [" + getId() + "]=" + this.buffer[iii].getClass().getCanonicalName() + "*sizeof(float) OGl_Id=" + this.vbo[iii]);
OpenGL.bindBuffer(this.vbo[iii]);
// select the buffer to set data inside it ...
if (this.buffer[iii] instanceof float[]) {
diff --git a/src/org/atriasoft/gale/test/sample1/Sample1.java b/src/org/atriasoft/gale/test/sample1/Sample1.java
index 5d4002d..53674d2 100644
--- a/src/org/atriasoft/gale/test/sample1/Sample1.java
+++ b/src/org/atriasoft/gale/test/sample1/Sample1.java
@@ -4,9 +4,12 @@ import org.atriasoft.etk.Uri;
import org.atriasoft.gale.Gale;
public class Sample1 {
- private Sample1() {}
- public static void main(String[] args) {
- Uri.setGroup("DATA", "src/org/atriasoft/gale/test/sample1/");
+ public static void main(final String[] args) {
+ Gale.init();
+ //Uri.setGroup("DATA", "src/org/atriasoft/gale/test/sample1/");
+ Uri.setApplication(Sample1.class, "/org/atriasoft/gale/test/sample1/");
Gale.run(new Sample1Application(), args);
}
+
+ private Sample1() {}
}
diff --git a/src/org/atriasoft/gale/test/sample1/Sample1Application.java b/src/org/atriasoft/gale/test/sample1/Sample1Application.java
index f038ad5..1300c4a 100644
--- a/src/org/atriasoft/gale/test/sample1/Sample1Application.java
+++ b/src/org/atriasoft/gale/test/sample1/Sample1Application.java
@@ -8,12 +8,12 @@ import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.gale.Application;
import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.context.Context;
-import org.atriasoft.gale.resource.ResourceProgram;
-import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
import org.atriasoft.gale.key.KeyKeyboard;
import org.atriasoft.gale.key.KeySpecial;
import org.atriasoft.gale.key.KeyStatus;
import org.atriasoft.gale.key.KeyType;
+import org.atriasoft.gale.resource.ResourceProgram;
+import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
public class Sample1Application extends Application {
private ResourceProgram oGLprogram;
@@ -23,32 +23,21 @@ public class Sample1Application extends Application {
private float angle;
private ResourceVirtualArrayObject verticesVBO;
-
@Override
- public void onCreate(Context context) {
- this.canDraw = true;
- setSize(new Vector2f(800, 600));
+ public void onCreate(final Context context) {
+ //setSize(new Vector2f(800, 600));
this.angle = 0.0f;
this.oGLprogram = ResourceProgram.create(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag"));
if (this.oGLprogram != null) {
- this.oGLMatrixTransformation = this.oGLprogram.getUniform("matrixTransformation");
- this.oGLMatrixProjection = this.oGLprogram.getUniform("matrixProjection");
- this.oGLMatrixView = this.oGLprogram.getUniform("matrixView");
+ this.oGLMatrixTransformation = this.oGLprogram.getUniform("in_matrixTransformation");
+ this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection");
+ this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView");
}
- float[] vertices = {
- -0.5f, -0.5f, -1.0f,
- 0.0f, 0.5f, -1.0f,
- 0.5f,-0.5f, -1.0f
- };
- float[] colors = {
- 1.0f, 0.0f, 0.0f, 1.0f,
- 0.0f, 1.0f, 0.0f, 1.0f,
- 0.0f, 0.0f, 1.0f, 1.0f,
- };
- int[] indices = {
- 0, 1, 2,
- };
+ //float[] vertices = { 0.2f, 0.1f, 0.0f, 0.3f, 0.4f, 0.0f, 0.1f, 0.4f, 0.0f };
+ float[] vertices = { -0.5f, -0.5f, -1.0f, 0.0f, 0.5f, -1.0f, 0.5f, -0.5f, -1.0f };
+ float[] colors = { 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, };
+ int[] indices = { 0, 1, 2 };
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, colors, indices);
// TO facilitate some debugs we add a name of the VBO:
@@ -57,24 +46,26 @@ public class Sample1Application extends Application {
this.verticesVBO.flush();
Log.info("==> Init APPL (END)");
}
+
@Override
- public void onDraw(Context context) {
+ public void onDraw(final Context context) {
this.angle += 0.01;
//Log.info("==> appl Draw ...");
Vector2f size = getSize();
// set the basic openGL view port: (position drawed in the windows)
- OpenGL.setViewPort(new Vector2f(0,0), size);
+ OpenGL.setViewPort(Vector2f.ZERO, size);
// Clear all the stacked matrix ...
OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
// clear background
- Color bgColor = new Color(0.0f, 1.0f, 1.0f, 0.75f);
+ Color bgColor = Color.CYAN;
OpenGL.clearColor(bgColor);
// real clear request:
OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer);
- // create a local matrix environnement.
+ // create a local matrix environment.
OpenGL.push();
Matrix4f tmpProjection = Matrix4f.createMatrixOrtho(-getAspectRatio(), getAspectRatio(), -1, 1, -50, 50);
+ //Matrix4f tmpProjection = Matrix4f.IDENTITY;
// set internal matrix system:
OpenGL.setMatrix(tmpProjection);
if (this.oGLprogram == null) {
@@ -84,46 +75,41 @@ public class Sample1Application extends Application {
//EWOL_DEBUG(" display " + this.coord.size() + " elements" );
this.oGLprogram.use();
- // set Matrix : translation/positionMatrix
+ // set Matrix: translation/positionMatrix
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
- Matrix4f transforamtionMatrix = Matrix4f.createMatrixRotate(new Vector3f(0,0,1),this.angle);
+ Matrix4f transforamtionMatrix = Matrix4f.createMatrixRotate(new Vector3f(0, 0, 1), this.angle);
Matrix4f viewMatrix = OpenGL.getCameraMatrix();
//Matrix4f tmpMatrix = projMatrix * camMatrix;
-
+
this.verticesVBO.bindForRendering();
this.oGLprogram.uniformMatrix(this.oGLMatrixView, viewMatrix);
this.oGLprogram.uniformMatrix(this.oGLMatrixProjection, projectionMatrix);
// Change the position for each element with the same pipeline you need to render ...
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, transforamtionMatrix);
- // Request the draw od the elements:
+ // Request the draw of the elements:
this.verticesVBO.render(OpenGL.RenderMode.triangle);
this.verticesVBO.unBindForRendering();
this.oGLprogram.unUse();
// Restore context of matrix
OpenGL.pop();
- this.markDrawingIsNeeded();
+ markDrawingIsNeeded();
}
+
@Override
- public void onPointer(KeySpecial special,
- KeyType type,
- int pointerID,
- Vector2f pos,
- KeyStatus state) {
-// Log.info("input event: type=" + type);
-// Log.info(" id=" + pointerID);
-// Log.info(" pos=" + pos);
-// Log.info(" state=" + state);
- }
- @Override
- public void onKeyboard( KeySpecial special,
- KeyKeyboard type,
- Character value,
- KeyStatus state) {
+ public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
Log.info("Keyboard event: special=" + special);
Log.info(" type=" + type);
Log.info(" value='" + value + "'");
Log.info(" state=" + state);
}
+
+ @Override
+ public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
+ // Log.info("input event: type=" + type);
+ // Log.info(" id=" + pointerID);
+ // Log.info(" pos=" + pos);
+ // Log.info(" state=" + state);
+ }
}
diff --git a/src/org/atriasoft/gale/test/sample1/basic.frag b/src/org/atriasoft/gale/test/sample1/data/basic.frag
similarity index 100%
rename from src/org/atriasoft/gale/test/sample1/basic.frag
rename to src/org/atriasoft/gale/test/sample1/data/basic.frag
diff --git a/src/org/atriasoft/gale/test/sample1/basic.vert b/src/org/atriasoft/gale/test/sample1/data/basic.vert
similarity index 75%
rename from src/org/atriasoft/gale/test/sample1/basic.vert
rename to src/org/atriasoft/gale/test/sample1/data/basic.vert
index 00c9732..417035e 100644
--- a/src/org/atriasoft/gale/test/sample1/basic.vert
+++ b/src/org/atriasoft/gale/test/sample1/data/basic.vert
@@ -16,6 +16,8 @@ uniform mat4 in_matrixView;
out vec4 io_color;
void main(void) {
+ //gl_Position = in_matrixProjection * vec4(in_position, 1.0);
gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0);
- f_color = in_colors;
+ //gl_Position = vec4(in_position, 1.0);
+ io_color = in_colors;
}
diff --git a/src/org/atriasoft/gale/test/sample2/Main.java b/src/org/atriasoft/gale/test/sample2/Main.java
index a741fe0..d85edf7 100644
--- a/src/org/atriasoft/gale/test/sample2/Main.java
+++ b/src/org/atriasoft/gale/test/sample2/Main.java
@@ -2,11 +2,14 @@ package org.atriasoft.gale.test.sample2;
import org.atriasoft.etk.Uri;
import org.atriasoft.gale.Gale;
+import org.atriasoft.gale.test.sample1.Sample1;
public class Main {
- private Main() {}
- public static void main(String[] args) {
- Uri.setGroup("DATA", "src/org/atriasoft/gale/test/sample2/");
+ public static void main(final String[] args) {
+ Gale.init();
+ Uri.setApplication(Sample1.class, "/org/atriasoft/gale/test/sample2/");
Gale.run(new Sample2Application(), args);
}
+
+ private Main() {}
}
diff --git a/src/org/atriasoft/gale/test/sample2/Sample2Application.java b/src/org/atriasoft/gale/test/sample2/Sample2Application.java
index f47773b..7d83699 100644
--- a/src/org/atriasoft/gale/test/sample2/Sample2Application.java
+++ b/src/org/atriasoft/gale/test/sample2/Sample2Application.java
@@ -8,13 +8,13 @@ import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.gale.Application;
import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.context.Context;
-import org.atriasoft.gale.resource.ResourceProgram;
-import org.atriasoft.gale.resource.ResourceTexture;
-import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
import org.atriasoft.gale.key.KeyKeyboard;
import org.atriasoft.gale.key.KeySpecial;
import org.atriasoft.gale.key.KeyStatus;
import org.atriasoft.gale.key.KeyType;
+import org.atriasoft.gale.resource.ResourceProgram;
+import org.atriasoft.gale.resource.ResourceTexture;
+import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
public class Sample2Application extends Application {
private ResourceProgram oGLprogram;
@@ -27,18 +27,16 @@ public class Sample2Application extends Application {
private ResourceVirtualArrayObject verticesVBO;
private ResourceTexture texture;
-
@Override
- public void onCreate(Context context) {
- this.canDraw = true;
+ public void onCreate(final Context context) {
setSize(new Vector2f(800, 600));
this.oGLprogram = ResourceProgram.create(new Uri("DATA", "basic.vert"), new Uri("DATA", "basic.frag"));
if (this.oGLprogram != null) {
- this.oGLMatrixTransformation = this.oGLprogram.getUniform("matrixTransformation");
- this.oGLMatrixProjection = this.oGLprogram.getUniform("matrixProjection");
- this.oGLMatrixView = this.oGLprogram.getUniform("matrixView");
+ this.oGLMatrixTransformation = this.oGLprogram.getUniform("in_matrixTransformation");
+ this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection");
+ this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView");
}
-
+ //@formatter:off
float[] vertices = {
-0.5f,0.5f,-0.5f,
-0.5f,-0.5f,-0.5f,
@@ -82,14 +80,16 @@ public class Sample2Application extends Application {
};
int[] indices = {
- 0,1,3, 3,1,2,
- 4,5,7, 7,5,6,
- 8,9,11, 11,9,10,
+ 1,0,3, 1,3,2,
+ 4,5,7, 7,5,6,
+ 9,8,11, 9,11,10,
12,13,15, 15,13,14,
- 16,17,19, 19,17,18,
+ 17,16,19, 17,19,18,
20,21,23, 23,21,22
};
+ //@formatter:on
+
// this is the properties of the buffer requested : "r"/"w" + "-" + buffer type "f"=float "i"=integer
this.verticesVBO = ResourceVirtualArrayObject.create(vertices, textureCoords, null, indices);
// TO facilitate some debugs we add a name of the VBO:
@@ -104,8 +104,9 @@ public class Sample2Application extends Application {
}
Log.info("==> Init APPL (END)");
}
+
@Override
- public void onDraw(Context context) {
+ public void onDraw(final Context context) {
this.angleX += 0.001;
this.angleY += 0.005;
this.angleZ += 0.01;
@@ -113,7 +114,7 @@ public class Sample2Application extends Application {
Vector2f size = getSize();
//Log.info("==> Windows size = " + size);
// 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 ...
OpenGL.setBasicMatrix(Matrix4f.IDENTITY);
// clear background
@@ -140,11 +141,11 @@ public class Sample2Application extends Application {
// set Matrix : translation/positionMatrix
Matrix4f projectionMatrix = tmpProjection; //OpenGL.getMatrix();
Matrix4f transforamtionMatrix = Matrix4f.IDENTITY;
- transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-1)));
- transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(1,0,0),this.angleX));
- transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,1,0),this.angleY));
- transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0,0,1),this.angleZ));
- Matrix4f viewMatrix = OpenGL.getCameraMatrix().multiply(Matrix4f.createMatrixTranslate(new Vector3f(0,0,-2)));
+ transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, -1)));
+ transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(1, 0, 0), this.angleX));
+ transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0, 1, 0), this.angleY));
+ transforamtionMatrix = transforamtionMatrix.multiply(Matrix4f.createMatrixRotate(new Vector3f(0, 0, 1), this.angleZ));
+ Matrix4f viewMatrix = OpenGL.getCameraMatrix().multiply(Matrix4f.createMatrixTranslate(new Vector3f(0, 0, -2)));
//Matrix4f tmpMatrix = projMatrix * camMatrix;
this.verticesVBO.bindForRendering();
this.oGLprogram.uniformMatrix(this.oGLMatrixView, viewMatrix);
@@ -162,27 +163,22 @@ public class Sample2Application extends Application {
this.oGLprogram.unUse();
// Restore context of matrix
OpenGL.pop();
- this.markDrawingIsNeeded();
+ markDrawingIsNeeded();
}
+
@Override
- public void onPointer(KeySpecial special,
- KeyType type,
- int pointerID,
- Vector2f pos,
- KeyStatus state) {
-// Log.info("input event: type=" + type);
-// Log.info(" id=" + pointerID);
-// Log.info(" pos=" + pos);
-// Log.info(" state=" + state);
- }
- @Override
- public void onKeyboard( KeySpecial special,
- KeyKeyboard type,
- Character value,
- KeyStatus state) {
+ public void onKeyboard(final KeySpecial special, final KeyKeyboard type, final Character value, final KeyStatus state) {
Log.info("Keyboard event: special=" + special);
Log.info(" type=" + type);
Log.info(" value='" + value + "'");
Log.info(" state=" + state);
}
+
+ @Override
+ public void onPointer(final KeySpecial special, final KeyType type, final int pointerID, final Vector2f pos, final KeyStatus state) {
+ // Log.info("input event: type=" + type);
+ // Log.info(" id=" + pointerID);
+ // Log.info(" pos=" + pos);
+ // Log.info(" state=" + state);
+ }
}
diff --git a/src/org/atriasoft/gale/test/sample2/basic.frag b/src/org/atriasoft/gale/test/sample2/data/basic.frag
similarity index 100%
rename from src/org/atriasoft/gale/test/sample2/basic.frag
rename to src/org/atriasoft/gale/test/sample2/data/basic.frag
diff --git a/src/org/atriasoft/gale/test/sample2/basic.vert b/src/org/atriasoft/gale/test/sample2/data/basic.vert
similarity index 100%
rename from src/org/atriasoft/gale/test/sample2/basic.vert
rename to src/org/atriasoft/gale/test/sample2/data/basic.vert
diff --git a/src/org/atriasoft/gale/test/sample2/tree_sample.png b/src/org/atriasoft/gale/test/sample2/data/tree_sample.png
similarity index 100%
rename from src/org/atriasoft/gale/test/sample2/tree_sample.png
rename to src/org/atriasoft/gale/test/sample2/data/tree_sample.png