Debian Codegraph @

src/scene/x3d/x3dnodes_generatedtextures.inc

raw
1 {%MainUnit x3dnodes.pas}
2 {
3 Copyright 2008-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 { Common stuff for generated textures. }
18
19 {$ifdef read_interface}
20
21 { Possible update modes for generated textures (like @link(TGeneratedCubeMapTextureNode.Update)). }
22 TTextureUpdate = (upNone, upNextFrameOnly, upAlways);
23
24 { Functionality for all X3D nodes that represent generated textures. }
25 TGeneratedTextureFunctionality = class(TNodeFunctionality)
26 strict private
27 FTextureNode: TAbstractTextureNode;
28 protected
29 function GetUpdate: TTextureUpdate; virtual; abstract;
30 procedure SetUpdate(const Value: TTextureUpdate); virtual; abstract;
31 public
32 { Used by TCastleScene to track when to set InternalUpdateNeeded. }
33 InternalLastStateId: TFrameId;
34
35 { When @link(Update) is upAlways, you can check this to know if really
36 something visible changed since last update.
37 If not, then you do not have to update the texture --- no point, since
38 it would look exactly like the current one.
39
40 TCastleScene takes care to set this field.
41 After each actual update of the texture,
42 it's set to @false. Each time something visible affecting the look
43 of this texture possibly changed, it's set to @true. }
44 InternalUpdateNeeded: boolean;
45
46 constructor Create(const TextureNode: TAbstractTextureNode);
47
48 { Depending on @link(Update), decide whether we need updating. }
49 function NeedsUpdate: Boolean;
50
51 { Call after NeedsUpdate returned @true and you updated the texture.
52 Will take care of sending "NONE" after "NEXT_FRAME_ONLY". }
53 procedure PostUpdate;
54
55 property Update: TTextureUpdate read GetUpdate write SetUpdate;
56 end;
57 {$endif read_interface}
58
59 {$ifdef read_implementation}
60 const
61 TextureUpdateNames: array [TTextureUpdate] of string = (
62 'NONE',
63 'NEXT_FRAME_ONLY',
64 'ALWAYS'
65 );
66
67 { TGeneratedTextureFunctionality --------------------------------------------- }
68
69 constructor TGeneratedTextureFunctionality.Create(const TextureNode: TAbstractTextureNode);
70 begin
71 FTextureNode := TextureNode;
72 inherited Create(TextureNode);
73 end;
74
75 function TGeneratedTextureFunctionality.NeedsUpdate: Boolean;
76 begin
77 Result :=
78 (Update = upNextFrameOnly) or
79 ( (Update = upAlways) and InternalUpdateNeeded );
80 end;
81
82 procedure TGeneratedTextureFunctionality.PostUpdate;
83 begin
84 if Update = upNextFrameOnly then
85 Update := upNone;
86 InternalUpdateNeeded := false;
87 end;
88
89 {$endif read_implementation}