Class TGeometryArrays

Unit

Declaration

type TGeometryArrays = class(TObject)

Description

Geometry represented as arrays of indexes, vertex positions, texture coordinates and such. Many (eventually, all) geometry nodes (TVRMLGeometryNode) can be processed into an instance of this class.

This can be used to render, as arrays here map very naturally to an efficient OpenGL vertex arrays and VBOs. We use interleaving, storing everything in two arrays: 1st one for positions and normals (stuff that changes during coordinate morphing, most common dynamic shapes, so we specifically think about optimizing it). 2nd one for everything else (colors, tex coords, also GLSL attributes). This should allow for the most efficient usage, making use of interleaving and still allowing fast dynamic updates in common cases.

Hierarchy

  • TObject
  • TGeometryArrays

Overview

Methods

Public constructor Create;
Public destructor Destroy; override;
Public function IndexesPtr(const Index: Cardinal): PtrUInt;
Public function Position: PVector3;
Public function Position(const Index: Cardinal): PVector3;
Public procedure IncPosition(var P: PVector3);
Public function Normal: PVector3;
Public function Normal(const Index: Cardinal): PVector3;
Public procedure IncNormal(var P: PVector3);
Public procedure AddColor(const AMode: TColorMode);
Public function Color(const Index: Cardinal = 0): PVector4;
Public procedure IncColor(var P: PVector4);
Public procedure AddFogCoord;
Public function FogCoord(const Index: Cardinal = 0): PSingle;
Public procedure AddTexCoord2D(const TextureUnit: Cardinal);
Public procedure AddTexCoord3D(const TextureUnit: Cardinal);
Public procedure AddTexCoord4D(const TextureUnit: Cardinal);
Public procedure AddTexCoordGenerated(const Generation: TTextureCoordinateGeneration; const TextureUnit: Cardinal);
Public procedure AddTexCoordCopy(const NewTextureUnit, ExistingTextureUnit: Cardinal);
Public function TexCoord(const TextureUnit, Index: Cardinal): Pointer;
Public function TexCoord2D(const TextureUnit, Index: Cardinal): PVector2;
Public function TexCoord3D(const TextureUnit, Index: Cardinal): PVector3;
Public function TexCoord4D(const TextureUnit, Index: Cardinal): PVector4;
Public procedure AddGLSLAttributeFloat(const Name: string; const Internal: boolean);
Public procedure AddGLSLAttributeVector2(const Name: string; const Internal: boolean);
Public procedure AddGLSLAttributeVector3(const Name: string; const Internal: boolean);
Public procedure AddGLSLAttributeVector4(const Name: string; const Internal: boolean);
Public procedure AddGLSLAttributeMatrix3(const Name: string; const Internal: boolean);
Public procedure AddGLSLAttributeMatrix4(const Name: string; const Internal: boolean);
Public function GLSLAttribute(A: TGeometryAttrib; const Offset: PtrUInt = 0): PtrUInt;
Public function GLSLAttributeFloat(const Name: string; const Index: Cardinal = 0): PSingle;
Public function GLSLAttributeVector2(const Name: string; const Index: Cardinal = 0): PVector2;
Public function GLSLAttributeVector3(const Name: string; const Index: Cardinal = 0): PVector3;
Public function GLSLAttributeVector4(const Name: string; const Index: Cardinal = 0): PVector4;
Public function GLSLAttributeMatrix3(const Name: string; const Index: Cardinal = 0): PMatrix3;
Public function GLSLAttributeMatrix4(const Name: string; const Index: Cardinal = 0): PMatrix4;
Public procedure FreeData;

Properties

Public property Indexes: TGeometryIndexList read FIndexes write FIndexes;
Public property IndexesCount: Cardinal read FIndexesCount;
Public property HasIndexes: boolean read FHasIndexes;
Public property Primitive: TGeometryPrimitive read FPrimitive write FPrimitive;
Public property Counts: TCardinalList read FCounts write FCounts;
Public property CoordinateArray: Pointer read FCoordinateArray;
Public property CoordinateSize: Cardinal read FCoordinateSize;
Public property CoordinatePreserveGeometryOrder: Boolean read FCoordinatePreserveGeometryOrder write FCoordinatePreserveGeometryOrder default false;
Public property AttributeArray: Pointer read FAttributeArray;
Public property AttributeSize: Cardinal read FAttributeSize;
Public property Count: Integer read FCount write SetCount;
Public property HasColor: boolean read FHasColor;
Public property ColorMode: TColorMode read FColorMode;
Public property ForceUnlit: boolean read FForceUnlit write FForceUnlit default false;
Public property ForcedUnlitColor: TVector4 read FForcedUnlitColor write FForcedUnlitColor;
Public property HasFogCoord: boolean read FHasFogCoord;
Public property FogDirectValues: boolean read FFogDirectValues write FFogDirectValues default false;
Public property TexCoords: TGeometryTexCoordList read FTexCoords;
Public property Attribs: TGeometryAttribList read FAttribs;
Public property CullFace: boolean read FCullFace write FCullFace default false;
Public property FrontFaceCcw: boolean read FFrontFaceCcw write FFrontFaceCcw default false;
Public property ForceFlatShading: boolean read FForceFlatShading write FForceFlatShading default false;
Public property DataFreed: boolean read FDataFreed;
Public property Faces: TFaceIndexesList read FFaces write FFaces;

