forked from Mirrors/openclonk
C4FoWRegion: Make more private
Code outside of C4FoWRegion should not care about the internals of the class. Therefore, we remove direct access to the backing surface (and secondary buffer surface) and replace it instead with accessors that return those few values that are required by outside code.shapetextures
parent
5a9baeddbf
commit
90293d019d
|
@ -477,7 +477,7 @@ void CStdGL::SetupMultiBlt(C4ShaderCall& call, const C4BltTransform* pTransform,
|
|||
|
||||
// Dynamic Light
|
||||
call.AllocTexUnit(C4SSU_LightTex);
|
||||
glBindTexture(GL_TEXTURE_2D, pFoW->getSurface()->textures[0].texName);
|
||||
glBindTexture(GL_TEXTURE_2D, pFoW->getSurfaceName());
|
||||
|
||||
float lightTransform[6];
|
||||
pFoW->GetFragTransform(ClipRect, OutRect, lightTransform);
|
||||
|
|
|
@ -518,7 +518,7 @@ namespace
|
|||
if(pFoW != NULL)
|
||||
{
|
||||
call.AllocTexUnit(C4SSU_LightTex);
|
||||
glBindTexture(GL_TEXTURE_2D, pFoW->getSurface()->textures[0].texName);
|
||||
glBindTexture(GL_TEXTURE_2D, pFoW->getSurfaceName());
|
||||
float lightTransform[6];
|
||||
pFoW->GetFragTransform(clipRect, outRect, lightTransform);
|
||||
call.SetUniformMatrix2x3fv(C4SSU_LightTransform, 1, lightTransform);
|
||||
|
|
|
@ -951,7 +951,7 @@ void C4LandscapeRenderGL::Draw(const C4TargetFacet &cgo, const C4FoWRegion *Ligh
|
|||
}
|
||||
if(Light && ShaderCall.AllocTexUnit(C4LRU_LightTex))
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, Light->getSurface()->textures[0].texName);
|
||||
glBindTexture(GL_TEXTURE_2D, Light->getSurfaceName());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
@ -1008,8 +1008,8 @@ void C4LandscapeRenderGL::Draw(const C4TargetFacet &cgo, const C4FoWRegion *Ligh
|
|||
if (Light)
|
||||
{
|
||||
const C4Rect LightRect = Light->getRegion();
|
||||
int32_t iLightWdt = Light->getSurface()->Wdt,
|
||||
iLightHgt = Light->getSurface()->Hgt;
|
||||
int32_t iLightWdt = Light->getSurfaceWidth(),
|
||||
iLightHgt = Light->getSurfaceHeight();
|
||||
lTexBlt.left = (fx - LightRect.x) / iLightWdt;
|
||||
lTexBlt.top = 1.0 - (fy - LightRect.y) / iLightHgt;
|
||||
lTexBlt.right = (fx + cgo.Wdt - LightRect.x) / iLightWdt;
|
||||
|
|
|
@ -36,8 +36,8 @@ void C4FoWDrawLightTextureStrategy::Begin(int32_t passPar)
|
|||
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
|
||||
float width = region->getSurface()->Wdt;
|
||||
float height = region->getSurface()->Hgt / 2.0;
|
||||
float width = region->getSurfaceWidth();
|
||||
float height = region->getSurfaceHeight() / 2.0;
|
||||
|
||||
// Set up blend equation, see C4FoWDrawLightTextureStrategy::DrawVertex
|
||||
// for details.
|
||||
|
@ -125,7 +125,7 @@ void C4FoWDrawLightTextureStrategy::DrawVertex(float x, float y, bool shadow)
|
|||
break;
|
||||
case C4DP_Color: // has a block so that alpha is scoped to this block only
|
||||
{
|
||||
y_offset = region->getSurface()->Hgt / 2;
|
||||
y_offset = region->getSurfaceHeight() / 2;
|
||||
|
||||
float alpha; // 0.0 == fully transparent (takes old color), 1.0 == solid color (takes new color)
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ bool C4FoWRegion::BindFramebuf()
|
|||
iHgt *= 2;
|
||||
|
||||
// Create the texture
|
||||
if (!pSurface->Create(iWdt, iHgt, false, 0, 0))
|
||||
if (!pSurface->Create(iWdt, iHgt, false, 0, 0) || !pBackSurface->Create(iWdt, iHgt, false, 0, 0))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,26 @@ bool C4FoWRegion::BindFramebuf()
|
|||
return true;
|
||||
}
|
||||
|
||||
int32_t C4FoWRegion::getSurfaceHeight() const
|
||||
{
|
||||
return pSurface->Hgt;
|
||||
}
|
||||
|
||||
int32_t C4FoWRegion::getSurfaceWidth() const
|
||||
{
|
||||
return pSurface->Wdt;
|
||||
}
|
||||
|
||||
#ifndef USE_CONSOLE
|
||||
GLuint C4FoWRegion::getSurfaceName() const
|
||||
{
|
||||
assert(!pSurface->textures.empty());
|
||||
if (pSurface->textures.empty())
|
||||
return 0;
|
||||
return pSurface->textures[0].texName;
|
||||
}
|
||||
#endif
|
||||
|
||||
void C4FoWRegion::Update(C4Rect r, const FLOAT_RECT& vp)
|
||||
{
|
||||
// Set the new region
|
||||
|
@ -122,21 +142,21 @@ void C4FoWRegion::Render(const C4TargetFacet *pOnScreen)
|
|||
return;
|
||||
|
||||
// Set up a clean context
|
||||
glViewport(0, 0, getSurface()->Wdt, getSurface()->Hgt);
|
||||
glViewport(0, 0, pSurface->Wdt, pSurface->Hgt);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
gluOrtho2D(0, getSurface()->Wdt, getSurface()->Hgt, 0);
|
||||
gluOrtho2D(0, pSurface->Wdt, pSurface->Hgt, 0);
|
||||
|
||||
// Clear texture contents
|
||||
assert(getSurface()->Hgt % 2 == 0);
|
||||
glScissor(0, getSurface()->Hgt / 2, getSurface()->Wdt, getSurface()->Hgt / 2);
|
||||
assert(pSurface->Hgt % 2 == 0);
|
||||
glScissor(0, pSurface->Hgt / 2, pSurface->Wdt, pSurface->Hgt / 2);
|
||||
glClearColor(0.0f, 0.5f / 1.5f, 0.5f / 1.5f, 0.0f);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// clear lower half of texture
|
||||
glScissor(0, 0, getSurface()->Wdt, getSurface()->Hgt / 2);
|
||||
glScissor(0, 0, pSurface->Wdt, pSurface->Hgt / 2);
|
||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
@ -169,15 +189,15 @@ void C4FoWRegion::Render(const C4TargetFacet *pOnScreen)
|
|||
// Transform into texture coordinates
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
squad[i*2] = squad[i*2] / getBackSurface()->Wdt;
|
||||
squad[i*2+1] = 1.0 - squad[i*2+1] / getBackSurface()->Hgt;
|
||||
squad[i*2] = squad[i*2] / pBackSurface->Wdt;
|
||||
squad[i*2+1] = 1.0 - squad[i*2+1] / pBackSurface->Hgt;
|
||||
}
|
||||
|
||||
// Copy using shader
|
||||
C4ShaderCall Call(pShader);
|
||||
Call.Start();
|
||||
if (Call.AllocTexUnit(0))
|
||||
glBindTexture(GL_TEXTURE_2D, getBackSurface()->textures[0].texName);
|
||||
glBindTexture(GL_TEXTURE_2D, pBackSurface->textures[0].texName);
|
||||
glBlendFunc(GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR);
|
||||
float normalBlend = 1.0f / 4.0f, // Normals change quickly
|
||||
brightBlend = 1.0f / 16.0f; // Intensity more slowly
|
||||
|
@ -218,9 +238,9 @@ void C4FoWRegion::GetFragTransform(const C4Rect& clipRect, const C4Rect& outRect
|
|||
// Offset between viewport and light texture
|
||||
trans.Translate(vpRect.left - lightRect.x, vpRect.top - lightRect.y);
|
||||
// Light surface normalization
|
||||
trans.Scale(1.0f / getSurface()->Wdt, 1.0f / getSurface()->Hgt);
|
||||
trans.Scale(1.0f / pSurface->Wdt, 1.0f / pSurface->Hgt);
|
||||
// Light surface Y offset
|
||||
trans.Translate(0.0f, 1.0f - (float)(lightRect.Hgt) / (float)getSurface()->Hgt);
|
||||
trans.Translate(0.0f, 1.0f - (float)(lightRect.Hgt) / (float)pSurface->Hgt);
|
||||
|
||||
// Extract matrix
|
||||
trans.Get2x3(lightTransform);
|
||||
|
|
|
@ -44,8 +44,12 @@ public:
|
|||
const C4FoW* getFoW() const { return pFoW; }
|
||||
const C4Rect &getRegion() const { return Region; }
|
||||
const FLOAT_RECT &getViewportRegion() const { return ViewportRegion; }
|
||||
const C4Surface *getSurface() const { return pSurface.get(); }
|
||||
const C4Surface *getBackSurface() const { return pBackSurface.get(); }
|
||||
int32_t getSurfaceHeight() const;
|
||||
int32_t getSurfaceWidth() const;
|
||||
|
||||
#ifndef USE_CONSOLE
|
||||
GLuint getSurfaceName() const;
|
||||
#endif
|
||||
|
||||
void Update(C4Rect r, const FLOAT_RECT& vp);
|
||||
void Render(const C4TargetFacet *pOnScreen = NULL);
|
||||
|
|
Loading…
Reference in New Issue