Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / include / renderer / renderer.h
blobcb100a8d44eb160bfddade91b6af40b28d51157d
1 //
2 // Copyright (C) 2007-2008 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file renderer.h
22 * Encapsulates chosen renderer/display
25 #pragma once
27 #include <vector>
29 #include "types.h"
30 #include "math/matrix.h"
31 #include "core/client/display.h"
33 namespace tre {
35 class PVolume;
36 class AttribBufferSet;
37 class IndexBuffer;
38 class Canvas;
39 class Effect;
40 struct EffectVars;
42 struct FrameStats {
43 uint triangles;
44 uint batches; // number of draw calls
46 // visible lights
47 // fps
51 -frame:
52 -triangles (unique vs. total)
53 -batches (unique vs. total) - draw calls
54 -visible lights
55 -fps
56 -seconds per frame
57 -global:
58 -total frames
59 -time spent rendering?
60 -average fps
61 -average triangles
62 -average batches
63 -average lights
66 uint time;
68 uint count; // frame count
71 class GeometryInfo {
72 public:
73 const Matrix4x4f * trans;
74 const AttribBufferSet * attribs;
75 const IndexBuffer * indices;
76 const Effect * effect;
77 const EffectVars * fxVars;
79 // bounding volume?
81 public:
82 GeometryInfo(const Matrix4x4f & t, const AttribBufferSet * a,
83 const IndexBuffer * i, const Effect * e, const EffectVars & ev)
84 : trans(&t), attribs(a), indices(i), effect(e), fxVars(&ev) {}
86 GeometryInfo(const Matrix4x4f * t, const AttribBufferSet * a,
87 const IndexBuffer * i, const Effect * e, const EffectVars * ev)
88 : trans(t), attribs(a), indices(i), effect(e), fxVars(ev) {}
91 typedef std::vector<GeometryInfo> GeometryBatch;
93 class Renderer {
94 public:
95 static bool CheckErrors(const char * msg=NULL, bool confirmOK=false);
97 public:
98 FrameStats frame;
100 public:
101 Renderer() {}
102 virtual ~Renderer() {}
104 virtual void Init(void) = 0;
106 virtual void NewFrame(void) = 0;
107 virtual void FlushFrame(void) = 0;
108 virtual void PresentFrame(void) = 0;
110 virtual void SetCamera(const PVolume & cam) = 0;
111 virtual void SetCameraTransform(const Matrix4x4f * cnv) = 0;
113 virtual void PushCanvas(const Canvas * cnv) = 0;
114 virtual void PopCanvas(void) = 0;
116 virtual void DrawGeometry(const GeometryBatch::iterator & begin,
117 const GeometryBatch::iterator & end) = 0;
120 Renderer & sRenderer(void);