scenegraph: added the ability to define whether a ChildRenderPass will be inserted...
[fail.git] / src / scenegraph / scenegraph.fidl
blobb4dd6226aeeb964a9cdd37b633d7926f61ca51a2
1 /*
2     Fail game engine
3     Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
4  
5     This file is part of Fail.
7     Fail is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License version 3
9     as published by the Free Software Foundation.
11     Fail is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #include "../core/core.fidl"
20 #include "../services/objdb/objdb.fidl"
21 #include "../math/math.fidl"
22 #include "animation.fih"
23 #include "geometry.fih"
24 #include "material.fih"
26 namespace fail { namespace scenegraph
28         // A rendering context. This represent one rendering into one pixmap (either the screen
29         // or a texture). A pointer to a rendering context is passed to the Renderables at evaluation time.
30         // A renderable can choose to create a new rendering context and evaluate a sub-scene into it.
31         // For instance a portal could render its target to a texture, and then append a geometry with just
32         // one quad with this texture into the rendering context it's been given.
33         //
34         // There is a global list of contexts. Each new context is inserted in front of the list, and they
35         // are rendered in order. In effect, it means that any sub context created when evaluating a renderable
36         // will be rendered first (as they are dependencies of the original context)
37         class RenderPass
38         {
39                 RenderPass( Pointer< ViewPort > pViewPort );
40                 RenderPass( Pointer< ViewPort > pViewPort, Pointer< Scissor > pScissor );
42                 void appendToRenderList();
43                 void prependToRenderList();
45                 void addPreRenderChildPass( Pointer< RenderPass > pChildPass );
46                 void addPostRenderChildPass( Pointer< RenderPass > pChildPass );
47         
48                 static void RenderAll();
49                 static void ClearAll();
50                 void clear();
51                 
52                 Pointer< ViewPort > pViewPort;
53                 Pointer< Scissor > pScissor;
54         };
56         // A high-level renderable object. This is an interface.
57         // It can be a simple mesh, a composite mesh, a character, a world sector,
58         // a terrain, a culling object, a portal etc.
59         // The root object for the world is a Renderable.
60         [ Abstract=true ]
61         class Renderable : Persistable
62         {
63                 virtual void evaluate( Pointer< RenderPass > pPass );
64         };
65         [ default ]
67         // A spatial transformation node. It may have a parent, and a number of children.
68         // The transformation tree represented by those live independently of the tree of
69         // renderable objects, which points to Frames to define their positions.
70         // Object outside of the renderable tree (camera, collision entities, physics objects,
71         // game code objects, lights) will also point to and interact with those.
72         class Frame : Persistable
73         {
74                 Frame();
75                 Pointer< Frame > pParent;
76                 
77                 void dirty() const;
78                 Signal<> Dirty;
80                 math::Matrix44f LocalToParent;
81         };
82         
83         // An elementary renderable object. It points to a material, some geometric data, and
84         // some state data (like its position, or the position of all the bones it refers to)
85         // It can be anything from a billboard to a bunch of textured polygons to
86         // a particle system or a piece of terrain, depending on the shaders in the material
87         // and what kind of geometry is actually described.
88         class Drawable : Renderable
89         {
90                 Drawable( Pointer< Geometry > pGeometry, Pointer< Material > pMaterial, Pointer< Frame > pFrame );
91         
92                 Pointer< Geometry >     pGeometry;
93                 Pointer< Material >     pMaterial;
94                 Pointer< Frame >        pFrame;
95                 
96                 //vector< Input >       Uniforms;
97         };
98         
99         // A group of renderable objects
100         class Group : Renderable
101         {
102                 Group();
103                 void add( Pointer< Renderable > pChild );
104                 
105                 Pointer< Frame > pFrame;
106         
107                 [ Scriptable=false ]
108                 vector< Pointer< Renderable > > Children;
109         };
110         
111         // A sub rendering pass, useful when some object needs to render something in a different viewport before
112         // rendering itself (like for instance something needing to render a scene in a texture before rendering
113         // itself). When evaluate is invoked, the child rendering pass is added as a child of the provided render pass,
114         // and the child renderable (the root renderable of child scene) is evaluated.
115         // This is also used in the gui to render a clipped child widget (by setting up a child render context
116         // with a viewport and scissoring)
117         class ChildRenderPass : Renderable
118         {
119                 ChildRenderPass( Pointer< RenderPass > pChildPass, Pointer< Renderable > pSubRenderable );
120                 ChildRenderPass( Pointer< RenderPass > pChildPass, Pointer< Renderable > pSubRenderable, bool bPostRender );
121                 Pointer< RenderPass >   pChildPass;
122                 Pointer< Renderable >   pSubRenderable;
123                 bool                                    bPostRender;
124         };
125         
126         
127         class Camera
128         {
129                 Camera( Pointer< Frame > pFrame );
130                 Pointer< Frame >        pFrame;
131                 float                           FOV;
132         };
133         
134         [ Abstract=true Polymorphic=true ]
135         class Projection
136         {
137         };
138         [ default ]
139         
140         class PerspectiveProjection : Projection
141         {
142                 PerspectiveProjection();
143         };
144         
145         // A projection setup so that the x and y axis directly match pixel coordinates.
146         // To be used to render the GUI's scenegraph.
147         // Not that the Y axis points upward, with its origin at the bottom of the window.
148         // This is to keep a right-hand coordinate system, so that doing things like
149         // inserting 3d models directly in the gui scenegraph will work without much
150         // hassle.
151         class PixelProjection : Projection
152         {
153                 PixelProjection();
154         };
155         
156         class ViewPort
157         {
158                 ViewPort( Pointer< Projection > pProjection, Pointer< Camera > pCamera );
159                 ViewPort( Pointer< Projection > pProjection );
161                 Pointer< Projection >   pProjection;
162                 Pointer< Camera >               pCamera;
163                 math::Rectu32                   Rect;
164                 float                                   ZNear;
165                 float                                   ZFar;
166                 bool                                    bClearColorBuffer;
167                 bool                                    bClearDepthBuffer;
168         };
170         class Scissor
171         {
172                 Scissor( math::Rectu32 rect );
173                 Scissor( math::Vector2u32 position, math::Vector2u32 size );
174                 Scissor( uint32_t left, uint32_t top, uint32_t width, uint32_t height );
176                 math::Rectu32   Rect;
177         };
178         
179         // This is the rudimentary, rushed font class from the old renderer that
180         // has been ported over into scenegraph hastily, along with a specific
181         // rendering system for fonts as the scenegraph is currently not very well
182         // suited for this kind of things: the number of quads to draw is kindof
183         // dynamic and it would feel a bit inneficient to allocate/free that many
184         // drawables, and to assign each of them their own frame etc.
185         // something nicer using instanciation will have to be devised later,
186         // in the meantime fonts are rendered by letting ftgl send vertices manually)
187         [ Storable=false ]
188         class Font
189         {
190                 Font( string Filename, uint32_t Size );
191                 
192                 float getHeight();
193                 float getTextWidth( string Text );
194         };
195         
196         class Text : Renderable
197         {
198                 Text( Pointer< Font > pFont, Pointer< Frame > pFrame, Pointer< Material > pMaterial );
199                 Text( Pointer< Font > pFont, Pointer< Frame > pFrame, Pointer< Material > pMaterial, string Text );
200                 
201                 Pointer< Font > pFont;
202                 Pointer< Frame > pFrame;
203                 Pointer< Material > pMaterial;
204                 string TextString;
205         };
206         [ default ]