Allow controlling per-viewport if debug geometry should be rendered, instead of hardcoding to just backbuffer views.

This commit is contained in:
Lasse Öörni 2014-10-01 21:15:30 +03:00
Родитель 2dc6c117cd
Коммит 7f4b8e5b35
8 изменённых файлов: 33 добавлений и 9 удалений

Просмотреть файл

@ -737,6 +737,7 @@ The steps for rendering each viewport on each frame are roughly the following:
- Check the influence of each visible light on the objects. If the light casts shadows, query the octree for shadowcaster objects.
- Construct render operations (batches) for the visible objects, according to the scene passes in the render path command sequence.
- Perform the render path command sequence during the rendering step at the end of the frame.
- If the scene has a DebugRenderer component and the viewport has debug rendering enabled, render debug geometry last. Can be controlled with \ref Viewport::SetDrawDebug "SetDrawDebug()", default is enabled.
In the default render paths, the rendering operations proceed in the following order:

Просмотреть файл

@ -717,9 +717,8 @@ void Renderer::DrawDebugGeometry(bool depthTest)
for (unsigned i = 0; i < numViews_; ++i)
{
// Make sure it's a main view, and process each node only once
View* view = views_[i];
if (view->GetRenderTarget())
if (!view->GetDrawDebug())
continue;
Octree* octree = view->GetOctree();
if (!octree)
@ -728,6 +727,7 @@ void Renderer::DrawDebugGeometry(bool depthTest)
if (!debug || !debug->IsEnabledEffective())
continue;
// Process geometries / lights only once
const PODVector<Drawable*>& geometries = view->GetGeometries();
const PODVector<Light*>& lights = view->GetLights();

Просмотреть файл

@ -314,6 +314,7 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
if (!renderPath_)
return false;
drawDebug_ = viewport->GetDrawDebug();
hasScenePasses_ = false;
// Make sure that all necessary batch queues exist
@ -568,8 +569,8 @@ void View::Render()
if (currentRenderTarget_ != renderTarget_)
BlitFramebuffer(static_cast<Texture2D*>(currentRenderTarget_->GetParentTexture()), renderTarget_, true);
// If this is a main view, draw the associated debug geometry now
if (!renderTarget_ && octree_ && camera_)
// Draw the associated debug geometry now if enabled
if (drawDebug_ && octree_ && camera_)
{
DebugRenderer* debug = octree_->GetComponent<DebugRenderer>();
if (debug && debug->IsEnabledEffective())

Просмотреть файл

@ -139,6 +139,8 @@ public:
const FrameInfo& GetFrameInfo() const { return frame_; }
/// Return the rendertarget. 0 if using the backbuffer.
RenderSurface* GetRenderTarget() const { return renderTarget_; }
/// Return whether should draw debug geometry.
bool GetDrawDebug() const { return drawDebug_; }
/// Return geometry objects.
const PODVector<Drawable*>& GetGeometries() const { return geometries_; }
/// Return occluder objects.
@ -312,6 +314,8 @@ private:
bool useLitBase_;
/// Has scene passes flag. If no scene passes, view can be defined without a valid scene or camera to only perform quad rendering.
bool hasScenePasses_;
/// Draw debug geometry flag. Copied from the viewport.
bool drawDebug_;
/// Renderpath.
RenderPath* renderPath_;
/// Per-thread octree query results.

Просмотреть файл

@ -38,7 +38,8 @@ namespace Urho3D
Viewport::Viewport(Context* context) :
Object(context),
rect_(IntRect::ZERO)
rect_(IntRect::ZERO),
drawDebug_(true)
{
SetRenderPath((RenderPath*)0);
}
@ -47,7 +48,8 @@ Viewport::Viewport(Context* context, Scene* scene, Camera* camera, RenderPath* r
Object(context),
scene_(scene),
camera_(camera),
rect_(IntRect::ZERO)
rect_(IntRect::ZERO),
drawDebug_(true)
{
SetRenderPath(renderPath);
}
@ -56,7 +58,8 @@ Viewport::Viewport(Context* context, Scene* scene, Camera* camera, const IntRect
Object(context),
scene_(scene),
camera_(camera),
rect_(rect)
rect_(rect),
drawDebug_(true)
{
SetRenderPath(renderPath);
}
@ -80,6 +83,11 @@ void Viewport::SetRect(const IntRect& rect)
rect_ = rect;
}
void Viewport::SetDrawDebug(bool enable)
{
drawDebug_ = enable;
}
void Viewport::SetRenderPath(RenderPath* renderPath)
{
if (renderPath)

Просмотреть файл

@ -61,6 +61,8 @@ public:
void SetRenderPath(RenderPath* path);
/// Set rendering path from an XML file.
void SetRenderPath(XMLFile* file);
/// Set whether to render debug geometry. Default true.
void SetDrawDebug(bool enable);
/// Return scene.
Scene* GetScene() const;
@ -70,6 +72,8 @@ public:
const IntRect& GetRect() const { return rect_; }
/// Return rendering path.
RenderPath* GetRenderPath() const;
/// Return whether to draw debug geometry.
bool GetDrawDebug() const { return drawDebug_; }
/// Return ray corresponding to normalized screen coordinates.
Ray GetScreenRay(int x, int y) const;
// Convert a world space point to normalized screen coordinates.
@ -86,6 +90,8 @@ private:
IntRect rect_;
/// Rendering path.
SharedPtr<RenderPath> renderPath_;
/// Debug draw flag.
bool drawDebug_;
};
}

Просмотреть файл

@ -12,20 +12,22 @@ class Viewport
void SetRect(const IntRect& rect);
void SetRenderPath(RenderPath* path);
void SetRenderPath(XMLFile* file);
void SetDrawDebug(bool enable);
Scene* GetScene() const;
Camera* GetCamera() const;
const IntRect& GetRect() const;
RenderPath* GetRenderPath() const;
bool GetDrawDebug() const;
Ray GetScreenRay(int x, int y) const;
IntVector2 WorldToScreenPoint(const Vector3& worldPos) const;
Vector3 ScreenToWorldPoint(int x, int y, float depth) const;
tolua_property__get_set Scene* scene;
tolua_property__get_set Camera* camera;
tolua_property__get_set IntRect& rect;
tolua_property__get_set RenderPath* renderPath;
tolua_property__get_set bool drawDebug;
};
${

Просмотреть файл

@ -424,6 +424,8 @@ static void RegisterTextures(asIScriptEngine* engine)
engine->RegisterObjectMethod("Viewport", "RenderPath@+ get_renderPath() const", asMETHOD(Viewport, GetRenderPath), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "void set_rect(const IntRect&in)", asMETHOD(Viewport, SetRect), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "const IntRect& get_rect() const", asMETHOD(Viewport, GetRect), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "void set_drawDebug(bool)", asMETHOD(Viewport, SetDrawDebug), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "bool get_drawDebug() const", asMETHOD(Viewport, GetDrawDebug), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "Ray GetScreenRay(int, int) const", asMETHOD(Viewport, GetScreenRay), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "Vector2 WorldToScreenPoint(const Vector3&in) const", asMETHOD(Viewport, WorldToScreenPoint), asCALL_THISCALL);
engine->RegisterObjectMethod("Viewport", "Vector3 ScreenToWorldPoint(int, int, float) const", asMETHOD(Viewport, ScreenToWorldPoint), asCALL_THISCALL);