File: renderer.h

package info (click to toggle)
megaglest 3.13.0-10.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,448 kB
  • sloc: cpp: 144,271; ansic: 11,861; sh: 3,233; perl: 1,904; python: 1,751; objc: 142; asm: 42; makefile: 21
file content (166 lines) | stat: -rw-r--r-- 4,198 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// ==============================================================
// This file is part of MegaGlest (www.glest.org)
//
// Copyright (C) 2011 - by Mark Vejvoda <mark_vejvoda@hotmail.com>
//
//	You can redistribute this code and/or modify it under
//	the terms of the GNU General Public License as published
//	by the Free Software Foundation; either version 2 of the
//	License, or (at your option) any later version
// ==============================================================

#ifndef _SHADER_G3DVIEWER_RENDERER_H_
#define _SHADER_G3DVIEWER_RENDERER_H_

#ifdef WIN32
    #include <winsock2.h>
    #include <winsock.h>
#endif

#include "model_renderer.h"
#include "texture_manager.h"
#include "model.h"
#include "texture.h"

#include "particle_renderer.h"
#include "model_manager.h"
#include "graphics_interface.h"

//#include "model_manager.h"
//#include "graphics_factory_gl.h"

using Shared::Graphics::ModelRenderer;
using Shared::Graphics::TextureManager;
using Shared::Graphics::ModelManager;
using Shared::Graphics::Model;
using Shared::Graphics::Texture2D;
using Shared::Graphics::ParticleRenderer;
using Shared::Graphics::ParticleManager;
using Shared::Graphics::ParticleSystem;
//#include "model_renderer.h"

using Shared::Graphics::MeshCallback;
using Shared::Graphics::Mesh;
using Shared::Graphics::Texture;

using namespace Shared::Graphics;

namespace Shared{ namespace G3dViewer{

// ===============================================
// 	class MeshCallbackTeamColor
// ===============================================

class MeshCallbackTeamColor: public MeshCallback{
private:
	const Texture *teamTexture;

public:
	MeshCallbackTeamColor() : MeshCallback() {
		teamTexture = NULL;
	}
	void setTeamTexture(const Texture *teamTexture)	{this->teamTexture= teamTexture;}
	virtual void execute(const Mesh *mesh);
};

// ===============================
// 	class Renderer
// ===============================

class Renderer : public RendererInterface {
public:
	static int windowX;
	static int windowY;
	static int windowW;
	static int windowH;

public:
	enum PlayerColor{
		pcRed,
		pcBlue,
		pcGreen,
		pcYellow,
		pcWhite,
		pcCyan,
		pcOrange,
		pcMagenta
	};

private:
	bool wireframe;
	bool normals;
	bool grid;

	int width;
	int height;

	ModelRenderer *modelRenderer;
	TextureManager *textureManager;
	ParticleRenderer *particleRenderer;

	ParticleManager *particleManager;
	ModelManager *modelManager;

	Texture2D *customTextureRed;
	Texture2D *customTextureBlue;
	Texture2D *customTextureGreen;
	Texture2D *customTextureYellow;
	Texture2D *customTextureWhite;
	Texture2D *customTextureCyan;
	Texture2D *customTextureOrange;
	Texture2D *customTextureMagenta;
	MeshCallbackTeamColor meshCallbackTeamColor;

	float red;
	float green;
	float blue;
	float alpha;

	Renderer();
	void checkGlCaps();
	void checkExtension(const string &extension, const string &msg);

public:
	virtual ~Renderer();
	static Renderer *getInstance();

	void init();
	void reset(int w, int h, PlayerColor playerColor);
	void transform(float rotX, float rotY, float zoom);
	void renderGrid();

	bool getNormals() const		{return normals;}
	bool getWireframe() const	{return wireframe;}
	bool getGrid() const		{return grid;}

	void toggleNormals();
	void toggleWireframe();
	void toggleGrid();

	void renderTheModel(Model *model, float f);

	void manageParticleSystem(ParticleSystem *particleSystem);
	void updateParticleManager();
	void renderParticleManager();
	Texture2D *getPlayerColorTexture(PlayerColor playerColor);

	Texture2D * getNewTexture2D();

	Model *newModel(ResourceScope rs,const string &path,bool deletePixMapAfterLoad=false,std::map<string,vector<pair<string, string> > > *loadedFileList=NULL, string *sourceLoader=NULL);
	void endModel(ResourceScope rs,Model *model);
	Texture2D *newTexture2D(ResourceScope rs) { return getNewTexture2D(); }

	void initTextureManager();
	void initModelManager();

	void end();

	void setBackgroundColor(float red, float green, float blue);
	void setAlphaColor(float alpha);
	void saveScreen(const string &path,std::pair<int,int> *overrideSize);
	bool hasActiveParticleSystem(ParticleSystem::ParticleSystemType typeName) const;
};

}}//end namespace

#endif