Commit 83f5bd60 authored by Maciej Suminski's avatar Maciej Suminski
Browse files

Moved fields containing information about currently used color, shader and...

Moved fields containing information about currently used color, shader and transformation for vertices from VBO_ITEM to VBO_CONTAINER (OPENGL_GAL).
parent 4de43d7c
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -1543,7 +1543,7 @@ void OPENGL_GAL::Save()
    if( isGrouping )
    if( isGrouping )
    {
    {
        transformStack.push( transform );
        transformStack.push( transform );
        curVboItem->SetTransformMatrix( &transform );
        vboContainer->SetTransformMatrix( &transform );
    }
    }
    else
    else
    {
    {
@@ -1562,7 +1562,7 @@ void OPENGL_GAL::Restore()
        if( transformStack.empty() )
        if( transformStack.empty() )
        {
        {
            // Disable transforming, as the selected matrix is identity
            // Disable transforming, as the selected matrix is identity
            curVboItem->SetTransformMatrix( NULL );
            vboContainer->SetTransformMatrix( NULL );
        }
        }
    }
    }
    else
    else
+43 −3
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@
 */
 */


#include <gal/opengl/vbo_container.h>
#include <gal/opengl/vbo_container.h>
#include <gal/opengl/vbo_item.h>
#include <cstring>
#include <cstring>
#include <wx/log.h>
#include <wx/log.h>
#ifdef __WXDEBUG__
#ifdef __WXDEBUG__
@@ -40,8 +39,11 @@
using namespace KiGfx;
using namespace KiGfx;


