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 <memory>
24 #include <vector>
25 
26 #include "SWFeatureLevel.h"
27 #include "SWFeatureLevel.h"
28 #include <Client/SceneDefinition.h>
29 #include <Core/Math.h>
30 #include <Core/MiniHeap.h>
31 #include <Core/RefCountedObject.h>
32 
33 namespace spades {
34 	namespace client {
35 		class GameMap;
36 	}
37 
38 	class Bitmap;
39 
40 	namespace draw {
41 		class SWRenderer;
42 		class SWMapRenderer {
43 			struct Line;
44 			struct LinePixel;
45 
46 			int w, h;
47 			SWRenderer *renderer;
48 
49 			SWFeatureLevel level;
50 			client::SceneDefinition sceneDef;
51 			Handle<client::GameMap> map;
52 			Bitmap *frameBuf;
53 			float *depthBuf;
54 			std::vector<Line> lines;
55 			std::vector<MiniHeap::Ref> rle;
56 			std::vector<size_t> rleLen;
57 
58 			int lineResolution;
59 
60 			typedef int8_t RleData;
61 			std::vector<RleData> rleBuf;
62 
63 			MiniHeap rleHeap;
64 
65 			template <SWFeatureLevel level>
66 			void BuildLine(Line &line, float minPitch, float maxPitch);
67 			void BuildRle(int x, int y, std::vector<RleData> &);
68 
69 			template <SWFeatureLevel level, int undersamp>
70 			void RenderFinal(float yawMin, float yawMax, unsigned int numLines,
71 			                 unsigned int threadId, unsigned int numThreads);
72 
73 			template <SWFeatureLevel level>
74 			void RenderInner(const client::SceneDefinition &, Bitmap *fb, float *depthBuffer);
75 
76 		public:
77 			SWMapRenderer(SWRenderer *r, client::GameMap *, SWFeatureLevel level);
78 			~SWMapRenderer();
79 
80 			void Render(const client::SceneDefinition &, Bitmap *fb, float *depthBuffer);
81 
82 			void UpdateRle(int x, int y);
83 		};
84 	}
85 }
86