DGL
https://delphigl.com/forum/

Block Uniform
https://delphigl.com/forum/viewtopic.php?f=20&t=11338
Seite 1 von 1

Autor:  mathias [ Mi Feb 04, 2015 23:00 ]
Betreff des Beitrags:  Block Uniform

In dem Shader-Object habe ich colx als vec3 deklariert.
Wieso funktioniert die Übergabe bei glBufferData mit TVector4f und mit TVector3f nicht ?
Mit TVector3f wird mein Object rot, anstelle grün.
Es müsste ja eigentlich umgekehrt sein. :roll:
Code:
  1. // --- TVector4f
  2.  
  3. type
  4.   TMaterial4 = packed record
  5.     col1, col2: TVector4f;
  6.   end;
  7.  
  8. const
  9.   Material4: TMaterial4 = (
  10.     col1: (1.0, 1.0, 1.0, 1.0);
  11.     col2: (0.0, 1.0, 0.0, 1.0));
  12.  
  13.   // --- TVector3f
  14.  
  15. type
  16.   TMaterial3 = packed record
  17.     col1, col2: TVector3f;
  18.   end;
  19.  
  20. const
  21.   Material3: TMaterial3 = (
  22.     col1: (1.0, 1.0, 1.0);
  23.     col2: (0.0, 1.0, 0.0)); // col2 ist rot.
  24. ....
  25.  
  26. glBufferData(GL_UNIFORM_BUFFER, sizeof(Material4), @Material4, GL_DYNAMIC_DRAW); // geht
  27. glBufferData(GL_UNIFORM_BUFFER, sizeof(Material3), @Material3, GL_DYNAMIC_DRAW); // geht nicht


Code:
  1. #version 330
  2.  
  3. layout (std140) uniform allUniforms {
  4.   vec3 col1;
  5.   vec3 col2;
  6. };
  7.  
  8. out vec4 OutColor;
  9.  
  10. void main()
  11. {
  12.   OutColor = vec4(col1 * col2, 0);
  13. }

Autor:  end [ Do Feb 05, 2015 03:45 ]
Betreff des Beitrags:  Re: Block Uniform

Lies dir mal die Spec vom std140 Speicherlayout durch ;)

Faustregel: Es wird oft nach vec4 aligned.

Autor:  mathias [ Do Feb 05, 2015 18:01 ]
Betreff des Beitrags:  Re: Block Uniform

http://www.opentk.com/node/2926
Da ist es beschrieben, wie std140 funktioniert.
Code:
  1. The shader variable alignment is as follows: (I'll only cover the basic floats here, but the principle applies all round)
  2. vec4 - 4N
  3. vec3 - 4N
  4. vec2 - 2N
  5. float - N


Komischweise geht dies auch nicht, obwohl dort packed steht.
Code:
  1. layout (packed) uniform allUniforms {
  2.   vec3 col1;
  3.   vec3 col2;
  4. };  





Bei diesem Code müsste bei der ID-Ermittlung eine 2 kommen. aber bei mir kommt eine 0.
Code:
  1. layout (location = 2, std140) uniform allUniforms {
  2.   vec3 col1;
  3.   vec3 col2;
  4. };  
Code:
  1.     Mat_ID := glGetUniformBlockIndex(Program_ID, 'allUniforms');
  2.     Writeln('Mat_ID: ', Mat_ID);
  3.     glUniformBlockBinding(Program_ID, Mat_ID, bindingPoint);  


Bei inPos, kommt eine 3. :roll:
Code:
  1. layout (location = 3) in vec4 inPos;  

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/