From d9053ee8596ca0f20aa799b5c710a8da718dd878 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 31 Dec 2015 10:26:04 -1000 Subject: [PATCH] better memory conservation for Table vert buf --- specter/include/Specter/Table.hpp | 6 +++--- specter/lib/FileBrowser.cpp | 9 ++++----- specter/lib/Table.cpp | 14 +++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/specter/include/Specter/Table.hpp b/specter/include/Specter/Table.hpp index 739200b85..a7ed099bc 100644 --- a/specter/include/Specter/Table.hpp +++ b/specter/include/Specter/Table.hpp @@ -8,7 +8,6 @@ namespace Specter { #define SPECTER_TABLE_MAX_ROWS 128ul -#define SPECTER_TABLE_MAX_COLUMNS 32ul enum class SortDirection { @@ -38,6 +37,7 @@ class Table : public View ITableDataBinding* m_data; ITableStateBinding* m_state; + size_t m_maxColumns; size_t m_rows = 0; size_t m_columns = 0; struct CellView : public View @@ -58,7 +58,7 @@ class Table : public View { Table& m_t; - SolidShaderVert m_verts[SPECTER_TABLE_MAX_ROWS * SPECTER_TABLE_MAX_COLUMNS * 6]; + std::unique_ptr m_verts; boo::IGraphicsBufferD* m_vertsBuf = nullptr; boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */ boo::IShaderDataBinding* m_shaderBinding = nullptr; @@ -76,7 +76,7 @@ class Table : public View } m_rowsView; public: - Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state=nullptr); + Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state=nullptr, size_t maxColumns=8); void setMultiplyColor(const Zeus::CColor& color); diff --git a/specter/lib/FileBrowser.cpp b/specter/lib/FileBrowser.cpp index c8f131f5b..f10a35359 100644 --- a/specter/lib/FileBrowser.cpp +++ b/specter/lib/FileBrowser.cpp @@ -58,14 +58,14 @@ FileBrowser::FileBrowser(ViewResources& res, View& parentView, const std::string IViewManager& vm = rootView().viewManager(); m_fileField.m_view.reset(new TextField(res, *this, &m_fileFieldBind)); - m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind)); - m_systemBookmarks.m_view.reset(new Table(res, *this, &m_systemBookmarkBind)); + m_fileListing.m_view.reset(new Table(res, *this, &m_fileListingBind, nullptr, 3)); + m_systemBookmarks.m_view.reset(new Table(res, *this, &m_systemBookmarkBind, nullptr, 1)); m_systemBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); m_systemBookmarksLabel->typesetGlyphs(vm.translateOr("system_locations", "System Locations"), res.themeData().uiText()); - m_projectBookmarks.m_view.reset(new Table(res, *this, &m_projectBookmarkBind)); + m_projectBookmarks.m_view.reset(new Table(res, *this, &m_projectBookmarkBind, nullptr, 1)); m_projectBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); m_projectBookmarksLabel->typesetGlyphs(vm.translateOr("recent_projects", "Recent Projects"), res.themeData().uiText()); - m_recentBookmarks.m_view.reset(new Table(res, *this, &m_recentBookmarkBind)); + m_recentBookmarks.m_view.reset(new Table(res, *this, &m_recentBookmarkBind, nullptr, 1)); m_recentBookmarksLabel.reset(new TextView(res, *this, res.m_mainFont)); m_recentBookmarksLabel->typesetGlyphs(vm.translateOr("recent_files", "Recent Files"), res.themeData().uiText()); @@ -288,7 +288,6 @@ void FileBrowser::LeftSide::resized(const boo::SWindowRect& root, const boo::SWi m_fb.m_recentBookmarks.m_view->resized(root, bookmarkRect); m_fb.m_recentBookmarksLabel->resized(root, labelRect); - } void FileBrowser::RightSide::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) diff --git a/specter/lib/Table.cpp b/specter/lib/Table.cpp index 49773032c..17c98f6a8 100644 --- a/specter/lib/Table.cpp +++ b/specter/lib/Table.cpp @@ -7,8 +7,8 @@ namespace Specter #define ROW_HEIGHT 18 #define CELL_MARGIN 1 -Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state) -: View(res, parentView), m_data(data), m_state(state), m_rowsView(*this, res) +Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state, size_t maxColumns) +: View(res, parentView), m_data(data), m_state(state), m_maxColumns(maxColumns), m_rowsView(*this, res) { commitResources(res); @@ -18,10 +18,10 @@ Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITab } Table::RowsView::RowsView(Table& t, ViewResources& res) -: View(res, t), m_t(t) +: View(res, t), m_t(t), m_verts(new SolidShaderVert[SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6]) { m_vertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), - SPECTER_TABLE_MAX_ROWS * SPECTER_TABLE_MAX_COLUMNS * 6); + SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6); if (!res.m_viewRes.m_texVtxFmt) { @@ -52,7 +52,7 @@ Table::CellView::CellView(Table& t, ViewResources& res) void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWindowRect& scissor) { - SolidShaderVert* v = m_verts; + SolidShaderVert* v = m_verts.get(); const ThemeData& theme = rootView().themeData(); if (m_t.m_cellViews.empty()) @@ -77,7 +77,7 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind { const Zeus::CColor& color = (r&1) ? theme.tableCellBg1() : theme.tableCellBg2(); int xOff = 0; - for (c=0 ; cload(m_verts, sizeof(SolidShaderVert) * 6 * r * c); + m_vertsBuf->load(m_verts.get(), sizeof(SolidShaderVert) * 6 * r * c); } void Table::setMultiplyColor(const Zeus::CColor& color)