mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-21 11:01:36 +00:00
- rewrote sky dome rendering to use a static vertex buffer if not on OpenGL 2.x.
This commit is contained in:
parent
2ad47935ef
commit
8d9a90cd22
8 changed files with 244 additions and 153 deletions
|
@ -325,6 +325,7 @@ void FFlatVertexBuffer::BindVBO()
|
||||||
glTexCoordPointer(2,GL_FLOAT, sizeof(FFlatVertex), &VTO->u);
|
glTexCoordPointer(2,GL_FLOAT, sizeof(FFlatVertex), &VTO->u);
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,4 +95,47 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct FSkyVertex
|
||||||
|
{
|
||||||
|
float x, y, z, u, v;
|
||||||
|
PalEntry color;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FSkyVertexBuffer : public FVertexBuffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const int SKYHEMI_UPPER = 1;
|
||||||
|
static const int SKYHEMI_LOWER = 2;
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SKYMODE_MAINLAYER = 0,
|
||||||
|
SKYMODE_SECONDLAYER = 1,
|
||||||
|
SKYMODE_FOGLAYER = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
TArray<FSkyVertex> mVertices;
|
||||||
|
TArray<unsigned int> mPrimStart;
|
||||||
|
|
||||||
|
int mRows, mColumns;
|
||||||
|
|
||||||
|
void SkyVertex(int r, int c, bool yflip);
|
||||||
|
void CreateSkyHemisphere(int hemi);
|
||||||
|
void CreateDome();
|
||||||
|
void RenderRow(int prim, int row, bool color);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FSkyVertexBuffer();
|
||||||
|
virtual ~FSkyVertexBuffer();
|
||||||
|
virtual void BindVBO();
|
||||||
|
void RenderDome(FMaterial *tex, int mode);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#define VSO ((FSkyVertex*)NULL)
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -284,7 +284,7 @@ void FVoxelVertexBuffer::BindVBO()
|
||||||
glTexCoordPointer(2,GL_FLOAT, sizeof(FVoxelVertex), &VVO->u);
|
glTexCoordPointer(2,GL_FLOAT, sizeof(FVoxelVertex), &VVO->u);
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glEnableClientState(GL_INDEX_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@ FGLRenderer::FGLRenderer(OpenGLFrameBuffer *fb)
|
||||||
mViewVector = FVector2(0,0);
|
mViewVector = FVector2(0,0);
|
||||||
mCameraPos = FVector3(0,0,0);
|
mCameraPos = FVector3(0,0,0);
|
||||||
mVBO = NULL;
|
mVBO = NULL;
|
||||||
|
mSkyVBO = NULL;
|
||||||
gl_spriteindex = 0;
|
gl_spriteindex = 0;
|
||||||
mShaderManager = NULL;
|
mShaderManager = NULL;
|
||||||
glpart2 = glpart = gllight = mirrortexture = NULL;
|
glpart2 = glpart = gllight = mirrortexture = NULL;
|
||||||
|
@ -107,6 +108,7 @@ void FGLRenderer::Initialize()
|
||||||
gllight = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/gllight.png"), FTexture::TEX_MiscPatch);
|
gllight = FTexture::CreateTexture(Wads.GetNumForFullName("glstuff/gllight.png"), FTexture::TEX_MiscPatch);
|
||||||
|
|
||||||
mVBO = new FFlatVertexBuffer;
|
mVBO = new FFlatVertexBuffer;
|
||||||
|
mSkyVBO = new FSkyVertexBuffer;
|
||||||
gl_RenderState.SetVertexBuffer(mVBO);
|
gl_RenderState.SetVertexBuffer(mVBO);
|
||||||
mFBID = 0;
|
mFBID = 0;
|
||||||
SetupLevel();
|
SetupLevel();
|
||||||
|
@ -122,6 +124,7 @@ FGLRenderer::~FGLRenderer()
|
||||||
//if (mThreadManager != NULL) delete mThreadManager;
|
//if (mThreadManager != NULL) delete mThreadManager;
|
||||||
if (mShaderManager != NULL) delete mShaderManager;
|
if (mShaderManager != NULL) delete mShaderManager;
|
||||||
if (mVBO != NULL) delete mVBO;
|
if (mVBO != NULL) delete mVBO;
|
||||||
|
if (mSkyVBO != NULL) delete mSkyVBO;
|
||||||
if (glpart2) delete glpart2;
|
if (glpart2) delete glpart2;
|
||||||
if (glpart) delete glpart;
|
if (glpart) delete glpart;
|
||||||
if (mirrortexture) delete mirrortexture;
|
if (mirrortexture) delete mirrortexture;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
struct particle_t;
|
struct particle_t;
|
||||||
class FCanvasTexture;
|
class FCanvasTexture;
|
||||||
class FFlatVertexBuffer;
|
class FFlatVertexBuffer;
|
||||||
|
class FSkyVertexBuffer;
|
||||||
class OpenGLFrameBuffer;
|
class OpenGLFrameBuffer;
|
||||||
struct FDrawInfo;
|
struct FDrawInfo;
|
||||||
struct pspdef_t;
|
struct pspdef_t;
|
||||||
|
@ -69,6 +70,7 @@ public:
|
||||||
FVector3 mCameraPos;
|
FVector3 mCameraPos;
|
||||||
|
|
||||||
FFlatVertexBuffer *mVBO;
|
FFlatVertexBuffer *mVBO;
|
||||||
|
FSkyVertexBuffer *mSkyVBO;
|
||||||
|
|
||||||
|
|
||||||
FGLRenderer(OpenGLFrameBuffer *fb);
|
FGLRenderer(OpenGLFrameBuffer *fb);
|
||||||
|
|
|
@ -100,6 +100,12 @@ public:
|
||||||
mVertexBuffer = vb;
|
mVertexBuffer = vb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResetVertexBuffer()
|
||||||
|
{
|
||||||
|
// forces rebinding with the next 'apply' call.
|
||||||
|
mCurrentVertexBuffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void SetColor(float r, float g, float b, float a = 1.f, int desat = 0)
|
void SetColor(float r, float g, float b, float a = 1.f, int desat = 0)
|
||||||
{
|
{
|
||||||
mColor.Set(r, g, b, a);
|
mColor.Set(r, g, b, a);
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
|
|
||||||
#include "gl/system/gl_interface.h"
|
#include "gl/system/gl_interface.h"
|
||||||
#include "gl/data/gl_data.h"
|
#include "gl/data/gl_data.h"
|
||||||
|
#include "gl/data/gl_vertexbuffer.h"
|
||||||
#include "gl/renderer/gl_lightdata.h"
|
#include "gl/renderer/gl_lightdata.h"
|
||||||
#include "gl/renderer/gl_renderstate.h"
|
#include "gl/renderer/gl_renderstate.h"
|
||||||
#include "gl/scene/gl_drawinfo.h"
|
#include "gl/scene/gl_drawinfo.h"
|
||||||
|
@ -63,171 +64,208 @@
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
CVAR (Int, gl_sky_detail, 16, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
CVAR(Float, skyoffset, 0, 0) // for testing
|
||||||
EXTERN_CVAR (Bool, r_stretchsky)
|
|
||||||
|
|
||||||
extern int skyfog;
|
extern int skyfog;
|
||||||
|
|
||||||
// The texture offset to be applied to the texture coordinates in SkyVertex().
|
|
||||||
|
|
||||||
static angle_t maxSideAngle = ANGLE_180 / 3;
|
|
||||||
static int rows, columns;
|
|
||||||
static fixed_t scale = 10000 << FRACBITS;
|
|
||||||
static bool yflip;
|
|
||||||
static int texw;
|
|
||||||
static float yAdd;
|
|
||||||
static bool foglayer;
|
|
||||||
static bool secondlayer;
|
|
||||||
static bool skymirror;
|
|
||||||
|
|
||||||
#define SKYHEMI_UPPER 0x1
|
|
||||||
#define SKYHEMI_LOWER 0x2
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void SkyVertex(int r, int c)
|
FSkyVertexBuffer::FSkyVertexBuffer()
|
||||||
{
|
{
|
||||||
angle_t topAngle= (angle_t)(c / (float)columns * ANGLE_MAX);
|
CreateDome();
|
||||||
angle_t sideAngle = maxSideAngle * (rows - r) / rows;
|
}
|
||||||
|
|
||||||
|
FSkyVertexBuffer::~FSkyVertexBuffer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSkyVertexBuffer::BindVBO()
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
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);
|
||||||
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void FSkyVertexBuffer::SkyVertex(int r, int c, bool yflip)
|
||||||
|
{
|
||||||
|
static const angle_t maxSideAngle = ANGLE_180 / 3;
|
||||||
|
static const fixed_t scale = 10000 << FRACBITS;
|
||||||
|
|
||||||
|
angle_t topAngle= (angle_t)(c / (float)mColumns * ANGLE_MAX);
|
||||||
|
angle_t sideAngle = maxSideAngle * (mRows - r) / mRows;
|
||||||
fixed_t height = finesine[sideAngle>>ANGLETOFINESHIFT];
|
fixed_t height = finesine[sideAngle>>ANGLETOFINESHIFT];
|
||||||
fixed_t realRadius = FixedMul(scale, finecosine[sideAngle>>ANGLETOFINESHIFT]);
|
fixed_t realRadius = FixedMul(scale, finecosine[sideAngle>>ANGLETOFINESHIFT]);
|
||||||
fixed_t x = FixedMul(realRadius, finecosine[topAngle>>ANGLETOFINESHIFT]);
|
fixed_t x = FixedMul(realRadius, finecosine[topAngle>>ANGLETOFINESHIFT]);
|
||||||
fixed_t y = (!yflip) ? FixedMul(scale, height) : FixedMul(scale, height) * -1;
|
fixed_t y = (!yflip) ? FixedMul(scale, height) : FixedMul(scale, height) * -1;
|
||||||
fixed_t z = FixedMul(realRadius, finesine[topAngle>>ANGLETOFINESHIFT]);
|
fixed_t z = FixedMul(realRadius, finesine[topAngle>>ANGLETOFINESHIFT]);
|
||||||
float fx, fy, fz;
|
|
||||||
float color = r * 1.f / rows;
|
FSkyVertex vert;
|
||||||
float u, v;
|
|
||||||
float timesRepeat;
|
|
||||||
|
|
||||||
timesRepeat = (short)(4 * (256.f / texw));
|
vert.color = r == 0 ? 0xffffff : 0xffffffff;
|
||||||
if (timesRepeat == 0.f) timesRepeat = 1.f;
|
|
||||||
|
// And the texture coordinates.
|
||||||
if (!foglayer)
|
if(!yflip) // Flipped Y is for the lower hemisphere.
|
||||||
{
|
{
|
||||||
// this must not use the renderstate because it's inside a primitive.
|
vert.u = (-c / (float)mColumns) ;
|
||||||
glColor4f(1.f, 1.f, 1.f, r==0? 0.0f : 1.0f);
|
vert.v = (r / (float)mRows);
|
||||||
|
|
||||||
// And the texture coordinates.
|
|
||||||
if(!yflip) // Flipped Y is for the lower hemisphere.
|
|
||||||
{
|
|
||||||
u = (-timesRepeat * c / (float)columns) ;
|
|
||||||
v = (r / (float)rows) + yAdd;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
u = (-timesRepeat * c / (float)columns) ;
|
|
||||||
v = 1.0f + ((rows-r)/(float)rows) + yAdd;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
glTexCoord2f(skymirror? -u:u, v);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vert.u = (-c / (float)mColumns);
|
||||||
|
vert.v = 1.0f + ((mRows - r) / (float)mRows);
|
||||||
|
}
|
||||||
|
|
||||||
if (r != 4) y+=FRACUNIT*300;
|
if (r != 4) y+=FRACUNIT*300;
|
||||||
// And finally the vertex.
|
// And finally the vertex.
|
||||||
fx =-FIXED2FLOAT(x); // Doom mirrors the sky vertically!
|
vert.x =-FIXED2FLOAT(x); // Doom mirrors the sky vertically!
|
||||||
fy = FIXED2FLOAT(y);
|
vert.y = FIXED2FLOAT(y) - 1.f;
|
||||||
fz = FIXED2FLOAT(z);
|
vert.z = FIXED2FLOAT(z);
|
||||||
glVertex3f(fx, fy - 1.f, fz);
|
|
||||||
|
mVertices.Push(vert);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Hemi is Upper or Lower. Zero is not acceptable.
|
//
|
||||||
// The current texture is used. SKYHEMI_NO_TOPCAP can be used.
|
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void RenderSkyHemisphere(int hemi, bool mirror)
|
void FSkyVertexBuffer::CreateSkyHemisphere(int hemi)
|
||||||
{
|
{
|
||||||
int r, c;
|
int r, c;
|
||||||
|
bool yflip = !!(hemi & SKYHEMI_LOWER);
|
||||||
if (hemi & SKYHEMI_LOWER)
|
|
||||||
|
mPrimStart.Push(mVertices.Size());
|
||||||
|
|
||||||
|
for (c = 0; c < mColumns; c++)
|
||||||
{
|
{
|
||||||
yflip = true;
|
SkyVertex(1, c, yflip);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
yflip = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
skymirror = mirror;
|
// The total number of triangles per hemisphere can be calculated
|
||||||
|
// as follows: rows * columns * 2 + 2 (for the top cap).
|
||||||
// The top row (row 0) is the one that's faded out.
|
for (r = 0; r < mRows; r++)
|
||||||
// There must be at least 4 columns. The preferable number
|
|
||||||
// is 4n, where n is 1, 2, 3... There should be at least
|
|
||||||
// two rows because the first one is always faded.
|
|
||||||
rows = 4;
|
|
||||||
|
|
||||||
// Draw the cap as one solid color polygon
|
|
||||||
if (!foglayer)
|
|
||||||
{
|
{
|
||||||
columns = 4 * (gl_sky_detail > 0 ? gl_sky_detail : 1);
|
mPrimStart.Push(mVertices.Size());
|
||||||
foglayer=true;
|
for (c = 0; c <= mColumns; c++)
|
||||||
gl_RenderState.EnableTexture(false);
|
|
||||||
gl_RenderState.Apply();
|
|
||||||
|
|
||||||
|
|
||||||
if (!secondlayer)
|
|
||||||
{
|
{
|
||||||
glBegin(GL_TRIANGLE_FAN);
|
SkyVertex(r + yflip, c, yflip);
|
||||||
for(c = 0; c < columns; c++)
|
SkyVertex(r + 1 - yflip, c, yflip);
|
||||||
{
|
|
||||||
SkyVertex(1, c);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
gl_RenderState.SetObjectColor(0xffffffff); // unset the cap's color
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gl_RenderState.EnableTexture(true);
|
//-----------------------------------------------------------------------------
|
||||||
foglayer=false;
|
//
|
||||||
gl_RenderState.Apply();
|
//
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void FSkyVertexBuffer::CreateDome()
|
||||||
|
{
|
||||||
|
if (gl.version < 3.0f)
|
||||||
|
{
|
||||||
|
mColumns = 64;
|
||||||
|
mRows = 4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gl_RenderState.Apply();
|
mColumns = 128;
|
||||||
columns=4; // no need to do more!
|
mRows = 4;
|
||||||
glBegin(GL_TRIANGLE_FAN);
|
}
|
||||||
for(c = 0; c < columns; c++)
|
CreateSkyHemisphere(SKYHEMI_UPPER);
|
||||||
|
CreateSkyHemisphere(SKYHEMI_LOWER);
|
||||||
|
mPrimStart.Push(mVertices.Size());
|
||||||
|
if (gl.version >= 3.f)
|
||||||
|
{
|
||||||
|
// we won't bother with a real buffer for GL 2.x because the lack of shaders and therefore the objectColor uniform will require different handling.
|
||||||
|
// It'd also prevent changing to core features only.
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void FSkyVertexBuffer::RenderRow(int prim, int row, bool color)
|
||||||
|
{
|
||||||
|
if (gl.version < 3.f)
|
||||||
|
{
|
||||||
|
glBegin(prim);
|
||||||
|
for (unsigned int i = mPrimStart[row]; i < mPrimStart[row + 1]; i++)
|
||||||
{
|
{
|
||||||
SkyVertex(0, c);
|
if (color) glColor4ubv((GLubyte*)&mVertices[i].color);
|
||||||
|
glTexCoord2fv(&mVertices[i].u);
|
||||||
|
glVertex3fv(&mVertices[i].x);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
// The total number of triangles per hemisphere can be calculated
|
|
||||||
// as follows: rows * columns * 2 + 2 (for the top cap).
|
|
||||||
for(r = 0; r < rows; r++)
|
|
||||||
{
|
{
|
||||||
if (yflip)
|
glDrawArrays(prim, mPrimStart[row], mPrimStart[row + 1] - mPrimStart[row]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void FSkyVertexBuffer::RenderDome(FMaterial *tex, int mode)
|
||||||
|
{
|
||||||
|
int rc = mRows + 1;
|
||||||
|
|
||||||
|
if (mode != SKYMODE_SECONDLAYER)
|
||||||
|
{
|
||||||
|
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
||||||
{
|
{
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
PalEntry pe = tex->tex->GetSkyCapColor(false);
|
||||||
SkyVertex(r + 1, 0);
|
gl_RenderState.SetObjectColor(pe);
|
||||||
SkyVertex(r, 0);
|
gl_RenderState.EnableTexture(false);
|
||||||
for(c = 1; c <= columns; c++)
|
|
||||||
{
|
|
||||||
SkyVertex(r + 1, c);
|
|
||||||
SkyVertex(r, c);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
else
|
gl_RenderState.Apply();
|
||||||
|
RenderRow(GL_TRIANGLE_FAN, 0, false);
|
||||||
|
|
||||||
|
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
||||||
{
|
{
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
PalEntry pe = tex->tex->GetSkyCapColor(true);
|
||||||
SkyVertex(r, 0);
|
gl_RenderState.SetObjectColor(pe);
|
||||||
SkyVertex(r + 1, 0);
|
|
||||||
for(c = 1; c <= columns; c++)
|
|
||||||
{
|
|
||||||
SkyVertex(r, c);
|
|
||||||
SkyVertex(r + 1, c);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
gl_RenderState.Apply();
|
||||||
|
RenderRow(GL_TRIANGLE_FAN, rc, false);
|
||||||
|
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
||||||
|
{
|
||||||
|
gl_RenderState.EnableTexture(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gl_RenderState.SetObjectColor(0xffffffff);
|
||||||
|
gl_RenderState.Apply();
|
||||||
|
for (int i = 1; i <= mRows; i++)
|
||||||
|
{
|
||||||
|
RenderRow(GL_TRIANGLE_STRIP, i, true);
|
||||||
|
RenderRow(GL_TRIANGLE_STRIP, rc + i, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,12 +275,11 @@ static void RenderSkyHemisphere(int hemi, bool mirror)
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
CVAR(Float, skyoffset, 0, 0) // for testing
|
|
||||||
|
|
||||||
static void RenderDome(FTextureID texno, FMaterial * tex, float x_offset, float y_offset, bool mirror)
|
void RenderDome(FMaterial * tex, float x_offset, float y_offset, bool mirror, int mode)
|
||||||
{
|
{
|
||||||
int texh = 0;
|
int texh = 0;
|
||||||
bool texscale = false;
|
int texw = 0;
|
||||||
|
|
||||||
// 57 world units roughly represent one sky texel for the glTranslate call.
|
// 57 world units roughly represent one sky texel for the glTranslate call.
|
||||||
const float skyoffsetfactor = 57;
|
const float skyoffsetfactor = 57;
|
||||||
|
@ -255,8 +292,9 @@ static void RenderDome(FTextureID texno, FMaterial * tex, float x_offset, float
|
||||||
texh = tex->TextureHeight(GLUSE_TEXTURE);
|
texh = tex->TextureHeight(GLUSE_TEXTURE);
|
||||||
|
|
||||||
glRotatef(-180.0f+x_offset, 0.f, 1.f, 0.f);
|
glRotatef(-180.0f+x_offset, 0.f, 1.f, 0.f);
|
||||||
yAdd = y_offset/texh;
|
|
||||||
|
|
||||||
|
float xscale = 1024.f / float(texw);
|
||||||
|
float yscale = 1.f;
|
||||||
if (texh < 200)
|
if (texh < 200)
|
||||||
{
|
{
|
||||||
glTranslatef(0.f, -1250.f, 0.f);
|
glTranslatef(0.f, -1250.f, 0.f);
|
||||||
|
@ -271,37 +309,25 @@ static void RenderDome(FTextureID texno, FMaterial * tex, float x_offset, float
|
||||||
{
|
{
|
||||||
glTranslatef(0.f, (-40 + tex->tex->SkyOffset + skyoffset)*skyoffsetfactor, 0.f);
|
glTranslatef(0.f, (-40 + tex->tex->SkyOffset + skyoffset)*skyoffsetfactor, 0.f);
|
||||||
glScalef(1.f, 1.2f * 1.17f, 1.f);
|
glScalef(1.f, 1.2f * 1.17f, 1.f);
|
||||||
glMatrixMode(GL_TEXTURE);
|
yscale = 240.f / texh;
|
||||||
glPushMatrix();
|
|
||||||
glLoadIdentity();
|
|
||||||
glScalef(1.f, 240.f / texh, 1.f);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
texscale = true;
|
|
||||||
}
|
}
|
||||||
|
glMatrixMode(GL_TEXTURE);
|
||||||
|
glPushMatrix();
|
||||||
|
glLoadIdentity();
|
||||||
|
glScalef(mirror? -xscale : xscale, yscale, 1.f);
|
||||||
|
glTranslatef(1.f, y_offset / texh, 1.f);
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tex && !secondlayer)
|
GLRenderer->mSkyVBO->RenderDome(tex, mode);
|
||||||
{
|
|
||||||
PalEntry pe = tex->tex->GetSkyCapColor(false);
|
|
||||||
gl_RenderState.SetObjectColor(pe);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderSkyHemisphere(SKYHEMI_UPPER, mirror);
|
if (tex)
|
||||||
|
|
||||||
if (tex && !secondlayer)
|
|
||||||
{
|
|
||||||
PalEntry pe = tex->tex->GetSkyCapColor(true);
|
|
||||||
gl_RenderState.SetObjectColor(pe);
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderSkyHemisphere(SKYHEMI_LOWER, mirror);
|
|
||||||
if (texscale)
|
|
||||||
{
|
{
|
||||||
glMatrixMode(GL_TEXTURE);
|
glMatrixMode(GL_TEXTURE);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
if (tex) glPopMatrix();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,12 +553,16 @@ void GLSkyPortal::DrawContents()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (gl.version >= 3.f)
|
||||||
|
{
|
||||||
|
gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO);
|
||||||
|
}
|
||||||
if (origin->texture[0]==origin->texture[1] && origin->doublesky) origin->doublesky=false;
|
if (origin->texture[0]==origin->texture[1] && origin->doublesky) origin->doublesky=false;
|
||||||
|
|
||||||
if (origin->texture[0])
|
if (origin->texture[0])
|
||||||
{
|
{
|
||||||
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
gl_RenderState.SetTextureMode(TM_OPAQUE);
|
||||||
RenderDome(origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored);
|
RenderDome(origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyVertexBuffer::SKYMODE_MAINLAYER);
|
||||||
gl_RenderState.SetTextureMode(TM_MODULATE);
|
gl_RenderState.SetTextureMode(TM_MODULATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,19 +571,22 @@ void GLSkyPortal::DrawContents()
|
||||||
|
|
||||||
if (origin->doublesky && origin->texture[1])
|
if (origin->doublesky && origin->texture[1])
|
||||||
{
|
{
|
||||||
secondlayer=true;
|
RenderDome(origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER);
|
||||||
RenderDome(FNullTextureID(), origin->texture[1], origin->x_offset[1], origin->y_offset, false);
|
|
||||||
secondlayer=false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skyfog>0 && (FadeColor.r ||FadeColor.g || FadeColor.b))
|
if (skyfog>0 && (FadeColor.r ||FadeColor.g || FadeColor.b))
|
||||||
{
|
{
|
||||||
gl_RenderState.EnableTexture(false);
|
gl_RenderState.EnableTexture(false);
|
||||||
foglayer=true;
|
|
||||||
gl_RenderState.SetColorAlpha(FadeColor, skyfog / 255.0f);
|
gl_RenderState.SetColorAlpha(FadeColor, skyfog / 255.0f);
|
||||||
RenderDome(FNullTextureID(), NULL, 0, 0, false);
|
// for the fog layer we must temporarily disable the color part of the vertex buffer.
|
||||||
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
RenderDome(NULL, 0, 0, false, FSkyVertexBuffer::SKYMODE_FOGLAYER);
|
||||||
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
gl_RenderState.EnableTexture(true);
|
gl_RenderState.EnableTexture(true);
|
||||||
foglayer=false;
|
}
|
||||||
|
if (gl.version >= 3.f)
|
||||||
|
{
|
||||||
|
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
|
@ -122,7 +122,10 @@ void gl_LoadExtensions()
|
||||||
InitContext();
|
InitContext();
|
||||||
CollectExtensions();
|
CollectExtensions();
|
||||||
|
|
||||||
const char *version = (const char*)glGetString(GL_VERSION);
|
const char *version = Args->CheckValue("-glversion");
|
||||||
|
if (version == NULL) version = (const char*)glGetString(GL_VERSION);
|
||||||
|
else Printf("Emulating OpenGL v %s\n", version);
|
||||||
|
|
||||||
|
|
||||||
// Don't even start if it's lower than 1.3
|
// Don't even start if it's lower than 1.3
|
||||||
if (strcmp(version, "2.0") < 0)
|
if (strcmp(version, "2.0") < 0)
|
||||||
|
@ -139,9 +142,9 @@ void gl_LoadExtensions()
|
||||||
if (CheckExtension("GL_EXT_texture_compression_s3tc")) gl.flags|=RFL_TEXTURE_COMPRESSION_S3TC;
|
if (CheckExtension("GL_EXT_texture_compression_s3tc")) gl.flags|=RFL_TEXTURE_COMPRESSION_S3TC;
|
||||||
if (CheckExtension("GL_ARB_buffer_storage")) gl.flags |= RFL_BUFFER_STORAGE;
|
if (CheckExtension("GL_ARB_buffer_storage")) gl.flags |= RFL_BUFFER_STORAGE;
|
||||||
|
|
||||||
gl.version = strtod((char*)glGetString(GL_VERSION), NULL);
|
gl.version = strtod(version, NULL);
|
||||||
gl.glslversion = strtod((char*)glGetString(GL_SHADING_LANGUAGE_VERSION), NULL);
|
gl.glslversion = strtod((char*)glGetString(GL_SHADING_LANGUAGE_VERSION), NULL);
|
||||||
if (Args->CheckParm("-noshader")) gl.glslversion = 0.0f;
|
if (gl.version < 3.f) gl.glslversion = 0.f;
|
||||||
|
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&gl.max_texturesize);
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&gl.max_texturesize);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
Loading…
Reference in a new issue