Allocate VBO buffers in OverlayRenderer only after graphics capabilities and shader path have been properly determined. Fixes #824.

This was SVN commit r11654.
This commit is contained in:
vts 2012-04-23 18:55:32 +00:00
parent ac4e25e17f
commit 97f49954cd
4 changed files with 43 additions and 16 deletions

View File

@ -577,16 +577,16 @@ static void InitRenderer()
new CRenderer;
// set renderer options from command line options - NOVBO must be set before opening the renderer
g_Renderer.SetOptionBool(CRenderer::OPT_NOVBO,g_NoGLVBO);
g_Renderer.SetOptionBool(CRenderer::OPT_SHADOWS,g_Shadows);
g_Renderer.SetOptionBool(CRenderer::OPT_FANCYWATER,g_FancyWater);
g_Renderer.SetOptionBool(CRenderer::OPT_NOVBO, g_NoGLVBO);
g_Renderer.SetOptionBool(CRenderer::OPT_SHADOWS, g_Shadows);
g_Renderer.SetOptionBool(CRenderer::OPT_FANCYWATER, g_FancyWater);
g_Renderer.SetRenderPath(CRenderer::GetRenderPathByName(g_RenderPath));
g_Renderer.SetOptionBool(CRenderer::OPT_SHADOWPCF, g_ShadowPCF);
// create terrain related stuff
new CTerrainTextureManager;
g_Renderer.Open(g_xres,g_yres);
g_Renderer.Open(g_xres, g_yres);
// Setup lighting environment. Since the Renderer accesses the
// lighting environment through a pointer, this has to be done before
@ -596,10 +596,10 @@ static void InitRenderer()
// I haven't seen the camera affecting GUI rendering and such, but the
// viewport has to be updated according to the video mode
SViewPort vp;
vp.m_X=0;
vp.m_Y=0;
vp.m_Width=g_xres;
vp.m_Height=g_yres;
vp.m_X = 0;
vp.m_Y = 0;
vp.m_Width = g_xres;
vp.m_Height = g_yres;
g_Renderer.SetViewport(vp);
ColorActivateFastImpl();

View File

@ -118,6 +118,11 @@ struct OverlayRendererInternals
/// Small vertical offset of overlays from terrain to prevent visual glitches
static const float OVERLAY_VOFFSET;
/// Performs one-time setup. Called from CRenderer::Open, after graphics capabilities have
/// been detected. Note that no VBOs must be created before this is called, since the shader
/// path and graphics capabilities are not guaranteed to be stable before this point.
void Initialize();
};
const float OverlayRendererInternals::OVERLAY_VOFFSET = 0.2f;
@ -137,6 +142,21 @@ OverlayRendererInternals::OverlayRendererInternals()
quadAttributeUV.type = GL_SHORT; // don't use GL_UNSIGNED_SHORT here, TexCoordPointer won't accept it
quadVertices.AddAttribute(&quadAttributeUV);
// Note that we're reusing the textured overlay line shader for the quad overlay rendering. This
// is because their code is almost identical; the only difference is that for the quad overlays
// we want to use a vertex color stream as opposed to an objectColor uniform. To this end, the
// shader has been set up to switch between the two behaviours based on the USE_OBJECTCOLOR define.
defsOverlayLineNormal.Add("USE_OBJECTCOLOR", "1");
defsOverlayLineAlwaysVisible.Add("USE_OBJECTCOLOR", "1");
defsOverlayLineAlwaysVisible.Add("IGNORE_LOS", "1");
}
void OverlayRendererInternals::Initialize()
{
// Perform any initialization after graphics capabilities have been detected. Notably,
// only at this point can we safely allocate VBOs (in contrast to e.g. in the constructor),
// because their creation depends on the shader path, which is not reliably set before this point.
quadVertices.SetNumVertices(MAX_QUAD_OVERLAYS * 4);
quadVertices.Layout(); // allocate backing store
@ -158,14 +178,6 @@ OverlayRendererInternals::OverlayRendererInternals()
}
quadIndices.Upload();
quadIndices.FreeBackingStore();
// Note that we're reusing the textured overlay line shader for the quad overlay rendering. This
// is because their code is almost identical; the only difference is that for the quad overlays
// we want to use a vertex color stream as opposed to an objectColor uniform. To this end, the
// shader has been set up to switch between the two behaviours based on the USE_OBJECTCOLOR define.
defsOverlayLineNormal.Add("USE_OBJECTCOLOR", "1");
defsOverlayLineAlwaysVisible.Add("USE_OBJECTCOLOR", "1");
defsOverlayLineAlwaysVisible.Add("IGNORE_LOS", "1");
}
class CTexturedLineRData : public CRenderData
@ -236,6 +248,11 @@ OverlayRenderer::~OverlayRenderer()
delete m;
}
void OverlayRenderer::Initialize()
{
m->Initialize();
}
void OverlayRenderer::Submit(SOverlayLine* line)
{
ENSURE(line->m_Coords.size() % 3 == 0);

View File

@ -38,6 +38,12 @@ public:
OverlayRenderer();
~OverlayRenderer();
/**
* Performs one-time initialization. Called by CRenderer::Open after graphics
* capabilities and the shader path have been determined (notably VBO support).
*/
void Initialize();
/**
* Add a line overlay for rendering in this frame.
* @param overlay Must be non-null. The pointed-to object must remain valid at least

View File

@ -618,6 +618,10 @@ bool CRenderer::Open(int width, int height)
// Validate the currently selected render path
SetRenderPath(m_Options.m_RenderPath);
// Let component renderers perform one-time initialization after graphics capabilities and
// the shader path have been determined.
m->overlayRenderer.Initialize();
return true;
}