Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


syskrank

Member Since 31 Mar 2014
Offline Last Active Nov 26 2014 04:25 AM

Posts I've Made

In Topic: libgdx unwanted gaps btw tiles/objects

05 September 2014 - 12:18 PM

Allright, after some digging and experiments here the complex solution:

 

To avoid gaps between objects or graphics entities in a libGDX application one should:

 

1. ensure to use floats everywhere - even for storing target screen resolution, to avoid unwanted casts and following precision loss; OpenGL is using floats for positioning, so should you;

 

2. use power-of-two textures: those with side sizes aliquot to 2^x - 32x32, 16x64, 128x256 and so on; doing so will satisfy the minimization of memory usage on GPU and will help to avoid texture coordinates distortions due to float-int casts, that may or may not happen whithin the rendering process ( whatch for your shaders and datatypes );

 

3. use POT textures even if documentation says that you can do the opposite; POTs are great;

 

4. try to use NEAREST filtering for loaded textures and texture atlases; this would protect you from wrong 'pixel mix', when OpenGL will try to average your color-filled pixels with transparent ones; however, for me that showed no significant results;

 

5. hit your artist smile.png ensure that all of your full-frame graphics elements have no transparent or half-transparent pixels at the edges - sith happens, you now smile.png

 

6.  use tight alignment and/or scale your objects just a little bit, so that they will overlay each other.

 

_____

Hope that would help someone. Cheers.


In Topic: uniforms optimized-out

14 August 2014 - 09:11 AM

Hi, Stainless.

What do you mean by sanity check?

I've tried playing with shader 'version' string with no luck.

 

Edit: I mentioned that my Java Shader object detects only the first element of the uniform array:  'useBoneWeight[0]' and 'boneTransform[0]' are located;

So, theoretically, I can use OpenGL's glUniform*() capabilities to send a whole array of data to the shader.

I will try that somehow.

 

 

What OS/GPU do you run it on?

 

I'm developing on two machines with Linux Mint 16 and Linux Debian 7 resp.

First system has Intel HD4000 and NV GF740M cards ( tried both ) and the last one has NV GT630. I'm using libgdx 1.2.0.

Android emulator produces same results.


In Topic: uniforms optimized-out

14 August 2014 - 03:44 AM

Ok, here it is. I'm building on top of libgdx' ShaderProgram :

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.Disposable;

import java.util.Map;
import java.util.HashMap;

public class Shader implements Disposable {
    public ShaderProgram program;
    public Map<String, Integer> uniforms;
    public final static String SHADER_TAG = Shader.class.getSimpleName();

    public static final int SHADER_OK = 0;
    public static final int SHADER_ERROR = 1;

    public Shader( String vertexShader, String fragmentShader ) {
        ShaderProgram.pedantic = false;
        program = new ShaderProgram( Gdx.files.internal( vertexShader ), Gdx.files.internal( fragmentShader ) );
        if ( program.isCompiled() ) {
            Gdx.app.log( SHADER_TAG, "Shader compiled." );
        } else {
            Gdx.app.log( SHADER_TAG, "Shader compilation failed: " + program.getLog() );
        }
        uniforms = new HashMap<String, Integer>();
    }

    public void bind() {
        program.begin();
    }

    public void unbind() {
        program.end();
    }

    public int addUniform( String name ) {
        int location = program.getUniformLocation( name );
        if ( -1 == location ) {
            Gdx.app.log( SHADER_TAG, "Failed to get uniform's '" + name + "' location." );
            return SHADER_ERROR;
        } else {
            uniforms.put( name, location );
        }
        return SHADER_OK;
    }

    public int setUniformInt( String name, int value ) {
        Integer location = uniforms.get( name );
        if ( null == location ) {
            Gdx.app.log( SHADER_TAG, "Integer uniform '" + name + "' doesn't exists." );
            return SHADER_ERROR;
        } else {
            program.setUniformi( location.intValue(), value );
        }
        return SHADER_OK;
    }

