Skip to content

Commit 58e7bda

Browse files
author
gabriel
committed
Revert "Basic shadow implement"
This reverts commit 84a81a7.
1 parent 84a81a7 commit 58e7bda

6 files changed

Lines changed: 31 additions & 116 deletions

File tree

res/raw/core_native_view.frag

Lines changed: 0 additions & 63 deletions
This file was deleted.

res/raw/core_native_view.vert

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/br/nullexcept/mux/core/texel/GLProgramView.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
package br.nullexcept.mux.core.texel;
22

3-
import br.nullexcept.mux.utils.BufferUtils;
4-
53
class GLProgramView extends GLProgram {
64
private final String fragment;
75
private final String vertex;
86

97
GLProgramView(){
10-
fragment = BufferUtils.utfFromStream(getClass().getResourceAsStream("/res/raw/core_native_view.frag"));
11-
vertex = BufferUtils.utfFromStream(getClass().getResourceAsStream("/res/raw/core_native_view.vert"));
8+
fragment =
9+
"precision mediump float;\n" +
10+
"\n" +
11+
"uniform float alpha;\n" +
12+
"uniform float time;\n" +
13+
"uniform sampler2D __texture__;\n" +
14+
"varying vec2 xuv;\n" +
15+
"\n" +
16+
"void main(){\n" +
17+
" vec4 pixel = texture2D(__texture__, xuv);\n" +
18+
" pixel.a *= alpha;\n" +
19+
" if(pixel.a < 0.001) discard; " +
20+
" gl_FragColor = pixel;\n" +
21+
"}";
22+
vertex =
23+
"attribute vec4 __position__;\n" +
24+
"attribute vec2 __uv__;\n" +
25+
"\n" +
26+
"varying vec2 xuv;\n" +
27+
"\n" +
28+
"void main(){\n" +
29+
" gl_Position = vec4(__position__.xy,0.0, 1.0);\n" +
30+
" xuv = __uv__ ;\n" +
31+
"}";
1232
}
1333

1434
@Override

src/br/nullexcept/mux/core/texel/GLTexel.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package br.nullexcept.mux.core.texel;
22

33
import br.nullexcept.mux.graphics.Color;
4-
import br.nullexcept.mux.lang.Function;
5-
import br.nullexcept.mux.lang.Function2;
6-
import br.nullexcept.mux.view.View;
74
import org.lwjgl.BufferUtils;
85

96
import java.nio.FloatBuffer;
10-
import java.util.List;
117

128
import static br.nullexcept.mux.hardware.GLES.*;
139

@@ -56,9 +52,9 @@ public static void drawTexture(float x, float y, float width, float height, GLTe
5652
drawTexture(x, y, width, height, GLShaderList.TEXTURE, texture.getTexture());
5753
}
5854

59-
public static void drawViewLayers(float[][] vertices, int[] textures, View[] views){
55+
public static void drawViewLayers(float[][] vertices, int[] textures, float[] alphas){
6056
glEnable(GL_BLEND);
61-
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
57+
glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
6258
GLProgram program = GLShaderList.VIEW;
6359

6460
program.bind();
@@ -68,15 +64,11 @@ public static void drawViewLayers(float[][] vertices, int[] textures, View[] vie
6864
int uTexture = program.uniform(GLProgram.UNIFORM_TEXTURE);
6965
int uAlpha = program.uniform("alpha");
7066
int uTime = program.uniform("time");
71-
int uMode = program.uniform("mode");
72-
int uSize = program.uniform("size");
73-
int uElevation = program.uniform("elevation");
74-
int uShadowColor = program.uniform("shadowColor");
7567

7668
glEnableVertexAttribArray(vPosition);
7769
glEnableVertexAttribArray(vTextureCoords);
7870

79-
Function2<Integer, Integer> draw = (i, mode) -> {
71+
for (int i = 0; i < vertices.length; i++) {
8072
bufferRect.put(vertices[i]);
8173
bufferRect.position(0);
8274

@@ -85,27 +77,10 @@ public static void drawViewLayers(float[][] vertices, int[] textures, View[] vie
8577
glVertexAttribPointer(vTextureCoords, 2, GL_FLOAT, false, 0, bufferUV);
8678

8779
glUniform1i(uTexture, GL_TEXTURE_2D);
88-
glUniform1i(uMode, mode);
89-
glUniform1f(uElevation, views[i].getElevation());
90-
glUniform1f(uAlpha, views[i].getAlpha());
91-
glUniform4f(uShadowColor,
92-
Color.red(views[i].getShadowColor()) / 255.0f,
93-
Color.green(views[i].getShadowColor()) / 255.0f,
94-
Color.blue(views[i].getShadowColor()) / 255.0f,
95-
Color.alpha(views[i].getShadowColor()) / 255.0f
96-
);
97-
98-
glUniform2f(uSize, views[i].getWidth(), views[i].getHeight());
80+
glUniform1f(uAlpha, alphas[i]);
9981
glUniform1f(uTime, (System.currentTimeMillis() & 1000)/1000.0f);
10082
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
10183
glDisable(GL_DEPTH_TEST);
102-
};
103-
104-
for (int i = 0; i < views.length; i++) {
105-
if (views[i].getElevation() > 0.001f) {
106-
draw.run(i, 1); // Draw shadow
107-
}
108-
draw.run(i, 0);
10984
}
11085

11186
program.unbind();

src/br/nullexcept/mux/core/texel/ViewRenderer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ public void drawInternal(CanvasTexel canvas, View view){
4040
}
4141
}
4242
float[][] borders = new float[drawables][2*4];
43-
View[] list = new View[drawables];
43+
float[] alphas = new float[drawables];
4444
int[] textures = new int[drawables];
4545
int index = 0;
4646
for (View child: children){
4747
if (child.isVisible()){
4848
CanvasTexel texel = registry.get(child.hashCode()).canvas;
4949
borders[index] = createMesh(canvas, child);
50-
list[index] = child;
50+
alphas[index] = child.getAlpha();
5151
textures[index] = texel.getFramebuffer().getTexture().getTexture();
5252
index++;
5353
}
5454
}
5555
canvas.getFramebuffer().bind();
56-
GLTexel.drawViewLayers(borders,textures, list);
56+
GLTexel.drawViewLayers(borders,textures, alphas);
5757
canvas.getFramebuffer().unbind();
5858
canvas.begin();
5959
}

src/br/nullexcept/mux/view/View.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,6 @@ public Object getTag() {
530530
return tag;
531531
}
532532

533-
public int getShadowColor() {
534-
return Color.argb(20,1,0,0);
535-
}
536-
537-
public float getElevation() {
538-
return 0.0f;
539-
}
540-
541533
public interface OnClickListener {
542534
void onClick(View view);
543535
}

0 commit comments

Comments
 (0)