| 1 |
{ |
| 2 |
Copyright 2001-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Various utilities for OpenGL(ES) rendering. } |
| 17 |
unit CastleGLUtils; |
| 18 |
|
| 19 |
{$I castleconf.inc} |
| 20 |
{$I openglmac.inc} |
| 21 |
|
| 22 |
interface |
| 23 |
|
| 24 |
uses |
| 25 |
SysUtils, Math, Generics.Collections, Classes, |
| 26 |
{$ifdef OpenGLES} CastleGLES, {$else} CastleGL, {$endif} |
| 27 |
CastleImages, CastleUtils, CastleVectors, CastleRectangles, |
| 28 |
CastleColors, CastleProjection, CastleRenderOptions; |
| 29 |
|
| 30 |
{$define read_interface} |
| 31 |
|
| 32 |
{$I castleglutils_types.inc} |
| 33 |
{$I castleglutils_features.inc} |
| 34 |
{$I castleglutils_draw_primitive_2d.inc} |
| 35 |
{$I castleglutils_information.inc} |
| 36 |
{$I castleglutils_vertex_array_object.inc} |
| 37 |
|
| 38 |
{$undef read_interface} |
| 39 |
|
| 40 |
implementation |
| 41 |
|
| 42 |
{$define read_implementation} |
| 43 |
|
| 44 |
uses |
| 45 |
CastleFilesUtils, CastleStringUtils, CastleGLVersion, CastleGLShaders, |
| 46 |
CastleLog, CastleApplicationProperties, CastleRenderContext, CastleGLImages, |
| 47 |
CastleInternalGLUtils, CastleTimeUtils; |
| 48 |
|
| 49 |
{$I castleglutils_types.inc} |
| 50 |
{$I castleglutils_features.inc} |
| 51 |
{$I castleglutils_draw_primitive_2d.inc} |
| 52 |
{$I castleglutils_information.inc} |
| 53 |
{$I castleglutils_vertex_array_object.inc} |
| 54 |
|
| 55 |
{ initialization, finalization ----------------------------------------------- } |
| 56 |
|
| 57 |
procedure ContextClose; |
| 58 |
begin |
| 59 |
FreeAndNil(Primitive2DRes); |
| 60 |
|
| 61 |
{ free things created by GLInformationInitialize } |
| 62 |
FreeAndNil(GLVersion); |
| 63 |
|
| 64 |
FreeAndNil(GLFeatures); |
| 65 |
end; |
| 66 |
|
| 67 |
initialization |
| 68 |
{ Our GLVersion, GLFeatures should be freed at the very end, |
| 69 |
as a lot of code uses them. So place ContextClose to be called last, |
| 70 |
OnGLContextClose[0]. |
| 71 |
Every other unit initializion does OnGLContextClose.Add, |
| 72 |
so our initialization will stay as OnGLContextClose[0]. } |
| 73 |
ApplicationProperties.OnGLContextClose.Insert(0, @ContextClose); |
| 74 |
end. |