    public int setUniformFloat( String name, float value ) {
        Integer location = uniforms.get( name );
        if ( null == location ) {
            Gdx.app.log( SHADER_TAG, "Float uniform '" + name + "' doesn't exists." );
            return SHADER_ERROR;
        } else {
            program.setUniformf( location.intValue(), value );
        }
        return SHADER_OK;
    }

    public int setUniformVec2( String name, Vector2 value ) {
        Integer location = uniforms.get( name );
        if ( null == location ) {
            Gdx.app.log( SHADER_TAG, "Vector2 uniform '" + name + "' doesn't exists." );
            return SHADER_ERROR;
        } else {
            program.setUniformf( location.intValue(), value );
        }
        return SHADER_OK;
    }

    public int setUniformVec3( String name, Vector3 value ) {
        Integer location = uniforms.get( name );
        if ( null == location ) {
            Gdx.app.log( SHADER_TAG, "Vector3 uniform '" + name + "' doesn't exists." );
            return SHADER_ERROR;
        } else {
            program.setUniformf( location.intValue(), value );
        }
        return SHADER_OK;
    }

    public int setUniformMat4( String name, Matrix4 value ) {
        Integer location = uniforms.get( name );
        if ( null == location ) {
            Gdx.app.log( SHADER_TAG, "Matrix4 uniform '" + name + "' doesn't exists." );
            return SHADER_ERROR;
        } else {
            program.setUniformMatrix( location.intValue(), value );
        }
        return SHADER_OK;
    }

    @Override
    public void dispose() {
        program.dispose();
    }

}

ShaderProgram, in it's turn, has the following code inside:

    private void fetchUniforms () {
        params.clear();
        Gdx.gl20.glGetProgramiv(program, GL20.GL_ACTIVE_UNIFORMS, params);
        int numUniforms = params.get(0);

        uniformNames = new String[numUniforms];

        for (int i = 0; i < numUniforms; i++) {
            params.clear();
            params.put(0, 1);
            type.clear();
            String name = Gdx.gl20.glGetActiveUniform(program, i, params, type);
            int location = Gdx.gl20.glGetUniformLocation(program, name);
            uniforms.put(name, location);
            uniformTypes.put(name, type.get(0));
            uniformSizes.put(name, params.get(0));
            uniformNames[i] = name;
        }
    }

So, yeah, basically, I'm fetching uniforms not directly from shader, but from libgdx' object, which kind of sucks.


In Topic: libgdx, 3d models, fbx and coordinate system mess

12 August 2014 - 02:08 PM

So, I've managed to find a solution to this wrong FBX model orientation problem.

It's completely a hack, but there's no better solution since fbx-conv, or Blender exported have bugs inside their code.

The solution is: create own Transform class, incorporate it inside GameEntity class and every time you update graphics component's transform, set it's orientation with constant delta offset rotation around X axis by -90 degrees.

Will see in future how this affects skeletons and animations but it SHOULD be Ok.


In Topic: glDrawElements invalid operation

07 June 2014 - 08:45 AM

Thank you, clb, that was really helpful.

 

I've checked for NULL VAOs and incorrect indices count and figured out that meshes like that are really presented within the scene.

Furthermore, I've disabled rendering for them and still every object in the scene is in it's place, which is verty strange. I assume that on the asset loading stage I'm getting some garbage or I'm creating some invalid objects without graphics component and trying to render them.

 

Another strange ( but not suprising ) thing is that on different GPUs I am getting different quantity of spam error messages. The maximum of verbosity is achieved  on AMD HD6670,  nVidia GT630 goes pretty the same, but  nVidia GT740M is a silent dude :)

 

Will try my best with AMD CodeXL, thank you for advice.

 

P.S.

As for GPUs I've mentioned one interesting thing: the GT740M ( on which I am now ) is the only one, who refused to initialize the exact profile and version I demanded.

GT630 and HD6670 giving me 3.3 core profile, while the 740M gives 4.3 core ( I'm initializing with SDL2 and GLEW ).


PARTNERS