From ea7c800947a82f013c4263add1b75708a93ac396 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 7 Jun 2021 23:26:30 +0200 Subject: [PATCH] [DEV] update shape rendering --- .../ewol/theme/shape/aaRenderShape.vert | 7 ++- .../CompositingGraphicContext.java | 1 + .../atriasoft/ewol/compositing/GuiShape.java | 51 ++++++++++++------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/resources/resources/ewol/theme/shape/aaRenderShape.vert b/resources/resources/ewol/theme/shape/aaRenderShape.vert index e7b436b..09510bb 100644 --- a/resources/resources/ewol/theme/shape/aaRenderShape.vert +++ b/resources/resources/ewol/theme/shape/aaRenderShape.vert @@ -9,6 +9,8 @@ precision mediump int; layout (location = 0) in vec3 in_position; layout (location = 1) in vec2 in_textureCoords; +uniform vec3 in_offsetScale; + uniform mat4 in_matrixTransformation; uniform mat4 in_matrixProjection; uniform mat4 in_matrixView; @@ -17,6 +19,9 @@ uniform mat4 in_matrixView; out vec2 io_textureCoords; void main(void) { - gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * vec4(in_position, 1.0); + vec4 position = vec4(in_position.x + sign(in_position.x)*in_offsetScale.x, + in_position.y + sign(in_position.y)*in_offsetScale.y, + in_position.z + sign(in_position.z)*in_offsetScale.z, 1.0); + gl_Position = in_matrixProjection * in_matrixView * in_matrixTransformation * position; io_textureCoords = in_textureCoords; } diff --git a/src/org/atriasoft/ewol/compositing/CompositingGraphicContext.java b/src/org/atriasoft/ewol/compositing/CompositingGraphicContext.java index 7529f92..58c3ffd 100644 --- a/src/org/atriasoft/ewol/compositing/CompositingGraphicContext.java +++ b/src/org/atriasoft/ewol/compositing/CompositingGraphicContext.java @@ -263,4 +263,5 @@ public class CompositingGraphicContext extends Compositing { public void text(final Vector2f position, final String data) { this.context.text(position, data); } + } diff --git a/src/org/atriasoft/ewol/compositing/GuiShape.java b/src/org/atriasoft/ewol/compositing/GuiShape.java index 5d90ba0..e73a35d 100644 --- a/src/org/atriasoft/ewol/compositing/GuiShape.java +++ b/src/org/atriasoft/ewol/compositing/GuiShape.java @@ -49,13 +49,14 @@ public class GuiShape extends Compositing { private int oGLMatrixTransformation = -1; //!< openGL id on the element (transformation matrix) private int oGLMatrixView = -1; //!< openGL id on the element (view matrix) private int oGLPaletteOffset = -1; //!< openGL id on the element (offset for the palet rendering) + private int oGLOffsetScale = -1; // openGL shaders programs: private ResourceProgram oGLprogram = null; //!< pointer on the opengl display program // For the Image : private ResourcePaletteFile palette; private ResourceTexture2 texture; - private ResourceMesh shape = null; + private ResourceMesh mesh = null; private Padding sizeObject = Padding.ZERO; private int stateActivate = -1; //!< Activate state of the element private GuiShapeMode stateNew = GuiShapeMode.NORMAL; //!< destination state @@ -63,6 +64,8 @@ public class GuiShape extends Compositing { private Matrix4f transform = Matrix4f.IDENTITY; private Uri uri; //!< Name of the configuration of the shaper. + private Vector3f offsetScale = Vector3f.ZERO; + // dynamic change: private float stateTransition = 0; //!< working state between 2 states @@ -148,13 +151,13 @@ public class GuiShape extends Compositing { Matrix4f camMatrix = OpenGL.getCameraMatrix(); Matrix4f tmpMatrix = this.matrixApply.multiply(this.transform); this.oGLprogram.use(); - this.shape.bindForRendering(); + this.mesh.bindForRendering(); this.oGLprogram.uniformMatrix(this.oGLMatrixProjection, projMatrix); this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, tmpMatrix); this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix); - Set layers = this.shape.getLayers(); + Set layers = this.mesh.getLayers(); Log.verbose("get layers:" + layers); // Texture: float imageDelta = (float)1 / ResourcePaletteFile.getHeight(); @@ -184,18 +187,21 @@ public class GuiShape extends Compositing { Log.verbose("colorDelta = " + basicValue + " old = " + this.stateOld + "(" + this.stateOld.getValue()*imageDelta + ") new = " + this.stateNew + "(" + this.stateNew.getValue()*imageDelta + ")"); this.oGLprogram.uniformFloat(this.oGLPaletteOffset, basicValue); + Log.error("plop: " + this.offsetScale); + this.oGLprogram.uniformVector(this.oGLOffsetScale, this.offsetScale); + this.texture.bindForRendering(0); - this.shape.render("palette"); + this.mesh.render("palette"); if (secondaryTexture != null) { this.oGLprogram.uniformFloat(this.oGLPaletteOffset, 0); secondaryTexture.bindForRendering(0); - this.shape.render("gui_dynamic_1"); + this.mesh.render("gui_dynamic_1"); } // Request the draw of the elements: - this.shape.render(); + this.mesh.render(); - this.shape.unBindForRendering(); + this.mesh.unBindForRendering(); this.oGLprogram.unUse(); OpenGL.disable(Flag.flag_depthTest); } @@ -313,8 +319,8 @@ public class GuiShape extends Compositing { } String objectFile = this.config.getString(this.confObjectFile); if (!objectFile.isEmpty()) { - this.shape = ResourceMesh.create(Uri.valueOf(objectFile)); - List verticesToModify = this.shape.getGeneratedPosition(); + this.mesh = ResourceMesh.create(Uri.valueOf(objectFile)); + List verticesToModify = this.mesh.getGeneratedPosition(); float top = 0; float bottom = 0; float left = 0; @@ -351,6 +357,7 @@ public class GuiShape extends Compositing { this.oGLMatrixProjection = this.oGLprogram.getUniform("in_matrixProjection"); this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView"); this.oGLPaletteOffset = this.oGLprogram.getUniform("in_offsetPalette"); + this.oGLOffsetScale = this.oGLprogram.getUniform("in_offsetScale"); } } } @@ -460,7 +467,9 @@ public class GuiShape extends Compositing { public void setShape(final Vector2f origin, final Vector2f size, final Vector2f insidePos, final Vector2f insideSize) { //Log.error("Set shape property : origin=" + origin + " size=" + size + " in-pos=" + insidePos + " in-size=" + insideSize); Vector2f halfSize = insideSize.multiply(0.5f); - List verticesToModify = this.shape.getGeneratedPosition(); + this.offsetScale = new Vector3f(halfSize.x(), halfSize.y(), 1.0f); + /* + List verticesToModify = this.mesh.getGeneratedPosition(); float[] newVertices = new float[verticesToModify.size()*3]; for (int iii=0; iii verticesToModify = this.shape.getGeneratedPosition(); + this.offsetScale = halfSize; + /* + List verticesToModify = this.mesh.getGeneratedPosition(); float[] newVertices = new float[verticesToModify.size()*3]; for (int iii=0; iii