mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 15:22:15 +00:00
- changed rendering of sky cubemaps to use precalculated vertex data from the SkyVertexBuffer.
This commit is contained in:
parent
d8ab0b40dc
commit
7ba6269450
3 changed files with 86 additions and 93 deletions
|
@ -322,7 +322,7 @@ static void PrepareTransparentDoors(sector_t * sector)
|
||||||
sector_t * nextsec=NULL;
|
sector_t * nextsec=NULL;
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if (sector-sectors==2)
|
if (sector-sectors==34)
|
||||||
{
|
{
|
||||||
int a = 0;
|
int a = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,6 +167,10 @@ private:
|
||||||
|
|
||||||
int mRows, mColumns;
|
int mRows, mColumns;
|
||||||
|
|
||||||
|
// indices for sky cubemap faces
|
||||||
|
int mFaceStart[7];
|
||||||
|
int mSideStart;
|
||||||
|
|
||||||
void SkyVertex(int r, int c, bool yflip);
|
void SkyVertex(int r, int c, bool yflip);
|
||||||
void CreateSkyHemisphere(int hemi);
|
void CreateSkyHemisphere(int hemi);
|
||||||
void CreateDome();
|
void CreateDome();
|
||||||
|
@ -178,6 +182,11 @@ public:
|
||||||
virtual ~FSkyVertexBuffer();
|
virtual ~FSkyVertexBuffer();
|
||||||
void RenderDome(FMaterial *tex, int mode);
|
void RenderDome(FMaterial *tex, int mode);
|
||||||
void BindVBO();
|
void BindVBO();
|
||||||
|
int FaceStart(int i)
|
||||||
|
{
|
||||||
|
if (i >= 0 && i < 7) return mFaceStart[i];
|
||||||
|
else return mSideStart;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,72 @@ void FSkyVertexBuffer::CreateDome()
|
||||||
CreateSkyHemisphere(SKYHEMI_UPPER);
|
CreateSkyHemisphere(SKYHEMI_UPPER);
|
||||||
CreateSkyHemisphere(SKYHEMI_LOWER);
|
CreateSkyHemisphere(SKYHEMI_LOWER);
|
||||||
mPrimStart.Push(mVertices.Size());
|
mPrimStart.Push(mVertices.Size());
|
||||||
|
|
||||||
|
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
|
||||||
|
ptr[0].Set(128.f, 128.f, -128.f, 0, 0);
|
||||||
|
ptr[1].Set(128.f, -128.f, -128.f, 0, 1);
|
||||||
|
ptr[2].Set(-128.f, 128.f, -128.f, 0.25f, 0);
|
||||||
|
ptr[3].Set(-128.f, -128.f, -128.f, 0.25f, 1);
|
||||||
|
ptr[4].Set(-128.f, 128.f, 128.f, 0.5f, 0);
|
||||||
|
ptr[5].Set(-128.f, -128.f, 128.f, 0.5f, 1);
|
||||||
|
ptr[6].Set(128.f, 128.f, 128.f, 0.75f, 0);
|
||||||
|
ptr[7].Set(128.f, -128.f, 128.f, 0.75f, 1);
|
||||||
|
ptr[8].Set(128.f, 128.f, -128.f, 1, 0);
|
||||||
|
ptr[9].Set(128.f, -128.f, -128.f, 1, 1);
|
||||||
|
|
||||||
|
// north face
|
||||||
|
ptr[10].Set(128.f, 128.f, -128.f, 0, 0);
|
||||||
|
ptr[11].Set(-128.f, 128.f, -128.f, 1, 0);
|
||||||
|
ptr[12].Set(128.f, -128.f, -128.f, 0, 1);
|
||||||
|
ptr[13].Set(-128.f, -128.f, -128.f, 1, 1);
|
||||||
|
|
||||||
|
// east face
|
||||||
|
ptr[14].Set(-128.f, 128.f, -128.f, 0, 0);
|
||||||
|
ptr[15].Set(-128.f, 128.f, 128.f, 1, 0);
|
||||||
|
ptr[16].Set(-128.f, -128.f, -128.f, 0, 1);
|
||||||
|
ptr[17].Set(-128.f, -128.f, 128.f, 1, 1);
|
||||||
|
|
||||||
|
// south face
|
||||||
|
ptr[18].Set(-128.f, 128.f, 128.f, 0, 0);
|
||||||
|
ptr[19].Set(128.f, 128.f, 128.f, 1, 0);
|
||||||
|
ptr[20].Set(-128.f, -128.f, 128.f, 0, 1);
|
||||||
|
ptr[21].Set(128.f, -128.f, 128.f, 1, 1);
|
||||||
|
|
||||||
|
// west face
|
||||||
|
ptr[22].Set(128.f, 128.f, 128.f, 0, 0);
|
||||||
|
ptr[23].Set(128.f, 128.f, -128.f, 1, 0);
|
||||||
|
ptr[24].Set(128.f, -128.f, 128.f, 0, 1);
|
||||||
|
ptr[25].Set(128.f, -128.f, -128.f, 1, 1);
|
||||||
|
|
||||||
|
// bottom face
|
||||||
|
ptr[26].Set(128.f, -128.f, -128.f, 0, 0);
|
||||||
|
ptr[27].Set(-128.f, -128.f, -128.f, 1, 0);
|
||||||
|
ptr[28].Set(128.f, -128.f, 128.f, 0, 1);
|
||||||
|
ptr[29].Set(-128.f, -128.f, 128.f, 1, 1);
|
||||||
|
|
||||||
|
// top face
|
||||||
|
ptr[30].Set(128.f, 128.f, -128.f, 0, 0);
|
||||||
|
ptr[31].Set(-128.f, 128.f, -128.f, 1, 0);
|
||||||
|
ptr[32].Set(128.f, 128.f, 128.f, 0, 1);
|
||||||
|
ptr[33].Set(-128.f, 128.f, 128.f, 1, 1);
|
||||||
|
|
||||||
|
// top face flipped
|
||||||
|
ptr[34].Set(128.f, 128.f, -128.f, 0, 1);
|
||||||
|
ptr[35].Set(-128.f, 128.f, -128.f, 1, 1);
|
||||||
|
ptr[36].Set(128.f, 128.f, 128.f, 0, 0);
|
||||||
|
ptr[37].Set(-128.f, 128.f, 128.f, 1, 0);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -327,7 +393,6 @@ void RenderDome(FMaterial * tex, float x_offset, float y_offset, bool mirror, in
|
||||||
|
|
||||||
GLRenderer->mSkyVBO->RenderDome(tex, mode);
|
GLRenderer->mSkyVBO->RenderDome(tex, mode);
|
||||||
gl_RenderState.EnableTextureMatrix(false);
|
gl_RenderState.EnableTextureMatrix(false);
|
||||||
gl_RenderState.EnableModelMatrix(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -351,7 +416,6 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
|
||||||
else
|
else
|
||||||
gl_RenderState.mModelMatrix.rotate(-180.0f+x_offset, glset.skyrotatevector2.X, glset.skyrotatevector2.Z, glset.skyrotatevector2.Y);
|
gl_RenderState.mModelMatrix.rotate(-180.0f+x_offset, glset.skyrotatevector2.X, glset.skyrotatevector2.Z, glset.skyrotatevector2.Y);
|
||||||
|
|
||||||
FFlatVertex *ptr;
|
|
||||||
if (sb->faces[5])
|
if (sb->faces[5])
|
||||||
{
|
{
|
||||||
faces=4;
|
faces=4;
|
||||||
|
@ -360,65 +424,25 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[0], false);
|
tex = FMaterial::ValidateTexture(sb->faces[0], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(0), 4);
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(128.f, 128.f, -128.f, 0, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, 128.f, -128.f, 1, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, -128.f, 0, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, -128.f, 1, 1);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
|
|
||||||
// east
|
// east
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[1], false);
|
tex = FMaterial::ValidateTexture(sb->faces[1], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(1), 4);
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(-128.f, 128.f, -128.f, 0, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, 128.f, 128.f, 1, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, -128.f, 0, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, 128.f, 1, 1);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
|
|
||||||
// south
|
// south
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[2], false);
|
tex = FMaterial::ValidateTexture(sb->faces[2], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(2), 4);
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(-128.f, 128.f, 128.f, 0, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, 128.f, 128.f, 1, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, 128.f, 0, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, 128.f, 1, 1);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
|
|
||||||
// west
|
// west
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[3], false);
|
tex = FMaterial::ValidateTexture(sb->faces[3], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(3), 4);
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(128.f, 128.f, 128.f, 0, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, 128.f, -128.f, 1, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, 128.f, 0, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, -128.f, 1, 1);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -426,62 +450,21 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[0], false);
|
tex = FMaterial::ValidateTexture(sb->faces[0], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(-1), 10);
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(128.f, 128.f, -128.f, 0, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, -128.f, 0, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, 128.f, -128.f, 0.25f, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, -128.f, 0.25f, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, 128.f, 128.f, 0.5f, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, 128.f, 0.5f, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, 128.f, 128.f, 0.75f, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, 128.f, 0.75f, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, 128.f, -128.f, 1, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, -128.f, 1, 1);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// top
|
// top
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[faces], false);
|
tex = FMaterial::ValidateTexture(sb->faces[faces], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(sb->fliptop? 6:5), 4);
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(128.f, 128.f, -128.f, 0, sb->fliptop);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, 128.f, -128.f, 1, sb->fliptop);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, 128.f, 128.f, 0, !sb->fliptop);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, 128.f, 128.f, 1, !sb->fliptop);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
|
|
||||||
// bottom
|
// bottom
|
||||||
tex = FMaterial::ValidateTexture(sb->faces[faces+1], false);
|
tex = FMaterial::ValidateTexture(sb->faces[faces+1], false);
|
||||||
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
gl_RenderState.SetMaterial(tex, CLAMP_XY, 0, -1, false);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, GLRenderer->mSkyVBO->FaceStart(4), 4);
|
||||||
|
|
||||||
ptr = GLRenderer->mVBO->GetBuffer();
|
|
||||||
ptr->Set(128.f, -128.f, -128.f, 0, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, -128.f, 1, 0);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(128.f, -128.f, 128.f, 0, 1);
|
|
||||||
ptr++;
|
|
||||||
ptr->Set(-128.f, -128.f, 128.f, 1, 1);
|
|
||||||
ptr++;
|
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
|
||||||
gl_RenderState.EnableModelMatrix(false);
|
gl_RenderState.EnableModelMatrix(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,13 +495,13 @@ void GLSkyPortal::DrawContents()
|
||||||
gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
|
gl_MatrixStack.Push(gl_RenderState.mViewMatrix);
|
||||||
GLRenderer->SetupView(0, 0, 0, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
|
GLRenderer->SetupView(0, 0, 0, ViewAngle, !!(MirrorFlag&1), !!(PlaneMirrorFlag&1));
|
||||||
|
|
||||||
|
gl_RenderState.SetVertexBuffer(GLRenderer->mSkyVBO);
|
||||||
if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox)
|
if (origin->texture[0] && origin->texture[0]->tex->gl_info.bSkybox)
|
||||||
{
|
{
|
||||||
RenderBox(origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2);
|
RenderBox(origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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])
|
||||||
|
@ -547,11 +530,12 @@ void GLSkyPortal::DrawContents()
|
||||||
gl_RenderState.EnableTexture(true);
|
gl_RenderState.EnableTexture(true);
|
||||||
gl_RenderState.SetObjectColor(0xffffffff);
|
gl_RenderState.SetObjectColor(0xffffffff);
|
||||||
}
|
}
|
||||||
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
|
||||||
}
|
}
|
||||||
|
gl_RenderState.SetVertexBuffer(GLRenderer->mVBO);
|
||||||
gl_MatrixStack.Pop(gl_RenderState.mViewMatrix);
|
gl_MatrixStack.Pop(gl_RenderState.mViewMatrix);
|
||||||
gl_RenderState.ApplyMatrices();
|
gl_RenderState.ApplyMatrices();
|
||||||
glset.lightmode = oldlightmode;
|
glset.lightmode = oldlightmode;
|
||||||
gl_RenderState.SetDepthClamp(oldClamp);
|
gl_RenderState.SetDepthClamp(oldClamp);
|
||||||
|
gl_RenderState.EnableModelMatrix(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue