2013-06-23 07:49:34 +00:00
|
|
|
|
/*
|
|
|
|
|
** gl_sky.cpp
|
|
|
|
|
**
|
|
|
|
|
** Draws the sky. Loosely based on the JDoom sky and the ZDoomGL 0.66.2 sky.
|
|
|
|
|
**
|
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
|
** Copyright 2003 Tim Stump
|
|
|
|
|
** Copyright 2005 Christoph Oelckers
|
|
|
|
|
** All rights reserved.
|
|
|
|
|
**
|
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
|
** are met:
|
|
|
|
|
**
|
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
|
** 4. Full disclosure of the entire project's source code, except for third
|
|
|
|
|
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
|
|
|
|
|
**
|
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
|
**
|
|
|
|
|
*/
|
|
|
|
|
#include "gl/system/gl_system.h"
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
|
#include "g_level.h"
|
|
|
|
|
#include "sc_man.h"
|
|
|
|
|
#include "w_wad.h"
|
|
|
|
|
#include "r_state.h"
|
2016-04-02 21:17:16 +00:00
|
|
|
|
#include "r_utility.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
//#include "gl/gl_intern.h"
|
|
|
|
|
|
2013-09-03 16:29:39 +00:00
|
|
|
|
#include "gl/system/gl_interface.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
#include "gl/data/gl_data.h"
|
2014-06-13 23:24:28 +00:00
|
|
|
|
#include "gl/data/gl_vertexbuffer.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
#include "gl/renderer/gl_lightdata.h"
|
|
|
|
|
#include "gl/renderer/gl_renderstate.h"
|
|
|
|
|
#include "gl/scene/gl_drawinfo.h"
|
|
|
|
|
#include "gl/scene/gl_portal.h"
|
|
|
|
|
#include "gl/shaders/gl_shader.h"
|
|
|
|
|
#include "gl/textures/gl_bitmap.h"
|
|
|
|
|
#include "gl/textures/gl_texture.h"
|
|
|
|
|
#include "gl/textures/gl_skyboxtexture.h"
|
|
|
|
|
#include "gl/textures/gl_material.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Shamelessly lifted from Doomsday (written by Jaakko Ker<65>nen)
|
|
|
|
|
// also shamelessly lifted from ZDoomGL! ;)
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
CVAR(Float, skyoffset, 0, 0) // for testing
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
extern int skyfog;
|
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
FSkyVertexBuffer::FSkyVertexBuffer()
|
|
|
|
|
{
|
|
|
|
|
CreateDome();
|
2016-04-26 14:26:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FSkyVertexBuffer::~FSkyVertexBuffer()
|
|
|
|
|
{
|
|
|
|
|
}
|
2014-06-13 23:24:28 +00:00
|
|
|
|
|
2016-04-26 14:26:34 +00:00
|
|
|
|
void FSkyVertexBuffer::BindVBO()
|
|
|
|
|
{
|
2014-06-13 23:24:28 +00:00
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
2016-04-26 14:44:03 +00:00
|
|
|
|
if (gl.glslversion > 0)
|
|
|
|
|
{
|
|
|
|
|
glVertexAttribPointer(VATTR_VERTEX, 3, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->x);
|
|
|
|
|
glVertexAttribPointer(VATTR_TEXCOORD, 2, GL_FLOAT, false, sizeof(FSkyVertex), &VSO->u);
|
|
|
|
|
glVertexAttribPointer(VATTR_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(FSkyVertex), &VSO->color);
|
|
|
|
|
glEnableVertexAttribArray(VATTR_VERTEX);
|
|
|
|
|
glEnableVertexAttribArray(VATTR_TEXCOORD);
|
|
|
|
|
glEnableVertexAttribArray(VATTR_COLOR);
|
|
|
|
|
glDisableVertexAttribArray(VATTR_VERTEX2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
glVertexPointer(3, GL_FLOAT, sizeof(FSkyVertex), &VSO->x);
|
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, sizeof(FSkyVertex), &VSO->u);
|
|
|
|
|
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(FSkyVertex), &VSO->color);
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2016-04-26 18:45:56 +00:00
|
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
2016-04-26 14:44:03 +00:00
|
|
|
|
}
|
2014-06-30 22:51:02 +00:00
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
|
void FSkyVertexBuffer::SkyVertex(int r, int c, bool zflip)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
|
static const FAngle maxSideAngle = 60.f;
|
|
|
|
|
static const float scale = 10000.;
|
2014-06-13 23:24:28 +00:00
|
|
|
|
|
2016-08-14 18:11:46 +00:00
|
|
|
|
FAngle topAngle = (c / (float)mColumns * 360.f);
|
2016-04-07 23:42:43 +00:00
|
|
|
|
FAngle sideAngle = maxSideAngle * (mRows - r) / mRows;
|
|
|
|
|
float height = sideAngle.Sin();
|
|
|
|
|
float realRadius = scale * sideAngle.Cos();
|
|
|
|
|
FVector2 pos = topAngle.ToVector(realRadius);
|
|
|
|
|
float z = (!zflip) ? scale * height : -scale * height;
|
2014-06-13 23:24:28 +00:00
|
|
|
|
|
|
|
|
|
FSkyVertex vert;
|
2016-08-14 18:11:46 +00:00
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
vert.color = r == 0 ? 0xffffff : 0xffffffff;
|
2016-08-14 18:11:46 +00:00
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
// And the texture coordinates.
|
2016-08-14 18:11:46 +00:00
|
|
|
|
if (!zflip) // Flipped Y is for the lower hemisphere.
|
2014-06-13 23:24:28 +00:00
|
|
|
|
{
|
2016-08-14 18:11:46 +00:00
|
|
|
|
vert.u = (-c / (float)mColumns);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
vert.v = (r / (float)mRows);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
2014-06-13 23:24:28 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vert.u = (-c / (float)mColumns);
|
|
|
|
|
vert.v = 1.0f + ((mRows - r) / (float)mRows);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-14 18:11:46 +00:00
|
|
|
|
if (r != 4) z += 300;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
// And finally the vertex.
|
2016-04-07 23:42:43 +00:00
|
|
|
|
vert.x = -pos.X; // Doom mirrors the sky vertically!
|
|
|
|
|
vert.y = z - 1.f;
|
|
|
|
|
vert.z = pos.Y;
|
2014-06-13 23:24:28 +00:00
|
|
|
|
|
|
|
|
|
mVertices.Push(vert);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
2014-06-13 23:24:28 +00:00
|
|
|
|
//
|
2013-06-23 07:49:34 +00:00
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
void FSkyVertexBuffer::CreateSkyHemisphere(int hemi)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
|
|
|
|
int r, c;
|
2016-04-07 23:42:43 +00:00
|
|
|
|
bool zflip = !!(hemi & SKYHEMI_LOWER);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
|
|
|
|
|
mPrimStart.Push(mVertices.Size());
|
|
|
|
|
|
|
|
|
|
for (c = 0; c < mColumns; c++)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
|
SkyVertex(1, c, zflip);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
// The total number of triangles per hemisphere can be calculated
|
|
|
|
|
// as follows: rows * columns * 2 + 2 (for the top cap).
|
|
|
|
|
for (r = 0; r < mRows; r++)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2014-06-13 23:24:28 +00:00
|
|
|
|
mPrimStart.Push(mVertices.Size());
|
|
|
|
|
for (c = 0; c <= mColumns; c++)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
|
SkyVertex(r + zflip, c, zflip);
|
|
|
|
|
SkyVertex(r + 1 - zflip, c, zflip);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
2014-06-13 23:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FSkyVertexBuffer::CreateDome()
|
|
|
|
|
{
|
2014-06-14 08:38:30 +00:00
|
|
|
|
// the first thing we put into the buffer is the fog layer object which is just 4 triangles around the viewpoint.
|
|
|
|
|
|
|
|
|
|
mVertices.Reserve(12);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
mVertices[0].Set(1.0f, 1.0f, -1.0f);
|
|
|
|
|
mVertices[1].Set(1.0f, -1.0f, -1.0f);
|
|
|
|
|
mVertices[2].Set(-1.0f, 0.0f, -1.0f);
|
2014-06-14 08:38:30 +00:00
|
|
|
|
|
2016-08-14 18:11:46 +00:00
|
|
|
|
mVertices[3].Set(1.0f, 1.0f, -1.0f);
|
|
|
|
|
mVertices[4].Set(1.0f, -1.0f, -1.0f);
|
|
|
|
|
mVertices[5].Set(0.0f, 0.0f, 1.0f);
|
2014-06-14 08:38:30 +00:00
|
|
|
|
|
|
|
|
|
mVertices[6].Set(-1.0f, 0.0f, -1.0f);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
mVertices[7].Set(1.0f, 1.0f, -1.0f);
|
|
|
|
|
mVertices[8].Set(0.0f, 0.0f, 1.0f);
|
2014-06-14 08:38:30 +00:00
|
|
|
|
|
|
|
|
|
mVertices[9].Set(1.0f, -1.0f, -1.0f);
|
|
|
|
|
mVertices[10].Set(-1.0f, 0.0f, -1.0f);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
mVertices[11].Set(0.0f, 0.0f, 1.0f);
|
2014-06-14 08:38:30 +00:00
|
|
|
|
|
|
|
|
|
mColumns = 128;
|
|
|
|
|
mRows = 4;
|
2014-06-13 23:24:28 +00:00
|
|
|
|
CreateSkyHemisphere(SKYHEMI_UPPER);
|
|
|
|
|
CreateSkyHemisphere(SKYHEMI_LOWER);
|
|
|
|
|
mPrimStart.Push(mVertices.Size());
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
mSideStart = mVertices.Size();
|
|
|
|
|
mFaceStart[0] = mSideStart + 10;
|
|
|
|
|
mFaceStart[1] = mFaceStart[0] + 4;
|
|
|
|
|
mFaceStart[2] = mFaceStart[1] + 4;
|
|
|
|
|
mFaceStart[3] = mFaceStart[2] + 4;
|
|
|
|
|
mFaceStart[4] = mFaceStart[3] + 4;
|
|
|
|
|
mFaceStart[5] = mFaceStart[4] + 4;
|
|
|
|
|
mFaceStart[6] = mFaceStart[5] + 4;
|
|
|
|
|
mVertices.Reserve(10 + 7*4);
|
|
|
|
|
FSkyVertex *ptr = &mVertices[mSideStart];
|
|
|
|
|
|
|
|
|
|
// all sides
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[0].SetXYZ(128.f, 128.f, -128.f, 0, 0);
|
|
|
|
|
ptr[1].SetXYZ(128.f, -128.f, -128.f, 0, 1);
|
|
|
|
|
ptr[2].SetXYZ(-128.f, 128.f, -128.f, 0.25f, 0);
|
|
|
|
|
ptr[3].SetXYZ(-128.f, -128.f, -128.f, 0.25f, 1);
|
|
|
|
|
ptr[4].SetXYZ(-128.f, 128.f, 128.f, 0.5f, 0);
|
|
|
|
|
ptr[5].SetXYZ(-128.f, -128.f, 128.f, 0.5f, 1);
|
|
|
|
|
ptr[6].SetXYZ(128.f, 128.f, 128.f, 0.75f, 0);
|
|
|
|
|
ptr[7].SetXYZ(128.f, -128.f, 128.f, 0.75f, 1);
|
|
|
|
|
ptr[8].SetXYZ(128.f, 128.f, -128.f, 1, 0);
|
|
|
|
|
ptr[9].SetXYZ(128.f, -128.f, -128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// north face
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[10].SetXYZ(128.f, 128.f, -128.f, 0, 0);
|
|
|
|
|
ptr[11].SetXYZ(-128.f, 128.f, -128.f, 1, 0);
|
|
|
|
|
ptr[12].SetXYZ(128.f, -128.f, -128.f, 0, 1);
|
|
|
|
|
ptr[13].SetXYZ(-128.f, -128.f, -128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// east face
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[14].SetXYZ(-128.f, 128.f, -128.f, 0, 0);
|
|
|
|
|
ptr[15].SetXYZ(-128.f, 128.f, 128.f, 1, 0);
|
|
|
|
|
ptr[16].SetXYZ(-128.f, -128.f, -128.f, 0, 1);
|
|
|
|
|
ptr[17].SetXYZ(-128.f, -128.f, 128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// south face
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[18].SetXYZ(-128.f, 128.f, 128.f, 0, 0);
|
|
|
|
|
ptr[19].SetXYZ(128.f, 128.f, 128.f, 1, 0);
|
|
|
|
|
ptr[20].SetXYZ(-128.f, -128.f, 128.f, 0, 1);
|
|
|
|
|
ptr[21].SetXYZ(128.f, -128.f, 128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// west face
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[22].SetXYZ(128.f, 128.f, 128.f, 0, 0);
|
|
|
|
|
ptr[23].SetXYZ(128.f, 128.f, -128.f, 1, 0);
|
|
|
|
|
ptr[24].SetXYZ(128.f, -128.f, 128.f, 0, 1);
|
|
|
|
|
ptr[25].SetXYZ(128.f, -128.f, -128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// bottom face
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[26].SetXYZ(128.f, -128.f, -128.f, 0, 0);
|
|
|
|
|
ptr[27].SetXYZ(-128.f, -128.f, -128.f, 1, 0);
|
|
|
|
|
ptr[28].SetXYZ(128.f, -128.f, 128.f, 0, 1);
|
|
|
|
|
ptr[29].SetXYZ(-128.f, -128.f, 128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// top face
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[30].SetXYZ(128.f, 128.f, -128.f, 0, 0);
|
|
|
|
|
ptr[31].SetXYZ(-128.f, 128.f, -128.f, 1, 0);
|
|
|
|
|
ptr[32].SetXYZ(128.f, 128.f, 128.f, 0, 1);
|
|
|
|
|
ptr[33].SetXYZ(-128.f, 128.f, 128.f, 1, 1);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
|
|
|
|
// top face flipped
|
2016-08-06 09:47:03 +00:00
|
|
|
|
ptr[34].SetXYZ(128.f, 128.f, -128.f, 0, 1);
|
|
|
|
|
ptr[35].SetXYZ(-128.f, 128.f, -128.f, 1, 1);
|
|
|
|
|
ptr[36].SetXYZ(128.f, 128.f, 128.f, 0, 0);
|
|
|
|
|
ptr[37].SetXYZ(-128.f, 128.f, 128.f, 1, 0);
|
2016-08-04 10:16:53 +00:00
|
|
|
|
|
2014-06-14 08:38:30 +00:00
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], GL_STATIC_DRAW);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2014-06-14 08:38:30 +00:00
|
|
|
|
inline void FSkyVertexBuffer::RenderRow(int prim, int row)
|
2014-06-13 23:24:28 +00:00
|
|
|
|
{
|
2014-06-14 08:38:30 +00:00
|
|
|
|
glDrawArrays(prim, mPrimStart[row], mPrimStart[row + 1] - mPrimStart[row]);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
void FSkyVertexBuffer::RenderDome(FMaterial *tex, int mode)
|
|
|
|
|
{
|
|
|
|
|
int rc = mRows + 1;
|
|
|
|
|
|
2014-06-14 12:58:17 +00:00
|
|
|
|
// The caps only get drawn for the main layer but not for the overlay.
|
2014-06-14 08:38:30 +00:00
|
|
|
|
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2014-06-14 08:38:30 +00:00
|
|
|
|
PalEntry pe = tex->tex->GetSkyCapColor(false);
|
|
|
|
|
gl_RenderState.SetObjectColor(pe);
|
|
|
|
|
gl_RenderState.EnableTexture(false);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2014-06-14 08:38:30 +00:00
|
|
|
|
RenderRow(GL_TRIANGLE_FAN, 0);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
|
2014-06-14 12:58:17 +00:00
|
|
|
|
pe = tex->tex->GetSkyCapColor(true);
|
2014-06-14 08:38:30 +00:00
|
|
|
|
gl_RenderState.SetObjectColor(pe);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2014-06-14 08:38:30 +00:00
|
|
|
|
RenderRow(GL_TRIANGLE_FAN, rc);
|
|
|
|
|
gl_RenderState.EnableTexture(true);
|
2016-04-26 18:45:56 +00:00
|
|
|
|
// The color array can only be activated now if this is drawn without shader
|
|
|
|
|
if (gl.glslversion == 0)
|
|
|
|
|
{
|
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
2014-06-13 23:24:28 +00:00
|
|
|
|
gl_RenderState.SetObjectColor(0xffffffff);
|
|
|
|
|
gl_RenderState.Apply();
|
|
|
|
|
for (int i = 1; i <= mRows; i++)
|
|
|
|
|
{
|
2014-06-14 08:38:30 +00:00
|
|
|
|
RenderRow(GL_TRIANGLE_STRIP, i);
|
|
|
|
|
RenderRow(GL_TRIANGLE_STRIP, rc + i);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
void RenderDome(FMaterial * tex, float x_offset, float y_offset, bool mirror, int mode)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
|
|
|
|
int texh = 0;
|
2014-06-13 23:24:28 +00:00
|
|
|
|
int texw = 0;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2014-05-11 20:57:42 +00:00
|
|
|
|
// 57 world units roughly represent one sky texel for the glTranslate call.
|
2013-06-23 07:49:34 +00:00
|
|
|
|
const float skyoffsetfactor = 57;
|
|
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
|
{
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_NONE, 0, -1, false);
|
2014-08-22 21:50:38 +00:00
|
|
|
|
texw = tex->TextureWidth();
|
|
|
|
|
texh = tex->TextureHeight();
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.EnableModelMatrix(true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.loadIdentity();
|
2016-08-14 18:11:46 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.rotate(-180.0f + x_offset, 0.f, 1.f, 0.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2016-04-01 16:07:18 +00:00
|
|
|
|
float xscale = texw < 1024.f ? floor(1024.f / float(texw)) : 1.f;
|
2014-06-13 23:24:28 +00:00
|
|
|
|
float yscale = 1.f;
|
2015-03-15 11:10:22 +00:00
|
|
|
|
if (texh < 128)
|
|
|
|
|
{
|
|
|
|
|
// smaller sky textures must be tiled. We restrict it to 128 sky pixels, though
|
|
|
|
|
gl_RenderState.mModelMatrix.translate(0.f, -1250.f, 0.f);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.scale(1.f, 128 / 230.f, 1.f);
|
2015-03-15 11:10:22 +00:00
|
|
|
|
yscale = 128 / texh; // intentionally left as integer.
|
|
|
|
|
}
|
|
|
|
|
else if (texh < 200)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.translate(0.f, -1250.f, 0.f);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.scale(1.f, texh / 230.f, 1.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
else if (texh <= 240)
|
|
|
|
|
{
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.translate(0.f, (200 - texh + tex->tex->SkyOffset + skyoffset)*skyoffsetfactor, 0.f);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.scale(1.f, 1.f + ((texh - 200.f) / 200.f) * 1.17f, 1.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.translate(0.f, (-40 + tex->tex->SkyOffset + skyoffset)*skyoffsetfactor, 0.f);
|
|
|
|
|
gl_RenderState.mModelMatrix.scale(1.f, 1.2f * 1.17f, 1.f);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
yscale = 240.f / texh;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
2014-07-13 18:41:20 +00:00
|
|
|
|
gl_RenderState.EnableTextureMatrix(true);
|
|
|
|
|
gl_RenderState.mTextureMatrix.loadIdentity();
|
2016-08-14 18:11:46 +00:00
|
|
|
|
gl_RenderState.mTextureMatrix.scale(mirror ? -xscale : xscale, yscale, 1.f);
|
2014-07-13 18:41:20 +00:00
|
|
|
|
gl_RenderState.mTextureMatrix.translate(1.f, y_offset / texh, 1.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 23:24:28 +00:00
|
|
|
|
GLRenderer->mSkyVBO->RenderDome(tex, mode);
|
2014-07-13 18:41:20 +00:00
|
|
|
|
gl_RenderState.EnableTextureMatrix(false);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
gl_RenderState.EnableModelMatrix(false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2014-05-11 19:47:54 +00:00
|
|
|
|
static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool sky2)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
|
|
|
|
FSkyBox * sb = static_cast<FSkyBox*>(gltex->tex);
|
|
|
|
|
int faces;
|
|
|
|
|
FMaterial * tex;
|
|
|
|
|
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.EnableModelMatrix(true);
|
2014-07-17 08:04:20 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.loadIdentity();
|
2014-07-13 20:37:34 +00:00
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
|
if (!sky2)
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.rotate(-180.0f+x_offset, glset.skyrotatevector.X, glset.skyrotatevector.Z, glset.skyrotatevector.Y);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
else
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.mModelMatrix.rotate(-180.0f+x_offset, glset.skyrotatevector2.X, glset.skyrotatevector2.Z, glset.skyrotatevector2.Y);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
if (sb->faces[5])
|
|
|
|
|
{
|
|
|
|
|
faces=4;
|
|
|
|
|
|
|
|
|
|
// north
|
2014-08-22 21:50:38 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[0], false);
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(0), 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
// east
|
2014-08-22 21:50:38 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[1], false);
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(1), 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
// south
|
2014-08-22 21:50:38 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[2], false);
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(2), 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
// west
|
2014-08-22 21:50:38 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[3], false);
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(3), 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
faces=1;
|
2014-12-19 15:35:34 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[0], false);
|
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(-1), 10);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// top
|
2014-08-22 21:50:38 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[faces], false);
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(sb->fliptop? 6:5), 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
// bottom
|
2014-08-22 21:50:38 +00:00
|
|
|
|
tex = FMaterial::ValidateTexture(sb->faces[faces+1], false);
|
2014-09-09 10:00:42 +00:00
|
|
|
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.Apply();
|
2016-08-04 10:16:53 +00:00
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(4), 4);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_RenderState.EnableModelMatrix(false);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
void GLSkyPortal::DrawContents()
|
|
|
|
|
{
|
|
|
|
|
bool drawBoth = false;
|
|
|
|
|
|
|
|
|
|
// We have no use for Doom lighting special handling here, so disable it for this function.
|
|
|
|
|
int oldlightmode = glset.lightmode;
|
2014-12-25 21:45:40 +00:00
|
|
|
|
if (glset.lightmode == 8)
|
|
|
|
|
{
|
|
|
|
|
glset.lightmode = 2;
|
|
|
|
|
gl_RenderState.SetSoftLightLevel(-1);
|
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
|
2014-05-11 20:57:42 +00:00
|
|
|
|
gl_RenderState.ResetColor();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.EnableFog(false);
|
2014-07-14 19:14:43 +00:00
|
|
|
|
gl_RenderState.AlphaFunc(GL_GEQUAL, 0.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2014-11-27 11:26:52 +00:00
|
|
|
|
bool oldClamp = gl_RenderState.SetDepthClamp(true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
|
2016-08-14 18:11:46 +00:00
|
|
|
|
GLRenderer->SetupView(0, 0, 0, ViewAngle, !!(MirrorFlag & 1), !!(PlaneMirrorFlag & 1));
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
2016-08-04 10:16:53 +00:00
|
|
|
|
gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox)
|
|
|
|
|
{
|
2014-05-11 19:47:54 +00:00
|
|
|
|
RenderBox(origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (origin->texture[0]==origin->texture[1] && origin->doublesky) origin->doublesky=false;
|
|
|
|
|
|
|
|
|
|
if (origin->texture[0])
|
|
|
|
|
{
|
|
|
|
|
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
RenderDome(origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyVertexBuffer::SKYMODE_MAINLAYER);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.SetTextureMode(TM_MODULATE);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 18:45:56 +00:00
|
|
|
|
gl_RenderState.AlphaFunc(GL_GREATER, 0.f);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
if (origin->doublesky && origin->texture[1])
|
|
|
|
|
{
|
2014-06-13 23:24:28 +00:00
|
|
|
|
RenderDome(origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 08:38:30 +00:00
|
|
|
|
if (skyfog>0 && gl_fixedcolormap == CM_DEFAULT && (origin->fadecolor & 0xffffff) != 0)
|
2013-06-23 07:49:34 +00:00
|
|
|
|
{
|
2014-06-14 08:38:30 +00:00
|
|
|
|
PalEntry FadeColor = origin->fadecolor;
|
|
|
|
|
FadeColor.a = clamp<int>(skyfog, 0, 255);
|
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.EnableTexture(false);
|
2014-06-14 08:38:30 +00:00
|
|
|
|
gl_RenderState.SetObjectColor(FadeColor);
|
|
|
|
|
gl_RenderState.Apply();
|
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 12);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
gl_RenderState.EnableTexture(true);
|
2014-07-15 18:49:21 +00:00
|
|
|
|
gl_RenderState.SetObjectColor(0xffffffff);
|
2014-06-13 23:24:28 +00:00
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
2016-08-04 10:16:53 +00:00
|
|
|
|
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
2014-07-13 20:37:34 +00:00
|
|
|
|
gl_MatrixStack.Pop(gl_RenderState.mViewMatrix);
|
|
|
|
|
gl_RenderState.ApplyMatrices();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
glset.lightmode = oldlightmode;
|
2014-11-27 11:26:52 +00:00
|
|
|
|
gl_RenderState.SetDepthClamp(oldClamp);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
}
|
|
|
|
|
|