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 "SWFeatureLevel.h" 24 #include <Core/Math.h> 25 #include <Core/RefCountedObject.h> 26 27 namespace spades { 28 class Bitmap; 29 30 namespace draw { 31 class SWImage; 32 class SWImageRenderer { 33 public: 34 struct Vertex { 35 Vector4 position; 36 Vector4 color; 37 Vector2 uv; 38 }; 39 enum class ShaderType { Image, Sprite }; 40 41 private: 42 Handle<Bitmap> frame; 43 float *depthBuffer; 44 ShaderType shader; 45 Vector4 fbSize4; 46 Vector4 fbCenter4; 47 float zNear; 48 Matrix4 matrix; 49 SWFeatureLevel featureLevel; 50 unsigned long long pixelsDrawn; 51 52 template <SWFeatureLevel, bool, bool, bool, bool, bool> struct PolygonRenderer; 53 54 template <SWFeatureLevel, bool, bool, bool, bool> struct PolygonRenderer3; 55 56 template <bool, bool, bool, bool> struct PolygonRenderer2; 57 58 public: 59 SWImageRenderer(SWFeatureLevel); 60 ~SWImageRenderer(); 61 void SetFramebuffer(Bitmap *); 62 void SetDepthBuffer(float *); 63 SetMatrix(const Matrix4 & m)64 void SetMatrix(const Matrix4 &m) { matrix = m; } 65 void SetZRange(float zNear, float zFar); 66 67 void SetShaderType(ShaderType); 68 69 void DrawPolygon(SWImage *img, const Vertex &v1, const Vertex &v2, const Vertex &v3); 70 GetPixelsDrawn()71 unsigned long long GetPixelsDrawn() { return pixelsDrawn; } ResetPixelStatistics()72 void ResetPixelStatistics() { pixelsDrawn = 0; } 73 }; 74 } 75 } 76