1 /*
2  Copyright (C) 2001-2006, William Joseph.
3  All Rights Reserved.
4 
5  This file is part of GtkRadiant.
6 
7  GtkRadiant is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  GtkRadiant is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with GtkRadiant; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #if !defined(INCLUDED_RENDERABLE_H)
23 #define INCLUDED_RENDERABLE_H
24 
25 #include "generic/constant.h"
26 
27 class Shader;
28 class OpenGLRenderable;
29 class Matrix4;
30 
31 /** This is a proxy class used in the first (sorting) stage of rendering, which
32  * accepts OpenGLRenderables and adds them to a suitable data structure for
33  * rendering in the second stage. Despite its name, this class does not
34  * actually render anything.
35  *
36  * Each Renderable in the scenegraph is passed a reference to a
37  * RenderableSortProxy, on which the Renderable sets that necessary state
38  * variables and then submits its OpenGLRenderable for later rendering. A
39  * single Renderable may submit more than one OpenGLRenderable, with a
40  * different state each time -- for instance a Renderable model class may
41  * submit each of its material surfaces separately with the respective shaders
42  * set beforehand.
43  *
44  * @todo
45  * This class probably doesn't need to be a state machine, convert it to a
46  * single submit method with necessary parameters. */
47 class Renderer
48 {
49 	public:
50 		enum EHighlightMode
51 		{
52 			eFace = 1 << 0,
53 			/*! Full highlighting. */
54 			ePrimitive = 1 << 1
55 		};
56 
57 		enum EStyle
58 		{
59 			eWireframeOnly, eFullMaterials
60 		};
61 
~Renderer()62 		virtual ~Renderer ()
63 		{
64 		}
65 
66 		virtual void PushState () = 0;
67 		virtual void PopState () = 0;
68 		virtual void SetState (Shader* state, EStyle mode) = 0;
69 		virtual EStyle getStyle () const = 0;
70 		virtual void Highlight (EHighlightMode mode, bool bEnable = true) = 0;
71 		virtual void addRenderable (const OpenGLRenderable& renderable, const Matrix4& world) = 0;
72 };
73 
74 class VolumeTest;
75 
76 /** Interface class for Renderable objects. All objects which wish to be
77  * rendered need to implement this interface. During the scenegraph traversal
78  * for rendering, each Renderable object is passed a Renderer object
79  * which it can use to submit its geometry and state parameters. */
80 class Renderable
81 {
82 	public:
83 		STRING_CONSTANT(Name, "Renderable");
84 
~Renderable()85 		virtual ~Renderable ()
86 		{
87 		}
88 
89 		/** Submit renderable geometry when rendering takes place in Solid mode. */
90 		virtual void renderSolid (Renderer& renderer, const VolumeTest& volume) const = 0;
91 		/** Submit renderable geometry when rendering takes place in Wireframe mode */
92 		virtual void renderWireframe (Renderer& renderer, const VolumeTest& volume) const = 0;
renderComponents(Renderer &,const VolumeTest &)93 		virtual void renderComponents (Renderer&, const VolumeTest&) const
94 		{
95 		}
viewChanged()96 		virtual void viewChanged () const
97 		{
98 		}
99 };
100 
101 #endif
102