c++ - GLSL : uniform buffer object example -


I have an array of variable size GLubyte. I want to pass it to the piece shader. I have seen and therefore I decided to use "Uniform Buffer Objects" but being a newbie in GLSL, I do not know:

1 - If I add it to a piece shader, then I How do I exceed my size? Should i make a straight

  Layout (std140) Uniforme Murera {GLubyte myDataArray [size]; // I do not understand GLSL GLubyte;);   

2- How and how does the C ++ code associate this buffer object?

3 - How to deal with GLubyte casting to float?

1 - If I add it to a piece shader, how do I cross the shape? Can i make a straight Using

Uniform Buffer (UB), you can not do this

Size should be stable and known when you link your GLSL program means that it should be done with hard work in real shaders.

A feature is used in modern ways with GL4 (SSB).

The SSB can have variable lengths (the last field can be declared as an unsized array, such as myDataArray [] ) and they have more data than UB Can archive.

In earlier versions of GL, you use a large amount of dynamic size data compared to SASB, but it is a cheap hack compared to SSB and you have a good struct can not access data using the -like interface.

3 - How to deal with GLubyte casting to float?

You really will not do this at all, it is quite complex.

The smallest data type you can use in a GLSL data structure is 32-bit when you use a special code like packUnorm4x8 (...) uint can pack and unpack data in small pieces.

packUnorm4x8 (.. .. This can be done without using any special GLSL function.

This was done deliberately, small sizes To avoid defining new data types with.) is equivalent to doing the following:

 for  (int i = 0; i <4; i ++) pack = + round (clamp (vec [i], 0, 1) * 255.0) * pow (2, i * 8);   

This takes a 4-component vector of floating-point values ​​in the range [0,1] and fixed-numeric arithmetic, all of them are given an unsigned generalized ( unorm) capturing the 8 bit integer on its own 1/4 uint .

New versions of GLSL show that, but the GPU is actually doing it as soon as the shaders are nearby, for things like that, Ever read / write a GL_RGBA8 texture with a shader packing or unpacking the 4 8-bit Asurians represented by a 32-bit integer.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -