openspades/Sources/Draw/GLRenderer.h

210 lines
6.3 KiB
C
Raw Normal View History

2013-08-29 11:45:22 +09:00
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
2013-08-18 16:18:06 +09:00
#pragma once
#include "../Client/IRenderer.h"
#include "../Core/Math.h"
#include "../Client/SceneDefinition.h"
#include <map>
#include "../Client/IGameMapListener.h"
#include "GLCameraBlurFilter.h"
#include "GLDynamicLight.h"
namespace spades {
namespace draw {
class IGLDevice;
class GLShader;
class GLProgram;
class GLProgramManager;
class GLImageManager;
class GLMapRenderer;
class GLModelManager;
class GLImageRenderer;
class GLFlatMapRenderer;
class IGLSpriteRenderer;
2013-08-30 21:05:51 +09:00
class GLLongSpriteRenderer;
2013-08-18 16:18:06 +09:00
class GLFramebufferManager;
class GLMapShadowRenderer;
class GLModelRenderer;
class IGLShadowMapRenderer;
class GLWaterRenderer;
class GLAmbientShadowRenderer;
class GLRadiosityRenderer;
2013-09-16 09:10:22 +09:00
class GLLensDustFilter;
2013-09-16 13:29:55 +09:00
class GLSoftLitSpriteRenderer;
2013-08-18 16:18:06 +09:00
class GLRenderer: public client::IRenderer, public client::IGameMapListener {
friend class GLShadowShader;
friend class IGLShadowMapRenderer;
friend class GLRadiosityRenderer;
2013-09-16 13:29:55 +09:00
friend class GLSoftLitSpriteRenderer;
2013-08-18 16:18:06 +09:00
struct DebugLine{
Vector3 v1, v2;
Vector4 color;
};
IGLDevice *device;
GLFramebufferManager *fbManager;
client::GameMap *map;
2013-08-18 16:18:06 +09:00
bool inited;
bool sceneUsedInThisFrame;
2013-08-18 16:18:06 +09:00
client::SceneDefinition sceneDef;
Plane3 frustrum[6];
std::vector<DebugLine> debugLines;
std::vector<GLDynamicLight> lights;
GLProgramManager *programManager;
GLImageManager *imageManager;
GLModelManager *modelManager;
IGLShadowMapRenderer *shadowMapRenderer;
GLMapShadowRenderer *mapShadowRenderer;
GLMapRenderer *mapRenderer;
GLImageRenderer *imageRenderer;
GLFlatMapRenderer *flatMapRenderer;
GLModelRenderer *modelRenderer;
IGLSpriteRenderer *spriteRenderer;
2013-08-30 21:05:51 +09:00
GLLongSpriteRenderer *longSpriteRenderer;
2013-08-18 16:18:06 +09:00
GLWaterRenderer *waterRenderer;
GLAmbientShadowRenderer *ambientShadowRenderer;
GLRadiosityRenderer *radiosityRenderer;
2013-09-06 11:44:36 +09:00
GLCameraBlurFilter *cameraBlur;
2013-09-16 09:10:22 +09:00
GLLensDustFilter *lensDustFilter;
2013-08-18 16:18:06 +09:00
// used when r_srgb = 1
IGLDevice::UInteger lastColorBufferTexture;
2013-08-18 16:18:06 +09:00
float fogDistance;
Vector3 fogColor;
Matrix4 projectionMatrix;
Matrix4 viewMatrix;
Matrix4 projectionViewMatrix;
2013-09-04 22:11:39 +09:00
bool renderingMirror;
2013-08-18 16:18:06 +09:00
Vector4 drawColor;
unsigned int lastTime;
void BuildProjectionMatrix();
void BuildView();
void BuildFrustrum();
void RenderDebugLines();
2013-09-04 22:11:39 +09:00
void RenderObjects();
2013-09-14 13:36:05 +09:00
protected:
virtual ~GLRenderer();
2013-08-18 16:18:06 +09:00
public:
GLRenderer(IGLDevice *glDevice);
virtual void Init();
2013-09-14 13:36:05 +09:00
virtual void Shutdown();
2013-08-18 16:18:06 +09:00
virtual client::IImage *RegisterImage(const char *filename);
virtual client::IModel *RegisterModel(const char *filename);
virtual client::IImage *CreateImage(Bitmap *);
virtual client::IModel *CreateModel(VoxelModel *);
virtual client::IModel *CreateModelOptimized(VoxelModel *);
GLProgram *RegisterProgram(const std::string& name);
GLShader *RegisterShader(const std::string& name);
virtual void SetGameMap(client::GameMap *);
virtual void SetFogColor(Vector3 v){fogColor = v;}
virtual void SetFogDistance(float f){fogDistance = f;}
Vector3 GetFogColor() { return fogColor; }
float GetFogDistance() { return fogDistance; }
2013-08-22 20:02:17 +09:00
Vector3 GetFogColorForSolidPass();
2013-08-18 16:18:06 +09:00
virtual void StartScene(const client::SceneDefinition&);
virtual void RenderModel(client::IModel *, const client::ModelRenderParam&);
virtual void AddLight(const client::DynamicLightParam& light);
virtual void AddDebugLine(Vector3 a, Vector3 b, Vector4 color);
virtual void AddSprite(client::IImage *, Vector3 center, float radius, float rotation);
2013-08-30 21:05:51 +09:00
virtual void AddLongSprite(client::IImage *, Vector3 p1, Vector3 p2, float radius);
2013-08-18 16:18:06 +09:00
virtual void EndScene();
virtual void MultiplyScreenColor(Vector3);
virtual void SetColor(Vector4);
virtual void DrawImage(client::IImage *, const Vector2& outTopLeft);
virtual void DrawImage(client::IImage *, const AABB2& outRect);
virtual void DrawImage(client::IImage *, const Vector2& outTopLeft, const AABB2& inRect);
virtual void DrawImage(client::IImage *, const AABB2& outRect, const AABB2& inRect);
virtual void DrawImage(client::IImage *, const Vector2& outTopLeft, const Vector2& outTopRight, const Vector2& outBottomLeft, const AABB2& inRect);
virtual void DrawFlatGameMap(const AABB2& outRect, const AABB2& inRect);
virtual void FrameDone();
virtual void Flip();
virtual Bitmap *ReadBitmap();
virtual float ScreenWidth();
virtual float ScreenHeight();
IGLDevice *GetGLDevice() {return device; }
GLFramebufferManager *GetFramebufferManager() { return fbManager; }
IGLShadowMapRenderer *GetShadowMapRenderer() { return shadowMapRenderer; }
GLAmbientShadowRenderer *GetAmbientShadowRenderer() { return ambientShadowRenderer; }
GLMapShadowRenderer *GetMapShadowRenderer() { return mapShadowRenderer; }
GLRadiosityRenderer *GetRadiosityRenderer() { return radiosityRenderer; }
2013-09-11 13:50:18 +09:00
GLModelRenderer *GetModelRenderer() { return modelRenderer; }
2013-08-18 16:18:06 +09:00
const Matrix4& GetProjectionMatrix() const { return projectionMatrix; }
const Matrix4& GetProjectionViewMatrix() const { return projectionViewMatrix; }
const Matrix4& GetViewMatrix() const { return viewMatrix; }
2013-09-04 22:11:39 +09:00
bool IsRenderingMirror() const { return renderingMirror; }
2013-08-18 16:18:06 +09:00
virtual void GameMapChanged(int x, int y, int z, client::GameMap *);
const client::SceneDefinition& GetSceneDef() const {
return sceneDef;
}
bool BoxFrustrumCull(const AABB3&);
bool SphereFrustrumCull(const Vector3& center,
float radius);
};
}
}