[DEV] add grahioc context

This commit is contained in:
Edouard DUPIN 2021-05-24 13:47:30 +02:00
parent 1319741a96
commit 943c19c1b2
17 changed files with 400 additions and 428 deletions

View File

@ -1,2 +1,71 @@
EMF(STRING) EMF(STRING)
# Blender v2.92.0 EMF File: 'Entry.blend' # Blender v2.92.0 EMF File: 'Entry.blend'
Mesh:EntryBox_Cube
Vertex:16
20.042355 7.751226 20.042355|20.042355 7.751226 -20.042355|20.042355 -4.633502 20.042355|20.042355 -4.633502 -20.042355|-20.042355 7.751226 20.042355|-20.042355 7.751226 -20.042355|-20.042355 -4.633502 20.042355|-20.042355 -4.633502 -20.042355|10.127714 -7.726907 10.127714|10.127714 -7.726907 -10.127714|-10.127714 -7.726907 10.127714|-10.127714 -7.726907 -10.127714|-10.127714 -9.146553 -10.127714|-10.127714 -9.146553 10.127714|10.127714 -9.146553 10.127714|10.127714 -9.146553 -10.127714|
UV-mapping:
0.000100 0.000100|0.999900 0.999900|0.000100 0.999900|0.999900 0.000100|0.074219 0.995849|0.120606 0.943115|0.121582 0.993408|0.112927 0.992387|0.078245 0.948093|0.073324 0.991157|0.101769 0.970961|0.080974 0.959440|0.102023 0.957458|0.111927 0.985005|0.078476 0.953015|0.082167 0.983774|0.074219 0.944092|0.111696 0.944402|0.080720 0.975385|0.113157 0.949323|0.174907 0.947863|0.131613 0.991157|0.132843 0.945402|0.178368 0.944941|0.137534 0.984544|0.142456 0.948632|0.171985 0.949093|0.136074 0.991157|0.137304 0.950323|0.174677 0.949093|0.135074 0.992387|0.136304 0.949093|0.178598 0.993618|0.178368 0.988235|0.173216 0.991157|0.175907 0.989926|0.013265 0.951784|0.051868 0.992387|0.013034 0.993618|0.054098 0.951784|0.137534 0.988235|0.177138 0.947863|0.135074 0.947862|0.172446 0.988465|
Normal(face):22
0.000000 -1.000000 0.000000|-0.297843 -0.954615 0.000000|0.000000 -0.954615 -0.297843|0.000000 -0.954615 0.297843|0.297843 -0.954615 0.000000|0.000000 0.000000 1.000000|-1.000000 0.000000 0.000000|0.000000 0.000000 -1.000000|1.000000 0.000000 -0.000000|0.000000 1.000000 -0.000000|
Face:22
gui_dynamic_1
14/0/0 12/1/0 15/2/0| 14/0/0 13/3/0 12/1/0|
palette:gui_border_1
7/4/1 10/5/1 6/6/1| 3/7/2 11/8/2 7/9/2| 6/10/3 8/11/3 2/12/3| 2/13/4 9/14/4 3/15/4| 7/4/1 11/16/1 10/5/1| 3/7/2 9/17/2 11/8/2| 6/10/3 10/18/3 8/11/3| 2/13/4 8/19/4 9/14/4|
palette:gui_border_2
4/20/5 2/21/5 0/22/5| 6/23/6 5/24/6 7/25/6| 1/26/7 7/27/7 5/28/7| 0/29/8 3/30/8 1/31/8| 4/20/5 6/32/5 2/21/5| 6/23/6 4/33/6 5/24/6| 1/26/7 3/34/7 7/27/7| 0/29/8 2/35/8 3/30/8|
palette:gui_center
9/36/0 10/37/0 11/38/0| 9/36/0 8/39/0 10/37/0|
palette:gui_back
5/40/9 0/41/9 1/42/9| 5/40/9 4/43/9 0/41/9|
Materials:gui_dynamic_1
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.450000
d 1.000000
illum 2
map_Kd empty_area.png
# Just for information:
Palettes:gui_back
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.000000 0.005632
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.450000
d 1.000000
illum 2
# Just for information:
Palettes:gui_border_1
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.000000 0.002615 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.450000
d 1.000000
illum 2
# Just for information:
Palettes:gui_border_2
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.000000 0.800000 0.170495
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.450000
d 1.000000
illum 2
# Just for information:
Palettes:gui_center
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.438544 0.438544 0.438544
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
vNi 1.450000
d 1.000000
illum 2

Binary file not shown.

Binary file not shown.

View File

@ -196,7 +196,7 @@ public class CompositingDrawing extends Compositing {
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, this.matrixApply); this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, this.matrixApply);
this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix); this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix);
// Request the draw of the elements: // Request the draw of the elements:
this.vbo.renderArrays(OpenGL.RenderMode.triangle); this.vbo.renderArrays(OpenGL.RenderMode.TRIANGLE);
this.vbo.unBindForRendering(); this.vbo.unBindForRendering();
this.oGLprogram.unUse(); this.oGLprogram.unUse();
} }

View File

