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( shared_ptr< ViewPort > pViewPort );
40 RenderPass( shared_ptr< ViewPort > pViewPort, shared_ptr< Scissor > pScissor );
42 void appendToRenderList();
43 void prependToRenderList();
45 void addPreRenderChildPass( shared_ptr< RenderPass > pChildPass );
46 void addPostRenderChildPass( shared_ptr< RenderPass > pChildPass );
48 static void RenderAll( bool bPreserveGLState );
49 static void ClearAll();
52 shared_ptr< ViewPort > pViewPort;
53 shared_ptr< Scissor > pScissor;
54 bool bClearColorBuffer;
55 bool bClearDepthBuffer;
58 math::Vector4f ColorClearValue;
59 uint32_t StencilClearValue;
62 // A high-level renderable object. This is an interface.
63 // It can be a simple mesh, a composite mesh, a character, a world sector,
64 // a terrain, a culling object, a portal etc.
65 // The root object for the world is a Renderable.
67 class Renderable : Persistable
69 virtual void evaluate( shared_ptr< RenderPass > pPass );
73 // A spatial transformation node. It may have a parent, and a number of children.
74 // The transformation tree represented by those live independently of the tree of
75 // renderable objects, which points to Frames to define their positions.
76 // Object outside of the renderable tree (camera, collision entities, physics objects,
77 // game code objects, lights) will also point to and interact with those.
78 class Frame : Persistable
81 shared_ptr< Frame > pParent;
86 math::Matrix44f LocalToParent;
89 // An elementary renderable object. It points to a material, some geometric data, and
90 // some state data (like its position, or the position of all the bones it refers to)
91 // It can be anything from a billboard to a bunch of textured polygons to
92 // a particle system or a piece of terrain, depending on the shaders in the material
93 // and what kind of geometry is actually described.
94 class Drawable : Renderable
96 Drawable( shared_ptr< Geometry > pGeometry, shared_ptr< Material > pMaterial, shared_ptr< Frame > pFrame );
98 shared_ptr< Geometry > pGeometry;
99 shared_ptr< Material > pMaterial;
100 shared_ptr< Frame > pFrame;
102 //vector< Input > Uniforms;
105 // A group of renderable objects
106 class Group : Renderable
109 void add( shared_ptr< Renderable > pChild );
111 // The remove function of group does a linear search and
112 // isn't the most effective thing. Group is not meant to contain tons of objects.
113 void remove( shared_ptr< Renderable > pChildToRemove );
115 shared_ptr< Frame > pFrame;
118 list< shared_ptr< Renderable > > Children;
121 // A sub rendering pass, useful when some object needs to render something in a different viewport before
122 // rendering itself (like for instance something needing to render a scene in a texture before rendering
123 // itself). When evaluate is invoked, the child rendering pass is added as a child of the provided render pass,
124 // and the child renderable (the root renderable of child scene) is evaluated.
125 // This is also used in the gui to render a clipped child widget (by setting up a child render context
126 // with a viewport and scissoring)
127 class ChildRenderPass : Renderable
129 ChildRenderPass( shared_ptr< RenderPass > pChildPass, shared_ptr< Renderable > pSubRenderable );
130 ChildRenderPass( shared_ptr< RenderPass > pChildPass, shared_ptr< Renderable > pSubRenderable, bool bPostRender );
131 shared_ptr< RenderPass > pChildPass;
132 shared_ptr< Renderable > pSubRenderable;
139 Camera( shared_ptr< Frame > pFrame );
140 shared_ptr< Frame > pFrame;
144 [ Abstract Polymorphic ]
150 class PerspectiveProjection : Projection
152 PerspectiveProjection();
155 // A projection setup so that the x and y axis directly match pixel coordinates.
156 // To be used to render the GUI's scenegraph.
157 // Not that the Y axis points upward, with its origin at the bottom of the window.
158 // This is to keep a right-hand coordinate system, so that doing things like
159 // inserting 3d models directly in the gui scenegraph will work without much
161 class PixelProjection : Projection
168 ViewPort( shared_ptr< Projection > pProjection, shared_ptr< Camera > pCamera );
169 ViewPort( shared_ptr< Projection > pProjection );
171 shared_ptr< Projection > pProjection;
172 shared_ptr< Camera > pCamera;
180 Scissor( math::Rectu32 rect );
181 Scissor( math::Vector2u32 position, math::Vector2u32 size );
182 Scissor( uint32_t left, uint32_t top, uint32_t width, uint32_t height );