Skip to main content
added 261 characters in body
Source Link
    //FragmentVertex shader
    var v_texCoord= var(0.0, 0.0,
                        0.0, 1.0,
                        1.0, 1.0,           
                        1.0, 0.0            
                        ); //Could I init this in the first vertex processing?
    uniformvarying sampler2Dvec2 s_texture;v_texCoord;
    attribute vec4 vPosition;
    void main()
    {
        gl_FragColorgl_Position = texture2D(s_texture,vPosition;" v_texCoord); //Why the second 
 parameter only accepts vec2? I am sending av_texCoord buffer from= Javav_texCoord;" Code  //To fragment shader
    }

Question: is possible put statically UVs in shader?

Performance:
Each blue region represents ONE texture rendering from a FRAME. Maybe its a minimal and unnecessary optimization... enter image description here

    //Fragment shader
    var v_texCoord= var(0.0, 0.0,
                        0.0, 1.0,
                        1.0, 1.0,           
                        1.0, 0.0            
                        );
    uniform sampler2D s_texture;
    void main()
    {
        gl_FragColor = texture2D(s_texture, v_texCoord); //Why the second parameter only accepts vec2? I am sending a buffer from Java Code
    }

Question: is possible put statically UVs in shader?

    //Vertex shader
    var v_texCoord= var(0.0, 0.0,
                        0.0, 1.0,
                        1.0, 1.0,           
                        1.0, 0.0            
                        ); //Could I init this in the first vertex processing?
    varying vec2 v_texCoord;
    attribute vec4 vPosition;
    void main()
    {
        gl_Position = vPosition;"     
        v_texCoord  = v_texCoord;"   //To fragment shader
    }

Question: is possible put statically UVs in shader?

Performance:
Each blue region represents ONE texture rendering from a FRAME. Maybe its a minimal and unnecessary optimization... enter image description here

deleted 1 character in body
Source Link

What I need to do? I tried to put the UVs in the shader code (I believe that is the way) but without success... more or less like this: (I tested more alternatives in the shader/fragment shader too... bellowbelow is only a example of my idea to solve this problem)

What I need to do? I tried to put the UVs in the shader code (I believe that is the way) but without success... more or less like this: (I tested more alternatives in the shader/fragment shader too... bellow is only a example of my idea to solve this problem)

What I need to do? I tried to put the UVs in the shader code (I believe that is the way) but without success... more or less like this: (I tested more alternatives in the shader/fragment shader too... below is only a example of my idea to solve this problem)

Source Link

OpenGLES texture coordinates in shader

Currently I'm doing an android 2D game using OpenGLES 2.0 and I noticed that my UVs never change in all of textures when rendering, like this in Java code:

    public static FloatBuffer vertexUv;

    public static void setUpUV()
    {
        float uvs[] = {0.0f, 0.0f,
                       0.0f, 1.0f,
                       1.0f, 1.0f,          
                       1.0f, 0.0f           
                      };
        ByteBuffer bb = ByteBuffer.allocateDirect(uvs.length*4);
        bb.order(ByteOrder.nativeOrder());
        vertexUv = bb.asFloatBuffer();
        vertexUv.put(uvs);
        vertexUv.position(0);
    }
    ...
    //UV sending in render
    int mTexCoordLoc = glGetAttribLocation(program, "a_texCoord");
    glEnableVertexAttribArray(mTexCoordLoc);
    glVertexAttribPointer(mTexCoordLoc, 2, GL_FLOAT, false, 0, vertexUv);
    ...

The problem is: even the UVs never change, I always sends via Java code to the GPU causing waste of CPU using VBOs or not(I tested it using OpenGLES tracer). All textures of my game is in 2D mode so I believe that I don't need send it every texture rendering.

What I need to do? I tried to put the UVs in the shader code (I believe that is the way) but without success... more or less like this: (I tested more alternatives in the shader/fragment shader too... bellow is only a example of my idea to solve this problem)

    //Fragment shader
    var v_texCoord= var(0.0, 0.0,
                        0.0, 1.0,
                        1.0, 1.0,           
                        1.0, 0.0            
                        );
    uniform sampler2D s_texture;
    void main()
    {
        gl_FragColor = texture2D(s_texture, v_texCoord); //Why the second parameter only accepts vec2? I am sending a buffer from Java Code
    }

Question: is possible put statically UVs in shader?

Thank you!!