better memory conservation for Table vert buf

This commit is contained in:
Jack Andersen 2015-12-31 10:26:04 -10:00
parent a469a81260
commit d9053ee859
3 changed files with 14 additions and 15 deletions

View File

@ -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<SolidShaderVert[]> 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);

View File

@ -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)

View File

@ -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 ; c<std::min(SPECTER_TABLE_MAX_COLUMNS, m_t.m_columns) ; ++c)
for (c=0 ; c<std::min(m_t.m_maxColumns, m_t.m_columns) ; ++c)
{
v[0].m_pos.assign(xOff + margin, yOff - margin, 0);
v[0].m_color = color;
@ -96,7 +96,7 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind
}
m_visibleStart = startIdx;
m_visibleRows = r;
m_vertsBuf->load(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)