Unit CastleGLUtils

Description

Various low-level utilities for working with OpenGL.

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Class EOpenGLError OpenGL error.
Class EOpenGLOutOfMemoryError GPU memory is not sufficient.
Class EOpenGLNoMoreDisplayLists  
Class TGLMemoryInfo OpenGL memory information.
Class TGLFeatures OpenGL(ES) features, analyzed based on extensions and version.
Record TLineStipple  
Class EGenerateMipmapNotAvailable Part of CastleGLUtils unit: mipmaps utils.

Functions and Procedures

procedure GLOutOfMemory(const AdditionalComment: string = '');
function GLErrorString(const ErrorCode: TGLenum; const AdditionalComment: string = ''): string;
procedure CheckGLErrors(const AdditionalComment: string = '');
procedure GLErrorRaise(ErrorCode: TGLenum); cdecl; deprecated 'this function is no longer useful, as you should not use GLU in cross-platform programs';
function glGetFloat(pname: TGLEnum): TGLfloat;
function glGetInteger(pname: TGLEnum): TGLint;
function glGetBoolean(pname: TGLEnum): TGLboolean;
procedure glColorv(const v: TVector3Byte); overload;
procedure glColorv(const v: TVector4Byte); overload;
procedure glColorv(const v: TVector3); overload;
procedure glColorv(const v: TVector4); overload;
procedure glTranslatev(const V: TVector3); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';
procedure glScalev(const V: Single); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';
procedure glScalev(const V: TVector3); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';
procedure glRotatev(const Angle: TGLfloat; const V: TVector3); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';
procedure glClipPlane(plane: TGLenum; const V: TVector4Double); overload;
procedure glNormalv(const v: TVector3); overload;
procedure glMaterialv(face, pname: TGLEnum; const params: TVector4); overload;
procedure glVertexv(const v: TVector2); overload;
procedure glVertexv(const v: TVector3); overload;
procedure glVertexv(const v: TVector4); overload;
procedure glTexCoordv(const v: TVector2); overload;
procedure glTexCoordv(const v: TVector3); overload;
procedure glTexCoordv(const v: TVector4); overload;
procedure glTexGenv(coord, pname: TGLenum; const params: TVector4); overload;
procedure glLightv(light, pname: TGLEnum; const params: TVector4); overload;
procedure glLightv(light, pname: TGLEnum; const params: TVector3); overload;
procedure glLightModelv(pname: TGLenum; const params: TVector4); overload;
procedure glFogv(pname: TGLEnum; const params: TVector4); overload;
procedure glMultMatrix(const m: TMatrix4); overload;
procedure glLoadMatrix(const m: TMatrix4); overload;
procedure glTexEnvv(target, pname: TGLEnum; const params: TVector4); overload;
procedure GLViewport(const Rect: TRectangle); deprecated 'use RenderContext.Viewport';
procedure GLSetEnabled(Value: TGLenum; IsEnabled: boolean);
procedure GLVerticalLine(x, y1, y2: TGLfloat); deprecated 'use DrawPrimitive2D';
procedure GLHorizontalLine(x1, x2, y: TGLfloat); deprecated 'use DrawPrimitive2D';
procedure GLDrawArrow(HeadThickness: TGLfloat = 0.4; HeadLength: TGLfloat = 0.5); deprecated 'use DrawPrimitive2D to draw shapes';
procedure glDrawAxisWire(const Position: TVector3; Size: Single); deprecated 'use TCastleScene to draw 3D stuff';
procedure glColorOpacity(const Color: TVector3; const Opacity: Single); overload; deprecated 'instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color';
procedure glColorOpacity(const Color: TVector3Byte; const Opacity: Single); overload; deprecated 'instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color';
function glGenListsCheck(range: TGLsizei; const Place: string): TGLuint; deprecated 'do not use display lists; they are not available on OpenGLES and modern OpenGL';
procedure glFreeDisplayList(var list: TGLuint); deprecated 'do not use display lists; they are not available on OpenGLES and modern OpenGL';
procedure glFreeBuffer(var Buffer: TGLuint);
procedure glSetDepthAndColorWriteable(const Writeable: boolean); deprecated 'set RenderContext.DepthBufferUpdate, RenderContext.ColorChannels explicitly, this allows to save/restore them reiably';
function GLEnableTexture(const Target: TEnableTextureTarget): boolean;
function BoolToGL(const Value: boolean): TGLboolean;
function PGLcharARBOrNil(const s: AnsiString): PGLcharARB;
procedure GLInformationInitialize;
procedure DrawRectangle(const R: TRectangle; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawRectangle(const R: TFloatRectangle; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawRectangleOutline(const R: TRectangle; const Color: TCastleColor; const LineWidth: Single = 1; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawRectangleOutline(const R: TFloatRectangle; const Color: TCastleColor; const LineWidth: Single = 1; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawCircle(const Middle: TVector2Integer; const HorizontalRadius, VerticalRadius: Integer; const Color: TCastleColor; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawCircle(const Middle: TVector2; const HorizontalRadius, VerticalRadius: Single; const Color: TCastleColor; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawCircleOutline(const Middle: TVector2Integer; const HorizontalRadius, VerticalRadius: Integer; const Color: TCastleColor; const LineWidth: Single = 1; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawCircleOutline(const Middle: TVector2; const HorizontalRadius, VerticalRadius: Single; const Color: TCastleColor; const LineWidth: Single = 1; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
procedure DrawPrimitive2D(const Mode: TPrimitiveMode; const Points: array of TVector2SmallInt; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false; const LineWidth: Single = 1; const PointSize: Cardinal = 1); overload;
procedure DrawPrimitive2D(const Mode: TPrimitiveMode; const Points: array of TVector2; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false; const LineWidth: Single = 1; const PointSize: Cardinal = 1); overload;
procedure DrawPrimitive2D(const Mode: TPrimitiveMode; const LineStipple: TLineStipple; const Points: array of TVector2; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false; const LineWidth: Single = 1; const PointSize: Cardinal = 1); overload;
procedure GLFadeRectangleDark(const X1, Y1, X2, Y2: Integer; const AFadeColor: TVector3; const FadeIntensity: Single); overload;
procedure GLFadeRectangleDark(const Rect: TRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
procedure GLFadeRectangleDark(const Rect: TFloatRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
procedure GLFadeRectangleLight(const Rect: TRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
procedure GLFadeRectangleLight(const Rect: TFloatRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
procedure GLFadeRectangle(const X1, Y1, X2, Y2: Integer; const AFadeColor: TVector3; const FadeIntensity: Single); overload; deprecated 'use GLFadeRectangleDark, or TCastleFlashEffect with Dark = true';
procedure GLFadeRectangle(const Rect: TRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload; deprecated 'use GLFadeRectangleDark, or TCastleFlashEffect with Dark = true';
procedure GLBlendRectangle(const X1, Y1, X2, Y2: Integer; const SourceFactor: TBlendingSourceFactor; const DestinationFactor: TBlendingDestinationFactor; const Color: TVector4); overload; deprecated 'use DrawRectangle';
procedure GLBlendRectangle(const Rect: TRectangle; const Color: TVector4); overload; deprecated 'use DrawRectangle';
procedure GLBlendFunction( SourceFactor: TBlendingSourceFactor; DestinationFactor: TBlendingDestinationFactor);
function GLInformationString: String;
function GLInformationStringSummary: String;
function HasGenerateMipmap: boolean;
procedure GenerateMipmap(target: TGLenum);
function Load_GL_EXT_framebuffer_blit: Boolean;

Types

TGLenum = GLenum;
TGLboolean = GLboolean;
TGLbitfield = GLbitfield;
TGLbyte = GLbyte;
TGLshort = GLshort;
TGLint = GLint;
TGLsizei = GLsizei;
TGLubyte = GLubyte;
TGLushort = GLushort;
TGLuint = GLuint;
TGLfloat = GLfloat;
TGLclampf = GLclampf;
TGLdouble = GLdouble;
TGLclampd = GLclampd;
TVector2f = TVector2 deprecated 'use TVector2';
PVector2f = PVector2 deprecated 'use PVector2';
TVector2ub = TVector2Byte deprecated 'use TVector2Byte';
PVector2ub = PVector2Byte deprecated 'use PVector2Byte';
TVector2i = TVector2Integer deprecated 'use TVector2Integer';
PVector2i = PVector2Integer deprecated 'use PVector2Integer';
TVector3f = TVector3 deprecated 'use TVector3';
PVector3f = PVector3 deprecated 'use PVector3';
TVector3ub = TVector3Byte deprecated 'use TVector3Byte';
PVector3ub = PVector3Byte deprecated 'use PVector3Byte';
TVector3i = TVector3Integer deprecated 'use TVector3Integer';
PVector3i = PVector3Integer deprecated 'use PVector3Integer';
TVector4f = TVector4 deprecated 'use TVector4';
PVector4f = PVector4 deprecated 'use PVector4';
TVector4ub = TVector4Byte deprecated 'use TVector4Byte';
PVector4ub = PVector4Byte deprecated 'use PVector4Byte';
TVector4i = TVector4Integer deprecated 'use TVector4Integer';
PVector4i = PVector4Integer deprecated 'use PVector4Integer';
TMatrix2f = TMatrix2 deprecated 'use TMatrix2';
PMatrix2f = PMatrix2 deprecated 'use PMatrix2';
TMatrix3f = TMatrix3 deprecated 'use TMatrix3';
PMatrix3f = PMatrix3 deprecated 'use PMatrix3';
TMatrix4f = TMatrix4 deprecated 'use TMatrix4';
PMatrix4f = PMatrix4 deprecated 'use PMatrix4';
TEnableTextureTarget = (...);
TGLSupport = (...);
TPrimitiveMode = (...);

Constants

GLSupportNames: array [TGLSupport] of string = ( 'None', 'Extension', 'Standard' );
DefaultCircleSlices = 32;
GL_READ_FRAMEBUFFER_EXT = $8CA8;
GL_DRAW_FRAMEBUFFER_EXT = $8CA9;
GL_DRAW_FRAMEBUFFER_BINDING_EXT = $8CA6;
GL_READ_FRAMEBUFFER_BINDING_EXT = $8CAA;

Variables

GLOutOfMemoryError: boolean = false;
CurrentColor: TCastleColor deprecated 'instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color';
WindowPos: TVector2Integer deprecated 'use drawing routines that take position as parameters, like TDrawableImage.Draw(X,Y) or TCastleAbstractFont.Print(X,Y,...)';
GLFeatures: TGLFeatures;
LogGLInformationVerbose: Boolean = false;
glBlitFramebufferEXT: procedure( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1: TGLint; mask: TGLbitfield; filter: TGLenum);

Description

Functions and Procedures

procedure GLOutOfMemory(const AdditionalComment: string = '');
 
function GLErrorString(const ErrorCode: TGLenum; const AdditionalComment: string = ''): string;
 
procedure CheckGLErrors(const AdditionalComment: string = '');

Check are any OpenGL errors recorded (in glGetError). If there are errors, our behavior depends on whether we were compiled with -dRELEASE. With -dRELEASE, we make WritelnWarning. This way eventual errors in release builds don't completely abort your program.

Note that the behavior on GL_OUT_OF_MEMORY is different. -dRELEASE does not matter here. Only GLOutOfMemoryError boolean dictates if we should raise an exception or merely make warning, regardless of -dRELEASE state.

Without -dRELEASE, we raise EOpenGLError. So a developer is strongly suggested to fix the code to not produce OpenGL errors, never ever.

Exceptions raised
EOpenGLError
procedure GLErrorRaise(ErrorCode: TGLenum); cdecl; deprecated 'this function is no longer useful, as you should not use GLU in cross-platform programs';

Warning: this symbol is deprecated: this function is no longer useful, as you should not use GLU in cross-platform programs

Raise EOpenGLError for given OpenGL error code. This has calling convention suitable for registering this procedure as GLU_TESS_ERROR for gluTessCallback, or GLU_ERROR for gluQuadricCallback.

function glGetFloat(pname: TGLEnum): TGLfloat;

Comfortable wrappers for OpenGL glGet* that return a single value.

Guarantee that result is zero in case of OpenGL error. (Otherwise, OpenGL could leave them undefined and only set glGetError.)

function glGetInteger(pname: TGLEnum): TGLint;
 
function glGetBoolean(pname: TGLEnum): TGLboolean;
 
procedure glColorv(const v: TVector3Byte); overload;
 
procedure glColorv(const v: TVector4Byte); overload;
 
procedure glColorv(const v: TVector3); overload;
 
procedure glColorv(const v: TVector4); overload;
 
procedure glTranslatev(const V: TVector3); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';

Warning: this symbol is deprecated: use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D

 
procedure glScalev(const V: Single); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';

Warning: this symbol is deprecated: use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D

 
procedure glScalev(const V: TVector3); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';

Warning: this symbol is deprecated: use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D

 
procedure glRotatev(const Angle: TGLfloat; const V: TVector3); overload; deprecated 'use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D';

Warning: this symbol is deprecated: use other methods to transform things, e.g. TCastleUserInterface position / anchors, or TCastleTransform for TCastleScene, or TTransformNode in X3D

 
procedure glClipPlane(plane: TGLenum; const V: TVector4Double); overload;
 
procedure glNormalv(const v: TVector3); overload;
 
procedure glMaterialv(face, pname: TGLEnum; const params: TVector4); overload;
 
procedure glVertexv(const v: TVector2); overload;
 
procedure glVertexv(const v: TVector3); overload;
 
procedure glVertexv(const v: TVector4); overload;
 
procedure glTexCoordv(const v: TVector2); overload;
 
procedure glTexCoordv(const v: TVector3); overload;
 
procedure glTexCoordv(const v: TVector4); overload;
 
procedure glTexGenv(coord, pname: TGLenum; const params: TVector4); overload;
 
procedure glLightv(light, pname: TGLEnum; const params: TVector4); overload;
 
procedure glLightv(light, pname: TGLEnum; const params: TVector3); overload;
 
procedure glLightModelv(pname: TGLenum; const params: TVector4); overload;
 
procedure glFogv(pname: TGLEnum; const params: TVector4); overload;
 
procedure glMultMatrix(const m: TMatrix4); overload;
 
procedure glLoadMatrix(const m: TMatrix4); overload;
 
procedure glTexEnvv(target, pname: TGLEnum; const params: TVector4); overload;
 
procedure GLViewport(const Rect: TRectangle); deprecated 'use RenderContext.Viewport';

Warning: this symbol is deprecated: use RenderContext.Viewport

 
procedure GLSetEnabled(Value: TGLenum; IsEnabled: boolean);

Enable or disable given OpenGL flag.

procedure GLVerticalLine(x, y1, y2: TGLfloat); deprecated 'use DrawPrimitive2D';

Warning: this symbol is deprecated: use DrawPrimitive2D

Draw vertical line using OpenGL. Uses current OpenGL color.

Deprecated, do not draw lines directly like this, instead use DrawPrimitive2D or UI interface drawing like Theme.Draw and TDrawableImage.Draw.

procedure GLHorizontalLine(x1, x2, y: TGLfloat); deprecated 'use DrawPrimitive2D';

Warning: this symbol is deprecated: use DrawPrimitive2D

Draw horizontal line using OpenGL. Uses current OpenGL color.

Deprecated, do not draw lines directly like this, instead use DrawPrimitive2D or UI interface drawing like Theme.Draw and TDrawableImage.Draw.

procedure GLDrawArrow(HeadThickness: TGLfloat = 0.4; HeadLength: TGLfloat = 0.5); deprecated 'use DrawPrimitive2D to draw shapes';

Warning: this symbol is deprecated: use DrawPrimitive2D to draw shapes

Draw arrow shape. Arrow is placed on Z = 0 plane, points to the up, has height = 2 (from y = 0 to y = 2) and width 1 (from x = -0.5 to 0.5).

Everything is drawn CCW when seen from standard view (x grows right, y up). Uses current OpenGL color.

procedure glDrawAxisWire(const Position: TVector3; Size: Single); deprecated 'use TCastleScene to draw 3D stuff';

Warning: this symbol is deprecated: use TCastleScene to draw 3D stuff

Draw axis (3 lines) around given position. Nothing is generated besides vertex positions — no normal vectors, no texture coords, nothing.

procedure glColorOpacity(const Color: TVector3; const Opacity: Single); overload; deprecated 'instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color';

Warning: this symbol is deprecated: instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color

Call glColor, taking Opacity as separate Single argument. Deprecated, do not use colors like that, instead pass TCastleColor to appropriate routines like TCastleAbstractFont.Print.

procedure glColorOpacity(const Color: TVector3Byte; const Opacity: Single); overload; deprecated 'instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color';

Warning: this symbol is deprecated: instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color

 
function glGenListsCheck(range: TGLsizei; const Place: string): TGLuint; deprecated 'do not use display lists; they are not available on OpenGLES and modern OpenGL';

Warning: this symbol is deprecated: do not use display lists; they are not available on OpenGLES and modern OpenGL

Call glGenLists(range) and checks the result.

Exceptions raised
EOpenGLNoMoreDisplayLists
When glGenLists(Range) returned zero for non-zero Range. The exception's Message shows Place, which may describe where this is called — makes it easier to debug.
procedure glFreeDisplayList(var list: TGLuint); deprecated 'do not use display lists; they are not available on OpenGLES and modern OpenGL';

Warning: this symbol is deprecated: do not use display lists; they are not available on OpenGLES and modern OpenGL

If List <> 0 then it does glDeleteList on List and sets List to 0. In other words this is simply glDeleteList but

  1. only if List really should be deleted

  2. sets List to 0 after deletion

procedure glFreeBuffer(var Buffer: TGLuint);

If Buffer <> 0 then it does glDeleteBuffers and sets Buffer to 0.

procedure glSetDepthAndColorWriteable(const Writeable: boolean); deprecated 'set RenderContext.DepthBufferUpdate, RenderContext.ColorChannels explicitly, this allows to save/restore them reiably';

Warning: this symbol is deprecated: set RenderContext.DepthBufferUpdate, RenderContext.ColorChannels explicitly, this allows to save/restore them reiably

Set color and depth buffers writeable or not.

This is just a shortcut for setting RenderContext.DepthBufferUpdate, RenderContext.ColorChannels.

Which are in turn shortcuts to doing this in OpenGL(ES):

glDepthMask(Writeable);
glColorMask(Writeable, Writeable, Writeable, Writeable);

function GLEnableTexture(const Target: TEnableTextureTarget): boolean;

Enable exactly one (or none, for Target=etNone) OpenGL texture target for fixed-function pipeline. Always use this instead of manually calling glDisable(GL_TEXTURE_2D), glEnable(GL_TEXTURE_2D) and such. This makes sure to have at most one texture target enabled, and disable others.

Remember that this state is different for every texture unit in OpenGL, in case you use multi-texturing.

Remember that not all texture targets are guaranteed to be supported by OpenGL. Target=etNone and Target=et2D are always supported. For the rest, check appropriate GLFeatures property (before even creating a texture with such type). If you pass an unsupported target type to this procedure, it will be ignored (all targets will be disabled, like for Target=etNone).

Note that this is only for fixed-function OpenGL pipeline. Shader pipeline completely ignores the enabled state of texture units.

function BoolToGL(const Value: boolean): TGLboolean;
 
function PGLcharARBOrNil(const s: AnsiString): PGLcharARB;

PGLcharARBOrNil simply returns a Pointer(S), you can think of it as a NO-OP. If string is empty, this returns Nil, otherwise it works just like PGLcharARBOrNil(S): returns a Pointer(S) with appropriate type cast.

procedure GLInformationInitialize;

Initialize GLVersion and GLFeatures.

procedure DrawRectangle(const R: TRectangle; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;

Draw a rectangle filled with a color.

Like with DrawPrimitive2D: Blending is automatically used if Color alpha < 1. ForceBlending forces the usage of blending. When it is False, we use blending only if Color[3] (alpha) < 1.

procedure DrawRectangle(const R: TFloatRectangle; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
 
procedure DrawRectangleOutline(const R: TRectangle; const Color: TCastleColor; const LineWidth: Single = 1; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;

Draw a rectangle frame.

Like with DrawPrimitive2D: Blending is automatically used if Color alpha < 1. ForceBlending forces the usage of blending. When it is False, we use blending only if Color[3] (alpha) < 1.

procedure DrawRectangleOutline(const R: TFloatRectangle; const Color: TCastleColor; const LineWidth: Single = 1; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
 
procedure DrawCircle(const Middle: TVector2Integer; const HorizontalRadius, VerticalRadius: Integer; const Color: TCastleColor; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;

Draw a circle. It may be scaled differently in X than Y, thus resembling an ellipse.

Like with DrawPrimitive2D: Blending is automatically used if Color alpha < 1. ForceBlending forces the usage of blending. When it is False, we use blending only if Color[3] (alpha) < 1.

procedure DrawCircle(const Middle: TVector2; const HorizontalRadius, VerticalRadius: Single; const Color: TCastleColor; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
 
procedure DrawCircleOutline(const Middle: TVector2Integer; const HorizontalRadius, VerticalRadius: Integer; const Color: TCastleColor; const LineWidth: Single = 1; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;

Draw a circle outline. It may be scaled differently in X than Y, thus resembling an ellipse.

Like with DrawPrimitive2D: Blending is automatically used if Color alpha < 1. ForceBlending forces the usage of blending. When it is False, we use blending only if Color[3] (alpha) < 1.

procedure DrawCircleOutline(const Middle: TVector2; const HorizontalRadius, VerticalRadius: Single; const Color: TCastleColor; const LineWidth: Single = 1; const CircleSlices: Cardinal = DefaultCircleSlices; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false); overload;
 
procedure DrawPrimitive2D(const Mode: TPrimitiveMode; const Points: array of TVector2SmallInt; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false; const LineWidth: Single = 1; const PointSize: Cardinal = 1); overload;

Draw a simple 2D primitive with a given color. This can be used to draw a series of points, lines or triangles, depending on the Mode parameter.

Blending is automatically used if Color alpha < 1. ForceBlending forces the usage of blending. When it is False, we use blending only if Color[3] (alpha) < 1.

Parameters
LineWidth
Line width, only used when Mode indicates lines.

Note that values other than 1 are not guaranteed to be supported. While it's a fast method to have thick lines, it is implementation-limited in case of

  1. desktop OpenGL with anti-aliasing, see https://www.opengl.org/sdk/docs/man/html/glLineWidth.xhtml

  2. mobile OpenGLES, with or without anti-aliasing, see https://www.khronos.org/opengles/sdk/docs/man/xhtml/glLineWidth.xml

PointSize
Point size, only used when Mode indicates points.

Note that values other than 1 are not guaranteed to be supported. Mobile OpenGLES does not support setting point size like this. And desktop OpenGL limits point size in case anti-aliasing is used, see https://www.opengl.org/sdk/docs/man2/xhtml/glPointSize.xml .

procedure DrawPrimitive2D(const Mode: TPrimitiveMode; const Points: array of TVector2; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false; const LineWidth: Single = 1; const PointSize: Cardinal = 1); overload;
 
procedure DrawPrimitive2D(const Mode: TPrimitiveMode; const LineStipple: TLineStipple; const Points: array of TVector2; const Color: TCastleColor; const BlendingSourceFactor: TBlendingSourceFactor = bsSrcAlpha; const BlendingDestinationFactor: TBlendingDestinationFactor = bdOneMinusSrcAlpha; const ForceBlending: boolean = false; const LineWidth: Single = 1; const PointSize: Cardinal = 1); overload;

Draw primitive, using a stipple (pattern) for line rendering. Note that the stipple is ignored on mobile (OpenGLES).

procedure GLFadeRectangleDark(const X1, Y1, X2, Y2: Integer; const AFadeColor: TVector3; const FadeIntensity: Single); overload;

Draw a rectangle that modulates colors underneath, making nice animation to AFadeColor while FadeIntensity changes from 1.0 down to 0.0.

The GLFadeRectangleLight version makes a flash to AFadeColor, then goes back to normal. It works reasonably with any color (light or dark).

The GLFadeRectangleDark version makes additional flash to blackness in the middle (so it goes from no modulation, to AFadeColor, to pure black, and then back to normal). So the "Dark" version is a little more impressive when you're flashing with a dark color.

These are nice as a screen effect, to flash some color (e.g. flash red color when the player is hurt).

Only RGB portion of AFadeColor is used.

procedure GLFadeRectangleDark(const Rect: TRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
 
procedure GLFadeRectangleDark(const Rect: TFloatRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
 
procedure GLFadeRectangleLight(const Rect: TRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
 
procedure GLFadeRectangleLight(const Rect: TFloatRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload;
 
procedure GLFadeRectangle(const X1, Y1, X2, Y2: Integer; const AFadeColor: TVector3; const FadeIntensity: Single); overload; deprecated 'use GLFadeRectangleDark, or TCastleFlashEffect with Dark = true';

Warning: this symbol is deprecated: use GLFadeRectangleDark, or TCastleFlashEffect with Dark = true

 
procedure GLFadeRectangle(const Rect: TRectangle; const AFadeColor: TCastleColor; const FadeIntensity: Single); overload; deprecated 'use GLFadeRectangleDark, or TCastleFlashEffect with Dark = true';

Warning: this symbol is deprecated: use GLFadeRectangleDark, or TCastleFlashEffect with Dark = true

 
procedure GLBlendRectangle(const X1, Y1, X2, Y2: Integer; const SourceFactor: TBlendingSourceFactor; const DestinationFactor: TBlendingDestinationFactor; const Color: TVector4); overload; deprecated 'use DrawRectangle';

Warning: this symbol is deprecated: use DrawRectangle

Draw a rectangle with blending. Deprecated, use DrawRectangle instead.

procedure GLBlendRectangle(const Rect: TRectangle; const Color: TVector4); overload; deprecated 'use DrawRectangle';

Warning: this symbol is deprecated: use DrawRectangle

 
procedure GLBlendFunction( SourceFactor: TBlendingSourceFactor; DestinationFactor: TBlendingDestinationFactor);

Call OpenGL glBlendFunc, https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml . Accepts parameters as enumerated types TBlendingSourceFactor, TBlendingDestinationFactor. Secures from using source or destination factor unsupported on current OpenGL version: makes a warnings and falls back on a sensible default (so it will always call glBlendFunc anyway).

function GLInformationString: String;

Multiline string describing attributes of current OpenGL(ES) library. This simply queries OpenGL(ES) using glGet* functions about many things. Does not change OpenGL(ES) state in any way.

Note that the last line of returned string does not terminate with a newline character (so e.g. you may want to do Writeln(GLInformationString) instead of just Write(GLInformationString)).

function GLInformationStringSummary: String;

One-line string summarizing current OpenGL(ES).

function HasGenerateMipmap: boolean;

Is GenerateMipmap avaiable. This checks some GL extensions/versions that give us glGenerateMipmap or glGenerateMipmapEXT call, used by GenerateMipmap.

procedure GenerateMipmap(target: TGLenum);

Call glGenerateMipmap (or analogous function from some OpenGL extension).

Exceptions raised
EGenerateMipmapNotAvailable
If no glGenerateMipmap version is available on this OpenGL version. If you don't want to get this exception, you can always check HasGenerateMipmap before calling this.
function Load_GL_EXT_framebuffer_blit: Boolean;

Check the existence of OpenGL EXT_framebuffer_blit extension. See https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_blit.txt .

Types

TGLenum = GLenum;
 
TGLboolean = GLboolean;
 
TGLbitfield = GLbitfield;
 
TGLbyte = GLbyte;
 
TGLshort = GLshort;
 
TGLint = GLint;
 
TGLsizei = GLsizei;
 
TGLubyte = GLubyte;
 
TGLushort = GLushort;
 
TGLuint = GLuint;
 
TGLfloat = GLfloat;
 
TGLclampf = GLclampf;
 
TGLdouble = GLdouble;
 
TGLclampd = GLclampd;
 
TVector2f = TVector2 deprecated 'use TVector2';

Warning: this symbol is deprecated: use TVector2

 
PVector2f = PVector2 deprecated 'use PVector2';

Warning: this symbol is deprecated: use PVector2

 
TVector2ub = TVector2Byte deprecated 'use TVector2Byte';

Warning: this symbol is deprecated: use TVector2Byte

 
PVector2ub = PVector2Byte deprecated 'use PVector2Byte';

Warning: this symbol is deprecated: use PVector2Byte

 
TVector2i = TVector2Integer deprecated 'use TVector2Integer';

Warning: this symbol is deprecated: use TVector2Integer

 
PVector2i = PVector2Integer deprecated 'use PVector2Integer';

Warning: this symbol is deprecated: use PVector2Integer

 
TVector3f = TVector3 deprecated 'use TVector3';

Warning: this symbol is deprecated: use TVector3

 
PVector3f = PVector3 deprecated 'use PVector3';

Warning: this symbol is deprecated: use PVector3

 
TVector3ub = TVector3Byte deprecated 'use TVector3Byte';

Warning: this symbol is deprecated: use TVector3Byte

 
PVector3ub = PVector3Byte deprecated 'use PVector3Byte';

Warning: this symbol is deprecated: use PVector3Byte

 
TVector3i = TVector3Integer deprecated 'use TVector3Integer';

Warning: this symbol is deprecated: use TVector3Integer

 
PVector3i = PVector3Integer deprecated 'use PVector3Integer';

Warning: this symbol is deprecated: use PVector3Integer

 
TVector4f = TVector4 deprecated 'use TVector4';

Warning: this symbol is deprecated: use TVector4

 
PVector4f = PVector4 deprecated 'use PVector4';

Warning: this symbol is deprecated: use PVector4

 
TVector4ub = TVector4Byte deprecated 'use TVector4Byte';

Warning: this symbol is deprecated: use TVector4Byte

 
PVector4ub = PVector4Byte deprecated 'use PVector4Byte';

Warning: this symbol is deprecated: use PVector4Byte

 
TVector4i = TVector4Integer deprecated 'use TVector4Integer';

Warning: this symbol is deprecated: use TVector4Integer

 
PVector4i = PVector4Integer deprecated 'use PVector4Integer';

Warning: this symbol is deprecated: use PVector4Integer

 
TMatrix2f = TMatrix2 deprecated 'use TMatrix2';

Warning: this symbol is deprecated: use TMatrix2

 
PMatrix2f = PMatrix2 deprecated 'use PMatrix2';

Warning: this symbol is deprecated: use PMatrix2

 
TMatrix3f = TMatrix3 deprecated 'use TMatrix3';

Warning: this symbol is deprecated: use TMatrix3

 
PMatrix3f = PMatrix3 deprecated 'use PMatrix3';

Warning: this symbol is deprecated: use PMatrix3

 
TMatrix4f = TMatrix4 deprecated 'use TMatrix4';

Warning: this symbol is deprecated: use TMatrix4

 
PMatrix4f = PMatrix4 deprecated 'use PMatrix4';

Warning: this symbol is deprecated: use PMatrix4

 
TEnableTextureTarget = (...);
 
Values
  • etNone
  • et2D
  • etCubeMap
  • et3D
TGLSupport = (...);

Part of CastleGLUtils unit: TGLFeatures and friends.

Values
  • gsNone
  • gsExtension
  • gsStandard
TPrimitiveMode = (...);

Primitive to draw using DrawPrimitive2D. The modes correspond to OpenGL drawing modes, see https://www.opengl.org/wiki/Primitive https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml

Values
  • pmPoints
  • pmLineStrip
  • pmLineLoop
  • pmLines
  • pmTriangleStrip
  • pmTriangleFan
  • pmTriangles

Constants

GLSupportNames: array [TGLSupport] of string = ( 'None', 'Extension', 'Standard' );
 
DefaultCircleSlices = 32;
 
GL_READ_FRAMEBUFFER_EXT = $8CA8;

Part of CastleGLUtils unit: EXT_framebuffer_blit constants and routines.

GL_DRAW_FRAMEBUFFER_EXT = $8CA9;
 
GL_DRAW_FRAMEBUFFER_BINDING_EXT = $8CA6;
 
GL_READ_FRAMEBUFFER_BINDING_EXT = $8CAA;
 

Variables

GLOutOfMemoryError: boolean = false;

When GPU runs out of memory, raise exception (EOpenGLOutOfMemoryError) or merely make a warning. Merely making a warning is very risky (you risk all kinds of rendering artifacts), but sometimes the rendering is actually smooth even though GPU complains.

CurrentColor: TCastleColor deprecated 'instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color';

Warning: this symbol is deprecated: instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color

Current color, set by glColorv and used for TCastleAbstractFont font printing (in case you use deprecated TCastleAbstractFont.Print overloads without explicit colors).

Instead of this, use drawing routines that take Color from parameters or properties, like TCastleAbstractFont.Print(X,Y,Color,...) or TDrawableImage.Color.

WindowPos: TVector2Integer deprecated 'use drawing routines that take position as parameters, like TDrawableImage.Draw(X,Y) or TCastleAbstractFont.Print(X,Y,...)';

Warning: this symbol is deprecated: use drawing routines that take position as parameters, like TDrawableImage.Draw(X,Y) or TCastleAbstractFont.Print(X,Y,...)

Global position for drawing 2D stuff. Do this use this. Instead of this, use drawing routines that take position as parameters, like TDrawableImage.Draw(X,Y) or TCastleAbstractFont.Print(X,Y,...).

GLFeatures: TGLFeatures;
 
LogGLInformationVerbose: Boolean = false;

Much more verbose logging of current context capabilities in GLInformationInitialize.

glBlitFramebufferEXT: procedure( srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1: TGLint; mask: TGLbitfield; filter: TGLenum);
 

Generated by PasDoc 0.16.0.