@ -0,0 +1,259 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.ewol.compositing;
import org.atriasoft.esvg.CapMode;
import org.atriasoft.esvg.GraphicContext;
import org.atriasoft.esvg.JoinMode;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.internal.Log;
import org.atriasoft.gale.resource.ResourceTexture2;
public class CompositingGraphicContext extends Compositing {
GraphicContext context = new GraphicContext();
private final ResourceTexture2 resourcTexture = null;
public CompositingGraphicContext() {
}
public Vector2i calculateTextSize(final String data) {
return this.context.calculateTextSize(data);
}
public void circle(final Vector2f position, final float radius) {
this.context.circle(position, radius);
}
/**
* clear alll tre registered element in the current element
*/
@Override
public void clear() {
// call upper class
super.clear();
// reset Buffer :
this.context.clear();
}
/**
* Clear the fill color (disable fill ==> better that set it transparent)
*/
public void clearColorFill() {
this.context.clearColorFill();
}
/**
* Clear the Stroke color (disable stroke)
*/
public void clearColorStroke() {
this.context.clearColorStroke();
}
@Override
public void draw(final boolean disableDepthTest) {
// TODO Auto-generated method stub
}
public void ellipse(final Vector2f center, final Vector2f radius) {
this.context.ellipse(center, radius);
}
@Override
public void flush() {
if (this.resourcTexture == null) {
Log.warning("texture is null");
return;
}
this.resourcTexture.set(this.context.render());
this.resourcTexture.flush();
}
/**
* Get the fill color.
* @return fill color.
*/
public Color getColorFill() {
return this.context.getColorFill();
}
/**
* Get the stroke color.
* @return Stroke color.
*/
public Color getColorStroke() {
return this.context.getColorStroke();
}
public CapMode getLineCap() {
return this.context.getLineCap();
}
public JoinMode getLineJoin() {
return this.context.getLineJoin();
}
public float getMiterLimit() {
return this.context.getMiterLimit();
}
public float getOpacity() {
return this.context.getOpacity();
}
/**
* get the source image registered size in the file (<0 when multiple size image)
* @return tre image registered size
*/
public Vector2i getRealSize() {
return this.resourcTexture.get().getSize();
}
public int getRendererId() {
return this.resourcTexture.getRendererId();
}
public ResourceTexture2 getResourceTexture() {
return this.resourcTexture;
}
public float getStrokeWidth() {
return this.context.getStrokeWidth();
}
public int getTextHeight() {
return this.context.getTextHeight();
}
/**
* Sometimes the user declare an image but not allocate the ressources all the time, this is to know it ..
* @return the validity od the resources.
*/
public boolean hasSources() {
return true;
}
public void line(final Vector2f origin, final Vector2f destination) {
this.context.line(origin, destination);
}
public void lineRel(final Vector2f origin, final Vector2f relativeDestination) {
this.context.lineRel(origin, relativeDestination);
}
public void pathLine(final Vector2f pos) {
this.context.pathLine(pos);
}
public void pathLineTo(final Vector2f pos) {
this.context.pathLineTo(pos);
}
public void pathMove(final Vector2f pos) {
this.context.pathMove(pos);
}
public void pathMoveTo(final Vector2f pos) {
this.context.pathMoveTo(pos);
}
public void pathStart() {
this.context.pathStart();
}
public void pathStop() {
this.context.pathStop();
}
public void pathStopLinked() {
this.context.pathStopLinked();
}
public void rectangle(final Vector2f position, final Vector2f destination) {
this.context.rectangle(position, destination);
}
public void rectangleRounded(final Vector2f position, final Vector2f destination, final Vector2f ruound) {
this.context.rectangleRounded(position, destination, ruound);
}
public void rectangleRoundedWidth(final Vector2f position, final Vector2f width, final Vector2f ruound) {
this.context.rectangleRoundedWidth(position, width, ruound);
}
public void rectangleWidth(final Vector2f position, final Vector2f width) {
this.context.rectangleWidth(position, width);
}
/**
* set the fill color
* @param color Color to set on fill
* @apiNote use clearFill() if you want to remove drawing of fill
*/
public void setColorFill(final Color color) {
this.context.setColorFill(color);
}
/**
* set the stroke color
* @param color Color to set on stroke
* @apiNote use clearStroke() if you want to remove drawing of stroke
*/
public void setColorStroke(final Color color) {
this.context.setColorStroke(color);
}
public void setLineCap(final CapMode lineCap) {
this.context.setLineCap(lineCap);
}
public void setLineJoin(final JoinMode lineJoin) {
this.context.setLineJoin(lineJoin);
}
public void setMiterLimit(final float miterLimit) {
this.context.setMiterLimit(miterLimit);
}
public void setOpacity(final float opacity) {
this.context.setOpacity(opacity);
}
/**
* Set global size of the Graphic context (output render size)
* @param xxx Width of the image
* @param yyy Height of the image
* @apiNote It will clear the current context.
*/
public void setSize(final int xxx, final int yyy) {
this.context.setSize(xxx, yyy);
}
/**
* Set global size of the Graphic contexct (output render size)
* @param vector2i New size of the image
* @apiNote It will clear the current context.
*/
public void setSize(final Vector2i size) {
this.context.setSize(size.x(), size.y());
}
public void setStrokeWidth(final float strokeWidth) {
this.context.setStrokeWidth(strokeWidth);
}
public void text(final Vector2f position, final float height, final String data) {
this.context.text(position, height, data);
}
public void text(final Vector2f position, final String data) {
this.context.text(position, data);
}
}

View File