VBO_CONTAINER::VBO_CONTAINER( int aSize ) :
VBO_CONTAINER::VBO_CONTAINER( int aSize ) :
        m_freeSpace( aSize ), m_currentSize( aSize ), itemStarted( false )
        m_freeSpace( aSize ), m_currentSize( aSize ), itemStarted( false ), m_transform( NULL )
{
{
    // By default no shader is used
    m_shader[0] = 0;

    m_vertices = new VBO_VERTEX[aSize];
    m_vertices = new VBO_VERTEX[aSize];


    // In the beginning there is only free space
    // In the beginning there is only free space
@@ -88,6 +90,7 @@ void VBO_CONTAINER::EndItem()
void VBO_CONTAINER::Add( VBO_ITEM* aVboItem, const VBO_VERTEX* aVertex, unsigned int aSize )
void VBO_CONTAINER::Add( VBO_ITEM* aVboItem, const VBO_VERTEX* aVertex, unsigned int aSize )
{
{
    unsigned int offset;
    unsigned int offset;
    VBO_VERTEX* vertexPtr;


    if( itemStarted )   // There is an item being created with an unknown size..
    if( itemStarted )   // There is an item being created with an unknown size..
    {
    {
@@ -146,7 +149,44 @@ void VBO_CONTAINER::Add( VBO_ITEM* aVboItem, const VBO_VERTEX* aVertex, unsigned
        offset = getChunkOffset( *it ) + itemSize;
        offset = getChunkOffset( *it ) + itemSize;
    }
    }


    memcpy( &m_vertices[offset], aVertex, aSize * VBO_ITEM::VertByteSize );
    for( unsigned int i = 0; i < aSize; ++i )
    {
        // Pointer to the vertex that we are currently adding
        vertexPtr = &m_vertices[offset + i];

        // Modify the vertex according to the currently used transformations
        if( m_transform != NULL )
        {
            // Apply transformations
            glm::vec4 vertex( aVertex[i].x, aVertex[i].y, aVertex[i].z, 1.0f );
            vertex = *m_transform * vertex;

            // Replace only coordinates, leave color as it is
            vertexPtr->x = vertex.x;
            vertexPtr->y = vertex.y;
            vertexPtr->z = vertex.z;
        }
        else
        {
            // Simply copy coordinates
            vertexPtr->x = aVertex[i].x;
            vertexPtr->y = aVertex[i].y;
            vertexPtr->z = aVertex[i].z;
        }

        // Apply currently used color
        vertexPtr->r = m_color[0];
        vertexPtr->g = m_color[1];
        vertexPtr->b = m_color[2];
        vertexPtr->a = m_color[3];

        // Apply currently used shader
        for( unsigned int i = 0; i < VBO_ITEM::ShaderStride; ++i )
        {
            vertexPtr->shader[i] = m_shader[i];
        }
    }

}
}




+3 −31
Original line number Original line Diff line number Diff line
@@ -37,12 +37,8 @@ VBO_ITEM::VBO_ITEM( VBO_CONTAINER* aContainer ) :
        m_offset( 0 ),
        m_offset( 0 ),
        m_size( 0 ),
        m_size( 0 ),
        m_container( aContainer ),
        m_container( aContainer ),
        m_isDirty( true ),
        m_isDirty( true )
        m_transform( NULL )
{
{
    // By default no shader is used
    m_shader[0] = 0;

    // The item's size is not known yet, so we just start an item in the container
    // The item's size is not known yet, so we just start an item in the container
    aContainer->StartItem( this );
    aContainer->StartItem( this );
}
}
@@ -54,32 +50,8 @@ VBO_ITEM::~VBO_ITEM()
}
}




void VBO_ITEM::PushVertex( VBO_VERTEX* aVertex )
void VBO_ITEM::PushVertex( const VBO_VERTEX* aVertex )
{
    if( m_transform != NULL )
    {
        // Apply transformations
        glm::vec4 vertex( aVertex->x, aVertex->y, aVertex->z, 1.0f );
        vertex = *m_transform * vertex;

        // Replace only coordinates, leave color as it is
        aVertex->x = vertex.x;
        aVertex->y = vertex.y;
        aVertex->z = vertex.z;
    }

    // Apply currently used color
    aVertex->r = m_color[0];
    aVertex->g = m_color[1];
    aVertex->b = m_color[2];
    aVertex->a = m_color[3];

    // Apply currently used shader
    for( int i = 0; i < ShaderStride; ++i )
{
{
        aVertex->shader[i] = m_shader[i];
    }

    m_container->Add( this, aVertex );
    m_container->Add( this, aVertex );


    m_size++;
    m_size++;
@@ -87,7 +59,7 @@ void VBO_ITEM::PushVertex( VBO_VERTEX* aVertex )
}
}




void VBO_ITEM::PushVertices( VBO_VERTEX* aVertices, GLuint aSize )
void VBO_ITEM::PushVertices( const VBO_VERTEX* aVertices, GLuint aSize )
{
{
    for( unsigned int i = 0; i < aSize; ++i )
    for( unsigned int i = 0; i < aSize; ++i )
    {
    {
+4 −5
Original line number Original line Diff line number Diff line
@@ -37,7 +37,7 @@
#define GLM_FORCE_RADIANS
#define GLM_FORCE_RADIANS
#include <gal/opengl/glm/gtc/matrix_transform.hpp>
#include <gal/opengl/glm/gtc/matrix_transform.hpp>


#include <gal/opengl/vbo_item.h>
#include <gal/opengl/vbo_container.h>
#include <gal/opengl/shader.h>
#include <gal/opengl/shader.h>


// wxWidgets imports
// wxWidgets imports
@@ -58,7 +58,6 @@
namespace KiGfx
namespace KiGfx
{
{
class SHADER;
class SHADER;
class VBO_CONTAINER;


/**
/**
 * @brief Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer.
 * @brief Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer.
@@ -601,7 +600,7 @@ private:
    {
    {
        if( isGrouping )
        if( isGrouping )
        {
        {
            curVboItem->UseColor( COLOR4D( aRed, aGreen, aBlue, aAlpha ) );
            vboContainer->UseColor( aRed, aGreen, aBlue, aAlpha );
        }
        }
        else
        else
        {
        {
@@ -620,7 +619,7 @@ private:
    {
    {
        if( isGrouping )
        if( isGrouping )
        {
        {
            curVboItem->UseColor( aColor );
            vboContainer->UseColor( aColor );
        }
        }
        else
        else
        {
        {
@@ -642,7 +641,7 @@ private:
        {
        {
            const GLfloat shader[] = { aShader, aParam1, aParam2, aParam3 };
            const GLfloat shader[] = { aShader, aParam1, aParam2, aParam3 };


            curVboItem->UseShader( shader );
            vboContainer->UseShader( shader );
        }
        }
    }
    }
};
};
+87 −7
Original line number Original line Diff line number Diff line
@@ -31,6 +31,9 @@
#define VBO_CONTAINER_H_
#define VBO_CONTAINER_H_


#include <GL/gl.h>
#include <GL/gl.h>
#include <gal/opengl/glm/glm.hpp>
#include <gal/opengl/vbo_item.h>
#include <gal/color4d.h>
#include <map>
#include <map>
#include <wx/log.h>
#include <wx/log.h>


@@ -118,6 +121,73 @@ public:
        return m_currentSize;
        return m_currentSize;
    }
    }


    /**
     * Function SetTransformMatrix()
     * Sets transformation matrix for vertices that are added to VBO_ITEM. If you do not want to
     * transform vertices at all, pass NULL as the argument.
     * @param aMatrix is the new transform matrix or NULL if you do not want to use transformation
     * matrix.
     */
    inline void SetTransformMatrix( const glm::mat4* aMatrix )
    {
        m_transform = aMatrix;
    }

    /**
     * Function UseColor()
     * Sets color used for all added vertices.
     * @param aColor is the color used for added vertices.
     */
    inline void UseColor( const COLOR4D& aColor )
    {
        m_color[0] = aColor.r;
        m_color[1] = aColor.g;
        m_color[2] = aColor.b;
        m_color[3] = aColor.a;
    }

    /**
     * Function UseColor()
     * Sets color used for all added vertices.
     * @param aColor is the color used for added vertices.
     */
    inline void UseColor( const GLfloat aColor[VBO_ITEM::ColorStride] )
    {
        for( unsigned int i = 0; i < VBO_ITEM::ColorStride; ++i )
        {
            m_color[i] = aColor[i];
        }
    }

    /**
     * Function UseColor()
     * Sets color used for all added vertices.
     * @param aR is the red component of the color.
     * @param aG is the green component of the color.
     * @param aB is the blue component of the color.
     * @param aA is the alpha component of the color.
     */
    inline void UseColor( GLfloat aR, GLfloat aG, GLfloat aB, GLfloat aA )
    {
        m_color[0] = aR;
        m_color[1] = aG;
        m_color[2] = aB;
        m_color[3] = aA;
    }

    /**
     * Function UseShader()
     * Sets shader and its parameters used for all added vertices.
     * @param aShader is the array that contains shader number followed by its parameters.
     */
    inline void UseShader( const GLfloat aShader[VBO_ITEM::ShaderStride] )
    {
        for( unsigned int i = 0; i < VBO_ITEM::ShaderStride; ++i )
        {
            m_shader[i] = aShader[i];
        }
    }

private:
private:
    ///< Stores size & offset of free chunks.
    ///< Stores size & offset of free chunks.
    FreeChunkMap        m_freeChunks;
    FreeChunkMap        m_freeChunks;
@@ -233,15 +303,25 @@ private:
    bool            itemStarted;
    bool            itemStarted;


    ///< Variables holding the state of the item currently being added
    ///< Variables holding the state of the item currently being added
    unsigned int itemSize, itemChunkSize;
    unsigned int    itemSize;
    unsigned int    itemChunkSize;
    VBO_ITEM*       item;
    VBO_ITEM*       item;


    ///< Color used for new vertices pushed.
    GLfloat         m_color[VBO_ITEM::ColorStride];

    ///< Shader and its parameters used for new vertices pushed
    GLfloat         m_shader[VBO_ITEM::ShaderStride];

    ///< Current transform matrix applied for every new vertex pushed.
    const glm::mat4*    m_transform;

    /**
    /**
     * Function getPowerOf2()
     * Function getPowerOf2()
     * Returns the nearest power of 2, bigger than aNumber.
     * Returns the nearest power of 2, bigger than aNumber.
     * @param aNumber is the number for which we look for a bigger power of 2.
     * @param aNumber is the number for which we look for a bigger power of 2.
     */
     */
    unsigned int getPowerOf2( unsigned int aNumber )
    unsigned int getPowerOf2( unsigned int aNumber ) const
    {
    {
        unsigned int power = 1;
        unsigned int power = 1;


Loading