Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
bbc0e8eb
Commit
bbc0e8eb
authored
Jul 17, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactorization of VBO_CONTAINER.
parent
99e88140
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
288 additions
and
293 deletions
+288
-293
vbo_container.cpp
common/gal/opengl/vbo_container.cpp
+193
-194
vbo_item.cpp
common/gal/opengl/vbo_item.cpp
+1
-2
vbo_container.h
include/gal/opengl/vbo_container.h
+71
-86
vbo_item.h
include/gal/opengl/vbo_item.h
+23
-11
No files found.
common/gal/opengl/vbo_container.cpp
View file @
bbc0e8eb
This diff is collapsed.
Click to expand it.
common/gal/opengl/vbo_item.cpp
View file @
bbc0e8eb
...
@@ -52,9 +52,8 @@ VBO_ITEM::~VBO_ITEM()
...
@@ -52,9 +52,8 @@ VBO_ITEM::~VBO_ITEM()
void
VBO_ITEM
::
PushVertex
(
const
VBO_VERTEX
*
aVertex
)
void
VBO_ITEM
::
PushVertex
(
const
VBO_VERTEX
*
aVertex
)
{
{
m_container
->
Add
(
this
,
aVertex
);
m_container
->
Add
(
aVertex
);
m_size
++
;
m_isDirty
=
true
;
m_isDirty
=
true
;
}
}
...
...
include/gal/opengl/vbo_container.h
View file @
bbc0e8eb
...
@@ -35,8 +35,7 @@
...
@@ -35,8 +35,7 @@
#include <gal/opengl/vbo_item.h>
#include <gal/opengl/vbo_item.h>
#include <gal/color4d.h>
#include <gal/color4d.h>
#include <map>
#include <map>
#include <boost/unordered_map.hpp>
#include <set>
#include <wx/log.h>
namespace
KiGfx
namespace
KiGfx
{
{
...
@@ -47,23 +46,22 @@ class VBO_CONTAINER
...
@@ -47,23 +46,22 @@ class VBO_CONTAINER
{
{
public
:
public
:
VBO_CONTAINER
(
unsigned
int
aSize
=
defaultInitSize
);
VBO_CONTAINER
(
unsigned
int
aSize
=
defaultInitSize
);
~
VBO_CONTAINER
();
virtual
~
VBO_CONTAINER
();
///< Maps size of free memory chunks to their offsets
///< Maps size of free memory chunks to their offsets
typedef
std
::
pair
<
const
unsigned
int
,
unsigned
int
>
Chunk
;
typedef
std
::
pair
<
const
unsigned
int
,
unsigned
int
>
Chunk
;
typedef
std
::
multimap
<
const
unsigned
int
,
unsigned
int
>
FreeChunkMap
;
typedef
std
::
multimap
<
const
unsigned
int
,
unsigned
int
>
FreeChunkMap
;
///< Maps VBO_ITEMs to reserved memory chunks offsets & sizes
/// List of all the stored items
typedef
std
::
pair
<
VBO_ITEM
*
const
,
Chunk
>
ReservedChunk
;
typedef
std
::
set
<
VBO_ITEM
*>
Items
;
typedef
boost
::
unordered_map
<
VBO_ITEM
*
const
,
Chunk
>
ReservedChunkMap
;
/**
/**
* Function StartItem()
* Function StartItem()
* S
tarts an unknown sized item. After calling the function it is possible to add vertices
* S
ets an item to start its modifications. After calling the function it is possible to add
* using function Add().
*
vertices
using function Add().
* @param a
Vbo
Item is the item that is going to store vertices in the container.
* @param aItem is the item that is going to store vertices in the container.
*/
*/
void
StartItem
(
VBO_ITEM
*
a
Vbo
Item
);
void
StartItem
(
VBO_ITEM
*
aItem
);
/**
/**
* Function EndItem()
* Function EndItem()
...
@@ -74,30 +72,20 @@ public:
...
@@ -74,30 +72,20 @@ public:
/**
/**
* Function Add()
* Function Add()
* Stores given number of vertices in the container for the specific VBO_ITEM.
* Stores given number of vertices in the container for the specific VBO_ITEM (started by
* @param aVboItem is the owner of the vertices.
* StartItem() function).
* @param aItem is the owner of the vertices.
* @param aVertex are vertices data to be stored.
* @param aVertex are vertices data to be stored.
* @param aSize is the number of vertices to be added.
* @param aSize is the number of vertices to be added.
*/
*/
void
Add
(
VBO_ITEM
*
aVboItem
,
const
VBO_VERTEX
*
aVertex
,
unsigned
int
aSize
=
1
);
void
Add
(
const
VBO_VERTEX
*
aVertex
,
unsigned
int
aSize
=
1
);
/**
/**
* Function Free()
* Function Free()
* Frees the chunk reserved by the a
Vbo
Item.
* Frees the chunk reserved by the aItem.
* @param a
Vbo
Item is the owner of the chunk to be freed.
* @param aItem is the owner of the chunk to be freed.
*/
*/
inline
void
Free
(
VBO_ITEM
*
aVboItem
)
void
Free
(
VBO_ITEM
*
aItem
);
{
ReservedChunkMap
::
iterator
it
=
m_reservedChunks
.
find
(
aVboItem
);
freeChunk
(
it
);
// Dynamic memory freeing, there is no point in holding
// a large amount of memory when there is no use for it
if
(
m_freeSpace
>
(
m_currentSize
/
2
)
)
{
resizeContainer
(
m_currentSize
/
2
);
}
}
/**
/**
* Function Clear()
* Function Clear()
...
@@ -115,9 +103,9 @@ public:
...
@@ -115,9 +103,9 @@ public:
/**
/**
* Function GetVertices()
* Function GetVertices()
* Returns vertices stored by the specific item.
* Returns vertices stored by the specific item.
* @a
Vbo
Item is the specific item.
* @aItem is the specific item.
*/
*/
VBO_VERTEX
*
GetVertices
(
const
VBO_ITEM
*
a
Vbo
Item
)
const
;
VBO_VERTEX
*
GetVertices
(
const
VBO_ITEM
*
aItem
)
const
;
/**
/**
* Function GetVertices()
* Function GetVertices()
...
@@ -208,51 +196,50 @@ public:
...
@@ -208,51 +196,50 @@ public:
private
:
private
:
///< Stores size & offset of free chunks.
///< Stores size & offset of free chunks.
FreeChunkMap
m_freeChunks
;
FreeChunkMap
m_freeChunks
;
///< Store
s owners (VBO_ITEM*) of reserved chunks and their size & offset.
///< Store
d VERTEX_ITEMs
ReservedChunkMap
m_reservedChunk
s
;
Items
m_item
s
;
/**
/**
* Function allocate()
* Function allocate()
* Finds an offset where the number of vertices can be stored in a continous space. If there is
* Allocates the given amount of memory for the current VBO_ITEM (set by StartItem() function).
* no such chunk, appropriate amount of memory is allocated first.
* @param aSize is the number of vertices that are requested to be allocated.
* @param aVboItem is the owner of vertices to be stored.
* @return Pointer to the allocated space.
*/
VBO_VERTEX
*
allocate
(
unsigned
int
aSize
);
/**
* Function reallocate()
* Resizes the chunk that stores the current item to the given size.
* @param aSize is the number of vertices to be stored.
* @param aSize is the number of vertices to be stored.
* @return Offset of the new chunk.
*/
*/
unsigned
int
allocate
(
VBO_ITEM
*
aVboItem
,
unsigned
int
aSize
);
unsigned
int
reallocate
(
unsigned
int
aSize
);
/**
/**
* Function getChunkSize()
* Function getChunkSize()
* Returns size of the given chunk
(works both for reserved and free chunks)
.
* Returns size of the given chunk.
* @param aChunk is the chunk.
* @param aChunk is the chunk.
* @return Size of the chunk.
*/
*/
inline
int
getChunkSize
(
const
Chunk
&
aChunk
)
const
inline
unsigned
int
getChunkSize
(
const
Chunk
&
aChunk
)
const
{
{
return
aChunk
.
first
;
return
aChunk
.
first
;
}
}
inline
int
getChunkSize
(
const
ReservedChunk
&
aChunk
)
const
{
return
aChunk
.
second
.
first
;
}
/**
/**
* Function getChunkOffset()
* Function getChunkOffset()
* Returns offset of the given chunk
(works both for reserved and free chunks)
.
* Returns offset of the given chunk.
* @param aChunk is the chunk.
* @param aChunk is the chunk.
* @return Offset of the chunk.
*/
*/
inline
unsigned
int
getChunkOffset
(
const
Chunk
&
aChunk
)
const
inline
unsigned
int
getChunkOffset
(
const
Chunk
&
aChunk
)
const
{
{
return
aChunk
.
second
;
return
aChunk
.
second
;
}
}
inline
unsigned
int
getChunkOffset
(
const
ReservedChunk
&
aChunk
)
const
{
return
aChunk
.
second
.
second
;
}
/**
/**
* Function
g
etChunkOffset()
* Function
s
etChunkOffset()
* Up
adtes offset of the given chunk (works both for reserved and free chunks)
.
* Up
dates offset of the given chunk
.
* !! IMPORTANT: it does not reallocate the chunk, it just changes its properties.
* !! IMPORTANT: it does not reallocate the chunk, it just changes its properties.
* @param aChunk is the chunk.
* @param aChunk is the chunk.
*/
*/
...
@@ -261,51 +248,45 @@ private:
...
@@ -261,51 +248,45 @@ private:
aChunk
.
second
=
aOffset
;
aChunk
.
second
=
aOffset
;
}
}
inline
void
setChunkOffset
(
ReservedChunk
&
aChunk
,
unsigned
int
aOffset
)
const
{
aChunk
.
second
.
second
=
aOffset
;
}
/**
* Function getChunkVboItem()
* Returns owner of the given reserved chunk.
* @param aChunk is the chunk.
*/
inline
VBO_ITEM
*
getChunkVboItem
(
const
ReservedChunk
&
aChunk
)
const
{
return
aChunk
.
first
;
}
/**
/**
* Function defragment()
* Function defragment()
* Removes empty spaces between chunks, so after that there is a long continous space
* Removes empty spaces between chunks, so after that there is a long continous space
* for storing vertices at the and of the container.
* for storing vertices at the and of the container.
* @return false in case of failure (eg. memory shortage)
* @return false in case of failure (eg. memory shortage)
.
*/
*/
bool
defragment
(
VBO_VERTEX
*
aTarget
=
NULL
);
bool
defragment
(
VBO_VERTEX
*
aTarget
=
NULL
);
/**
/**
* Function resizeChunk()
* Function mergeFreeChunks()
* Changes size of the chunk that stores vertices of aVboItem.
* Looks for consecutive free memory chunks and merges them, decreasing fragmentation of
* @param aVboItem is the item for which reserved space size should be changed.
* memory.
* @param aNewSize is the new size for the aVboItem, expressed in vertices number.
*/
*/
void
resizeChunk
(
VBO_ITEM
*
aVboItem
,
int
aNewSize
);
void
mergeFreeChunks
(
);
/**
/**
* Function resizeContainer()
* Function resizeContainer()
* Prepares a bigger container of a given size.
* Prepares a bigger container of a given size.
* @param aNewSize is the new size of container, expressed in vertices
* @param aNewSize is the new size of container, expressed in vertices
* @return false in case of failure (eg. memory shortage)
* @return false in case of failure (eg. memory shortage)
.
*/
*/
bool
resizeContainer
(
unsigned
int
aNewSize
);
bool
resizeContainer
(
unsigned
int
aNewSize
);
/**
/**
* Function free
Chunk
()
* Function free
Item
()
* Frees the space
described in aChunk
and returns it to the free space pool.
* Frees the space
occupied by the item
and returns it to the free space pool.
* @param a
Chunk is a space
to be freed.
* @param a
Item is the item
to be freed.
*/
*/
void
freeChunk
(
const
ReservedChunkMap
::
iterator
&
aChunk
);
void
freeItem
(
VBO_ITEM
*
aItem
);
/**
* Function reservedSpace()
* Returns size of the reserved memory space.
* @return Size of the reserved memory space (expressed as a number of vertices).
*/
unsigned
int
reservedSpace
()
{
return
m_currentSize
-
m_freeSpace
;
}
///< How many vertices we can store in the container
///< How many vertices we can store in the container
unsigned
int
m_freeSpace
;
unsigned
int
m_freeSpace
;
...
@@ -316,15 +297,16 @@ private:
...
@@ -316,15 +297,16 @@ private:
///< Actual storage memory
///< Actual storage memory
VBO_VERTEX
*
m_vertices
;
VBO_VERTEX
*
m_vertices
;
///<
A flag saying if there is the item with an unknown size being added
///<
Initial size, used on clearing the container
bool
itemStarted
;
unsigned
int
m_initialSize
;
///< Variables holding the state of the item currently being added
///< Variables holding the state of the item currently being modified
unsigned
int
itemSize
;
unsigned
int
m_itemSize
;
unsigned
int
itemChunkSize
;
unsigned
int
m_chunkSize
;
VBO_ITEM
*
item
;
unsigned
int
m_chunkOffset
;
VBO_ITEM
*
m_item
;
///< Color used for new vertices pushed.
///< Color used for
the
new vertices pushed.
GLubyte
m_color
[
VBO_ITEM
::
ColorStride
];
GLubyte
m_color
[
VBO_ITEM
::
ColorStride
];
///< Shader and its parameters used for new vertices pushed
///< Shader and its parameters used for new vertices pushed
...
@@ -353,6 +335,9 @@ private:
...
@@ -353,6 +335,9 @@ private:
///< Default initial size of a container (expressed in vertices)
///< Default initial size of a container (expressed in vertices)
static
const
unsigned
int
defaultInitSize
=
1048576
;
static
const
unsigned
int
defaultInitSize
=
1048576
;
///< Basic tests for the container, use only for debugging.
void
test
()
const
;
};
};
}
// namespace KiGfx
}
// namespace KiGfx
...
...
include/gal/opengl/vbo_item.h
View file @
bbc0e8eb
...
@@ -47,6 +47,8 @@ class VBO_CONTAINER;
...
@@ -47,6 +47,8 @@ class VBO_CONTAINER;
class
VBO_ITEM
class
VBO_ITEM
{
{
friend
class
VBO_CONTAINER
;
public
:
public
:
VBO_ITEM
(
VBO_CONTAINER
*
aContainer
);
VBO_ITEM
(
VBO_CONTAINER
*
aContainer
);
~
VBO_ITEM
();
~
VBO_ITEM
();
...
@@ -89,16 +91,6 @@ public:
...
@@ -89,16 +91,6 @@ public:
return
m_size
;
return
m_size
;
}
}
/**
* Function SetOffset()
* Sets data offset in the VBO.
* @param aOffset is the offset expressed as a number of vertices.
*/
inline
void
SetOffset
(
unsigned
int
aOffset
)
{
m_offset
=
aOffset
;
}
/**
/**
* Function GetOffset()
* Function GetOffset()
* Returns data offset in the VBO.
* Returns data offset in the VBO.
...
@@ -149,7 +141,7 @@ public:
...
@@ -149,7 +141,7 @@ public:
static
const
unsigned
int
IndByteSize
=
sizeof
(
GLuint
);
static
const
unsigned
int
IndByteSize
=
sizeof
(
GLuint
);
pr
ivate
:
pr
otected
:
///< Offset and size of data stored in the VBO_CONTAINER.
///< Offset and size of data stored in the VBO_CONTAINER.
unsigned
int
m_offset
;
unsigned
int
m_offset
;
unsigned
int
m_size
;
unsigned
int
m_size
;
...
@@ -159,6 +151,26 @@ private:
...
@@ -159,6 +151,26 @@ private:
///< Flag telling if the item should be recached in VBO or not.
///< Flag telling if the item should be recached in VBO or not.
bool
m_isDirty
;
bool
m_isDirty
;
/**
* Function setSize()
* Sets data size in the VBO.
* @param aSize is the size expressed as a number of vertices.
*/
void
setSize
(
unsigned
int
aSize
)
{
m_size
=
aSize
;
}
/**
* Function setOffset()
* Sets data offset in the VBO.
* @param aOffset is the offset expressed as a number of vertices.
*/
inline
void
setOffset
(
unsigned
int
aOffset
)
{
m_offset
=
aOffset
;
}
};
};
}
// namespace KiGfx
}
// namespace KiGfx
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment