Good news

classic Classic list List threaded Threaded
11 messages Options
adi
Reply | Threaded
Open this post in threaded view
|

Good news

adi
This post was updated on .
Uniform Blocks works good with jogl.
I have tested it with some shaders und objects that make bindings to
the projection matrix on a NVIDEA GTX TITAN Z and GTX 780.
The vertex shader source is:

#version 440 core
layout (location=0) in vec4 position;
layout (location=5) uniform dmat4 modelViewMatrix;
layout (location=2)out vec3 texCoord;

layout (shared,binding=0) uniform GlobalDatas {
    dmat4 projectionsMatrix;
};

layout (shared,binding=1) uniform GlobalDatasDynamic {
    dvec3 cameraPosition;
};

void main()
{
    texCoord = position.xyz;
    dvec4 posi = projectionsMatrix*modelViewMatrix*dvec4(position);
    gl_Position = vec4(posi);
}
Reply | Threaded
Open this post in threaded view
|

Re: Good news

gouessej
Administrator
Hi

Have you tried with more complicated uniform blocks? Good to know it works.
Julien Gouesse | Personal blog | Website
adi
Reply | Threaded
Open this post in threaded view
|

Re: Good news

adi
This post was updated on .
Hi also

In the next days i will test it with more complicated uniform blocks.
But i think, there will be no problems with it.
adi
Reply | Threaded
Open this post in threaded view
|

Re: Good news

adi
In reply to this post by gouessej
Hi

Your are right, complexer datas are not read correct in.
I habe send this with  

gl.glBindBufferRange(GL4.GL_UNIFORM_BUFFER, 2, uboBuffer[2], 0, size);
gl.glBufferData(GL4.GL_UNIFORM_BUFFER, size, storage, GL4.GL_STATIC_DRAW);

The datas in the ByteBuffer storage are correct, i have testet it before.

In that uniform block

layout (shared,binding=2) uniform LightDatas {
vec4 lightPosition;
vec4 specular;
vec4 lightColor;
float ambientCoefficient;
float constantAttenuation;
float linearAttenuation;
float quadraticAttenuation;
float spotCutoff;
float spotCosCutoff;
float shininess;
vec3 spotDirection;
}

all datas are set to 0.0
Only simple datas with one element works .

Can it be, that the method glBufferData can not handle the data type ByteBuffer correct?
ByteBuffer holds different java data types.

Reply | Threaded
Open this post in threaded view
|

Re: Good news

gouessej
Administrator
I don't think that glBufferData does something wrong. Does your example work in plain C?
Julien Gouesse | Personal blog | Website
adi
Reply | Threaded
Open this post in threaded view
|

Re: Good news

adi
I write only in java.
 
I have 3 uniform blocks:

layout (shared,binding=0) uniform GlobalDatas {
    dmat4 projectionsMatrix;
};

layout (shared,binding=1) uniform GlobalDatasDynamic {
    dvec3 cameraPosition;
};

layout (shared,binding=2) uniform LightDatas {
    vec4 lightPosition;
    vec4 specular;
    vec4 lightColor;
    float ambientCoefficient;
    float constantAttenuation;
    float linearAttenuation;
    float quadraticAttenuation;
    float spotCutoff;
    float spotCosCutoff;
    float shininess;
    vec3 spotDirection;
} ;

The datas in the buffers is send with this commands:

gl.glGenBuffers( uboBuffer.length, uboBuffer, 0);

gl.glBindBufferRange(GL4.GL_UNIFORM_BUFFER, 0, uboBuffer[0], 0, 128);
gl.glBufferData(GL4.GL_UNIFORM_BUFFER, 128 , projectionsBuffer, GL4.GL_STATIC_DRAW);
( projectionsBuffer is a DoubleBuffer)

gl.glBindBufferRange(GL4.GL_UNIFORM_BUFFER, BINDING_POINT_1, uboBuffer[1], 0, 16);
gl.glBufferData(GL4.GL_UNIFORM_BUFFER, 16 , null, GL4.GL_STREAM_DRAW);
(room for dynamic vector )

gl.glBindBufferRange(GL4.GL_UNIFORM_BUFFER, BINDING_POINT_2, uboBuffer[2], 0, size);
gl.glBufferData(GL4.GL_UNIFORM_BUFFER, size, storage, GL4.GL_STATIC_DRAW);
(storage is a ByteBuffer)

Only the values from the first and second block (from the projectionsBuffer and the dynamic vector)
are correct reachable and correct in the shader.
The datas in the third buffer are not correct, all set to null,
how a fresh created buffer.


 

 
adi
Reply | Threaded
Open this post in threaded view
|

Re: Good news

adi
This post was updated on .
In reply to this post by gouessej
Hi

Now i have it, the third Buffer works also now.
Problem was, the both function's glBufferData and glBufferSubData,
can't handle ByteBuffer's.
With FloatBuffer an DoubleBuffer they work correkt.
All datas are now correct present in the Shader.

That is problematic, if some other datas as only float's and double's
must be used, how a mix von java data types, that is in the moment
not possible. Only ByteBuffer can handle mixed java data types.
In java i have no structs :-)  And simple (data) classes can the
function's not handle.

The problem must lie in the functions, then only a simlple change from
ByteBuffer to FloatBuffer was taken, and all works's correct.
It seems i have found a bug in the driver?

But it works at last:


     
 
Reply | Threaded
Open this post in threaded view
|

Re: Good news

gouessej
Administrator
Please provide a small unit test. Maybe there is a small detail that makes it work with ByteBuffer, it depends on how you create it. Good job :)
Julien Gouesse | Personal blog | Website
adi
Reply | Threaded
Open this post in threaded view
|

Re: Good news

adi
Hi

I have found the error.
Ih have used now
ByteBuffer.allocateDirect( dataLength ).order(ByteOrder.nativeOrder());
then it works.
ByteBuffer.allocate( dataLength ); is not enough:-)
Reply | Threaded
Open this post in threaded view
|

Re: Good news

Sven Gothel
Administrator
On 09/08/2014 11:07 AM, adi [via jogamp] wrote:
> Hi
>
> I have found the error.
> Ih have used now
> *ByteBuffer.allocateDirect( dataLength ).order(ByteOrder.nativeOrder());*
> then it works.
> *ByteBuffer.allocate( dataLength );* is not enough:-)

Yup .. we use this in our Buffers class as well.



signature.asc (828 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Good news

gouessej
Administrator
adi should have called this method:
http://jogamp.org/deployment/jogamp-next/javadoc/gluegen/javadoc/com/jogamp/common/nio/Buffers.html#newDirectByteBuffer(int)

which takes care of the native byte order. com.jogamp.common.nio.Buffers should always be used to create direct NIO buffers for JOGL except when the design of an engine doesn't allow you to do so (then you have to do exactly the same operations in your own code).
Julien Gouesse | Personal blog | Website