1173 | | |
1174 | | if (screenScissor.x1 < screenScissor.x2 && screenScissor.y1 < screenScissor.y2) |
| 1175 | |
| 1176 | glEnable(GL_SCISSOR_TEST); |
| 1177 | glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1178 | |
| 1179 | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_WaterBuffer); |
| 1180 | pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, wm.m_ReflectionTexture, 0); |
| 1181 | |
| 1182 | GLenum status = pglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); |
| 1183 | if(status != GL_FRAMEBUFFER_COMPLETE_EXT) |
1176 | | glEnable(GL_SCISSOR_TEST); |
1177 | | glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
1178 | | |
1179 | | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
1180 | | |
1181 | | glFrontFace(GL_CW); |
1182 | | |
1183 | | // Render sky, terrain and models |
1184 | | m->skyManager.RenderSky(); |
1185 | | ogl_WarnIfError(); |
1186 | | RenderPatches(context, &m_ViewCamera.GetFrustum()); |
1187 | | ogl_WarnIfError(); |
1188 | | RenderModels(context, &m_ViewCamera.GetFrustum()); |
1189 | | ogl_WarnIfError(); |
1190 | | RenderTransparentModels(context, TRANSPARENT_OPAQUE, &m_ViewCamera.GetFrustum()); |
1191 | | ogl_WarnIfError(); |
1192 | | |
1193 | | glFrontFace(GL_CCW); |
1194 | | |
1195 | | glDisable(GL_SCISSOR_TEST); |
1196 | | |
1197 | | // Copy the image to a texture |
1198 | | pglActiveTextureARB(GL_TEXTURE0); |
1199 | | glEnable(GL_TEXTURE_2D); |
1200 | | glBindTexture(GL_TEXTURE_2D, wm.m_ReflectionTexture); |
1201 | | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, |
1202 | | screenScissor.x1, screenScissor.y1, |
1203 | | screenScissor.x1, screenScissor.y1, |
1204 | | screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1185 | wm.m_WaterBuffer = -1; |
| 1186 | // revert to old method |
| 1187 | if (screenScissor.x1 < screenScissor.x2 && screenScissor.y1 < screenScissor.y2) |
| 1188 | { |
| 1189 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 1190 | |
| 1191 | glFrontFace(GL_CW); |
| 1192 | |
| 1193 | // Render sky, terrain and models |
| 1194 | m->skyManager.RenderSky(); |
| 1195 | ogl_WarnIfError(); |
| 1196 | RenderPatches(context, &m_ViewCamera.GetFrustum()); |
| 1197 | ogl_WarnIfError(); |
| 1198 | RenderModels(context, &m_ViewCamera.GetFrustum()); |
| 1199 | ogl_WarnIfError(); |
| 1200 | RenderTransparentModels(context, TRANSPARENT_OPAQUE, &m_ViewCamera.GetFrustum()); |
| 1201 | ogl_WarnIfError(); |
| 1202 | |
| 1203 | glFrontFace(GL_CCW); |
| 1204 | |
| 1205 | glDisable(GL_SCISSOR_TEST); |
| 1206 | |
| 1207 | // Copy the image to a texture |
| 1208 | pglActiveTextureARB(GL_TEXTURE0); |
| 1209 | glEnable(GL_TEXTURE_2D); |
| 1210 | glBindTexture(GL_TEXTURE_2D, wm.m_ReflectionTexture); |
| 1211 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, |
| 1212 | screenScissor.x1, screenScissor.y1, |
| 1213 | screenScissor.x1, screenScissor.y1, |
| 1214 | screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1215 | } |
| 1216 | // Reset old camera |
| 1217 | m_ViewCamera = normalCamera; |
| 1218 | m->SetOpenGLCamera(m_ViewCamera); |
| 1219 | |
| 1220 | return screenScissor; |
| 1223 | glClearColor(0.5f,0.5f,1.0f,0.0f); |
| 1224 | glClear(GL_COLOR_BUFFER_BIT); |
| 1225 | glFrontFace(GL_CW); |
| 1226 | |
| 1227 | // Render sky, terrain and models |
| 1228 | m->skyManager.RenderSky(); |
| 1229 | ogl_WarnIfError(); |
| 1230 | RenderPatches(context, &m_ViewCamera.GetFrustum()); |
| 1231 | ogl_WarnIfError(); |
| 1232 | RenderModels(context, &m_ViewCamera.GetFrustum()); |
| 1233 | ogl_WarnIfError(); |
| 1234 | RenderTransparentModels(context, TRANSPARENT_OPAQUE, &m_ViewCamera.GetFrustum()); |
| 1235 | ogl_WarnIfError(); |
| 1236 | |
| 1237 | glFrontFace(GL_CCW); |
| 1238 | glDisable(GL_SCISSOR_TEST); |
| 1239 | |
1265 | | // Render terrain and models |
1266 | | RenderPatches(context, &m_ViewCamera.GetFrustum()); |
1267 | | ogl_WarnIfError(); |
1268 | | RenderModels(context, &m_ViewCamera.GetFrustum()); |
1269 | | ogl_WarnIfError(); |
1270 | | RenderTransparentModels(context, TRANSPARENT_OPAQUE, &m_ViewCamera.GetFrustum()); |
1271 | | ogl_WarnIfError(); |
1272 | | |
1273 | | glDisable(GL_SCISSOR_TEST); |
1274 | | |
1275 | | // Copy the image to a texture |
1276 | | pglActiveTextureARB(GL_TEXTURE0); |
1277 | | glEnable(GL_TEXTURE_2D); |
1278 | | glBindTexture(GL_TEXTURE_2D, wm.m_RefractionTexture); |
1279 | | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, |
1280 | | screenScissor.x1, screenScissor.y1, |
1281 | | screenScissor.x1, screenScissor.y1, |
1282 | | screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1296 | glEnable(GL_SCISSOR_TEST); |
| 1297 | glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1298 | |
| 1299 | pglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, wm.m_WaterBuffer); |
| 1300 | pglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, wm.m_RefractionTexture, 0); |
| 1301 | |
| 1302 | GLenum status = pglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); |
| 1303 | if(status != GL_FRAMEBUFFER_COMPLETE_EXT) |
| 1304 | { |
| 1305 | wm.m_WaterBuffer = -1; |
| 1306 | // revert to old method |
| 1307 | if (screenScissor.x1 < screenScissor.x2 && screenScissor.y1 < screenScissor.y2) |
| 1308 | { |
| 1309 | glEnable(GL_SCISSOR_TEST); |
| 1310 | glScissor(screenScissor.x1, screenScissor.y1, screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1311 | |
| 1312 | glClearColor(0.5f, 0.5f, 0.5f, 1.0f); // a neutral gray to blend in with shores |
| 1313 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 1314 | |
| 1315 | // Render terrain and models |
| 1316 | RenderPatches(context, &m_ViewCamera.GetFrustum()); |
| 1317 | ogl_WarnIfError(); |
| 1318 | RenderModels(context, &m_ViewCamera.GetFrustum()); |
| 1319 | ogl_WarnIfError(); |
| 1320 | RenderTransparentModels(context, TRANSPARENT_OPAQUE, &m_ViewCamera.GetFrustum()); |
| 1321 | ogl_WarnIfError(); |
| 1322 | |
| 1323 | glDisable(GL_SCISSOR_TEST); |
| 1324 | |
| 1325 | // Copy the image to a texture |
| 1326 | pglActiveTextureARB(GL_TEXTURE0); |
| 1327 | glEnable(GL_TEXTURE_2D); |
| 1328 | glBindTexture(GL_TEXTURE_2D, wm.m_RefractionTexture); |
| 1329 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, |
| 1330 | screenScissor.x1, screenScissor.y1, |
| 1331 | screenScissor.x1, screenScissor.y1, |
| 1332 | screenScissor.x2 - screenScissor.x1, screenScissor.y2 - screenScissor.y1); |
| 1333 | } |
| 1334 | // Reset old camera |
| 1335 | m_ViewCamera = normalCamera; |
| 1336 | m->SetOpenGLCamera(m_ViewCamera); |
| 1337 | |
| 1338 | return screenScissor; |