22
33import br .nullexcept .mux .graphics .Color ;
44import org .lwjgl .BufferUtils ;
5+ import org .lwjgl .opengles .OESDrawBuffersIndexed ;
56
67import java .nio .FloatBuffer ;
78
@@ -54,42 +55,57 @@ public static void drawTexture(float x, float y, float width, float height, GLTe
5455
5556 public static void drawViewLayers (float [][] vertices , int [] textures , float [] alphas ){
5657 glEnable (GL_BLEND );
57- glBlendFuncSeparate (GL_ONE , GL_ONE_MINUS_SRC_ALPHA , GL_ONE , GL_ONE_MINUS_SRC_ALPHA );
58- GLProgram program = GLShaderList .VIEW ;
58+ /**
59+ * X = FUNC SRC
60+ * Y = FUNC DST
61+ *
62+ * dstColor = src.rgb * X + dest.rgb * Y;
63+ */
64+ glBlendFuncSeparate (
65+ GL_ONE ,
66+ GL_ONE_MINUS_SRC_ALPHA ,
67+ GL_ONE ,
68+ GL_ONE_MINUS_SRC_ALPHA
69+ );
70+
71+
72+ GLProgramView program = GLShaderList .VIEW ;
5973
6074 program .bind ();
61-
62- int vPosition = program .attribute (GLProgram .ATTRIBUTE_POSITION );
63- int vTextureCoords = program .attribute (GLProgram .ATTRIBUTE_UV );
64- int uTexture = program .uniform (GLProgram .UNIFORM_TEXTURE );
65- int uAlpha = program .uniform ("alpha" );
66- int uTime = program .uniform ("time" );
67-
68- glEnableVertexAttribArray (vPosition );
69- glEnableVertexAttribArray (vTextureCoords );
75+ glEnableVertexAttribArray (program .position );
76+ glEnableVertexAttribArray (program .uv );
7077
7178 for (int i = 0 ; i < vertices .length ; i ++) {
7279 bufferRect .put (vertices [i ]);
7380 bufferRect .position (0 );
7481
7582 glBindTexture (GL_TEXTURE_2D , textures [i ]);
76- glVertexAttribPointer (vPosition , 2 , GL_FLOAT , false , 0 , bufferRect );
77- glVertexAttribPointer (vTextureCoords , 2 , GL_FLOAT , false , 0 , bufferUV );
7883
79- glUniform1i (uTexture , GL_TEXTURE_2D );
80- glUniform1f (uAlpha , alphas [i ]);
81- glUniform1f (uTime , (System .currentTimeMillis () & 1000 )/1000.0f );
84+ glVertexAttribPointer (program .position , 2 , GL_FLOAT , false , 0 , bufferRect );
85+ glVertexAttribPointer (program .uv , 2 , GL_FLOAT , false , 0 , bufferUV );
86+
87+ glUniform1iv (program .params , new int []{});
88+
89+ glUniform1i (program .texture , GL_TEXTURE_2D );
8290 glDrawArrays (GL_TRIANGLE_STRIP , 0 , 4 );
83- glDisable ( GL_DEPTH_TEST );
91+ glFinish ( );
8492 }
8593
8694 program .unbind ();
8795 glBindTexture (GL_TEXTURE_2D , 0 );
8896 }
8997
98+
99+ private static FloatBuffer allocateVertices (float [][] vectors ) {
100+ FloatBuffer vertx = BufferUtils .createFloatBuffer (vectors .length *vectors [0 ].length );
101+ vertx .position (0 );
102+ for (int i = 0 ; i < vectors .length ; i ++)
103+ vertx .put (vectors [i ]);
104+ vertx .position (0 );
105+ return vertx ;
106+ }
107+
90108 public static void drawTexture (float x , float y , float width , float height , GLProgram program , int texture ){
91- glEnable (GL_BLEND );
92- glBlendFunc (GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA );
93109 prepareRect (x , y , width , height );
94110 //bufferColor.put(new float[]{ Color.red(color)/255.0f, Color.green(color)/255.0f, Color.blue(color)/255.0f, Color.alpha(color)/255.0f });
95111 program .bind ();
@@ -113,6 +129,5 @@ public static void drawTexture(float x, float y, float width, float height, GLPr
113129 glDrawArrays (GL_TRIANGLE_STRIP , 0 , 4 );
114130 program .unbind ();
115131 glBindTexture (GL_TEXTURE_2D ,0 );
116- glDisable (GL_DEPTH_TEST );
117132 }
118133}
0 commit comments