Class TGLTextureNode

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TGLTextureNode = class(TResourceRenderer)

Description

OpenGL handling for VRML/X3D texture node.

Hierarchy

Overview

Methods

Protected procedure HandleTexturePropertiesCore( TextureProperties: TTexturePropertiesNode; out Filter: TTextureFilter; out Anisotropy: TGLfloat);
Protected procedure HandleTextureProperties( TextureProperties: TX3DNode; out Filter: TTextureFilter; out Anisotropy: TGLfloat);
Protected class function IsClassForTextureNode( ANode: TAbstractTextureNode): boolean; virtual; abstract;
Protected procedure PrepareCore(State: TX3DGraphTraverseState); virtual; abstract;
Public constructor Create(ARenderer: TGLRenderer; ANode: TX3DNode); override;
Public function TextureNode: TAbstractTextureNode;
Public class function ClassForTextureNode( ANode: TAbstractTextureNode): TGLTextureNodeClass;
Public procedure Prepare(State: TX3DGraphTraverseState);
Public function Bind(const TextureUnit: Cardinal): boolean; virtual; abstract;
Public function Enable(const TextureUnit: Cardinal; Shader: TShader; const Env: TTextureEnv): boolean; virtual; abstract;
Public procedure EnableAll( const TextureUnitsCount: Cardinal; out TexCoordsNeeded: Cardinal; Shader: TShader); virtual; abstract;

Description

Methods

Protected procedure HandleTexturePropertiesCore( TextureProperties: TTexturePropertiesNode; out Filter: TTextureFilter; out Anisotropy: TGLfloat);

Calculate things from TextureProperties node. If TextureProperties = Nil, they are taken from defaults (possibly in Attributes).

Protected procedure HandleTextureProperties( TextureProperties: TX3DNode; out Filter: TTextureFilter; out Anisotropy: TGLfloat);

Calculate things from TextureProperties node. If TextureProperties = Nil or not of TTexturePropertiesNode class, they are taken from defaults (possibly in Attributes).

This is useful when interpreting VRML/X3D files, as you have no guarantee user didn't place there some disallowed node in "textureProperties" field.

Protected class function IsClassForTextureNode( ANode: TAbstractTextureNode): boolean; virtual; abstract;

Decide if this class can handle given texture Node.

Protected procedure PrepareCore(State: TX3DGraphTraverseState); virtual; abstract;

Do the time-consuming preparations before rendering this texture. Called from TGLRenderer.Prepare, always through our Prepare method. Our Prepare method takes care to catch common exceptions from this (EFramebufferError, ETextureLoadError), convert them to OnWarning and make Unprepare to undo the preparations. So Prepare-Unprepare work like constructor-destructor, with Unprepare having to be prepared to finilizing incomplete instance.

Public constructor Create(ARenderer: TGLRenderer; ANode: TX3DNode); override;

ANode must be TAbstractTextureNode

Public function TextureNode: TAbstractTextureNode;

Reference to handled texture node. Never Nil. It's guaranteed to satisfy IsClassForTextureNode method of this class.

Public class function ClassForTextureNode( ANode: TAbstractTextureNode): TGLTextureNodeClass;

Find suitable TGLTextureNode class that can best handle given Node. Returns Nil if not found.

Descedants implementors: override IsClassForTextureNode to be correctly recognized by this.

Public procedure Prepare(State: TX3DGraphTraverseState);

Do the time-consuming preparations before rendering this texture. Calls PrepareCore.

Public function Bind(const TextureUnit: Cardinal): boolean; virtual; abstract;

Bind texture for OpenGL (without enabling it).

Just like Enable, returns False when texture node was not successfully prepared for OpenGL. Returns True when it was successfully bound (caller can be sure then that given texture unit is currently active).

Public function Enable(const TextureUnit: Cardinal; Shader: TShader; const Env: TTextureEnv): boolean; virtual; abstract;

Enables texture for OpenGL. This has to bind texture identifier and enable proper texture state (for example: 2D, and not 3D, and not cube).

When returns False, it means that texture node was not successfully prepared for OpenGL, which means (we assume that you called Prepare before Enable) that texture failed to load, required not available OpenGL version / extension etc. Caller will then disable the texture unit, and you don't have to generate tex coords for it.

When returns True (success) caller can be sure that the specified TextureUnit is currently bound (if OpenGL multitexturing extensions are available at all). This is useful, if you want to later adjust texture unit parameters, like glTexEnvi(GL_TEXTURE_ENV, ...).

It's also already enabled (by glEnable(GL_TEXTURE_2D / GL_TEXTURE_CUBE_MAP / GL_TEXTURE_3D) ).

Public procedure EnableAll( const TextureUnitsCount: Cardinal; out TexCoordsNeeded: Cardinal; Shader: TShader); virtual; abstract;

Sets texture state for many texture units, based on this node. On every texture unit where something is enabled, proper texture identifier must be bound. Also, has to set complete glTexEnv on every enabled texture unit.

TextureUnitsCount says how many texture units can be enabled/disabled.

TextureUnitsCount does *not* take into account whether multitexturing OpenGL extensions are available at all. Look at GLFeatures.UseMultiTexturing for this. Think of GLFeatures.UseMultiTexturing as capping TextureUnitsCount to 1 (still, remember to honour TextureUnitsCount = 0 case in your implementation, even when GLFeatures.UseMultiTexturing = True).

You have to set TexCoordsNeeded, this is the count of texture units where some texture coordinates should be generated. This means that all texture units above TexCoordsNeeded (to TextureUnitsCount - 1) should be disabled by the caller (no need to do this in EnableAll), and there's no need to generated texture coords for them.

( Yes, there is some small optimization missed in the definition of TexCoordsNeeded: if some textures in the middle of multitexture children list failed to load, but some following children succeded, we'll generate tex coords even for the useless texture units in the middle. We could avoid generating texture coords for them, by changing TexCoordsNeeded into bool array. This optimization is not considered worthy implementing for now. )

You have to set texture state of all texture units < TexCoordsNeeded, and only on them.


Generated by PasDoc 0.13.0 on 2014-04-30 22:06:44