Commit eb041ee2 authored by Maciej Suminski's avatar Maciej Suminski

Removed most of deprecated OpenGL calls. Items used to be drawn in immediate...

Removed most of deprecated OpenGL calls. Items used to be drawn in immediate mode now are drawn using vertex arrays.
parent 408fb4f1
This diff is collapsed.
......@@ -38,7 +38,7 @@
using namespace KiGfx;
VBO_CONTAINER::VBO_CONTAINER( int aSize ) :
VBO_CONTAINER::VBO_CONTAINER( unsigned int aSize ) :
m_freeSpace( aSize ), m_currentSize( aSize ), itemStarted( false ), m_transform( NULL ),
m_failed( false )
{
......@@ -202,6 +202,30 @@ void VBO_CONTAINER::Add( VBO_ITEM* aVboItem, const VBO_VERTEX* aVertex, unsigned
}
void VBO_CONTAINER::Clear()
{
// Change size to the default one
m_vertices = static_cast<VBO_VERTEX*>( realloc( m_vertices,
defaultInitSize * sizeof( VBO_VERTEX ) ) );
// Reset state variables
m_freeSpace = defaultInitSize;
m_currentSize = defaultInitSize;
itemStarted = false;
m_transform = NULL;
m_failed = false;
// By default no shader is used
m_shader[0] = 0;
m_freeChunks.clear();
m_reservedChunks.clear();
// In the beginning there is only free space
m_freeChunks.insert( Chunk( m_freeSpace, 0 ) );
}
VBO_VERTEX* VBO_CONTAINER::GetAllVertices() const
{
return m_vertices;
......
......@@ -337,21 +337,22 @@ private:
wxEvtHandler* mouseListener;
wxEvtHandler* paintListener;
// VBO buffers & display lists (used in immediate mode)
// VBO buffered vertices for faster circle & semicircle drawing
VBO_CONTAINER precomputedContainer; ///< Container for storing display lists
VBO_ITEM verticesCircle; ///< Buffer for circle & semicircle vertices
GLuint displayListCircle; ///< Circle display list
GLuint displayListSemiCircle; ///< Semi circle display list
// Vertex buffer objects related fields
typedef boost::unordered_map<unsigned int, VBO_ITEM*> GroupsMap;
GroupsMap groups; ///< Stores informations about VBO objects (groups)
unsigned int groupCounter; ///< Counter used for generating keys for groups
VBO_ITEM* currentGroup; ///< Currently used VBO_ITEM (for grouping)
VBO_CONTAINER vboContainer; ///< Container for storing VBO_ITEMs
GLuint vboVertices; ///< Currently used vertices VBO handle
GLuint vboIndices; ///< Currently used indices VBO handle
VBO_ITEM* currentItem; ///< Currently used VBO_ITEM (for grouping)
VBO_CONTAINER* currentContainer; ///< Currently used VBO_CONTAINER (for storing VBO_ITEMs)
VBO_CONTAINER cachedVbo; ///< Container for storing VBO_ITEMs
GLuint cachedVerts; ///< Currently used vertices VBO handle
GLuint cachedInds; ///< Currently used indices VBO handle
bool vboNeedsUpdate; ///< Flag indicating if VBO should be rebuilt
VBO_CONTAINER nonCachedVbo; ///< Container for storing non-cached VBO_ITEMs
VBO_ITEM* nonCachedItem; ///< Item that is gathering non-cached vertices
glm::mat4 transform; ///< Current transformation matrix
std::stack<glm::mat4> transformStack; ///< Stack of transformation matrices
......@@ -432,10 +433,6 @@ private:
/// Compute the points of an unit circle & semicircle and store them in VBO.
void computeCircleVbo();
/// Compute the points of an unit circle & semicircle and store them in display lists
/// for drawing in immediate mode.
void computeCircleDisplayLists();
// Event handling
/**
* @brief This is the window creation event handler.
......@@ -527,26 +524,6 @@ private:
*/
unsigned int getGroupNumber();
///< OpenGL replacement functions (that are working both in immediate and VBO modes)
/**
* @brief Starts drawing in immediate mode or does nothing if an item's caching has started.
* @param aMode specifies the primitive or primitives that will be created.
*/
inline void begin( GLenum aMode )
{
if( !isGrouping )
glBegin( aMode );
}
/**
* @brief Ends drawing in immediate mode or does nothing if an item's caching has started.
*/
inline void end()
{
if( !isGrouping )
glEnd();
}
/**
* @brief Adds vertex to the current item or draws it in immediate mode.
* @param aX is X coordinate.
......@@ -555,22 +532,13 @@ private:
*/
inline void vertex3( double aX, double aY, double aZ )
{
if( isGrouping )
{
// New vertex coordinates for VBO
const VBO_VERTEX vertex = { aX, aY, aZ };
currentGroup->PushVertex( &vertex );
}
else
{
glVertex3d( aX, aY, aZ );
}
// New vertex coordinates for VBO
const VBO_VERTEX vertex = { aX, aY, aZ };
currentItem->PushVertex( &vertex );
}
/**
* @brief Function that replaces glTranslate and behaves according to isGrouping variable.
* In case isGrouping==false, it is simply glTranslate, in other case it
* modifies transformation matrix.
* @brief Function that replaces glTranslate. It modifies transformation matrix.
*
* @param aX is translation in X axis direction.
* @param aY is translation in Y axis direction.
......@@ -578,20 +546,11 @@ private:
*/
inline void translate3( double aX, double aY, double aZ )
{
if( isGrouping )
{
transform = glm::translate( transform, glm::vec3( aX, aY, aZ ) );
}
else
{
glTranslated( aX, aY, aZ );
}
transform = glm::translate( transform, glm::vec3( aX, aY, aZ ) );
}
/**
* @brief Function that replaces glColor and behaves according to isGrouping variable.
* In case isGrouping==false, it is simply glColor, in other case it
* modifies color used by current VBO_ITEM.
* @brief Function that replaces glColor. It modifies color used by current VBO_ITEM.
*
* @param aR is red component.
* @param aG is green component.
......@@ -600,33 +559,17 @@ private:
*/
inline void color4( double aRed, double aGreen, double aBlue, double aAlpha )
{
if( isGrouping )
{
vboContainer.UseColor( aRed, aGreen, aBlue, aAlpha );
}
else
{
glColor4d( aRed, aGreen, aBlue, aAlpha );
}
currentContainer->UseColor( aRed, aGreen, aBlue, aAlpha );
}
/**
* @brief Function that replaces glColor and behaves according to isGrouping variable.
* In case isGrouping==false, it is simply glColor, in other case it
* modifies color used by current VBO_ITEM.
* @brief Function that replaces glColor. It modifies color used by current VBO_ITEM.
*
* @param aColor is the new color.
*/
inline void color4( const COLOR4D& aColor )
{
if( isGrouping )
{
vboContainer.UseColor( aColor );
}
else
{
glColor4d( aColor.r, aColor.g, aColor.b, aColor.a);
}
currentContainer->UseColor( aColor );
}
/**
......@@ -639,11 +582,10 @@ private:
inline void setShader( SHADER_TYPE aShader, GLfloat aParam1 = 0.0f,
GLfloat aParam2 = 0.0f, GLfloat aParam3 = 0.0f )
{
if( isUseShader && isGrouping )
if( isUseShader )
{
const GLfloat shader[] = { aShader, aParam1, aParam2, aParam3 };
vboContainer.UseShader( shader );
currentContainer->UseShader( shader );
}
}
};
......
......@@ -46,7 +46,7 @@ typedef struct VBO_VERTEX VBO_VERTEX;
class VBO_CONTAINER
{
public:
VBO_CONTAINER( int aSize = 1048576 );
VBO_CONTAINER( unsigned int aSize = defaultInitSize );
~VBO_CONTAINER();
///< Maps size of free memory chunks to their offsets
......@@ -99,6 +99,12 @@ public:
}
}
/**
* Function Clear()
* Removes all the data stored in the container.
*/
void Clear();
/**
* Function GetAllVertices()
* Returns all vertices stored in the container. It is especially useful for transferring
......@@ -344,6 +350,9 @@ private:
return power;
}
///< Default initial size of a container (expressed in vertices)
static const unsigned int defaultInitSize = 1048576;
};
} // namespace KiGfx
......
......@@ -126,7 +126,7 @@ public:
///< Informs the container that there will be no more vertices for the current VBO_ITEM
void Finish();
///< Data organization information for vertices {X,Y,Z,R,G,B,A} (@see VBO_VERTEX).
///< Data structure for vertices {X,Y,Z,R,G,B,A,shader&param} (@see VBO_VERTEX).
static const unsigned int VertByteSize = sizeof(VBO_VERTEX);
static const unsigned int VertStride = VertByteSize / sizeof(GLfloat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment