1 // ==============================================================
2 //	This file is part of Glest (www.glest.org)
3 //
4 //	Copyright (C) 2001-2008 Martiño Figueroa
5 //
6 //	You can redistribute this code and/or modify it under
7 //	the terms of the GNU General Public License as published
8 //	by the Free Software Foundation; either version 2 of the
9 //	License, or (at your option) any later version
10 // ==============================================================
11 
12 #ifndef _GLEST_GAME_RENDERER_H_
13 #define _GLEST_GAME_RENDERER_H_
14 
15 #ifdef WIN32
16     #include <winsock2.h>
17     #include <winsock.h>
18 #endif
19 
20 #include "vec.h"
21 #include "math_util.h"
22 #include "model.h"
23 #include "particle.h"
24 #include "pixmap.h"
25 #include "font.h"
26 #include "matrix.h"
27 #include "selection.h"
28 #include "components.h"
29 #include "texture.h"
30 #include "model_manager.h"
31 #include "graphics_factory_gl.h"
32 #include "font_manager.h"
33 #include "camera.h"
34 #include <vector>
35 #include "model_renderer.h"
36 #include "model.h"
37 #include "graphics_interface.h"
38 #include "base_renderer.h"
39 #include "simple_threads.h"
40 #include "video_player.h"
41 
42 #ifdef DEBUG_RENDERING_ENABLED
43 #	define IF_DEBUG_EDITION(x) x
44 #	include "debug_renderer.h"
45 #else
46 #	define IF_DEBUG_EDITION(x)
47 #endif
48 
49 #include "leak_dumper.h"
50 
51 enum DebugUILevelType {
52 	debugui_fps 		= 0x01,
53 	debugui_unit_titles = 0x02
54 };
55 
56 namespace Glest{ namespace Game{
57 
58 using namespace ::Shared::Graphics;
59 using namespace ::Shared::PlatformCommon;
60 
61 //non shared classes
62 class Config;
63 class Game;
64 class GameCamera;
65 class MainMenu;
66 class Console;
67 class MenuBackground;
68 class ChatManager;
69 class Object;
70 class ConsoleLineInfo;
71 class SurfaceCell;
72 class Program;
73 // =====================================================
74 // 	class MeshCallbackTeamColor
75 // =====================================================
76 
77 class MeshCallbackTeamColor: public MeshCallback {
78 private:
79 	const Texture *teamTexture;
80 
81 public:
MeshCallbackTeamColor()82 	MeshCallbackTeamColor() : MeshCallback() {
83 		teamTexture = NULL;
84 	}
setTeamTexture(const Texture * teamTexture)85 	void setTeamTexture(const Texture *teamTexture)	{this->teamTexture= teamTexture;}
86 	virtual void execute(const Mesh *mesh);
87 
88 	static bool noTeamColors;
89 };
90 
91 // ===========================================================
92 // 	class Renderer
93 //
94 ///	OpenGL renderer, uses the shared library
95 // ===========================================================
96 
97 class VisibleQuadContainerCache {
98 protected:
99 
CopyAll(const VisibleQuadContainerCache & obj)100 	inline void CopyAll(const VisibleQuadContainerCache &obj) {
101 		cacheFrame 			= obj.cacheFrame;
102 		visibleObjectList	= obj.visibleObjectList;
103 		visibleUnitList		= obj.visibleUnitList;
104 		visibleQuadUnitList = obj.visibleQuadUnitList;
105 		visibleQuadUnitBuildList = obj.visibleQuadUnitBuildList;
106 		visibleScaledCellList = obj.visibleScaledCellList;
107 		visibleScaledCellToScreenPosList = obj.visibleScaledCellToScreenPosList;
108 		lastVisibleQuad		= obj.lastVisibleQuad;
109 		frustumData			= obj.frustumData;
110 		proj				= obj.proj;
111 		modl				= obj.modl;
112 		frustumDataCache	= obj.frustumDataCache;
113 	}
114 
115 public:
116 
VisibleQuadContainerCache()117 	inline VisibleQuadContainerCache() {
118 		cacheFrame = 0;
119 		clearFrustumData();
120 		clearCacheData();
121 	}
VisibleQuadContainerCache(const VisibleQuadContainerCache & obj)122 	inline VisibleQuadContainerCache(const VisibleQuadContainerCache &obj) {
123 		CopyAll(obj);
124 	}
125 	inline VisibleQuadContainerCache & operator=(const VisibleQuadContainerCache &obj) {
126 		CopyAll(obj);
127 		return *this;
128 	}
129 
clearCacheData()130 	inline void clearCacheData() {
131 		clearVolatileCacheData();
132 		clearNonVolatileCacheData();
133 	}
clearVolatileCacheData()134 	inline void clearVolatileCacheData() {
135 		visibleUnitList.clear();
136 		visibleQuadUnitList.clear();
137 		visibleQuadUnitBuildList.clear();
138 		//inVisibleUnitList.clear();
139 
140 		visibleUnitList.reserve(500);
141 		visibleQuadUnitList.reserve(500);
142 		visibleQuadUnitBuildList.reserve(100);
143 	}
clearNonVolatileCacheData()144 	inline void clearNonVolatileCacheData() {
145 		visibleObjectList.clear();
146 		visibleScaledCellList.clear();
147 		visibleScaledCellToScreenPosList.clear();
148 
149 		visibleObjectList.reserve(500);
150 		visibleScaledCellList.reserve(500);
151 	}
clearFrustumData()152 	inline void clearFrustumData() {
153 		frustumData = vector<vector<float> >(6,vector<float>(4,0));
154 		proj = vector<float>(16,0);
155 		modl = vector<float>(16,0);
156 		frustumDataCache.clear();
157 	}
158 	int cacheFrame;
159 	Quad2i lastVisibleQuad;
160 	std::vector<Object *> visibleObjectList;
161 	std::vector<Unit   *> visibleQuadUnitList;
162 	std::vector<UnitBuildInfo> visibleQuadUnitBuildList;
163 	std::vector<Unit   *> visibleUnitList;
164 	std::vector<Vec2i> visibleScaledCellList;
165 	std::map<Vec2i,Vec3f> visibleScaledCellToScreenPosList;
166 
167 	static bool enableFrustumCalcs;
168 	vector<vector<float> > frustumData;
169 	vector<float> proj;
170 	vector<float> modl;
171 	map<pair<vector<float>,vector<float> >, vector<vector<float> > > frustumDataCache;
172 
173 };
174 
175 class VisibleQuadContainerVBOCache {
176 public:
177 	// Vertex Buffer Object Names
178 	bool    hasBuiltVBOs;
179 	uint32	m_nVBOVertices;					// Vertex VBO Name
180 	uint32	m_nVBOFowTexCoords;				// Texture Coordinate VBO Name for fog of war texture coords
181 	uint32	m_nVBOSurfaceTexCoords;			// Texture Coordinate VBO Name for surface texture coords
182 	uint32	m_nVBONormals;					// Normal VBO Name
183 	//uint32	m_nVBOIndexes;					// Indexes VBO Name
184 };
185 
186 enum ConsoleMode {
187 	consoleOff,
188 	consoleNormal,
189 	consoleFull,
190 	consoleStoredOnly,
191 	consoleStoredAndNormal,
192 
193 	consoleCount
194 };
195 
196 class Renderer : public RendererInterface,
197 				 public BaseRenderer,
198 				 // This is for screen saver thread
199 				 public SimpleTaskCallbackInterface,
200 				 public VideoLoadingCallbackInterface {
201 public:
202 	//progress bar
203 	static const int maxProgressBar;
204 	static const Vec4f progressBarBack1;
205 	static const Vec4f progressBarBack2;
206 	static const Vec4f progressBarFront1;
207 	static const Vec4f progressBarFront2;
208 
209 	//sun and moon
210 	static const float sunDist;
211 	static const float moonDist;
212 	static const float lightAmbFactor;
213 
214 	//mouse
215 	static const int maxMouse2dAnim;
216 
217 	//texture units
218 	static const GLenum baseTexUnit;
219 	static const GLenum fowTexUnit;
220 	static const GLenum shadowTexUnit;
221 
222 	//selection
223 	static const float selectionCircleRadius;
224 	static const float magicCircleRadius;
225 
226 	//perspective values
227 	static const float perspFov;
228 	static const float perspNearPlane;
229 	static float perspFarPlane;
230 
231 	//default values
232 	static const float ambFactor;
233 	static const Vec4f defSpecularColor;
234 	static const Vec4f defDiffuseColor;
235 	static const Vec4f defAmbientColor;
236 	static const Vec4f defColor;
237 	static const Vec4f fowColor;
238 
239 	//light
240 	static const float maxLightDist;
241 
242 	static bool renderText3DEnabled;
243 
244 public:
245 	enum Shadows {
246 		sDisabled,
247 		sProjected,
248 		sShadowMapping,
249 
250 		sCount
251 	};
252 
253 private:
254 
255 	//config
256 	int maxLights;
257     bool photoMode;
258 	int shadowTextureSize;
259 	int shadowFrameSkip;
260 	float shadowIntensity;
261 	bool focusArrows;
262 	bool textures3D;
263 	Shadows shadows;
264 	int maxConsoleLines;
265 
266 	//game
267 	const Game *game;
268 	GameCamera *gameCamera;
269 	const MainMenu *menu;
270 	Program *program;
271 
272 	//misc
273 	int triangleCount;
274 	int pointCount;
275 	Quad2i visibleQuad;
276 	Quad2i visibleQuadFromCamera;
277 	Vec4f nearestLightPos;
278 	VisibleQuadContainerCache quadCache;
279 	VisibleQuadContainerCache quadCacheSelection;
280 
281 	//renderers
282 	ModelRenderer *modelRenderer;
283 	TextRenderer2D *textRenderer;
284 	TextRenderer3D *textRenderer3D;
285 	ParticleRenderer *particleRenderer;
286 
287 	//texture managers
288 	ModelManager *modelManager[rsCount];
289 	TextureManager *textureManager[rsCount];
290 	FontManager *fontManager[rsCount];
291 	ParticleManager *particleManager[rsCount];
292 
293 	//state lists
294 	//GLuint list3d;
295 	//bool list3dValid;
296 	//GLuint list2d;
297 	//bool list2dValid;
298 	//GLuint list3dMenu;
299 	//bool list3dMenuValid;
300 	//GLuint *customlist3dMenu;
301 	//const MainMenu *mm3d;
302 	const MainMenu *custom_mm3d;
303 
304 	//shadows
305 	GLuint shadowMapHandle;
306 	bool shadowMapHandleValid;
307 
308 	Matrix4f shadowMapMatrix;
309 	int shadowMapFrame;
310 
311 	//water
312 	float waterAnim;
313 
314 	bool allowRenderUnitTitles;
315 	//std::vector<std::pair<Unit *,Vec3f> > renderUnitTitleList;
316 	std::vector<Unit *> visibleFrameUnitList;
317 	string visibleFrameUnitListCameraKey;
318 
319 	bool no2DMouseRendering;
320 	bool showDebugUI;
321 	int showDebugUILevel;
322 
323 	int lastRenderFps;
324 	float smoothedRenderFps;
325 	bool shadowsOffDueToMinRender;
326 
327 	std::vector<std::pair<ParticleSystem *, ResourceScope> > deferredParticleSystems;
328 
329 	SimpleTaskThread *saveScreenShotThread;
330 	Mutex *saveScreenShotThreadAccessor;
331 	std::list<std::pair<string,Pixmap2D *> > saveScreenQueue;
332 
333 	std::map<Vec3f,Vec3f> worldToScreenPosCache;
334 
335 	//bool masterserverMode;
336 
337 	std::map<uint32,VisibleQuadContainerVBOCache > mapSurfaceVBOCache;
338 
339 	class SurfaceData {
340 	public:
SurfaceData()341 		inline SurfaceData() {
342 			uniqueId=0;
343 			bufferCount=0;
344 			textureHandle=0;
345 		}
346 		static uint32 nextUniqueId;
347 		uint32 uniqueId;
348 		int bufferCount;
349 		int textureHandle;
350 		vector<Vec2f> texCoords;
351 		vector<Vec2f> texCoordsSurface;
352 		vector<Vec3f> vertices;
353 		vector<Vec3f> normals;
354 	};
355 
356 	VisibleQuadContainerVBOCache * GetSurfaceVBOs(SurfaceData *cellData);
357 	void ReleaseSurfaceVBOs();
358 	std::map<string,std::pair<Chrono, std::vector<SurfaceData> > > mapSurfaceData;
359 	static bool rendererEnded;
360 
361 	class MapRenderer {
362 	public:
MapRenderer()363 		inline MapRenderer(): map(NULL) {}
~MapRenderer()364 		inline ~MapRenderer() { destroy(); }
365 		void render(const Map* map,float coordStep,VisibleQuadContainerCache &qCache);
366 		void renderVisibleLayers(const Map* map,float coordStep,VisibleQuadContainerCache &qCache);
367 		void destroy();
368 	private:
369 		void load(float coordStep);
370 		void loadVisibleLayers(float coordStep,VisibleQuadContainerCache &qCache);
371 
372 		const Map* map;
373 		struct Layer {
LayerLayer374 			inline Layer(int th):
375 				vbo_vertices(0), vbo_normals(0),
376 				vbo_fowTexCoords(0), vbo_surfTexCoords(0),
377 				vbo_indices(0), indexCount(0),
378 				textureHandle(th),textureCRC(0) {}
379 
380 			inline Layer & operator=(Layer &obj) {
381 				this->vertices = obj.vertices;
382 				this->normals = obj.normals;
383 				this->fowTexCoords = obj.fowTexCoords;
384 				this->surfTexCoords = obj.surfTexCoords;
385 				this->indices = obj.indices;
386 				this->cellToIndicesMap = obj.cellToIndicesMap;
387 				this->rowsToRenderCache = obj.rowsToRenderCache;
388 				this->vbo_vertices = obj.vbo_vertices;
389 				this->vbo_normals = obj.vbo_normals;
390 				this->vbo_fowTexCoords = obj.vbo_fowTexCoords;
391 				this->vbo_surfTexCoords = obj.vbo_surfTexCoords;
392 				this->vbo_indices = obj.vbo_indices;
393 				this->indexCount = obj.indexCount;
394 				this->textureHandle = obj.textureHandle;
395 				this->texturePath = obj.texturePath;
396 				this->textureCRC = obj.textureCRC;
397 
398 				return *this;
399 			}
400 
401 			~Layer();
402 			void load_vbos(bool vboEnabled);
403 			void render(VisibleQuadContainerCache &qCache);
404 			void renderVisibleLayer();
405 
406 			std::vector<Vec3f> vertices, normals;
407 			std::vector<Vec2f> fowTexCoords, surfTexCoords;
408 			std::vector<GLuint> indices;
409 			std::map<Vec2i, int> cellToIndicesMap;
410 			std::map<Quad2i, vector<pair<int,int> > > rowsToRenderCache;
411 
412 			GLuint vbo_vertices, vbo_normals,
413 				vbo_fowTexCoords, vbo_surfTexCoords,
414 				vbo_indices;
415 			int indexCount;
416 			int textureHandle;
417 			string texturePath;
418 			uint32 textureCRC;
419 		};
420 		typedef std::vector<Layer*> Layers;
421 		Layers layers;
422 		Quad2i lastVisibleQuad;
423 	} mapRenderer;
424 
425 	bool ExtractFrustum(VisibleQuadContainerCache &quadCacheItem);
426 	bool PointInFrustum(vector<vector<float> > &frustum, float x, float y, float z );
427 	bool SphereInFrustum(vector<vector<float> > &frustum,  float x, float y, float z, float radius);
428 	bool CubeInFrustum(vector<vector<float> > &frustum, float x, float y, float z, float size );
429 
430 private:
431 	Renderer();
432 	~Renderer();
433 
434 public:
435 	static Renderer &getInstance();
436 	static bool isEnded();
437 	//bool isMasterserverMode() const { return masterserverMode; }
438 
439 	void addToDeferredParticleSystemList(std::pair<ParticleSystem *, ResourceScope> deferredParticleSystem);
440 	void manageDeferredParticleSystems();
441 
442 	void reinitAll();
443 
444     //init
445 	void init();
446 	void initGame(const Game *game, GameCamera *gameCamera);
447 	void initMenu(const MainMenu *mm);
448 	void reset3d();
449 	void reset2d();
450 	void reset3dMenu();
451 
452 	//end
453 	void end();
454 	void endScenario();
455 	void endMenu();
456 	void endGame(bool isFinalEnd);
457 
458 	//get
getTriangleCount()459 	inline int getTriangleCount() const	{return triangleCount;}
getPointCount()460 	inline int getPointCount() const		{return pointCount;}
461 
462 	//misc
463 	void reloadResources();
464 
465 	//engine interface
466 	void initTexture(ResourceScope rs, Texture *texture);
467 	void endTexture(ResourceScope rs, Texture *texture,bool mustExistInList=false);
468 	void endLastTexture(ResourceScope rs, bool mustExistInList=false);
469 
470 	Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL);
471 	void endModel(ResourceScope rs, Model *model, bool mustExistInList=false);
472 	void endLastModel(ResourceScope rs, bool mustExistInList=false);
473 
474 	Texture2D *newTexture2D(ResourceScope rs);
475 	Texture3D *newTexture3D(ResourceScope rs);
476 	Font2D *newFont(ResourceScope rs);
477 	Font3D *newFont3D(ResourceScope rs);
478 	void endFont(::Shared::Graphics::Font *font, ResourceScope rs, bool mustExistInList=false);
479 	void resetFontManager(ResourceScope rs);
480 
getTextRenderer()481 	inline TextRenderer2D *getTextRenderer() const	{return textRenderer;}
getTextRenderer3D()482 	inline TextRenderer3D *getTextRenderer3D() const	{return textRenderer3D;}
483 
484 	void manageParticleSystem(ParticleSystem *particleSystem, ResourceScope rs);
485 	void cleanupParticleSystems(vector<ParticleSystem *> &particleSystems,ResourceScope rs);
486 	void cleanupUnitParticleSystems(vector<UnitParticleSystem *> &particleSystems,ResourceScope rs);
487 	bool validateParticleSystemStillExists(ParticleSystem * particleSystem,ResourceScope rs) const;
488 	void removeParticleSystemsForParticleOwner(ParticleOwner * particleOwner,ResourceScope rs);
489 	void updateParticleManager(ResourceScope rs,int renderFps=-1);
490 	void renderParticleManager(ResourceScope rs);
491 	void swapBuffers();
492 
493     //lights and camera
494 	void setupLighting();
495 	void setupLightingForRotatedModel();
496 	void loadGameCameraMatrix();
497 	void loadCameraMatrix(const Camera *camera);
498 	void computeVisibleQuad();
499 
500     //basic rendering
501 	void renderMouse2d(int mouseX, int mouseY, int anim, float fade= 0.f);
502     void renderMouse3d();
503 
504     void renderGhostModel(const UnitType *building, const Vec2i pos,CardinalDir facing,Vec4f *forceColor=NULL);
505 
506     void renderBackground(const Texture2D *texture);
507 	void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL);
508 	void renderConsole(const Console *console, ConsoleMode mode=consoleNormal, int overrideMaxConsoleLines=-1);
509 	void renderConsoleLine3D(int lineIndex, int xPosition, int yPosition, int lineHeight, Font3D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo);
510 	void renderConsoleLine(int lineIndex, int xPosition, int yPosition, int lineHeight, Font2D* font, string stringToHightlight, const ConsoleLineInfo *lineInfo);
511 
512 	void renderChatManager(const ChatManager *chatManager);
513 	void renderClock();
514 	void renderPerformanceStats();
515 	void renderResourceStatus();
516 	void renderSelectionQuad();
517 	void renderText(const string &text, Font2D *font, float alpha, int x, int y, bool centered= false);
518 	void renderText(const string &text, Font2D *font, const Vec3f &color, int x, int y, bool centered= false);
519 	void renderText(const string &text, Font2D *font, const Vec4f &color, int x, int y, bool centered=false);
520 	void renderTextShadow(const string &text, Font2D *font,const Vec4f &color, int x, int y, bool centered= false);
521 
522 	void renderText3D(const string &text, Font3D *font, float alpha, int x, int y, bool centered);
523 	void renderText3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, bool centered);
524 	void renderText3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, bool centered);
525 	void renderTextShadow3D(const string &text, Font3D *font,const Vec4f &color, int x, int y, bool centered=false);
526 	void renderProgressBar3D(int size, int x, int y, Font3D *font, int customWidth=-1, string prefixLabel="", bool centeredText=true,int customHeight=-1);
527 
528 	Vec2f getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, int w, int h, bool centeredW, bool centeredH);
529 	void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec4f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled, int maxEditWidth, int maxEditRenderWidth);
530 	void renderTextBoundingBox3D(const string &text, Font3D *font, const Vec3f &color, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth);
531 	void renderTextBoundingBox3D(const string &text, Font3D *font, float alpha, int x, int y, int w, int h, bool centeredW, bool centeredH, bool editModeEnabled,int maxEditWidth, int maxEditRenderWidth);
532 
533 	void renderTextSurroundingBox(int x, int y, int w, int h,int maxEditWidth, int maxEditRenderWidth);
534 
535 	void beginRenderToTexture(Texture2D **renderToTexture);
536 	void endRenderToTexture(Texture2D **renderToTexture);
537 
538 	void renderFPSWhenEnabled(int lastFps);
539 
540     //components
541 	void renderLabel(GraphicLabel *label);
542 	void renderLabel(GraphicLabel *label,const Vec3f *color);
543 	void renderLabel(GraphicLabel *label,const Vec4f *color);
544     void renderButton(GraphicButton *button,const Vec4f *fontColorOverride=NULL,bool *lightedOverride=NULL);
545     void renderCheckBox(const GraphicCheckBox *box);
546     void renderLine(const GraphicLine *line);
547     void renderScrollBar(const GraphicScrollBar *sb);
548     void renderListBox(GraphicListBox *listBox);
549 	void renderMessageBox(GraphicMessageBox *listBox);
550 	void renderPopupMenu(PopupMenu *menu);
551 
552     //complex rendering
553     void renderSurface(const int renderFps);
554 	void renderObjects(const int renderFps);
555 
556 	void renderWater();
557     void renderUnits(bool airUnits, const int renderFps);
558     void renderUnitsToBuild(const int renderFps);
559 
560 	void renderSelectionEffects(int healthbarMode);
561 	void renderHealthBars(int healthbarMode);
562 	void renderWaterEffects();
563 	void renderHud();
564 	void renderMinimap();
565     void renderDisplay();
566 	void renderMenuBackground(const MenuBackground *menuBackground);
567 	void renderMapPreview(const MapPreview *map, bool renderAll, int screenX, int screenY,Texture2D **renderToTexture=NULL);
568 	void renderMenuBackground(Camera *camera, float fade, Model *mainModel, vector<Model *> characterModels,const Vec3f characterPosition, float anim);
569 
570 	//computing
571     bool ccomputePosition(const Vec2i &screenPos, Vec2i &worldPos,bool exactCoords=false);
572 	void computeSelected(Selection::UnitContainer &units, const Object *&obj, const bool withObjectSelection, const Vec2i &posDown, const Vec2i &posUp);
573 	void selectUsingColorPicking(Selection::UnitContainer &units, const Object *&obj,const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp);
574 	void selectUsingSelectionBuffer(Selection::UnitContainer &units,const Object *&obj, const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp);
575 	void selectUsingFrustumSelection(Selection::UnitContainer &units,const Object *&obj, const bool withObjectSelection,const Vec2i &posDown, const Vec2i &posUp);
576 
577 
578     //gl wrap
579 	string getGlInfo();
580 	string getGlMoreInfo();
581 	void autoConfig();
582 
583 	//clear
584     void clearBuffers();
585 	void clearZBuffer();
586 
587 	//shadows
588 	void renderShadowsToTexture(const int renderFps);
589 
590 	//misc
591 	void loadConfig();
592 	void saveScreen(const string &path,int w=0, int h=0);
getVisibleQuad()593 	inline Quad2i getVisibleQuad() const		{return visibleQuad;}
getVisibleQuadFromCamera()594 	inline Quad2i getVisibleQuadFromCamera() const		{return visibleQuadFromCamera;}
595 	void renderTeamColorPlane();
596 	void renderSpecialHighlightUnits(std::map<int,HighlightSpecialUnitInfo> unitHighlightList);
597 	void renderTeamColorCircle();
598 	void renderMorphEffects();
599 
600 	//static
601 	static Shadows strToShadows(const string &s);
602 	static string shadowsToStr(Shadows shadows);
603 
getGame()604 	inline const Game * getGame() { return game; }
605 
606 	void setAllowRenderUnitTitles(bool value);
getAllowRenderUnitTitles()607 	inline bool getAllowRenderUnitTitles() { return allowRenderUnitTitles; }
608 	void renderUnitTitles(Font2D *font, Vec3f color);
609 	void renderUnitTitles3D(Font3D *font, Vec3f color);
610 	Vec3f computeScreenPosition(const Vec3f &worldPos);
611 
setPhotoMode(bool value)612 	void setPhotoMode(bool value) { photoMode = value; }
613 
getNo2DMouseRendering()614 	inline bool getNo2DMouseRendering() const { return no2DMouseRendering; }
setNo2DMouseRendering(bool value)615 	void setNo2DMouseRendering(bool value) { no2DMouseRendering = value; }
616 
getShowDebugUI()617 	inline bool getShowDebugUI() const { return showDebugUI; }
setShowDebugUI(bool value)618 	void setShowDebugUI(bool value) { showDebugUI = value; }
619 
getShowDebugUILevel()620 	inline int getShowDebugUILevel() const { return showDebugUILevel; }
setShowDebugUILevel(int value)621 	void setShowDebugUILevel(int value) { showDebugUILevel=value; }
622 	void cycleShowDebugUILevel();
623 
624 	void setLastRenderFps(int value);
getLastRenderFps()625 	inline int getLastRenderFps() const { return lastRenderFps;}
626 
627 	VisibleQuadContainerCache & getQuadCache(bool updateOnDirtyFrame=true,bool forceNew=false);
628 	std::pair<bool,Vec3f> posInCellQuadCache(Vec2i pos);
629 	Vec3f getMarkedCellScreenPosQuadCache(Vec2i pos);
630 	void updateMarkedCellScreenPosQuadCache(Vec2i pos);
631 	void forceQuadCacheUpdate();
632 	void renderVisibleMarkedCells(bool renderTextHint=false,int x=-1, int y=-1);
633 	void renderMarkedCellsOnMinimap();
634 
635 	void renderHighlightedCellsOnMinimap();
636 
637 	void removeObjectFromQuadCache(const Object *o);
638 	void removeUnitFromQuadCache(const Unit *unit);
639 
640 	std::size_t getCurrentPixelByteCount(ResourceScope rs=rsGame) const;
641 	unsigned int getSaveScreenQueueSize();
642 
643 	Texture2D *saveScreenToTexture(int x, int y, int width, int height);
644 
645 	void renderProgressBar(int size, int x, int y, Font2D *font,int customWidth=-1, string prefixLabel="", bool centeredText=true);
646 
647 	static Texture2D * findTexture(string logoFilename);
648 	static Texture2D * preloadTexture(string logoFilename);
getCachedSurfaceDataSize()649 	inline int getCachedSurfaceDataSize() const { return (int)mapSurfaceData.size(); }
650 
651 	//void setCustom3dMenuList(GLuint *customlist3dMenu) { this->customlist3dMenu = customlist3dMenu; }
652 	//inline GLuint * getCustom3dMenuList() const { return this->customlist3dMenu; }
setCustom3dMenu(const MainMenu * mm)653 	void setCustom3dMenu(const MainMenu *mm) { this->custom_mm3d = mm; }
getCustom3dMenu()654 	const MainMenu * getCustom3dMenu() { return this->custom_mm3d; }
655 
656 	void init3dListMenu(const MainMenu *mm);
657 
setProgram(Program * program)658 	void setProgram(Program *program) { this->program = program; }
659 
660 	void setupRenderForVideo();
661 	virtual void renderVideoLoading(int progressPercent);
662 
663 private:
664 	//private misc
665 	float computeSunAngle(float time);
666 	float computeMoonAngle(float time);
667 	Vec4f computeSunPos(float time);
668 	Vec4f computeMoonPos(float time);
computeWaterColor(float waterLevel,float cellHeight)669 	inline Vec4f computeWaterColor(float waterLevel, float cellHeight) {
670 		const float waterFactor= 1.5f;
671 		return Vec4f(1.f, 1.f, 1.f, clamp((waterLevel-cellHeight) * waterFactor, 0.f, 1.f));
672 	}
673 	void checkExtension(const string &extension, const string &msg);
674 
675 	//selection render
676 	vector<Object *> renderObjectsFast(bool renderingShadows = false, bool resourceOnly = false, bool colorPickingSelection = false);
677 	vector<Unit *> renderUnitsFast(bool renderingShadows = false, bool colorPickingSelection = false);
678 
679 	//gl requirements
680 	void checkGlCaps();
681 	void checkGlOptionalCaps();
682 
683 	//gl init
684 	void init3dList();
685     void init2dList();
686 
687 	//misc
688 	void loadProjectionMatrix();
689 	void enableProjectiveTexturing();
690 
691 	//private aux drawing
692 	void renderSelectionCircle(Vec3f v, int size, float radius, float thickness=0.2f);
693 	bool isHealthBarVisible(const Unit *unit,int healthbarMode);
694 	void renderHealthBar(Vec3f v, Unit *unit, float height, bool lineBorder, const Texture2D *texture=NULL, const Texture2D *backgroundTexture=NULL);
695 	void internalRenderHp(int numberOfBars, int barNumber, float hp, Vec3f posVector, float width, float singleHPheight, Vec3f rightVector, Vec3f upVector);
696 	void renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture);
697 	void renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec3f &color, float width);
698 	void renderTile(const Vec2i &pos);
699 	void renderQuad(int x, int y, int w, int h, const Texture2D *texture);
700 
701 	void simpleTask(BaseThread *callingThread,void *userdata);
702 
703 	//static
704     static Texture2D::Filter strToTextureFilter(const string &s);
705     void cleanupScreenshotThread();
706 
707     void render2dMenuSetup();
708     void render3dSetup();
709     void render3dMenuSetup(const MainMenu *mm);
710 
711     int renderResource(const Faction *factionForResourceView,
712     		bool localFactionResourcesOnly,bool twoResourceLines, const ResourceType *rt,
713     		int startRow, int &resourceCountRendered);
714 
715 };
716 
717 }} //end namespace
718 
719 #endif
720