glVertexAttribDivisor: Unterschied zwischen den Versionen

Aus DGL Wiki
Wechseln zu: Navigation, Suche
(Siehe auch)
(Beispiel)
Zeile 30: Zeile 30:
 
const
 
const
 
// Konstanten für ein Quadrat
 
// Konstanten für ein Quadrat
   square_vertices: array[0..1] of TFace3D =
+
   VPos: 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 41:
 
   // 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);
Zeile 51: Zeile 51:
 
   glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, Face_Count, Instance_Count);
 
   glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, Face_Count, Instance_Count);
 
</syntaxhighlight>
 
</syntaxhighlight>
 
  
 
== Siehe auch ==
 
== Siehe auch ==

Version vom 21. Juli 2018, 21:14 Uhr

glVertexAttribDivisor

Name

glVertexAttribDivisor - Definiert ein generisches AttribDivisor.

Delphi-Spezifikation

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

Parameter

index Gibt den Index des Vertexattributs an.
divisor Normalerweise 1.


Beschreibung

glVertexAttribDivisor Wird im Zusammenhang mit glDrawArraysInstanced gebraucht.

Beispiel

const
// Konstanten für ein Quadrat
  VPos: 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);

...

  // 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