Description

Methods

Public constructor Create;
 
Public destructor Destroy; override;
 
Public function IndexesPtr(const Index: Cardinal): PtrUInt;

Information about Indexes.

Before using FreeData, you could as well use the Indexes property to get the same information. You can use Indexes[Index], Indexes <> nil, Indexes.Count and such. However, FreeData call (that you should use to conserve memory usage after loading arrays to VBO) releases the Indexes property, while these properties stay the same.

IndexesPtr may be casted to "ˆTGeometryIndex", before the FreeData call.

Public function Position: PVector3;
 
Public function Position(const Index: Cardinal): PVector3;
 
Public procedure IncPosition(var P: PVector3);
 
Public function Normal: PVector3;
 
Public function Normal(const Index: Cardinal): PVector3;
 
Public procedure IncNormal(var P: PVector3);
 
Public procedure AddColor(const AMode: TColorMode);
 
Public function Color(const Index: Cardinal = 0): PVector4;
 
Public procedure IncColor(var P: PVector4);
 
Public procedure AddFogCoord;
 
Public function FogCoord(const Index: Cardinal = 0): PSingle;
 
Public procedure AddTexCoord2D(const TextureUnit: Cardinal);
 
Public procedure AddTexCoord3D(const TextureUnit: Cardinal);
 
Public procedure AddTexCoord4D(const TextureUnit: Cardinal);
 
Public procedure AddTexCoordGenerated(const Generation: TTextureCoordinateGeneration; const TextureUnit: Cardinal);

Add generated texture coord. Such texture coord will not have actual data allocated in the array (you're expected to instead setup and enable glTexGen when rendering). Generation passed here must not be tgExplicit.

Public procedure AddTexCoordCopy(const NewTextureUnit, ExistingTextureUnit: Cardinal);

Add texture coord, with configuration copied from existing texture coord.

Public function TexCoord(const TextureUnit, Index: Cardinal): Pointer;
 
Public function TexCoord2D(const TextureUnit, Index: Cardinal): PVector2;
 
Public function TexCoord3D(const TextureUnit, Index: Cardinal): PVector3;
 
Public function TexCoord4D(const TextureUnit, Index: Cardinal): PVector4;
 
Public procedure AddGLSLAttributeFloat(const Name: string; const Internal: boolean);
 
Public procedure AddGLSLAttributeVector2(const Name: string; const Internal: boolean);
 
Public procedure AddGLSLAttributeVector3(const Name: string; const Internal: boolean);
 
Public procedure AddGLSLAttributeVector4(const Name: string; const Internal: boolean);
 
Public procedure AddGLSLAttributeMatrix3(const Name: string; const Internal: boolean);
 
Public procedure AddGLSLAttributeMatrix4(const Name: string; const Internal: boolean);
 
Public function GLSLAttribute(A: TGeometryAttrib; const Offset: PtrUInt = 0): PtrUInt;
 
Public function GLSLAttributeFloat(const Name: string; const Index: Cardinal = 0): PSingle;
 
Public function GLSLAttributeVector2(const Name: string; const Index: Cardinal = 0): PVector2;
 
Public function GLSLAttributeVector3(const Name: string; const Index: Cardinal = 0): PVector3;
 
Public function GLSLAttributeVector4(const Name: string; const Index: Cardinal = 0): PVector4;
 
Public function GLSLAttributeMatrix3(const Name: string; const Index: Cardinal = 0): PMatrix3;
 
Public function GLSLAttributeMatrix4(const Name: string; const Index: Cardinal = 0): PMatrix4;
 
Public procedure FreeData;

Release the allocated memory for arrays (CoordinateArray, AttributeArray, Indexes). Further calls to IndexesPtr, Normal, Color and such will return only an offset relative to the original arrays pointer. This is necessary if you loaded arrays data into GPU memory (like Vertex Buffer Object of OpenGL), and it is also optimal – you should not need the data anymore, once loaded to VBO.

Properties

Public property Indexes: TGeometryIndexList read FIndexes write FIndexes;

Indexes to remaining arrays.

If non-nil, we will render using these indexes, which means that items on the remaining lists (vertex positions, tex coords etc.) may be used multiple times. This is good (the lists may be possibly shorter, and GPU will be able to reuse more calculation results), but it's also limited: a vertex must always have the same properties in this case (e.g. the same normal vector, so shape must be completely smooth).

When this is nil, we will simply use all the vertexes in order. So every item of the remaining lists will be processed exactly once, in the given order. This seems dumb, but actually we're often forced to use this: when you use flat (per-face) normals or colors, then the same vertex position must be used many times with different normal/color. If you want to use OpenGL vertex arrays for whole rendering, this vertex position will just have to be duplicated (which is OK, as the calculation results couldn't be shared anyway, since normal/color are different).

