graphics optimization feature inspirated by diablo3 engine

* the rendering now consits of two panes
- the background pane (for animated stuff like the map)
- the foreground pane (for steady stuff, like UI)
each pane has it own max FPS and works idependently
this may increase graphics performance on many platforms
This commit is contained in:
Eduardo Bart
2012-06-01 16:39:09 -03:00
parent c01b32b032
commit bd2faabe99
43 changed files with 461 additions and 138 deletions

View File

@@ -28,7 +28,6 @@
class UIManager;
class UIWidget;
class UITextEdit;
class UIFrameCounter;
class UILayout;
class UIBoxLayout;
class UIHorizontalLayout;
@@ -40,7 +39,6 @@ typedef std::shared_ptr<UIWidget> UIWidgetPtr;
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
typedef std::shared_ptr<UITextEdit> UITextEditPtr;
typedef std::shared_ptr<UIFrameCounter> UIFrameCounterPtr;
typedef std::shared_ptr<UILayout> UILayoutPtr;
typedef std::shared_ptr<UIBoxLayout> UIBoxLayoutPtr;
typedef std::shared_ptr<UIHorizontalLayout> UIHorizontalLayoutPtr;

View File

@@ -26,7 +26,6 @@
#include "uimanager.h"
#include "uiwidget.h"
#include "uitextedit.h"
#include "uiframecounter.h"
#include "uilayout.h"
#include "uihorizontallayout.h"
#include "uiverticallayout.h"

View File

@@ -1,62 +0,0 @@
/*
* Copyright (c) 2010-2012 OTClient <https://github.com/edubart/otclient>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "uiframecounter.h"
#include "uitranslator.h"
#include <framework/graphics/font.h>
#include <framework/otml/otmlnode.h>
#include <framework/core/clock.h>
#include <framework/graphics/graphics.h>
UIFrameCounter::UIFrameCounter()
{
m_focusable = false;
m_phantom = true;
m_align = Fw::AlignLeft;
m_lastFrameTicks = g_clock.ticks();
m_frameCount = 0;
}
void UIFrameCounter::drawSelf()
{
UIWidget::drawSelf();
if(g_clock.ticksElapsed(m_lastFrameTicks) >= 1000) {
m_fpsText = stdext::format("FPS: %d", m_frameCount);
m_lastFrameTicks = g_clock.ticks();
m_frameCount = 0;
}
m_frameCount++;
g_painter->setColor(Color::white);
m_font->drawText(m_fpsText, m_rect, m_align);
}
void UIFrameCounter::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
{
UIWidget::onStyleApply(styleName, styleNode);
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "align")
setAlign(Fw::translateAlignment(node->value()));
}
}

View File

@@ -27,6 +27,7 @@
#include <framework/graphics/graphics.h>
#include <framework/platform/platformwindow.h>
#include <framework/core/eventdispatcher.h>
#include <framework/application.h>
UIManager g_ui;
@@ -51,9 +52,9 @@ void UIManager::terminate()
m_pressedWidget = nullptr;
}
void UIManager::render()
void UIManager::render(bool foregroundPane)
{
m_rootWidget->draw(m_rootWidget->getRect());
m_rootWidget->draw(m_rootWidget->getRect(), foregroundPane);
}
void UIManager::resize(const Size& size)

View File

@@ -33,7 +33,7 @@ public:
void init();
void terminate();
void render();
void render(bool foregroundPane);
void resize(const Size& size);
void inputEvent(const InputEvent& event);

View File

@@ -40,8 +40,11 @@ UITextEdit::UITextEdit()
blinkCursor();
}
void UITextEdit::drawSelf()
void UITextEdit::drawSelf(bool foregroundPane)
{
if(!foregroundPane)
return;
drawBackground(m_rect);
drawBorder(m_rect);
drawImage(m_rect);

View File

@@ -30,7 +30,7 @@ class UITextEdit : public UIWidget
public:
UITextEdit();
virtual void drawSelf();
void drawSelf(bool foregroundPane);
private:
void update();

View File

@@ -30,6 +30,7 @@
#include <framework/graphics/graphics.h>
#include <framework/platform/platformwindow.h>
#include <framework/graphics/texturemanager.h>
#include <framework/application.h>
UIWidget::UIWidget()
{
@@ -51,26 +52,29 @@ UIWidget::~UIWidget()
#endif
}
void UIWidget::draw(const Rect& visibleRect)
void UIWidget::draw(const Rect& visibleRect, bool foregroundPane)
{
if(m_clipping)
g_painter->setClipRect(visibleRect);
drawSelf();
drawSelf(foregroundPane);
if(m_children.size() > 0) {
if(m_clipping)
g_painter->setClipRect(visibleRect.intersection(getClippingRect()));
drawChildren(visibleRect);
drawChildren(visibleRect, foregroundPane);
}
if(m_clipping)
g_painter->resetClipRect();
}
void UIWidget::drawSelf()
void UIWidget::drawSelf(bool foregroundPane)
{
if(!foregroundPane)
return;
// draw style components in order
if(m_backgroundColor.aF() > Fw::MIN_ALPHA) {
Rect backgroundDestRect = m_rect;
@@ -84,7 +88,7 @@ void UIWidget::drawSelf()
drawText(m_rect);
}
void UIWidget::drawChildren(const Rect& visibleRect)
void UIWidget::drawChildren(const Rect& visibleRect, bool foregroundPane)
{
// draw children
for(const UIWidgetPtr& child : m_children) {
@@ -103,10 +107,10 @@ void UIWidget::drawChildren(const Rect& visibleRect)
if(child->getOpacity() < oldOpacity)
g_painter->setOpacity(child->getOpacity());
child->draw(childVisibleRect);
child->draw(childVisibleRect, foregroundPane);
// debug draw box
if(g_ui.isDrawingDebugBoxes()) {
if(foregroundPane && g_ui.isDrawingDebugBoxes()) {
g_painter->setColor(Color::green);
g_painter->drawBoundingRect(child->getRect());
}
@@ -807,6 +811,7 @@ bool UIWidget::setRect(const Rect& rect)
if(rect == oldRect)
return false;
g_app->repaint();
m_rect = rect;
// updates own layout

View File

@@ -52,9 +52,9 @@ public:
virtual ~UIWidget();
protected:
virtual void draw(const Rect& visibleRect);
virtual void drawSelf();
virtual void drawChildren(const Rect& visibleRect);
virtual void draw(const Rect& visibleRect, bool foregroundPane);
virtual void drawSelf(bool foregroundPane);
virtual void drawChildren(const Rect& visibleRect, bool foregroundPane);
friend class UIManager;