mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-01 16:41:22 +00:00
- use buffer for rendering the sky on all GL versions since the differences for making GL2.0 work are rather small.
This commit is contained in:
parent
4ad1e0b4cb
commit
5e22c82e79
2 changed files with 61 additions and 73 deletions
|
@ -100,6 +100,17 @@ struct FSkyVertex
|
||||||
{
|
{
|
||||||
float x, y, z, u, v;
|
float x, y, z, u, v;
|
||||||
PalEntry color;
|
PalEntry color;
|
||||||
|
|
||||||
|
void Set(float xx, float zz, float yy, float uu=0, float vv=0, PalEntry col=0xffffffff)
|
||||||
|
{
|
||||||
|
x = xx;
|
||||||
|
z = zz;
|
||||||
|
y = yy;
|
||||||
|
u = uu;
|
||||||
|
v = vv;
|
||||||
|
color = col;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FSkyVertexBuffer : public FVertexBuffer
|
class FSkyVertexBuffer : public FVertexBuffer
|
||||||
|
|
|
@ -180,27 +180,33 @@ void FSkyVertexBuffer::CreateSkyHemisphere(int hemi)
|
||||||
|
|
||||||
void FSkyVertexBuffer::CreateDome()
|
void FSkyVertexBuffer::CreateDome()
|
||||||
{
|
{
|
||||||
if (gl.version < 3.0f)
|
// the first thing we put into the buffer is the fog layer object which is just 4 triangles around the viewpoint.
|
||||||
{
|
|
||||||
mColumns = 64;
|
mVertices.Reserve(12);
|
||||||
mRows = 4;
|
mVertices[0].Set( 1.0f, 1.0f, -1.0f);
|
||||||
}
|
mVertices[1].Set( 1.0f, -1.0f, -1.0f);
|
||||||
else
|
mVertices[2].Set(-1.0f, 0.0f, -1.0f);
|
||||||
{
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
mVertices[6].Set(-1.0f, 0.0f, -1.0f);
|
||||||
|
mVertices[7].Set( 1.0f, 1.0f, -1.0f);
|
||||||
|
mVertices[8].Set( 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
mVertices[9].Set(1.0f, -1.0f, -1.0f);
|
||||||
|
mVertices[10].Set(-1.0f, 0.0f, -1.0f);
|
||||||
|
mVertices[11].Set( 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
mColumns = 128;
|
mColumns = 128;
|
||||||
mRows = 4;
|
mRows = 4;
|
||||||
}
|
|
||||||
CreateSkyHemisphere(SKYHEMI_UPPER);
|
CreateSkyHemisphere(SKYHEMI_UPPER);
|
||||||
CreateSkyHemisphere(SKYHEMI_LOWER);
|
CreateSkyHemisphere(SKYHEMI_LOWER);
|
||||||
mPrimStart.Push(mVertices.Size());
|
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);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_id);
|
||||||
glBufferData(GL_ARRAY_BUFFER, mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, mVertices.Size() * sizeof(FSkyVertex), &mVertices[0], GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
@ -208,24 +214,10 @@ void FSkyVertexBuffer::CreateDome()
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void FSkyVertexBuffer::RenderRow(int prim, int row, bool color)
|
inline void FSkyVertexBuffer::RenderRow(int prim, int row)
|
||||||
{
|
|
||||||
if (gl.version < 3.f)
|
|
||||||
{
|
|
||||||
glBegin(prim);
|
|
||||||
for (unsigned int i = mPrimStart[row]; i < mPrimStart[row + 1]; i++)
|
|
||||||
{
|
|
||||||
if (color) glColor4ubv((GLubyte*)&mVertices[i].color);
|
|
||||||
glTexCoord2fv(&mVertices[i].u);
|
|
||||||
glVertex3fv(&mVertices[i].x);
|
|
||||||
}
|
|
||||||
glEnd();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
glDrawArrays(prim, mPrimStart[row], mPrimStart[row + 1] - mPrimStart[row]);
|
glDrawArrays(prim, mPrimStart[row], mPrimStart[row + 1] - mPrimStart[row]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
@ -237,35 +229,29 @@ void FSkyVertexBuffer::RenderDome(FMaterial *tex, int mode)
|
||||||
{
|
{
|
||||||
int rc = mRows + 1;
|
int rc = mRows + 1;
|
||||||
|
|
||||||
if (mode != SKYMODE_SECONDLAYER)
|
|
||||||
{
|
|
||||||
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
||||||
{
|
{
|
||||||
|
// if there's no shader we cannot use the default color from the buffer because the object color is part of the preset vertex attribute.
|
||||||
|
if (!gl.hasGLSL()) glDisableClientState(GL_COLOR_ARRAY);
|
||||||
PalEntry pe = tex->tex->GetSkyCapColor(false);
|
PalEntry pe = tex->tex->GetSkyCapColor(false);
|
||||||
gl_RenderState.SetObjectColor(pe);
|
gl_RenderState.SetObjectColor(pe);
|
||||||
gl_RenderState.EnableTexture(false);
|
gl_RenderState.EnableTexture(false);
|
||||||
}
|
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
RenderRow(GL_TRIANGLE_FAN, 0, false);
|
RenderRow(GL_TRIANGLE_FAN, 0);
|
||||||
|
|
||||||
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
|
||||||
{
|
|
||||||
PalEntry pe = tex->tex->GetSkyCapColor(true);
|
PalEntry pe = tex->tex->GetSkyCapColor(true);
|
||||||
gl_RenderState.SetObjectColor(pe);
|
gl_RenderState.SetObjectColor(pe);
|
||||||
}
|
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
RenderRow(GL_TRIANGLE_FAN, rc, false);
|
RenderRow(GL_TRIANGLE_FAN, rc);
|
||||||
if (mode == SKYMODE_MAINLAYER && tex != NULL)
|
|
||||||
{
|
|
||||||
gl_RenderState.EnableTexture(true);
|
gl_RenderState.EnableTexture(true);
|
||||||
}
|
if (!gl.hasGLSL()) glEnableClientState(GL_COLOR_ARRAY);
|
||||||
}
|
}
|
||||||
gl_RenderState.SetObjectColor(0xffffffff);
|
gl_RenderState.SetObjectColor(0xffffffff);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
for (int i = 1; i <= mRows; i++)
|
for (int i = 1; i <= mRows; i++)
|
||||||
{
|
{
|
||||||
RenderRow(GL_TRIANGLE_STRIP, i, true);
|
RenderRow(GL_TRIANGLE_STRIP, i);
|
||||||
RenderRow(GL_TRIANGLE_STRIP, rc + i, true);
|
RenderRow(GL_TRIANGLE_STRIP, rc + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,18 +511,12 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
|
||||||
void GLSkyPortal::DrawContents()
|
void GLSkyPortal::DrawContents()
|
||||||
{
|
{
|
||||||
bool drawBoth = false;
|
bool drawBoth = false;
|
||||||
PalEntry FadeColor(0,0,0,0);
|
|
||||||
|
|
||||||
// We have no use for Doom lighting special handling here, so disable it for this function.
|
// We have no use for Doom lighting special handling here, so disable it for this function.
|
||||||
int oldlightmode = glset.lightmode;
|
int oldlightmode = glset.lightmode;
|
||||||
if (glset.lightmode == 8) glset.lightmode = 2;
|
if (glset.lightmode == 8) glset.lightmode = 2;
|
||||||
|
|
||||||
|
|
||||||
if (!gl_fixedcolormap)
|
|
||||||
{
|
|
||||||
FadeColor = origin->fadecolor;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl_RenderState.ResetColor();
|
gl_RenderState.ResetColor();
|
||||||
gl_RenderState.EnableFog(false);
|
gl_RenderState.EnableFog(false);
|
||||||
gl_RenderState.EnableAlphaTest(false);
|
gl_RenderState.EnableAlphaTest(false);
|
||||||
|
@ -552,11 +532,8 @@ void GLSkyPortal::DrawContents()
|
||||||
gl_RenderState.EnableAlphaTest(true);
|
gl_RenderState.EnableAlphaTest(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (gl.version >= 3.f)
|
|
||||||
{
|
{
|
||||||
gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO);
|
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])
|
||||||
|
@ -574,21 +551,21 @@ void GLSkyPortal::DrawContents()
|
||||||
RenderDome(origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER);
|
RenderDome(origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skyfog>0 && (FadeColor.r ||FadeColor.g || FadeColor.b))
|
if (skyfog>0 && gl_fixedcolormap == CM_DEFAULT && (origin->fadecolor & 0xffffff) != 0)
|
||||||
{
|
{
|
||||||
|
PalEntry FadeColor = origin->fadecolor;
|
||||||
|
FadeColor.a = clamp<int>(skyfog, 0, 255);
|
||||||
|
|
||||||
gl_RenderState.EnableTexture(false);
|
gl_RenderState.EnableTexture(false);
|
||||||
gl_RenderState.SetColorAlpha(FadeColor, skyfog / 255.0f);
|
gl_RenderState.SetObjectColor(FadeColor);
|
||||||
// for the fog layer we must temporarily disable the color part of the vertex buffer.
|
gl_RenderState.Apply();
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
if (!gl.hasGLSL()) glDisableClientState(GL_COLOR_ARRAY);
|
||||||
RenderDome(NULL, 0, 0, false, FSkyVertexBuffer::SKYMODE_FOGLAYER);
|
glDrawArrays(GL_TRIANGLES, 0, 12);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
if (!gl.hasGLSL()) glEnableClientState(GL_COLOR_ARRAY);
|
||||||
gl_RenderState.EnableTexture(true);
|
gl_RenderState.EnableTexture(true);
|
||||||
}
|
}
|
||||||
if (gl.version >= 3.f)
|
|
||||||
{
|
|
||||||
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glset.lightmode = oldlightmode;
|
glset.lightmode = oldlightmode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue