3 Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
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.
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)
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 );
48 static void RenderAll();
49 static void ClearAll();
52 Pointer< ViewPort > pViewPort;
53 Pointer< Scissor > pScissor;
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.
61 class Renderable : Persistable
63 virtual void evaluate( Pointer< RenderPass > pPass );
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
75 Pointer< Frame > pParent;
80 math::Matrix44f LocalToParent;
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
90 Drawable( Pointer< Geometry > pGeometry, Pointer< Material > pMaterial, Pointer< Frame > pFrame );
92 Pointer< Geometry > pGeometry;
93 Pointer< Material > pMaterial;
94 Pointer< Frame > pFrame;
96 //vector< Input > Uniforms;
99 // A group of renderable objects
100 class Group : Renderable
103 void add( Pointer< Renderable > pChild );
105 Pointer< Frame > pFrame;
108 vector< Pointer< Renderable > > Children;
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
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;
129 Camera( Pointer< Frame > pFrame );
130 Pointer< Frame > pFrame;
134 [ Abstract=true Polymorphic=true ]
140 class PerspectiveProjection : Projection
142 PerspectiveProjection();
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
151 class PixelProjection : Projection
158 ViewPort( Pointer< Projection > pProjection, Pointer< Camera > pCamera );
159 ViewPort( Pointer< Projection > pProjection );
161 Pointer< Projection > pProjection;
162 Pointer< Camera > pCamera;
166 bool bClearColorBuffer;
167 bool bClearDepthBuffer;
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 );
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)
190 Font( string Filename, uint32_t Size );
193 float getTextWidth( string Text );
196 class Text : Renderable
198 Text( Pointer< Font > pFont, Pointer< Frame > pFrame, Pointer< Material > pMaterial );
199 Text( Pointer< Font > pFont, Pointer< Frame > pFrame, Pointer< Material > pMaterial, string Text );
201 Pointer< Font > pFont;
202 Pointer< Frame > pFrame;
203 Pointer< Material > pMaterial;