- convert skybox rendering to use the buffer interface.

This commit is contained in:
Christoph Oelckers 2014-06-15 11:50:54 +02:00
parent 6b038a5dae
commit ea332383a8

View file

@ -336,6 +336,7 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
else else
glRotatef(-180.0f+x_offset, glset.skyrotatevector2.X, glset.skyrotatevector2.Z, glset.skyrotatevector2.Y); glRotatef(-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;
@ -344,164 +345,125 @@ static void RenderBox(FTextureID texno, FMaterial * gltex, float x_offset, bool
tex = FMaterial::ValidateTexture(sb->faces[0]); tex = FMaterial::ValidateTexture(sb->faces[0]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0); tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0);
gl_RenderState.Apply(); gl_RenderState.Apply();
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0, 0); ptr = GLRenderer->mVBO->GetBuffer();
glVertex3f(128.f, 128.f, -128.f); ptr->Set(128.f, 128.f, -128.f, 0, 0);
glTexCoord2f(1, 0); ptr++;
glVertex3f(-128.f, 128.f, -128.f); ptr->Set(-128.f, 128.f, -128.f, 1, 0);
glTexCoord2f(1, 1); ptr++;
glVertex3f(-128.f, -128.f, -128.f); ptr->Set(128.f, -128.f, -128.f, 0, 1);
glTexCoord2f(0, 1); ptr++;
glVertex3f(128.f, -128.f, -128.f); ptr->Set(-128.f, -128.f, -128.f, 1, 1);
glEnd(); ptr++;
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
// east // east
tex = FMaterial::ValidateTexture(sb->faces[1]); tex = FMaterial::ValidateTexture(sb->faces[1]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0); tex->Bind(GLT_CLAMPX | GLT_CLAMPY, 0);
gl_RenderState.Apply(); gl_RenderState.Apply();
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0, 0); ptr = GLRenderer->mVBO->GetBuffer();
glVertex3f(-128.f, 128.f, -128.f); ptr->Set(-128.f, 128.f, -128.f, 0, 0);
glTexCoord2f(1, 0); ptr++;
glVertex3f(-128.f, 128.f, 128.f); ptr->Set(-128.f, 128.f, 128.f, 1, 0);
glTexCoord2f(1, 1); ptr++;
glVertex3f(-128.f, -128.f, 128.f); ptr->Set(-128.f, -128.f, -128.f, 0, 1);
glTexCoord2f(0, 1); ptr++;
glVertex3f(-128.f, -128.f, -128.f); ptr->Set(-128.f, -128.f, 128.f, 1, 1);
glEnd(); ptr++;
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
// south // south
tex = FMaterial::ValidateTexture(sb->faces[2]); tex = FMaterial::ValidateTexture(sb->faces[2]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0); tex->Bind(GLT_CLAMPX | GLT_CLAMPY, 0);
gl_RenderState.Apply(); gl_RenderState.Apply();
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0, 0); ptr = GLRenderer->mVBO->GetBuffer();
glVertex3f(-128.f, 128.f, 128.f); ptr->Set(-128.f, 128.f, 128.f, 0, 0);
glTexCoord2f(1, 0); ptr++;
glVertex3f(128.f, 128.f, 128.f); ptr->Set(128.f, 128.f, 128.f, 1, 0);
glTexCoord2f(1, 1); ptr++;
glVertex3f(128.f, -128.f, 128.f); ptr->Set(-128.f, -128.f, 128.f, 0, 1);
glTexCoord2f(0, 1); ptr++;
glVertex3f(-128.f, -128.f, 128.f); ptr->Set(128.f, -128.f, 128.f, 1, 1);
glEnd(); ptr++;
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
// west // west
tex = FMaterial::ValidateTexture(sb->faces[3]); tex = FMaterial::ValidateTexture(sb->faces[3]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0); tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0);
gl_RenderState.Apply(); gl_RenderState.Apply();
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0, 0); ptr = GLRenderer->mVBO->GetBuffer();
glVertex3f(128.f, 128.f, 128.f); ptr->Set(128.f, 128.f, 128.f, 0, 0);
glTexCoord2f(1, 0); ptr++;
glVertex3f(128.f, 128.f, -128.f); ptr->Set(128.f, 128.f, -128.f, 1, 0);
glTexCoord2f(1, 1); ptr++;
glVertex3f(128.f, -128.f, -128.f); ptr->Set(128.f, -128.f, 128.f, 0, 1);
glTexCoord2f(0, 1); ptr++;
glVertex3f(128.f, -128.f, 128.f); ptr->Set(128.f, -128.f, -128.f, 1, 1);
glEnd(); ptr++;
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
} }
else else
{ {
faces=1; faces=1;
// all 4 sides
tex = FMaterial::ValidateTexture(sb->faces[0]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0);
gl_RenderState.Apply(); ptr = GLRenderer->mVBO->GetBuffer();
glBegin(GL_TRIANGLE_FAN); ptr->Set(128.f, 128.f, -128.f, 0, 0);
glTexCoord2f(0, 0); ptr++;
glVertex3f(128.f, 128.f, -128.f); ptr->Set(128.f, -128.f, -128.f, 0, 1);
glTexCoord2f(.25f, 0); ptr++;
glVertex3f(-128.f, 128.f, -128.f); ptr->Set(-128.f, 128.f, -128.f, 0.25f, 0);
glTexCoord2f(.25f, 1); ptr++;
glVertex3f(-128.f, -128.f, -128.f); ptr->Set(-128.f, -128.f, -128.f, 0.25f, 1);
glTexCoord2f(0, 1); ptr++;
glVertex3f(128.f, -128.f, -128.f); ptr->Set(-128.f, 128.f, 128.f, 0.5f, 0);
glEnd(); ptr++;
ptr->Set(-128.f, -128.f, 128.f, 0.5f, 1);
// east ptr++;
glBegin(GL_TRIANGLE_FAN); ptr->Set(128.f, 128.f, 128.f, 0.75f, 0);
glTexCoord2f(.25f, 0); ptr++;
glVertex3f(-128.f, 128.f, -128.f); ptr->Set(128.f, -128.f, 128.f, 0.75f, 1);
glTexCoord2f(.5f, 0); ptr++;
glVertex3f(-128.f, 128.f, 128.f); ptr->Set(128.f, 128.f, -128.f, 1, 0);
glTexCoord2f(.5f, 1); ptr++;
glVertex3f(-128.f, -128.f, 128.f); ptr->Set(128.f, -128.f, -128.f, 1, 1);
glTexCoord2f(.25f, 1); ptr++;
glVertex3f(-128.f, -128.f, -128.f); GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
glEnd();
// south
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(.5f, 0);
glVertex3f(-128.f, 128.f, 128.f);
glTexCoord2f(.75f, 0);
glVertex3f(128.f, 128.f, 128.f);
glTexCoord2f(.75f, 1);
glVertex3f(128.f, -128.f, 128.f);
glTexCoord2f(.5f, 1);
glVertex3f(-128.f, -128.f, 128.f);
glEnd();
// west
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(.75f, 0);
glVertex3f(128.f, 128.f, 128.f);
glTexCoord2f(1, 0);
glVertex3f(128.f, 128.f, -128.f);
glTexCoord2f(1, 1);
glVertex3f(128.f, -128.f, -128.f);
glTexCoord2f(.75f, 1);
glVertex3f(128.f, -128.f, 128.f);
glEnd();
} }
// top // top
tex = FMaterial::ValidateTexture(sb->faces[faces]); tex = FMaterial::ValidateTexture(sb->faces[faces]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0); tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0);
gl_RenderState.Apply(); gl_RenderState.Apply();
glBegin(GL_TRIANGLE_FAN);
if (!sb->fliptop)
{
glTexCoord2f(0, 0);
glVertex3f(128.f, 128.f, -128.f);
glTexCoord2f(1, 0);
glVertex3f(-128.f, 128.f, -128.f);
glTexCoord2f(1, 1);
glVertex3f(-128.f, 128.f, 128.f);
glTexCoord2f(0, 1);
glVertex3f(128.f, 128.f, 128.f);
}
else
{
glTexCoord2f(0, 0);
glVertex3f(128.f, 128.f, 128.f);
glTexCoord2f(1, 0);
glVertex3f(-128.f, 128.f, 128.f);
glTexCoord2f(1, 1);
glVertex3f(-128.f, 128.f, -128.f);
glTexCoord2f(0, 1);
glVertex3f(128.f, 128.f, -128.f);
}
glEnd();
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]); tex = FMaterial::ValidateTexture(sb->faces[faces+1]);
tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0); tex->Bind(GLT_CLAMPX|GLT_CLAMPY, 0);
gl_RenderState.Apply(); gl_RenderState.Apply();
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0, 0);
glVertex3f(128.f, -128.f, -128.f);
glTexCoord2f(1, 0);
glVertex3f(-128.f, -128.f, -128.f);
glTexCoord2f(1, 1);
glVertex3f(-128.f, -128.f, 128.f);
glTexCoord2f(0, 1);
glVertex3f(128.f, -128.f, 128.f);
glEnd();
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);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------