Debian Codegraph @

prboom2/src/gl_sky.c

raw
1 /*
2 ** gl_sky.cpp
3 **
4 ** Draws the sky. Loosely based on the JDoom sky and the ZDoomGL 0.66.2 sky.
5 **
6 **---------------------------------------------------------------------------
7 ** Copyright 2003 Tim Stump
8 ** Copyright 2005 Christoph Oelckers
9 ** Copyright 2009 Andrey Budko
10 ** All rights reserved.
11 **
12 ** Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions
14 ** are met:
15 **
16 ** 1. Redistributions of source code must retain the above copyright
17 ** notice, this list of conditions and the following disclaimer.
18 ** 2. Redistributions in binary form must reproduce the above copyright
19 ** notice, this list of conditions and the following disclaimer in the
20 ** documentation and/or other materials provided with the distribution.
21 ** 3. The name of the author may not be used to endorse or promote products
22 ** derived from this software without specific prior written permission.
23 ** 4. Full disclosure of the entire project's source code, except for third
24 ** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 **---------------------------------------------------------------------------
37 **
38 */
39
40 #ifdef HAVE_CONFIG_H
41 #include "config.h"
42 #endif
43
44 #include "gl_opengl.h"
45
46 #include <SDL.h>
47 #include <math.h>
48
49 #include "doomtype.h"
50 #include "doomstat.h"
51 #include "v_video.h"
52 #include "gl_intern.h"
53 #include "r_plane.h"
54 #include "r_sky.h"
55 #include "r_main.h"
56 #include "sc_man.h"
57 #include "m_misc.h"
58 #include "lprintf.h"
59
60 #include "e6y.h"
61
62 #include "dsda/settings.h"
63
64 typedef struct
65 {
66 int mode;
67 int vertexcount;
68 int vertexindex;
69 int use_texture;
70 } GLSkyLoopDef;
71
72 typedef struct
73 {
74 GLuint id;
75 int rows, columns;
76 int loopcount;
77 GLSkyLoopDef *loops;
78 vbo_vertex_t *data;
79 } GLSkyVBO;
80
81 int gl_drawskys;
82 // Sky stretching is rather pointless with the GL renderer
83 // now that it can handle all sky heights.
84 int gl_stretchsky = false;
85
86 static PalEntry_t *SkyColor;
87
88 SkyBoxParams_t SkyBox;
89 float y_offset_saved;
90
91 void gld_InitSky(void)
92 {
93 memset(&SkyBox, 0, sizeof(SkyBox));
94 SkyBox.index = -1;
95 y_offset_saved = 0;
96 }
97
98 void gld_InitFrameSky(void)
99 {
100 SkyBox.type = SKY_NONE;
101 SkyBox.wall.gltexture = NULL;
102 SkyBox.x_offset = 0;
103 SkyBox.y_offset = 0;
104 }
105
106 void gld_DrawFakeSkyStrips(void)
107 {
108 int i;
109
110 // This draws a valid z-buffer into the stencil's contents to ensure it
111 // doesn't get overwritten by the level's geometry.
112
113 // Because some of outdated hardware has no support for
114 // glColorMask(0, 0, 0, 0) or something,
115 // I need to render fake strips of sky before dome with using
116 // full clearing of color buffer (only in compatibility mode)
117
118 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no graphics
119 gld_EnableTexture2D(GL_TEXTURE0_ARB, false);
120
121 for (i = gld_drawinfo.num_items[GLDIT_SWALL] - 1; i >= 0; i--)
122 {
123 GLWall* wall = gld_drawinfo.items[GLDIT_SWALL][i].item.wall;
124
125 glBegin(GL_TRIANGLE_STRIP);
126 glVertex3f(wall->glseg->x1,wall->ytop,wall->glseg->z1);
127 glVertex3f(wall->glseg->x1,wall->ybottom,wall->glseg->z1);
128 glVertex3f(wall->glseg->x2,wall->ytop,wall->glseg->z2);
129 glVertex3f(wall->glseg->x2,wall->ybottom,wall->glseg->z2);
130 glEnd();
131 }
132
133 gld_EnableTexture2D(GL_TEXTURE0_ARB, true);
134 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
135 }
136
137 // Sky textures with a zero index should be forced
138 // See third episode of requiem.wad
139 void gld_AddSkyTexture(GLWall *wall, int sky1, int sky2, int skytype)
140 {
141 side_t *s = NULL;
142 line_t *l = NULL;
143 int sky = texturetranslation[skytexture];
144
145 wall->gltexture = NULL;
146
147 if (sky1 & PL_SKYFLAT_LINE)
148 {
149 l = &lines[sky1 & ~PL_SKYFLAT_LINE];
150 }
151 else if (sky2 & PL_SKYFLAT_LINE)
152 {
153 l = &lines[sky2 & ~PL_SKYFLAT_LINE];
154 }
155
156 if (sky1 & PL_SKYFLAT_SECTOR)
157 {
158 sky = sky1 & ~PL_SKYFLAT_SECTOR;
159 }
160 else if (sky2 & PL_SKYFLAT_SECTOR)
161 {
162 sky = sky2 & ~PL_SKYFLAT_SECTOR;
163 }
164
165 if (l)
166 {
167 s = *l->sidenum + sides;
168 wall->gltexture = gld_RegisterSkyTexture(texturetranslation[s->toptexture],
169 texturetranslation[s->toptexture] == skytexture || l->special == 271 || l->special == 272);
170 if (wall->gltexture)
171 {
172 // As far as I can tell, textureoffset just adds directly to viewangle and is
173 // therefore affected by tiling, but rowoffset is not.
174 wall->skyyaw = (double) (viewangle + s->textureoffset) / (double) ANGLE_MAX;
175 wall->skypitch = skyYShift;
176 wall->skyoffset = (((float)s->rowoffset/(float)FRACUNIT - 28.0f)/wall->gltexture->buffer_height);
177 wall->flag = l->special == 272 ? GLDWF_SKY : GLDWF_SKYFLIP;
178 }
179 }
180 else
181 {
182 wall->gltexture = gld_RegisterSkyTexture(sky, true);
183 if (wall->gltexture)
184 {
185 int h = wall->gltexture->buffer_height;
186
187 wall->skyyaw = skyXShift;
188 wall->skypitch = skyYShift;
189 // Choose offset based on logic from r_sky.c
190 wall->skyoffset = skytexturemid / (float)FRACUNIT / h;
191 wall->flag = GLDWF_SKY;
192 }
193 }
194
195 if (wall->gltexture)
196 {
197 SkyBox.type |= skytype;
198
199 wall->gltexture->flags |= GLTEXTURE_SKY;
200
201 gld_AddDrawItem(GLDIT_SWALL, wall);
202
203 if (!SkyBox.wall.gltexture)
204 {
205 SkyBox.wall = *wall;
206
207 switch (gl_drawskys)
208 {
209 case skytype_skydome:
210 if (s)
211 {
212 SkyBox.x_offset = (float)s->textureoffset * 180.0f / (float)ANG180;
213 SkyBox.y_offset = (float)s->rowoffset / (float)FRACUNIT;
214 }
215 else if (raven)
216 {
217 SkyBox.y_offset = 39.0f;
218 }
219 break;
220 }
221 }
222 }
223 }
224
225 // The fussy arithmetic to correctly scale and translate the sky texture lives here.
226 void gld_SkyTransform(GLWall* wall)
227 {
228 // Make apparent scale of sky closer to software
229 const float scale_correction = 0.80f;
230 // 360 horizontal degrees of sky in texels (4 tilings of default sky)
231 float sky_width = 256 * 4;
232 // 360 vertical degrees of sky in texels (determined emperically with Heretic
233 // software mode)
234 float sky_height = 880;
235 // Texture dimensions
236 float w = wall->gltexture->buffer_width;
237 float h = wall->gltexture->buffer_height;
238 // Tile factors
239 float tilex = sky_width / w;
240 float tiley = sky_height / h;
241 // Adjustment for tall screens
242 float ratio = tallscreen ? (float)ratio_multiplier / ratio_scale : 1.0f;
243 // X flip coefficient
244 float flipx = wall->flag == GLDWF_SKYFLIP ? -1.0 : 1.0;
245 // Scale factors
246 float scalex = scale_correction / skyscale * flipx;
247 float scaley = scale_correction * ratio * (skystretch ? ( (float)SKYSTRETCH_HEIGHT / h ) : 1.0f) / skyscale;
248 // Translations
249 float transx = wall->skyyaw * tilex * flipx;
250 float transy = wall->skypitch * tiley;
251
252 // Apply scaling centered at horizon and view yaw
253 glTranslatef(transx, wall->skyoffset, 0.0f);
254 glScalef(1.0f / scalex, 1.0f / scaley, 1.0);
255 //glTranslatef(-transx, -wall->skyoffset, 0.0f);
256
257 // Apply offset
258 //glTranslatef(0, wall->skyoffset, 0.0f);
259
260 // Apply view yaw and pitch
261 //glTranslatef(transx, transy, 0.0f);
262
263 // The above translations (which are part of logically distinct operations)
264 // are commented out and combined here for efficiency
265 glTranslatef(0.0, transy, 0.0f);
266
267 // Scale texture coordinates generated by glTexGen so the range [0, 1]
268 // corresponds to the full range of the texture as usual
269 glScalef(MAP_COEFF / w, MAP_COEFF / h, 1.0f);
270 }
271
272 void gld_DrawStripsSky(void)
273 {
274 int i;
275 GLTexture *gltexture = NULL;
276
277 if (gl_drawskys == skytype_standard)
278 {
279 glEnable(GL_TEXTURE_GEN_S);
280 glEnable(GL_TEXTURE_GEN_T);
281 glEnable(GL_TEXTURE_GEN_Q);
282
283 glColor4fv(gl_whitecolor);
284
285 SetTextureMode(TM_OPAQUE);
286 }
287
288 glMatrixMode(GL_TEXTURE);
289
290 for (i = gld_drawinfo.num_items[GLDIT_SWALL] - 1; i >= 0; i--)
291 {
292 GLWall *wall = gld_drawinfo.items[GLDIT_SWALL][i].item.wall;
293
294 gltexture = (gl_drawskys == skytype_none ? NULL : wall->gltexture);
295 gld_BindSkyTexture(gltexture);
296
297 if (!gltexture)
298 {
299 glColor4f(1.0f,0.0f,0.0f,1.0f);
300 }
301
302 if (gltexture)
303 {
304 glPushMatrix();
305
306 gld_SkyTransform(wall);
307 }
308
309 glBegin(GL_TRIANGLE_STRIP);
310 glVertex3f(wall->glseg->x1,wall->ytop,wall->glseg->z1);
311 glVertex3f(wall->glseg->x1,wall->ybottom,wall->glseg->z1);
312 glVertex3f(wall->glseg->x2,wall->ytop,wall->glseg->z2);
313 glVertex3f(wall->glseg->x2,wall->ybottom,wall->glseg->z2);
314 glEnd();
315
316 if (gltexture)
317 {
318 glPopMatrix();
319 }
320 }
321
322 glMatrixMode(GL_MODELVIEW);
323
324 gld_DrawSkyCaps();
325
326 if (gl_drawskys == skytype_standard)
327 {
328 glDisable(GL_TEXTURE_GEN_Q);
329 glDisable(GL_TEXTURE_GEN_T);
330 glDisable(GL_TEXTURE_GEN_S);
331
332 SetFrameTextureMode();
333 }
334 }
335
336 void gld_DrawSkyCaps(void)
337 {
338 if (SkyBox.type && SkyBox.wall.gltexture)
339 {
340 if (dsda_MouseLook())
341 {
342 gld_BindSkyTexture(SkyBox.wall.gltexture);
343
344 glMatrixMode(GL_TEXTURE);
345 glPushMatrix();
346
347 gld_SkyTransform(&SkyBox.wall);
348
349 if (SkyBox.type & SKY_CEILING)
350 {
351 glBegin(GL_TRIANGLE_STRIP);
352 glVertex3f(-MAXCOORD,+MAXCOORD,+MAXCOORD);
353 glVertex3f(+MAXCOORD,+MAXCOORD,+MAXCOORD);
354 glVertex3f(-MAXCOORD,+MAXCOORD,-MAXCOORD);
355 glVertex3f(+MAXCOORD,+MAXCOORD,-MAXCOORD);
356 glEnd();
357 }
358
359 if (SkyBox.type & SKY_FLOOR)
360 {
361 glBegin(GL_TRIANGLE_STRIP);
362 glVertex3f(-MAXCOORD,-MAXCOORD,+MAXCOORD);
363 glVertex3f(+MAXCOORD,-MAXCOORD,+MAXCOORD);
364 glVertex3f(-MAXCOORD,-MAXCOORD,-MAXCOORD);
365 glVertex3f(+MAXCOORD,-MAXCOORD,-MAXCOORD);
366 glEnd();
367 }
368
369 glPopMatrix();
370 glMatrixMode(GL_MODELVIEW);
371 }
372 }
373 }
374
375 //===========================================================================
376 //
377 // averageColor
378 // input is RGBA8 pixel format.
379 // The resulting RGB color can be scaled uniformly so that the highest
380 // component becomes one.
381 //
382 //===========================================================================
383 #define APART(c) (((c)>>24)&0xff)
384 #define RPART(c) (((c)>>16)&0xff)
385 #define GPART(c) (((c)>>8)&0xff)
386 #define BPART(c) ((c)&0xff)
387
388 void averageColor(PalEntry_t * PalEntry, const unsigned int *data, int size, fixed_t maxout_factor)
389 {
390 int i;
391 int maxv;
392 unsigned int r, g, b;
393
394 // First clear them.
395 r = g = b = 0;
396 if (size == 0)
397 {
398 PalEntry->r = 255;
399 PalEntry->g = 255;
400 PalEntry->b = 255;
401 return;
402 }
403 for(i = 0; i < size; i++)
404 {
405 r += BPART(data[i]);
406 g += GPART(data[i]);
407 b += RPART(data[i]);
408 }
409
410 r = r / size;
411 g = g / size;
412 b = b / size;
413
414 maxv=MAX(MAX(r,g),b);
415
416 if(maxv && maxout_factor)
417 {
418 maxout_factor = FixedMul(maxout_factor, 255);
419 r = r * maxout_factor / maxv;
420 g = g * maxout_factor / maxv;
421 b = b * maxout_factor / maxv;
422 }
423
424 PalEntry->r = r;
425 PalEntry->g = g;
426 PalEntry->b = b;
427 return;
428 }
429
430 // The texture offset to be applied to the texture coordinates in SkyVertex().
431 static int rows, columns;
432 static dboolean yflip;
433 static int texw;
434 static float yMult, yAdd;
435 static dboolean foglayer;
436 static float delta = 0.0f;
437
438 //-----------------------------------------------------------------------------
439 //
440 //
441 //
442 //-----------------------------------------------------------------------------
443
444 void gld_GetSkyCapColors(void)
445 {
446 int color, width, height;
447 int frame_fixedcolormap_saved;
448 unsigned char *buffer = NULL;
449 const unsigned char *playpal = V_GetPlaypal();
450 const lighttable_t *colormap;
451 const lighttable_t *fixedcolormap_saved;
452 PalEntry_t *ceiling_rgb = &SkyBox.CeilingSkyColor[0];
453 PalEntry_t *floor_rgb = &SkyBox.FloorSkyColor[0];
454
455 // saving current colormap
456 fixedcolormap_saved = fixedcolormap;
457 frame_fixedcolormap_saved = frame_fixedcolormap;
458
459 fixedcolormap = fullcolormap;
460 frame_fixedcolormap = 0;
461
462 gld_BindSkyTexture(SkyBox.wall.gltexture);
463
464 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
465 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
466
467 buffer = Z_Malloc(width * height * 4);
468 glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
469
470 averageColor(ceiling_rgb, (unsigned int*)buffer, width * MIN(30, height), 0);
471
472 if (height > 30)
473 {
474 averageColor(floor_rgb,
475 ((unsigned int*)buffer) + (height - 30) * width, width * 30, 0);
476 }
477 else
478 {
479 *floor_rgb = *ceiling_rgb;
480 }
481
482 colormap = fullcolormap + INVERSECOLORMAP * 256 * sizeof(lighttable_t);
483
484 color = V_BestColor(playpal, ceiling_rgb->r, ceiling_rgb->g, ceiling_rgb->b);
485 SkyBox.CeilingSkyColor[1].r = playpal[colormap[color] * 3 + 0];
486 SkyBox.CeilingSkyColor[1].g = playpal[colormap[color] * 3 + 1];
487 SkyBox.CeilingSkyColor[1].b = playpal[colormap[color] * 3 + 2];
488
489 color = V_BestColor(playpal, floor_rgb->r, floor_rgb->g, floor_rgb->b);
490 SkyBox.FloorSkyColor[1].r = playpal[colormap[color] * 3 + 0];
491 SkyBox.FloorSkyColor[1].g = playpal[colormap[color] * 3 + 1];
492 SkyBox.FloorSkyColor[1].b = playpal[colormap[color] * 3 + 2];
493
494 // restorin current colormap
495 fixedcolormap = fixedcolormap_saved;
496 frame_fixedcolormap = frame_fixedcolormap_saved;
497
498 Z_Free(buffer);
499 }
500
501 //-----------------------------------------------------------------------------
502 //
503 //
504 //
505 //-----------------------------------------------------------------------------
506
507 static void SkyVertex(vbo_vertex_t *vbo, int r, int c)
508 {
509 static const float scale = 10000.0f;
510 static const float maxSideAngle = DEG2RAD(60.0f);
511
512 float topAngle = DEG2RAD(c / (float)columns * 360.0f);
513 float sideAngle = maxSideAngle * (float)(rows - r) / (float)rows;
514 float height = (float)sin(sideAngle);
515 float realRadius = scale * (float)cos(sideAngle);
516 float x = realRadius * (float)cos(topAngle);
517 float y = (!yflip) ? scale * height : -scale * height;
518 float z = realRadius * (float)sin(topAngle);
519 float timesRepeat;
520
521 timesRepeat = (short)(4 * (256.0f / texw));
522 if (timesRepeat == 0.0f)
523 timesRepeat = 1.0f;
524
525 if (!foglayer)
526 {
527 vbo->r = 255;
528 vbo->g = 255;
529 vbo->b = 255;
530 vbo->a = (r == 0 ? 0 : 255);
531
532 // And the texture coordinates.
533 if(!yflip) // Flipped Y is for the lower hemisphere.
534 {
535 vbo->u = (-timesRepeat * c / (float)columns) ;
536 vbo->v = (r / (float)rows) * 1.f * yMult + yAdd;
537 }
538 else
539 {
540 vbo->u = (-timesRepeat * c / (float)columns) ;
541 vbo->v = ((rows-r)/(float)rows) * 1.f * yMult + yAdd;
542 }
543
544 if (SkyBox.wall.flag == GLDWF_SKYFLIP)
545 vbo->u = -vbo->u;
546 }
547
548 if (r != 4)
549 {
550 y += 300;
551 }
552
553 // And finally the vertex.
554 vbo->x =-x / MAP_COEFF; // Doom mirrors the sky vertically!
555 vbo->y = y / MAP_COEFF + delta;
556 vbo->z = z / MAP_COEFF;
557 }
558
559 GLSkyVBO sky_vbo[2];
560
561 static void gld_BuildSky(int row_count, int col_count, SkyBoxParams_t *sky, int cm)
562 {
563 int texh, c, r;
564 vbo_vertex_t *vertex_p;
565 int vertex_count = 2 * row_count * (col_count * 2 + 2) + col_count * 2;
566 int vbo_idx = (cm == INVERSECOLORMAP ? 1 : 0);
567 GLSkyVBO *vbo = &sky_vbo[vbo_idx];
568
569 if ((vbo->columns != col_count) || (vbo->rows != row_count))
570 {
571 Z_Free(vbo->loops);
572 Z_Free(vbo->data);
573 vbo->loops = NULL;
574 vbo->data = NULL;
575 }
576
577 if (!vbo->data)
578 {
579 vbo->loops = Z_Malloc((row_count * 2 + 2) * sizeof(vbo->loops[0]));
580 // create vertex array
581 vbo->data = Z_Malloc(vertex_count * sizeof(vbo->data[0]));
582 }
583
584 vbo->columns = col_count;
585 vbo->rows = row_count;
586
587 texh = sky->wall.gltexture->buffer_height;
588 if (texh > 190 && gl_stretchsky)
589 texh = 190;
590 texw = sky->wall.gltexture->buffer_width;
591
592 vertex_p = &vbo->data[0];
593 vbo->loopcount = 0;
594 for (yflip = 0; yflip < 2; yflip++)
595 {
596 vbo->loops[vbo->loopcount].mode = GL_TRIANGLE_FAN;
597 vbo->loops[vbo->loopcount].vertexindex = vertex_p - &vbo->data[0];
598 vbo->loops[vbo->loopcount].vertexcount = col_count;
599 vbo->loops[vbo->loopcount].use_texture = false;
600 vbo->loopcount++;
601
602 yAdd = sky->y_offset / texh;
603 yMult = (texh <= 180 ? 1.0f : 180.0f / texh);
604 if (yflip == 0)
605 {
606 SkyColor = &sky->CeilingSkyColor[vbo_idx];
607 }
608 else
609 {
610 SkyColor = &sky->FloorSkyColor[vbo_idx];
611 if (texh <= 180) yMult = 1.0f; else yAdd += 180.0f / texh;
612 }
613
614 delta = 0.0f;
615 foglayer = true;
616 for(c = 0; c < col_count; c++)
617 {
618 SkyVertex(vertex_p, 1, c);
619 vertex_p->r = SkyColor->r;
620 vertex_p->g = SkyColor->g;
621 vertex_p->b = SkyColor->b;
622 vertex_p->a = 255;
623 vertex_p++;
624 }
625 foglayer = false;
626
627 delta = (yflip ? 5.0f : -5.0f) / MAP_COEFF;
628
629 for(r = 0; r < row_count; r++)
630 {
631 vbo->loops[vbo->loopcount].mode = GL_TRIANGLE_STRIP;
632 vbo->loops[vbo->loopcount].vertexindex = vertex_p - &vbo->data[0];
633 vbo->loops[vbo->loopcount].vertexcount = 2 * col_count + 2;
634 vbo->loops[vbo->loopcount].use_texture = true;
635 vbo->loopcount++;
636
637 for(c = 0; c <= col_count; c++)
638 {
639 SkyVertex(vertex_p++, r + (yflip ? 1 : 0), (c ? c : 0));
640 SkyVertex(vertex_p++, r + (yflip ? 0 : 1), (c ? c : 0));
641 }
642 }
643 }
644 }
645
646 //-----------------------------------------------------------------------------
647 //
648 //
649 //
650 //-----------------------------------------------------------------------------
651
652 static void RenderDome(SkyBoxParams_t *sky)
653 {
654 int i, j;
655 GLSkyVBO *vbo;
656 int vbosize;
657 dboolean rebuild_sky;
658
659 if (!sky || !sky->wall.gltexture)
660 return;
661
662 if (invul_cm && frame_fixedcolormap == INVERSECOLORMAP)
663 vbo = &sky_vbo[1];
664 else
665 vbo = &sky_vbo[0];
666
667 glRotatef(-180.0f + sky->x_offset, 0.f, 1.f, 0.f);
668
669 rows = 4;
670 columns = 64;
671 vbosize = 2 * rows * (columns * 2 + 2) + columns * 2;
672 rebuild_sky = sky->y_offset != y_offset_saved || sky->wall.gltexture->index != sky->index;
673
674 if (rebuild_sky)
675 {
676 y_offset_saved = sky->y_offset;
677
678 if (sky->wall.gltexture->index != sky->index)
679 {
680 sky->index = sky->wall.gltexture->index;
681 gld_GetSkyCapColors();
682 }
683
684 gld_BuildSky(rows, columns, sky, 0);
685 gld_BuildSky(rows, columns, sky, INVERSECOLORMAP);
686 }
687
688 if (gl_ext_arb_vertex_buffer_object)
689 {
690 if (rebuild_sky || !vbo->id)
691 {
692 if (vbo->id)
693 {
694 // delete VBO when already exists
695 GLEXT_glDeleteBuffersARB(1, &vbo->id);
696 }
697 // generate a new VBO and get the associated ID
698 GLEXT_glGenBuffersARB(1, &vbo->id);
699 // bind VBO in order to use
700 GLEXT_glBindBufferARB(GL_ARRAY_BUFFER, vbo->id);
701 // upload data to VBO
702 GLEXT_glBufferDataARB(GL_ARRAY_BUFFER,
703 vbosize * sizeof(vbo->data[0]),
704 vbo->data, GL_STATIC_DRAW_ARB);
705 }
706 }
707
708 gld_BindSkyTexture(SkyBox.wall.gltexture);
709
710 if (gl_ext_arb_vertex_buffer_object)
711 {
712 // bind VBO in order to use
713 GLEXT_glBindBufferARB(GL_ARRAY_BUFFER, vbo->id);
714 }
715
716 // activate and specify pointers to arrays
717 glVertexPointer(3, GL_FLOAT, sizeof(vbo->data[0]), sky_vbo_x);
718 glTexCoordPointer(2, GL_FLOAT, sizeof(vbo->data[0]), sky_vbo_u);
719 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vbo->data[0]), sky_vbo_r);
720
721 // activate vertex array, texture coord array and color arrays
722 glEnableClientState(GL_VERTEX_ARRAY);
723 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
724 glEnableClientState(GL_COLOR_ARRAY);
725
726 if (!gl_stretchsky)
727 {
728 int texh = sky->wall.gltexture->buffer_height;
729
730 if (texh <= 180)
731 {
732 glScalef(1.0f, (float)texh / 230.0f, 1.0f);
733 }
734 else
735 {
736 if (texh > 190)
737 glScalef(1.0f, 230.0f / 240.0f, 1.0f);
738 }
739 }
740
741 for(j = (HaveMouseLook() || !gl_stretchsky ? 0 : 1); j < 2; j++)
742 {
743 gld_EnableTexture2D(GL_TEXTURE0_ARB, j != 0);
744
745 for(i = 0; i < vbo->loopcount; i++)
746 {
747 GLSkyLoopDef *loop = &vbo->loops[i];
748
749 if (j == 0 ? loop->use_texture : !loop->use_texture)
750 continue;
751
752 glDrawArrays(loop->mode, loop->vertexindex, loop->vertexcount);
753 }
754 }
755
756 glScalef(1.0f, 1.0f, 1.0f);
757
758 // current color is undefined after glDrawArrays
759 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
760
761 if (gl_ext_arb_vertex_buffer_object)
762 {
763 // bind with 0, so, switch back to normal pointer operation
764 GLEXT_glBindBufferARB(GL_ARRAY_BUFFER, 0);
765 }
766 // deactivate color array
767 glDisableClientState(GL_COLOR_ARRAY);
768 }
769
770 void gld_DrawDomeSkyBox(void)
771 {
772 if (SkyBox.wall.gltexture)
773 {
774 GLint shading_mode = GL_FLAT;
775
776 gld_DrawFakeSkyStrips();
777
778 glGetIntegerv(GL_SHADE_MODEL, &shading_mode);
779 glShadeModel(GL_SMOOTH);
780
781 glDepthMask(false);
782
783 glDisable(GL_DEPTH_TEST);
784 glDisable(GL_ALPHA_TEST);
785 SetTextureMode(TM_OPAQUE);
786
787 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
788
789 glPushMatrix();
790 glMatrixMode(GL_MODELVIEW);
791 glLoadIdentity();
792
793 glRotatef(roll, 0.0f, 0.0f, 1.0f);
794 glRotatef(pitch, 1.0f, 0.0f, 0.0f);
795 glRotatef(yaw, 0.0f, 1.0f, 0.0f);
796 glScalef(-2.0f, 2.0f, 2.0f);
797 glTranslatef(0.f, -1250.0f / MAP_COEFF, 0.f);
798
799 RenderDome(&SkyBox);
800
801 glPopMatrix();
802
803 glEnable(GL_ALPHA_TEST);
804 glEnable(GL_DEPTH_TEST);
805 glDepthMask(true);
806
807 SetFrameTextureMode();
808
809 glShadeModel(shading_mode);
810 }
811 }