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 <vector>
24 #include <cstdint>
25 
26 #include "IGLDevice.h"
27 
28 namespace spades {
29 	namespace client {
30 		class GameMap;
31 	}
32 	namespace draw {
33 		class GLRenderer;
34 		class IGLDevice;
35 		class GLProgram;
36         class GLSettings;
37 		class GLWaterRenderer{
38 			class IWaveTank;
39 			class StandardWaveTank;
40             template <int SizeBits>
41 			class FFTWaveTank;
42 
43 			GLRenderer *renderer;
44 			IGLDevice *device;
45             GLSettings &settings;
46 			client::GameMap *map;
47 
48 			std::vector<IWaveTank *> waveTanks;
49 
50 			int w, h;
51 
52 			size_t updateBitmapPitch;
53 			std::vector<uint32_t> updateBitmap;
54 
55 			std::vector<uint32_t> bitmap;
56 
57 			IGLDevice::UInteger texture; // water color
58 			IGLDevice::UInteger waveTexture; // bumpmap
59 
60 			struct Vertex;
61 
62 			IGLDevice::UInteger buffer;
63 			IGLDevice::UInteger idxBuffer;
64 			size_t numIndices;
65 
66 			IGLDevice::UInteger tempFramebuffer;
67 			IGLDevice::UInteger tempDepthTexture;
68 
69 			IGLDevice::UInteger occlusionQuery;
70 
71 			GLProgram *program;
72 
73 			void BuildVertices();
74 			void MarkUpdate(int x, int y);
75 		public:
76 			GLWaterRenderer(GLRenderer *, client::GameMap *map);
77 			~GLWaterRenderer();
78 
79 			static void PreloadShaders(GLRenderer *);
80 
81 			void Render();
82 
83 			void Update(float dt);
84 
85 			void GameMapChanged(int x, int y, int z, client::GameMap *);
86 
GetOcclusionQuery()87 			IGLDevice::UInteger GetOcclusionQuery() {
88 				return occlusionQuery;
89 			}
90 		};
91 	}
92 }
93