glVertexAttribDivisor: Unterschied zwischen den Versionen

Aus DGL Wiki
Wechseln zu: Navigation, Suche
(Siehe auch)
(Beispiel)
 
(4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 2: Zeile 2:
  
 
== Name ==
 
== Name ==
'''glVertexAttribDivisor''' - Definiert ein generisches AttribDivisor.
+
'''glVertexAttribDivisor''' - Sagt wie das Vertex-Attribut verwendet wird.
  
 
== Delphi-Spezifikation ==
 
== Delphi-Spezifikation ==
Zeile 17: Zeile 17:
 
|-
 
|-
 
! ''divisor''  
 
! ''divisor''  
| Normalerweise '''1'''.
+
| Gibt an, wie das Vertex-Attribut verwendet wird<br>
 +
* '''0''' Gewöhnliches Vertex-Attribut<br>
 +
* '''>= 1''' Instance-Vertex-Attribut<br>
 +
Gibt an bei wie vielten Durchgang der Attribut-Zeiger erhöht wird. Meistens wird '''1''' verwendet.
 
|}
 
|}
 
  
 
== Beschreibung ==  
 
== Beschreibung ==  
Zeile 30: Zeile 32:
 
const
 
const
 
// Konstanten für ein Quadrat
 
// Konstanten für ein Quadrat
   square_vertices: array[0..1] of TFace3D =
+
   VectorPos: array[0..5] of TVector2f =
     (((-0.8, -0.8, 0.0), (-0.8, 0.8, 0.0), (0.8, 0.8, 0.0)),
+
     ((-0.8, -0.8), (-0.8, 0.8), (0.8, 0.8),
     ((-0.8, -0.8, 0.0), (0.8, -0.8, 0.0), (0.8, 0.8, 0.0)));
+
     (-0.8, -0.8), (0.8, -0.8), (0.8, 0.8));
  
 
// Konstanten der Instancen
 
// Konstanten der Instancen
   instance_position: array[0..3] of TVector3f =
+
   Instance_Pos: array[0..3] of TVector3f =
 
     ((-2.0, -2.0, 0.0), (2.0, -2.0, 0.0), (2.0, 2.0, 0.0), (-2.0, 2.0, 0.0));
 
     ((-2.0, -2.0, 0.0), (2.0, -2.0, 0.0), (2.0, 2.0, 0.0), (-2.0, 2.0, 0.0));
 
...
 
...
Zeile 41: Zeile 43:
 
   // VBO inizialisieren
 
   // VBO inizialisieren
 
   glBindBuffer(GL_ARRAY_BUFFER, VBOInstancePos);
 
   glBindBuffer(GL_ARRAY_BUFFER, VBOInstancePos);
   glBufferData(GL_ARRAY_BUFFER, SizeOf(instance_position), @instance_position, GL_STATIC_DRAW);
+
   glBufferData(GL_ARRAY_BUFFER, SizeOf(Instance_Pos), @Instance_Pos, GL_STATIC_DRAW);
 
   glEnableVertexAttribArray(2);
 
   glEnableVertexAttribArray(2);
 
   glVertexAttribPointer(2, 3, GL_FLOAT, False, 0, nil);
 
   glVertexAttribPointer(2, 3, GL_FLOAT, False, 0, nil);
   glVertexAttribDivisor(2, 1);
+
   glVertexAttribDivisor(2, 1); // Bei jeden Durchgang um 1 erhöhen
  
 
...
 
...
Zeile 51: Zeile 53:
 
   glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, Face_Count, Instance_Count);
 
   glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, Face_Count, Instance_Count);
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
== Siehe auch ==
 
== Siehe auch ==

Aktuelle Version vom 27. Juli 2018, 21:26 Uhr

glVertexAttribDivisor

Name

glVertexAttribDivisor - Sagt wie das Vertex-Attribut verwendet wird.

Delphi-Spezifikation

procedure glVertexAttribDivisor(index: GLuint; divisor: GLuint);

Parameter

index Gibt den Index des Vertexattributs an.
divisor Gibt an, wie das Vertex-Attribut verwendet wird
  • 0 Gewöhnliches Vertex-Attribut
  • >= 1 Instance-Vertex-Attribut

Gibt an bei wie vielten Durchgang der Attribut-Zeiger erhöht wird. Meistens wird 1 verwendet.

Beschreibung

glVertexAttribDivisor Wird im Zusammenhang mit glDrawArraysInstanced gebraucht.

Beispiel

const
// Konstanten für ein Quadrat
  VectorPos: array[0..5] of TVector2f =
    ((-0.8, -0.8), (-0.8, 0.8), (0.8, 0.8),
    (-0.8, -0.8), (0.8, -0.8), (0.8, 0.8));

// Konstanten der Instancen
  Instance_Pos: array[0..3] of TVector3f =
    ((-2.0, -2.0, 0.0), (2.0, -2.0, 0.0), (2.0, 2.0, 0.0), (-2.0, 2.0, 0.0));
...

  // VBO inizialisieren
  glBindBuffer(GL_ARRAY_BUFFER, VBOInstancePos);
  glBufferData(GL_ARRAY_BUFFER, SizeOf(Instance_Pos), @Instance_Pos, GL_STATIC_DRAW);
  glEnableVertexAttribArray(2);
  glVertexAttribPointer(2, 3, GL_FLOAT, False, 0, nil);
  glVertexAttribDivisor(2, 1); // Bei jeden Durchgang um 1 erhöhen

...

  // Zeichnen mit Instancen 
  glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, Face_Count, Instance_Count);

Siehe auch

Vertex Array Object

glArrayElement, glBindAttribLocation, glDisableVertexAttribArray, glDrawArrays, glDrawElements, glDrawRangeElements, glEnableVertexAttribArray, glMultiDrawArrays, glMultiDrawElements, glPopClientAttrib, glPushClientAttrib, glVertexAttrib