Public property IndexesCount: Cardinal read FIndexesCount;
 
Public property HasIndexes: boolean read FHasIndexes;
 
Public property Primitive: TGeometryPrimitive read FPrimitive write FPrimitive;
 
Public property Counts: TCardinalList read FCounts write FCounts;

If this is assigned, then the vertexes are divided into groups. This is the only way to put many triangle strips, triangle fans and such into one TGeometryArrays instance. For normal sets of triangles and quads this has no use, as there's never a need to divide them for rendering.

Each value of this list specifies to take consecutive number of vertexes for next primitive. If Indexes are assigned, then they are divided into groups. Otherwise, the other arrays (positions, normals etc.) are divided into groups.

The sum of values must be equal to the Indexes.Count (if Indexes assigned) or arrays Count (if Indexes not assigned).

Public property CoordinateArray: Pointer read FCoordinateArray;

Memory containing vertex positions and normals, that is everything that changes during Coordinate.coord animation. CoordinateSize is size, in bytes, of one item of this array (currently just constant, 2 * TVector3).

Public property CoordinateSize: Cardinal read FCoordinateSize;
 
Public property CoordinatePreserveGeometryOrder: Boolean read FCoordinatePreserveGeometryOrder write FCoordinatePreserveGeometryOrder default false;

Does the order of data in CoordinateArray preserves the order of geometry (order of vectors in TCoordinateNode.Coord in TAbstractGeometryNode.CoordField).

Public property AttributeArray: Pointer read FAttributeArray;

Memory containing everything other vertex attribute, like color, texture coordinates and GLSL attributes. AttributeSize is size, in bytes, of one item of this array.

Public property AttributeSize: Cardinal read FAttributeSize;
 
Public property Count: Integer read FCount write SetCount;

Allocated number of items in vertex positions, normals, colors and such arrays.

You can only set this once. You must do all necessary AddColor / AddAttribute calls before setting this.

You can access all Position / Normal etc. pointers only after setting this. Also, IndexesCount and HasIndexes is stored at this point.

Public property HasColor: boolean read FHasColor;
 
Public property ColorMode: TColorMode read FColorMode;
 
Public property ForceUnlit: boolean read FForceUnlit write FForceUnlit default false;

When ForceUnlit, the shape must be rendered like with UnlitMaterial, with UnlitMaterial.emissiveColor/alpha = ForcedUnlitColor.

Note that (as with UnlitMaterial) the colors may be overridden per-vertex using Color array (X3D Color/ColorRGBA nodes).

Public property ForcedUnlitColor: TVector4 read FForcedUnlitColor write FForcedUnlitColor;
 
Public property HasFogCoord: boolean read FHasFogCoord;
 
Public property FogDirectValues: boolean read FFogDirectValues write FFogDirectValues default false;

If FogCoord present, does it specify direct fog intensities, that should be used to change pixel colors without any further processing. When this is False, then fog coordinates are understood as distance from the eye, and they are processed by linear/exp equations before being used to blend pixel colors.

Public property TexCoords: TGeometryTexCoordList read FTexCoords;

Allocated in AttributeArray texture coords. Index is texture unit (counted from renderer first available texture unit). If given item is Nil on this list, then this texture unit is not allocated (just like it would be outside of TexCoords.Count).

Public property Attribs: TGeometryAttribList read FAttribs;
 
Public property CullFace: boolean read FCullFace write FCullFace default false;

Should we use backface-culling (ignore some faces during rendering).

Which faces are "back" (and will be culled) is determined by FrontFaceCcw. When FrontFaceCcw = True, the the faces ordered counter-clockwise are front, and thus the faces ordered clockwise will be culled. When FrontFaceCcw = False, the faces ordered counter-clockwise will be culled.

Public property FrontFaceCcw: boolean read FFrontFaceCcw write FFrontFaceCcw default false;

Which faces are front, for backface-culling (see CullFace) and for normals data (see Normal).

Public property ForceFlatShading: boolean read FForceFlatShading write FForceFlatShading default false;

Make the whole rendering with flat shading.

Public property DataFreed: boolean read FDataFreed;

Was FreeData called.

Public property Faces: TFaceIndexesList read FFaces write FFaces;

Information about faces. Generated for some geometry types. Generated only when TArraysGenerator.FacesNeeded is True. Generated only for indexed shapes. When Indexes <> nil, these have the same count as Indexes.Count. Otherwise these have the same count as our Count.


Generated by PasDoc 0.15.0.