192 | | CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); |
193 | | texture->Prefetch(); |
194 | | m_NormalMap[i] = texture; |
195 | | } |
196 | | |
197 | | // Load CoastalWaves |
198 | | { |
199 | | CTextureProperties textureProps(L"art/textures/terrain/types/water/coastalWave.png"); |
200 | | textureProps.SetWrap(GL_REPEAT); |
201 | | CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); |
202 | | texture->Prefetch(); |
203 | | m_WaveTex = texture; |
204 | | } |
205 | | |
206 | | // Load Foam |
207 | | { |
208 | | CTextureProperties textureProps(L"art/textures/terrain/types/water/foam.png"); |
209 | | textureProps.SetWrap(GL_REPEAT); |
210 | | CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); |
211 | | texture->Prefetch(); |
212 | | m_FoamTex = texture; |
213 | | } |
214 | | |
215 | | m_ReflectionTextureSize = g_Renderer.GetHeight() * 0.66; // Higher settings give a better result |
216 | | m_RefractionTextureSize = g_Renderer.GetHeight() * 0.33; // Lower settings actually sorta look better since it blurs. |
217 | | |
218 | | if (round_down_to_pow2(m_ReflectionTextureSize)/m_ReflectionTextureSize < 0.65) |
219 | | m_ReflectionTextureSize = round_up_to_pow2(m_ReflectionTextureSize); |
220 | | else |
221 | | m_ReflectionTextureSize = round_down_to_pow2(m_ReflectionTextureSize); |
222 | | |
223 | | if (round_down_to_pow2(m_RefractionTextureSize)/m_RefractionTextureSize < 0.7) |
224 | | m_RefractionTextureSize = round_up_to_pow2(m_RefractionTextureSize); |
225 | | else |
226 | | m_RefractionTextureSize = round_down_to_pow2(m_RefractionTextureSize); |
227 | | |
228 | | // Create reflection texture |
229 | | glGenTextures(1, &m_ReflectionTexture); |
230 | | glBindTexture(GL_TEXTURE_2D, m_ReflectionTexture); |
231 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
232 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
233 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); |
234 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); |
235 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
236 | | |
237 | | // Create refraction texture |
238 | | glGenTextures(1, &m_RefractionTexture); |
239 | | glBindTexture(GL_TEXTURE_2D, m_RefractionTexture); |
240 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
241 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
242 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); |
243 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); |
244 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
245 | | |
246 | | // Create depth textures |
247 | | glGenTextures(1, &m_ReflFboDepthTexture); |
248 | | glBindTexture(GL_TEXTURE_2D, m_ReflFboDepthTexture); |
249 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
250 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
251 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
252 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
253 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); |
254 | | |
255 | | glGenTextures(1, &m_RefrFboDepthTexture); |
256 | | glBindTexture(GL_TEXTURE_2D, m_RefrFboDepthTexture); |
257 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
258 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
259 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
260 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
261 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); |
262 | | |
263 | | // Create the Fancy Effects texture |
264 | | glGenTextures(1, &m_FancyTextureNormal); |
265 | | glBindTexture(GL_TEXTURE_2D, m_FancyTextureNormal); |
266 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
267 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
268 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
269 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
270 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)g_Renderer.GetWidth(), (GLsizei)g_Renderer.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL); |
271 | | |
272 | | glGenTextures(1, &m_FancyTextureOther); |
273 | | glBindTexture(GL_TEXTURE_2D, m_FancyTextureOther); |
274 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
275 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
276 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
277 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
278 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)g_Renderer.GetWidth(), (GLsizei)g_Renderer.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL); |
279 | | |
280 | | glGenTextures(1, &m_FancyTextureDepth); |
281 | | glBindTexture(GL_TEXTURE_2D, m_FancyTextureDepth); |
282 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
283 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
284 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
285 | | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
286 | | glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)g_Renderer.GetWidth(), (GLsizei)g_Renderer.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); |
287 | | |
288 | | glBindTexture(GL_TEXTURE_2D, 0); |
289 | | |
290 | | // Create the water framebuffers |
291 | | |
292 | | GLint currentFbo; |
293 | | glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, ¤tFbo); |
| 202 | // Load CoastalWaves |
| 203 | { |
| 204 | CTextureProperties textureProps(L"art/textures/terrain/types/water/coastalWave.png"); |
| 205 | textureProps.SetWrap(GL_REPEAT); |
| 206 | CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); |
| 207 | texture->Prefetch(); |
| 208 | m_WaveTex = texture; |
| 209 | } |
| 210 | |
| 211 | // Load Foam |
| 212 | { |
| 213 | CTextureProperties textureProps(L"art/textures/terrain/types/water/foam.png"); |
| 214 | textureProps.SetWrap(GL_REPEAT); |
| 215 | CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps); |
| 216 | texture->Prefetch(); |
| 217 | m_FoamTex = texture; |
| 218 | } |
| 219 | |
| 220 | m_ReflectionTextureSize = g_Renderer.GetHeight() * 0.66; // Higher settings give a better result |
| 221 | m_RefractionTextureSize = g_Renderer.GetHeight() * 0.33; // Lower settings actually sorta look better since it blurs. |
| 222 | |
| 223 | if (round_down_to_pow2(m_ReflectionTextureSize)/m_ReflectionTextureSize < 0.65) |
| 224 | m_ReflectionTextureSize = round_up_to_pow2(m_ReflectionTextureSize); |
| 225 | else |
| 226 | m_ReflectionTextureSize = round_down_to_pow2(m_ReflectionTextureSize); |
| 227 | |
| 228 | if (round_down_to_pow2(m_RefractionTextureSize)/m_RefractionTextureSize < 0.7) |
| 229 | m_RefractionTextureSize = round_up_to_pow2(m_RefractionTextureSize); |
| 230 | else |
| 231 | m_RefractionTextureSize = round_down_to_pow2(m_RefractionTextureSize); |
| 232 | |
| 233 | // Create reflection texture |
| 234 | glGenTextures(1, &m_ReflectionTexture); |
| 235 | glBindTexture(GL_TEXTURE_2D, m_ReflectionTexture); |
| 236 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 237 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 238 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); |
| 239 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); |
| 240 | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); |
| 241 | |
| 242 | // Create refraction texture |
| 243 | glGenTextures(1, &m_RefractionTexture); |
| 244 | glBindTexture(GL_TEXTURE_2D, m_RefractionTexture); |
| 245 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 246 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 247 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); |
| 248 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); |
| 249 | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); |
| 250 | |
| 251 | // Create depth textures |
| 252 | glGenTextures(1, &m_ReflFboDepthTexture); |
| 253 | glBindTexture(GL_TEXTURE_2D, m_ReflFboDepthTexture); |
| 254 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 255 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 256 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 257 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 258 | glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); |
| 259 | |
| 260 | glGenTextures(1, &m_RefrFboDepthTexture); |
| 261 | glBindTexture(GL_TEXTURE_2D, m_RefrFboDepthTexture); |
| 262 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 263 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 264 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 265 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 266 | glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); |
| 267 | |
| 268 | // Create the Fancy Effects texture |
| 269 | glGenTextures(1, &m_FancyTextureNormal); |
| 270 | glBindTexture(GL_TEXTURE_2D, m_FancyTextureNormal); |
| 271 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 272 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 273 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 274 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 275 | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)g_Renderer.GetWidth(), (GLsizei)g_Renderer.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL); |
| 276 | |
| 277 | glGenTextures(1, &m_FancyTextureOther); |
| 278 | glBindTexture(GL_TEXTURE_2D, m_FancyTextureOther); |
| 279 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 280 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 281 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 282 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 283 | glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)g_Renderer.GetWidth(), (GLsizei)g_Renderer.GetHeight(), 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL); |
| 284 | |
| 285 | glGenTextures(1, &m_FancyTextureDepth); |
| 286 | glBindTexture(GL_TEXTURE_2D, m_FancyTextureDepth); |
| 287 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 288 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 289 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 290 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 291 | glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)g_Renderer.GetWidth(), (GLsizei)g_Renderer.GetHeight(), 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL); |
| 292 | |
| 293 | glBindTexture(GL_TEXTURE_2D, 0); |
| 294 | |
| 295 | // Create the water framebuffers |
| 296 | |
| 297 | GLint currentFbo; |
| 298 | glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, ¤tFbo); |