@ -14,11 +14,11 @@ import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i; import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector3f; import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.internal.Log;
import org.atriasoft.ewol.resource.ResourceTexture2;
import org.atriasoft.ewol.resource.ResourceTextureFile;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.backend3d.OpenGL.RenderMode; import org.atriasoft.gale.backend3d.OpenGL.RenderMode;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
import org.atriasoft.gale.resource.ResourceTexture2;
import org.atriasoft.gale.resource.ResourceTextureFile;
import org.atriasoft.gale.resource.ResourceVirtualBufferObject; import org.atriasoft.gale.resource.ResourceVirtualBufferObject;
public class CompositingImage extends Compositing { public class CompositingImage extends Compositing {
@ -137,7 +137,7 @@ public class CompositingImage extends Compositing {
// color: // color:
this.oGLprogram.sendAttributePointer(this.oGLColor, this.vbo, CompositingImage.VBO_ID_COLOR); this.oGLprogram.sendAttributePointer(this.oGLColor, this.vbo, CompositingImage.VBO_ID_COLOR);
// Request the draw of the elements: // Request the draw of the elements:
OpenGL.drawArrays(RenderMode.triangle, 0, this.vbo.bufferSize(CompositingImage.VBO_ID_COORD)); OpenGL.drawArrays(RenderMode.TRIANGLE, 0, this.vbo.bufferSize(CompositingImage.VBO_ID_COORD));
this.oGLprogram.unUse(); this.oGLprogram.unUse();
} }

View File

@ -112,7 +112,7 @@ public class CompositingText extends TextBase {
this.oGLprogram.uniformInt(this.oGLtextWidth, this.font.getOpenGlSize().x()); this.oGLprogram.uniformInt(this.oGLtextWidth, this.font.getOpenGlSize().x());
this.oGLprogram.uniformInt(this.oGLtextHeight, this.font.getOpenGlSize().x()); this.oGLprogram.uniformInt(this.oGLtextHeight, this.font.getOpenGlSize().x());
// Request the draw of the elements: // Request the draw of the elements:
this.vbo.renderArrays(OpenGL.RenderMode.triangle); this.vbo.renderArrays(OpenGL.RenderMode.TRIANGLE);
this.vbo.unBindForRendering(); this.vbo.unBindForRendering();
this.oGLprogram.unUse(); this.oGLprogram.unUse();
@ -149,7 +149,7 @@ public class CompositingText extends TextBase {
this.oGLprogram.uniformInt(this.oGLtextWidth, this.font.getOpenGlSize().x()); this.oGLprogram.uniformInt(this.oGLtextWidth, this.font.getOpenGlSize().x());
this.oGLprogram.uniformInt(this.oGLtextHeight, this.font.getOpenGlSize().x()); this.oGLprogram.uniformInt(this.oGLtextHeight, this.font.getOpenGlSize().x());
// Request the draw of the elements: // Request the draw of the elements:
this.vbo.renderArrays(OpenGL.RenderMode.triangle); this.vbo.renderArrays(OpenGL.RenderMode.TRIANGLE);
this.vbo.unBindForRendering(); this.vbo.unBindForRendering();
this.oGLprogram.unUse(); this.oGLprogram.unUse();

View File

@ -13,11 +13,12 @@ import org.atriasoft.ewol.Padding;
import org.atriasoft.ewol.event.EventTime; import org.atriasoft.ewol.event.EventTime;
import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.internal.Log;
import org.atriasoft.ewol.resource.ResourceConfigFile; import org.atriasoft.ewol.resource.ResourceConfigFile;
import org.atriasoft.ewol.resource.ResourceTextureFile; import org.atriasoft.gale.TextureFilter;
import org.atriasoft.ewol.resource.TextureFilter;
import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.backend3d.OpenGL.Flag; import org.atriasoft.gale.backend3d.OpenGL.Flag;
import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceProgram;
import org.atriasoft.gale.resource.ResourceTexture2;
import org.atriasoft.gale.resource.ResourceTextureFile;
import org.atriasoft.loader3d.resources.ResourceStaticMeshObjBynamic; import org.atriasoft.loader3d.resources.ResourceStaticMeshObjBynamic;
/** /**
@ -49,7 +50,8 @@ public class GuiShape extends Compositing {
private int oGLMatrixView = -1; //!< openGL id on the element (view matrix) private int oGLMatrixView = -1; //!< openGL id on the element (view matrix)
// openGL shaders programs: // openGL shaders programs:
private ResourceProgram oGLprogram = null; //!< pointer on the opengl display program private ResourceProgram oGLprogram = null; //!< pointer on the opengl display program
private int oGLtexID = -1; //!< openGL id on the element (texture image) private int oGLtexID0 = -1; //!< openGL id on the element (texture image)
private int oGLtexID1 = -1; //!< openGL id on the element (texture image)
// For the Image : // For the Image :
private ResourceTextureFile resourceTexture = null; //!< texture resources (for the image) private ResourceTextureFile resourceTexture = null; //!< texture resources (for the image)
private ResourceStaticMeshObjBynamic shape = null; private ResourceStaticMeshObjBynamic shape = null;
@ -121,7 +123,40 @@ public class GuiShape extends Compositing {
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, tmpMatrix); this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, tmpMatrix);
this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix); this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix);
// Texture: // Texture:
this.oGLprogram.setTexture0(this.oGLtexID, this.resourceTexture.getRendererId()); this.oGLprogram.setTexture0(this.oGLtexID0, this.resourceTexture.getRendererId());
// Request the draw of the elements:
this.shape.render();
this.shape.unBindForRendering();
this.oGLprogram.unUse();
OpenGL.disable(Flag.flag_depthTest);
}
public void draw(final ResourceTexture2 secondaryTexture, final boolean disableDepthTest) {
if (this.config == null) {
// this is a normal case ... the user can choice to have no config basic file ...
return;
}
if (this.oGLprogram == null) {
Log.error("No shader ...");
}
OpenGL.enable(Flag.flag_depthTest);
// set Matrix : translation/positionMatrix
Matrix4f projMatrix = OpenGL.getMatrix();
Matrix4f camMatrix = OpenGL.getCameraMatrix();
Matrix4f tmpMatrix = this.matrixApply.multiply(this.transform);
this.oGLprogram.use();
this.shape.bindForRendering();
this.oGLprogram.uniformMatrix(this.oGLMatrixProjection, projMatrix);
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, tmpMatrix);
this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix);
// Texture:
this.oGLprogram.setTexture0(this.oGLtexID0, this.resourceTexture.getRendererId());
if (secondaryTexture == null) {
Log.warning("Request display shape with a second empty texture...");
} else {
this.oGLprogram.setTexture1(this.oGLtexID0, secondaryTexture.getRendererId());
}
// Request the draw of the elements: // Request the draw of the elements:
this.shape.render(); this.shape.render();
@ -275,7 +310,8 @@ public class GuiShape extends Compositing {
this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection"); this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection");
this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView"); this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView");
// for the texture ID : // for the texture ID :
this.oGLtexID = this.oGLprogram.getUniform("in_textureBase"); this.oGLtexID0 = this.oGLprogram.getUniform("in_textureBase");
this.oGLtexID1 = this.oGLprogram.getUniform("in_textureSecondary");
} }
} }
} }

View File

@ -1,22 +0,0 @@
package org.atriasoft.ewol.internal;
public class Tools {
/**
* get the next power 2 if the input
* @param value Value that we want the next power of 2
* @return result value
*/
public static int nextP2(final int value) {
int val = 1;
for (int iii = 1; iii < 31; iii++) {
if (value <= val) {
return val;
}
val *= 2;
}
Log.critical("impossible CASE....");
return val;
}
private Tools() {}
}

View File

@ -75,7 +75,7 @@ public class RefactorColored3DObject extends Resource {
// color : // color :
this.oGLprogram.uniformColor(this.oGLColor, color); this.oGLprogram.uniformColor(this.oGLColor, color);
// Request the draw od the elements: // Request the draw od the elements:
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size()); OpenGL.drawArrays(OpenGL.RenderMode.TRIANGLE, 0, vertices.size());
this.oGLprogram.unUse(); this.oGLprogram.unUse();
// Request the draw od the elements: // Request the draw od the elements:
// glDrawArrays(GLLINES, 0, vertices.size()); // glDrawArrays(GLLINES, 0, vertices.size());
@ -119,7 +119,7 @@ public class RefactorColored3DObject extends Resource {
// color : // color :
this.oGLprogram.uniformColor(this.oGLColor, color); this.oGLprogram.uniformColor(this.oGLColor, color);
// Request the draw od the elements: // Request the draw od the elements:
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size()); OpenGL.drawArrays(OpenGL.RenderMode.TRIANGLE, 0, vertices.size());
this.oGLprogram.unUse(); this.oGLprogram.unUse();
if (depthTest) { if (depthTest) {
if (!updateDepthBuffer) { if (!updateDepthBuffer) {
@ -410,7 +410,7 @@ public class RefactorColored3DObject extends Resource {
// color : // color :
this.oGLprogram.uniformColor(this.oGLColor, color); this.oGLprogram.uniformColor(this.oGLColor, color);
// 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());
this.oGLprogram.unUse(); this.oGLprogram.unUse();
if (depthTest) { if (depthTest) {
if (!updateDepthBuffer) { if (!updateDepthBuffer) {

View File

@ -1,262 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.ewol.resource;
import org.atriasoft.echrono.Steady;
import org.atriasoft.egami.ImageByte;
import org.atriasoft.egami.ImageByteRGBA;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.internal.Log;
import org.atriasoft.ewol.internal.Tools;
import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.resource.Resource;
public class ResourceTexture2 extends Resource {
public enum TextureColorMode {
rgb, // !< red/green/blue data
rgba // !< red/green/blue/alpha data
}
/*
* public static ResourceTexture2 createFromPng(final Uri uriTexture) { return
* createFromPng(uriTexture, 1); }
*
* public static ResourceTexture2 createFromPng(final Uri uriTexture, final int
* textureUnit) { ResourceTexture2 resource; Resource resource2; final String
* name = uriTexture.getValue(); if (name.isEmpty() == false && name != "---") {
* resource2 = getManager().localKeep(name); } else {
* Log.error("Can not create a shader without a filaname"); return null; } if
* (resource2 != null) { if (resource2 instanceof ResourceTexture2) {
* resource2.keep(); return (ResourceTexture2) resource2; }
* Log.critical("Request resource file : '" + name +
* "' With the wrong type (dynamic cast error)"); return null; } resource = new
* ResourceTexture2(uriTexture, textureUnit); final ImageRawData decodedData =
* ImageLoader.decodePngFile(uriTexture);
* resource.setTexture(decodedData.getBuffer(), new
* Vector2i(decodedData.getWidth(), decodedData.getHeight()),
* (decodedData.isHasAlpha() == true ? TextureColorMode.rgba :
* TextureColorMode.rgb), textureUnit); resource.flush(); return resource; }
*/
// openGl Context properties :
protected ImageByte data = new ImageByteRGBA(32, 32);
// !< Color space of the image.
private final TextureColorMode dataColorSpace = TextureColorMode.rgba;
// Filter apply at the image when rendering it
protected TextureFilter filter = TextureFilter.LINEAR;
// ! Last loaded size in the system openGL
protected Vector2i lastSize = new Vector2i(1, 1);
protected int lastSizeObject = 0;
protected int lastTypeObject = 0;
// internal state of the openGl system.
protected boolean loaded = false;
// ! 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 Vector2i realImageSize = new Vector2i(1, 1);
// repeat mode of the image (repeat the image if out of range [0..1])
protected boolean repeat = false;
protected int texId = -1; // !< openGl textureID.
public ResourceTexture2() {}
public ResourceTexture2(final String filename) {
super(filename);
}
/*
* public void bindForRendering(final int idTexture) { if (this.loaded == false)
* { return; } GL13.glActiveTexture(textureIdBinding[idTexture]);
* GL11.glBindTexture(GL11.GLTEXTURE2D, this.texId); if (this.dataColorSpace
* == TextureColorMode.rgb) { OpenGL.enable(OpenGL.Flag.flagcullFace);
* OpenGL.enable(OpenGL.Flag.flagback); } }
*/
public ResourceTexture2(final Uri filename) {
super(filename);
}
public void bindForRendering(final int idTexture) {
if (!this.loaded) {
return;
}
OpenGL.activeTexture(idTexture);
OpenGL.bindTexture2D(this.texId);
if (this.dataColorSpace == TextureColorMode.rgb) {
OpenGL.enable(OpenGL.Flag.flag_cullFace);
OpenGL.enable(OpenGL.Flag.flag_back);
}
}
@Override
public void cleanUp() {
removeContext();
}
// Flush the data to send it at the openGl system
public synchronized void flush() {
// request to the manager to be call at the next update ...
Log.verbose("Request UPDATE of Element");
Resource.getManager().update(this);
}
// Get the reference on this image to draw something on it ...
public ImageByte get() {
return this.data;
}
public Vector2i getOpenGlSize() {
return this.data.getSize();
}
public int getRendererId() {
return this.texId;
}
public Vector2i getUsableSize() {
return this.realImageSize;
}
@Override
public synchronized void removeContext() {
if (this.loaded) {
// Request remove texture ...
Log.info("TEXTURE: Rm [" + getId() + "] texId=" + this.texId);
// TODO Check if we are in the correct thread
OpenGL.glDeleteTextures(this.texId);
this.loaded = false;
}
}
@Override
public synchronized void removeContextToLate() {
this.loaded = false;
this.texId = -1;
}
/**
* Set the image in the texture system
* @note It will resize in square2 if needed by the system.
* @param image Image to set.
*/
public synchronized void set(final ImageByte image) {
Log.debug("Set a new image in a texture:");
Log.debug(" size=" + image.getSize());
this.data = image;
this.realImageSize = this.data.getSize();
final Vector2i compatibilityHWSize = new Vector2i(Tools.nextP2(this.realImageSize.x()), Tools.nextP2(this.realImageSize.y()));
if (!this.realImageSize.equals(compatibilityHWSize)) {
Log.verbose("RESIZE Image for HArwareCompatibility:" + this.realImageSize + " => " + compatibilityHWSize);
this.data.resize(compatibilityHWSize.x(), compatibilityHWSize.y());
}
flush();
}
/**
* Set the Filter mode to apply at the image when display with a scale
* (not 1:1 ratio)
* @param filter Value of the new filter mode
*/
public void setFilterMode(final TextureFilter filter) {
this.filter = filter;
}
// You must set the size here, because it will be set in multiple of pow(2)
public synchronized void setImageSize(Vector2i newSize) {
newSize = new Vector2i(Tools.nextP2(newSize.x()), Tools.nextP2(newSize.y()));
this.data.resize(newSize.x(), newSize.y());
}
/**
* Set the repeate mode of the images if UV range is out of [0..1]
* @param value Value of the new repeate mode
*/
public void setRepeat(final boolean value) {
this.repeat = value;
}
public void unBindForRendering() {
if (!this.loaded) {
return;
}
if (this.dataColorSpace == TextureColorMode.rgb) {
OpenGL.disable(OpenGL.Flag.flag_cullFace);
OpenGL.disable(OpenGL.Flag.flag_back);
}
}
@Override
public synchronized boolean updateContext() {
Log.verbose("updateContext [START]");
final Steady tic = Steady.now();
/*
* TODO : use unlockable synchronized ... if (lock.tryLock() == false) { //Lock
* error ==> try later ... return false; }
*/
final int typeObject = this.data.hasAlpha() ? OpenGL.GL_RGBA : OpenGL.GL_RGB;
final int sizeObject = OpenGL.GL_UNSIGNED_BYTE;
if (this.loaded) {
if (this.lastTypeObject != typeObject || this.lastSizeObject != sizeObject || !this.lastSize.equals(this.data.getSize())) {
Log.warning("TEXTURE: Rm [" + getId() + "] texId=" + this.texId);
OpenGL.glDeleteTextures(this.texId);
this.loaded = false;
}
}
if (!this.loaded) {
// Request a new texture at openGl :
this.texId = OpenGL.glGenTextures();
this.lastSize = this.data.getSize();
this.lastTypeObject = typeObject;
this.lastSizeObject = sizeObject;
Log.debug("TEXTURE: add [" + getId() + "]=" + this.data.getSize() + "=>" + this.data.getGPUSize() + " OGlId=" + this.texId + " type=" + this.data.getClass().getCanonicalName());
} else {
Log.debug("TEXTURE: update [" + getId() + "]=" + this.data.getSize() + "=>" + this.data.getGPUSize() + " OGlId=" + this.texId + " type=" + this.data.getClass().getCanonicalName());
}
// in all case we set the texture properties :
// TODO check error ???
OpenGL.bindTexture2D(this.texId);
if (!this.loaded) {
if (!this.repeat) {
OpenGL.setTexture2DWrapClampToEdge();
} else {
OpenGL.setTexture2DWrapRepeat();
}
if (this.filter == TextureFilter.LINEAR) {
OpenGL.setTexture2DFilterLinear();
} else {
OpenGL.setTexture2DFilterNearest();
}
}
// glPixelStorei(GLUNPACKALIGNMENT,1);
final Steady toc1 = Steady.now();
Log.verbose(" BIND ==> " + toc1.less(tic));
// egami::store(this.data, String("~/texture") + etk::toString(getId()) + ".bmp");
if (!this.loaded) {
OpenGL.glTexImage2D(0, // Level
typeObject, // Format internal
this.data.getWidth(), this.data.getHeight(), 0, // Border
typeObject, // format
sizeObject, // type
this.data.getRaw());
} else {
OpenGL.glTexSubImage2D(0, // Level
0, // x offset
0, // y offset
this.data.getWidth(), this.data.getHeight(), typeObject, // format
sizeObject, // type
this.data.getRaw());
}
// now the data is loaded
this.loaded = true;
final Steady toc = Steady.now();
// Log.error(" updateContext [STOP] ==> " + (toc - toc1));
return true;
}
}

View File

@ -1,102 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.ewol.resource;
import org.atriasoft.egami.ImageByte;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.internal.Log;
import org.atriasoft.ewol.internal.Tools;
import org.atriasoft.gale.resource.Resource;
import org.atriasoft.iogami.IOgami;
// TODO : Change tis file name ...
public class ResourceTextureFile extends ResourceTexture2 {
public static Vector2i sizeAuto = new Vector2i(-1, -1);
public static Vector2i sizeDefault = new Vector2i(0, 0);
public static ResourceTextureFile create(final Uri filename) {
return ResourceTextureFile.create(filename, ResourceTextureFile.sizeAuto);
}
public static ResourceTextureFile create(final Uri filename, final Vector2i size) {
return ResourceTextureFile.create(filename, size, ResourceTextureFile.sizeAuto);
}
/**
* keep the resource pointer.
* @note Never free this pointer by your own...
* @param uri Name of the image file.
* @param size size of the image (usefull when loading .svg to
* automatic rescale)
* @param sizeRegister size register in named (When you preaload the images
* the size write here will be )
* @return pointer on the resource or null if an error occured.
*/
public static ResourceTextureFile create(final Uri uri, final Vector2i inSize, final Vector2i sizeRegister) {
Log.verbose("KEEP: TextureFile: '" + uri + "' size=" + inSize + " sizeRegister=" + sizeRegister);
Vector2i size = inSize;
if (uri == null) {
return new ResourceTextureFile();
}
if (size.x() == 0) {
size = size.withX(-1);
// Log.error("Error Request the image size.x() =0 ???");
}
if (size.y() == 0) {
size = size.withY(-1);
// Log.error("Error Request the image size.y() =0 ???");
}
if (!uri.getExtention().toLowerCase().contentEquals("svg")) {
size = ResourceTextureFile.sizeAuto;
}
if (size.x() > 0 && size.y() > 0) {
Log.verbose(" == > specific size : " + size);
size = new Vector2i(Tools.nextP2(size.x()), Tools.nextP2(size.y()));
if (!sizeRegister.equals(ResourceTextureFile.sizeAuto)) {
if (!sizeRegister.equals(ResourceTextureFile.sizeDefault)) {
// tmpFilename.getQuery().set("x", "" + size.x));
// tmpFilename.getQuery().set("y", "" + size.y));
}
}
}
Log.verbose("KEEP: TextureFile: '" + uri + "' new size=" + size);
final Resource object2 = Resource.getManager().localKeep(uri.toString());
if (object2 != null) {
if (object2 instanceof ResourceTextureFile out) {
object2.keep();
return out;
}
Log.critical("Request resource file : '" + uri + "' With the wrong type (dynamic cast error)");
return null;
}
Log.debug("CREATE: TextureFile: '" + uri + "' size=" + size);
// need to crate a new one ...
ResourceTextureFile object = new ResourceTextureFile(uri.toString(), uri, size);
Resource.getManager().localAdd(object);
return object;
}
protected ResourceTextureFile() {}
protected ResourceTextureFile(final String genName, final Uri uri, final Vector2i size) {
super(genName);
Log.debug("create a new resource::Image : genName=" + genName + " uri=" + uri + " size=" + size);
final ImageByte tmp = IOgami.load(uri, size);
if (tmp == null) {
Log.error("Can not load the file : " + uri);
return;
}
set(tmp);
}
public Vector2i getRealSize() {
return this.realImageSize;
}
}

View File

@ -17,6 +17,7 @@ import org.atriasoft.ewol.internal.Log;
import org.atriasoft.ewol.resource.font.FontMode; import org.atriasoft.ewol.resource.font.FontMode;
import org.atriasoft.ewol.resource.font.GlyphProperty; import org.atriasoft.ewol.resource.font.GlyphProperty;
import org.atriasoft.gale.resource.Resource; import org.atriasoft.gale.resource.Resource;
import org.atriasoft.gale.resource.ResourceTexture2;
public class ResourceTexturedFont extends ResourceTexture2 { public class ResourceTexturedFont extends ResourceTexture2 {
public static ResourceTexturedFont create(final Uri fontBaseUri) { public static ResourceTexturedFont create(final Uri fontBaseUri) {

View File

@ -1,5 +0,0 @@
package org.atriasoft.ewol.resource;
public enum TextureFilter {
LINEAR, NEAREST
}

View File

@ -12,7 +12,7 @@ import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.Padding; import org.atriasoft.ewol.Padding;
import org.atriasoft.ewol.annotation.EwolDescription; import org.atriasoft.ewol.annotation.EwolDescription;
import org.atriasoft.ewol.annotation.EwolSignal; import org.atriasoft.ewol.annotation.EwolSignal;
import org.atriasoft.ewol.compositing.CompositingText; import org.atriasoft.ewol.compositing.CompositingGraphicContext;
import org.atriasoft.ewol.compositing.GuiShape; import org.atriasoft.ewol.compositing.GuiShape;
import org.atriasoft.ewol.event.EventEntry; import org.atriasoft.ewol.event.EventEntry;
import org.atriasoft.ewol.event.EventInput; import org.atriasoft.ewol.event.EventInput;
@ -50,6 +50,7 @@ public class Entry extends Widget {
private int displayCursorPosSelection = 2; //!< Selection position end (can be befor or after cursor and == this.displayCursorPos chan no selection availlable private int displayCursorPosSelection = 2; //!< Selection position end (can be befor or after cursor and == this.displayCursorPos chan no selection availlable
private int displayStartPosition = 0; //!< offset in pixel of the display of the UString private int displayStartPosition = 0; //!< offset in pixel of the display of the UString
private final CompositingGraphicContext gc = new CompositingGraphicContext(); //!< text display this.text
private boolean needUpdateTextPos = true; //!< text position can have change private boolean needUpdateTextPos = true; //!< text position can have change
protected Connection periodicConnectionHanble; //!< Periodic call handle to remove it when needed protected Connection periodicConnectionHanble; //!< Periodic call handle to remove it when needed
@XmlManaged @XmlManaged
@ -73,6 +74,7 @@ public class Entry extends Widget {
@XmlName(value = "regex") @XmlName(value = "regex")
@EwolDescription(value = "Control what it is write with a regular expression") @EwolDescription(value = "Control what it is write with a regular expression")
private String propertyRegex = ".*"; private String propertyRegex = ".*";
/// Text to display when nothing in in the entry (decorated text...) /// Text to display when nothing in in the entry (decorated text...)
@XmlManaged @XmlManaged
@XmlProperty @XmlProperty
@ -87,7 +89,6 @@ public class Entry extends Widget {
private String propertyValue = "Test Text..."; //!< string that must be displayed private String propertyValue = "Test Text..."; //!< string that must be displayed
private Pattern regex = null; //!< regular expression to check content private Pattern regex = null; //!< regular expression to check content
private GuiShape shape; private GuiShape shape;
//.create() //.create()
@EwolSignal(name = "click", description = "the user Click on the Entry box") @EwolSignal(name = "click", description = "the user Click on the Entry box")
@ -96,7 +97,6 @@ public class Entry extends Widget {
public Signal<String> signalEnter = new Signal<>(); //!< Enter key is pressed public Signal<String> signalEnter = new Signal<>(); //!< Enter key is pressed
@EwolSignal(name = "modify", description = "Entry box value change") @EwolSignal(name = "modify", description = "Entry box value change")
public Signal<String> signalModify = new Signal<>(); //!< data change public Signal<String> signalModify = new Signal<>(); //!< data change
private final CompositingText text = new CompositingText(); //!< text display this.text
/** /**
* Contuctor * Contuctor
@ -130,7 +130,7 @@ public class Entry extends Widget {
if (this.shape != null) { if (this.shape != null) {
padding = this.shape.getPadding(); padding = this.shape.getPadding();
} }
int minHeight = (int) this.text.getHeight();//calculateSize('A').y(); int minHeight = this.gc.getTextHeight();//calculateSize('A').y();
Vector2f minimumSizeBase = new Vector2f(20, minHeight); Vector2f minimumSizeBase = new Vector2f(20, minHeight);
// add padding : // add padding :
@ -303,9 +303,8 @@ public class Entry extends Widget {
@Override @Override
protected void onDraw() { protected void onDraw() {
if (this.shape != null) { if (this.shape != null) {
this.shape.draw(); this.shape.draw(this.gc.getResourceTexture(), true);
} }
this.text.draw();
} }
@Override @Override
@ -506,7 +505,7 @@ public class Entry extends Widget {
} }
//Log.verbose("Regenerate Display ==> is needed: '" + this.propertyValue + "'"); //Log.verbose("Regenerate Display ==> is needed: '" + this.propertyValue + "'");
this.shape.clear(); this.shape.clear();
this.text.clear(); this.gc.clear();
if (this.colorIdTextFg >= 0) { if (this.colorIdTextFg >= 0) {
//this.text.setDefaultColorFg(this.shape.getColor(this.colorIdTextFg)); //this.text.setDefaultColorFg(this.shape.getColor(this.colorIdTextFg));
//this.text.setDefaultColorBg(this.shape.getColor(this.colorIdTextBg)); //this.text.setDefaultColorBg(this.shape.getColor(this.colorIdTextBg));
@ -528,7 +527,7 @@ public class Entry extends Widget {
Vector2f tmpSizeText = tmpSizeShaper.less(padding.x(), padding.y()); Vector2f tmpSizeText = tmpSizeShaper.less(padding.x(), padding.y());
Vector2f tmpOriginText = this.size.less(tmpSizeText).multiply(0.5f); Vector2f tmpOriginText = this.size.less(tmpSizeText).multiply(0.5f);
// sometimes, the user define an height bigger than the real size needed == > in this case we need to center the text in the shaper ... // sometimes, the user define an height bigger than the real size needed == > in this case we need to center the text in the shaper ...
int minHeight = (int) this.text.getHeight(); int minHeight = this.gc.getTextHeight();
if (tmpSizeText.y() > minHeight) { if (tmpSizeText.y() > minHeight) {
tmpOriginText = tmpOriginText.add(0, (tmpSizeText.y() - minHeight) * 0.5f); tmpOriginText = tmpOriginText.add(0, (tmpSizeText.y() - minHeight) * 0.5f);
} }
@ -538,36 +537,35 @@ public class Entry extends Widget {
tmpSizeText = Vector2f.clipInt(tmpSizeText); tmpSizeText = Vector2f.clipInt(tmpSizeText);
tmpOriginText = Vector2f.clipInt(tmpOriginText); tmpOriginText = Vector2f.clipInt(tmpOriginText);
this.text.reset(); this.gc.clear();
this.text.setClippingWidth(tmpOriginText, tmpSizeText); /*
this.text.setPos(tmpOriginText.add(this.displayStartPosition, 0));
if (this.displayCursorPosSelection != this.displayCursorPos) { if (this.displayCursorPosSelection != this.displayCursorPos) {
this.text.setCursorSelection(this.displayCursorPos, this.displayCursorPosSelection); this.text.setCursorSelection(this.displayCursorPos, this.displayCursorPosSelection);
} else { } else {
this.text.setCursorPos(this.displayCursorPos); this.text.setCursorPos(this.displayCursorPos);
} }
*/
char[] valueToDisplay = this.propertyValue.toCharArray(); char[] valueToDisplay = this.propertyValue.toCharArray();
if (this.propertyPassword) { if (this.propertyPassword) {
Arrays.fill(valueToDisplay, '*'); Arrays.fill(valueToDisplay, '*');
} }
if (valueToDisplay.length != 0) { if (valueToDisplay.length != 0) {
this.text.print(new String(valueToDisplay)); this.gc.text(tmpOriginText.add(this.displayStartPosition, 0), new String(valueToDisplay));
} else if (this.propertyTextWhenNothing != null) { } else if (this.propertyTextWhenNothing != null) {
this.text.printDecorated(this.propertyTextWhenNothing); this.gc.text(tmpOriginText.add(this.displayStartPosition, 0), this.propertyTextWhenNothing);
} }
this.text.setClippingMode(false);
this.shape.setShape(tmpOriginShaper, tmpSizeShaper, tmpOriginText, tmpSizeText); this.shape.setShape(tmpOriginShaper, tmpSizeShaper, tmpOriginText, tmpSizeText);
this.text.flush(); this.gc.flush();
this.shape.flush(); this.shape.flush();
} }
/** /**
* Periodic call to update grapgic display * Periodic call to update grapgic display
* @param _event Time generic event * @param _event Time generic event
*/ */
protected void periodicCall(final EventTime event) { protected void periodicCall(final EventTime event) {
if (!this.shape.periodicCall(event)) { if (!this.shape.periodicCall(event)) {
this.periodicConnectionHanble.disconnect(); this.periodicConnectionHanble.disconnect();
@ -690,13 +688,13 @@ public class Entry extends Widget {
relPos = relPos.withX(relPos.x() - this.displayStartPosition - padding.left()); relPos = relPos.withX(relPos.x() - this.displayStartPosition - padding.left());
// try to find the new cursor position : // try to find the new cursor position :
String tmpDisplay = this.propertyValue.substring(0, this.displayStartPosition); String tmpDisplay = this.propertyValue.substring(0, this.displayStartPosition);
int displayHidenSize = (int) this.text.calculateSize(tmpDisplay).x(); int displayHidenSize = this.gc.calculateTextSize(tmpDisplay).x();
//Log.debug("hidenSize : " + displayHidenSize); //Log.debug("hidenSize : " + displayHidenSize);
int newCursorPosition = -1; int newCursorPosition = -1;
int tmpTextOriginX = (int) padding.left(); int tmpTextOriginX = (int) padding.left();
for (int iii = 0; iii < this.propertyValue.length(); iii++) { for (int iii = 0; iii < this.propertyValue.length(); iii++) {
tmpDisplay = this.propertyValue.substring(0, iii); tmpDisplay = this.propertyValue.substring(0, iii);
int tmpWidth = (int) (this.text.calculateSize(tmpDisplay).x() - displayHidenSize); int tmpWidth = this.gc.calculateTextSize(tmpDisplay).x() - displayHidenSize;
if (tmpWidth >= relPos.x() - tmpTextOriginX) { if (tmpWidth >= relPos.x() - tmpTextOriginX) {
newCursorPosition = iii; newCursorPosition = iii;
break; break;
@ -734,7 +732,7 @@ public class Entry extends Widget {
tmpSizeX = (int) this.size.x(); tmpSizeX = (int) this.size.x();
} }
int tmpUserSize = (int) (tmpSizeX - padding.x()); int tmpUserSize = (int) (tmpSizeX - padding.x());
int totalWidth = (int) this.text.calculateSize(this.propertyValue).x(); int totalWidth = this.gc.calculateTextSize(this.propertyValue).x();
// Check if the data inside the display can be contain in the entry box // Check if the data inside the display can be contain in the entry box
if (totalWidth < tmpUserSize) { if (totalWidth < tmpUserSize) {
// all can be display : // all can be display :
@ -742,8 +740,8 @@ public class Entry extends Widget {
} else { } else {
// all can not be set : // all can not be set :
String tmpDisplay = this.propertyValue.substring(0, this.displayCursorPos); String tmpDisplay = this.propertyValue.substring(0, this.displayCursorPos);
int pixelCursorPos = (int) this.text.calculateSize(tmpDisplay).x(); int pixelCursorPos = this.gc.calculateTextSize(tmpDisplay).x();
// check if the Cussor is visible at 10px nearest the border : // check if the Cursor is visible at 10px nearest the border :
int tmp1 = pixelCursorPos + this.displayStartPosition; int tmp1 = pixelCursorPos + this.displayStartPosition;
Log.debug("cursorPos=" + pixelCursorPos + "px maxSize=" + tmpUserSize + "px tmp1=" + tmp1); Log.debug("cursorPos=" + pixelCursorPos + "px maxSize=" + tmpUserSize + "px tmp1=" + tmp1);
if (tmp1 < 10) { if (tmp1 < 10) {