1 /* 2 Copyright (c) 2013 yvt 3 4 This file is part of OpenSpades. 5 6 OpenSpades is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 OpenSpades is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with OpenSpades. If not, see <http://www.gnu.org/licenses/>. 18 19 */ 20 21 #pragma once 22 23 #include <Core/Math.h> 24 #include "IImage.h" 25 #include "IModel.h" 26 #include "SceneDefinition.h" 27 #include <Core/RefCountedObject.h> 28 29 namespace spades { 30 class Bitmap; 31 class VoxelModel; 32 33 namespace client { 34 35 class GameMap; 36 37 struct ModelRenderParam { 38 Matrix4 matrix; 39 Vector3 customColor; 40 bool depthHack; 41 ModelRenderParamModelRenderParam42 ModelRenderParam() { 43 matrix = Matrix4::Identity(); 44 customColor = MakeVector3(0, 0, 0); 45 depthHack = false; 46 } 47 }; 48 49 enum DynamicLightType { DynamicLightTypePoint, DynamicLightTypeSpotlight }; 50 51 struct DynamicLightParam { 52 DynamicLightType type; 53 Vector3 origin; 54 float radius; 55 Vector3 color; 56 57 Vector3 spotAxis[3]; 58 IImage *image; 59 float spotAngle; 60 61 bool useLensFlare; 62 DynamicLightParamDynamicLightParam63 DynamicLightParam() { 64 image = NULL; 65 type = DynamicLightTypePoint; 66 spotAngle = 0.f; 67 useLensFlare = false; 68 } 69 }; 70 71 class IRenderer : public RefCountedObject { 72 protected: ~IRenderer()73 virtual ~IRenderer() {} 74 75 public: IRenderer()76 IRenderer() {} 77 78 virtual void Init() = 0; 79 virtual void Shutdown() = 0; 80 81 virtual IImage *RegisterImage(const char *filename) = 0; 82 virtual IModel *RegisterModel(const char *filename) = 0; 83 84 virtual IImage *CreateImage(Bitmap *) = 0; 85 virtual IModel *CreateModel(VoxelModel *) = 0; 86 87 virtual void SetGameMap(GameMap *) = 0; 88 89 virtual void SetFogDistance(float) = 0; 90 virtual void SetFogColor(Vector3) = 0; 91 92 /** Starts rendering a scene and waits for additional objects. */ 93 virtual void StartScene(const SceneDefinition &) = 0; 94 95 virtual void AddLight(const client::DynamicLightParam &light) = 0; 96 97 virtual void RenderModel(IModel *, const ModelRenderParam &) = 0; 98 virtual void AddDebugLine(Vector3 a, Vector3 b, Vector4 color) = 0; 99 100 virtual void AddSprite(IImage *, Vector3 center, float radius, float rotation) = 0; 101 virtual void AddLongSprite(IImage *, Vector3 p1, Vector3 p2, float radius) = 0; 102 103 /** Finalizes a scene. 2D drawing follows. */ 104 virtual void EndScene() = 0; 105 106 virtual void MultiplyScreenColor(Vector3) = 0; 107 108 /** Sets color for image drawing. Deprecated because 109 * some methods treats this as an alpha premultiplied, while 110 * others treats this as an alpha non-premultiplied. 111 * @deprecated */ 112 virtual void SetColor(Vector4) = 0; 113 114 /** Sets color for image drawing. Always alpha premultiplied. */ 115 virtual void SetColorAlphaPremultiplied(Vector4) = 0; 116 117 virtual void DrawImage(IImage *, const Vector2 &outTopLeft) = 0; 118 virtual void DrawImage(IImage *, const AABB2 &outRect) = 0; 119 virtual void DrawImage(IImage *, const Vector2 &outTopLeft, const AABB2 &inRect) = 0; 120 virtual void DrawImage(IImage *, const AABB2 &outRect, const AABB2 &inRect) = 0; 121 virtual void DrawImage(IImage *, const Vector2 &outTopLeft, const Vector2 &outTopRight, 122 const Vector2 &outBottomLeft, const AABB2 &inRect) = 0; 123 124 virtual void DrawFlatGameMap(const AABB2 &outRect, const AABB2 &inRect) = 0; 125 126 /** Finalizes a frame. */ 127 virtual void FrameDone() = 0; 128 129 /** displays a rendered image to the screen. */ 130 virtual void Flip() = 0; 131 132 /** get a rendered image. */ 133 virtual Bitmap *ReadBitmap() = 0; 134 135 virtual float ScreenWidth() = 0; 136 virtual float ScreenHeight() = 0; 137 }; 138 } 139 } 140