Commit 378f6664 authored by Christopher Tenter's avatar Christopher Tenter

- const correctness

- toString()

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15770 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ee338c14
......@@ -46,6 +46,7 @@
#include <assert.h>
#include <iostream>
#include <QTextStream>
#include "VertexDeclaration.hh"
......@@ -99,10 +100,22 @@ void VertexDeclaration::addElements(unsigned int _numElements, const VertexEleme
elements_.push_back(tmp);
}
updateOffsets();
if (!strideUserDefined_)
vertexStride_ = 0; // because of new elements, stride must be recomputed
{
// recompute vertex stride from declaration (based on last element)
unsigned int n = getNumElements();
if (n)
{
const VertexElement* pLastElement = getElement(n-1);
vertexStride_ = pLastElement->byteOffset_ + getElementSize( pLastElement );
}
}
updateOffsets();
}
......@@ -252,7 +265,7 @@ void VertexDeclaration::activateFixedFunction()
void VertexDeclaration::activateShaderPipeline(GLSL::Program* _prog)
void VertexDeclaration::activateShaderPipeline(GLSL::Program* _prog) const
{
// setup correct attribute locations as specified
......@@ -301,28 +314,14 @@ void VertexDeclaration::deactivateShaderPipeline( GLSL::Program* _prog ) const
const VertexElement* VertexDeclaration::getElement(unsigned int i)
const VertexElement* VertexDeclaration::getElement(unsigned int i) const
{
return &elements_[i];
}
unsigned int VertexDeclaration::getVertexStride()
unsigned int VertexDeclaration::getVertexStride() const
{
if (!strideUserDefined_ && !vertexStride_)
{
// compute vertex stride from declaration
unsigned int n = getNumElements();
if (n)
{
const VertexElement* pLastElement = getElement(n-1);
vertexStride_ = pLastElement->byteOffset_ + getElementSize( pLastElement );
}
}
return vertexStride_;
}
......@@ -341,6 +340,62 @@ void VertexDeclaration::clear()
elements_.clear();
}
QString VertexDeclaration::toString() const
{
// maps VERTEX_USAGE -> string
const char* usageStrings[] =
{
"POSITION",
"NORMAL",
"TEXCOORD",
"COLOR",
"BLENDWEIGHTS",
"BLENDINDICES"
};
QString result;
QTextStream resultStrm(&result);
resultStrm << "stride = " << getVertexStride() << "\n";
for (unsigned int i = 0; i < getNumElements(); ++i)
{
const VertexElement* el = getElement(i);
// convert element-type GLEnum to string
const char* typeString = "";
switch (el->type_)
{
case GL_FLOAT: typeString = "GL_FLOAT"; break;
case GL_DOUBLE: typeString = "GL_DOUBLE"; break;
case GL_INT: typeString = "GL_INT"; break;
case GL_UNSIGNED_INT: typeString = "GL_UNSIGNED_INT"; break;
case GL_SHORT: typeString = "GL_SHORT"; break;
case GL_UNSIGNED_SHORT: typeString = "GL_UNSIGNED_SHORT"; break;
case GL_BYTE: typeString = "GL_BYTE"; break;
case GL_UNSIGNED_BYTE: typeString = "GL_UNSIGNED_BYTE"; break;
default: typeString = "unknown"; break;
}
// get usage in string form
const char* usage = (el->usage_ < VERTEX_USAGE_SHADER_INPUT) ? usageStrings[el->usage_] : el->shaderInputName_;
resultStrm << "element " << i
<< " - [type: " << usage
<< ", count: " << el->numElements_
<< ", usage: " << usage
<< ", offset: " << el->byteOffset_ << "]\n";
}
return result;
}
//=============================================================================
} // namespace ACG
//=============================================================================
......@@ -46,6 +46,7 @@
#include <vector>
#include <list>
#include <QString>
#include <ACG/Config/ACGDefines.hh>
namespace GLSL
......@@ -213,7 +214,7 @@ public:
/*! prepare OpenGL to use a vertex buffer with this declaration
-> uses shader attribute pointers ( glVertexAttribPointer )
*/
void activateShaderPipeline(GLSL::Program* _prog);
void activateShaderPipeline(GLSL::Program* _prog) const;
/*! disables this vertex declaration to prevent any draw related crashes
......@@ -229,7 +230,7 @@ public:
/*! get vertex size
*/
unsigned int getVertexStride();
unsigned int getVertexStride() const;
/*! get num of vertex elements
*/
......@@ -237,7 +238,7 @@ public:
/*! get the i'th vertex element desc
*/
const VertexElement* getElement(unsigned int i);
const VertexElement* getElement(unsigned int i) const;
/*! get size of GL_FLOAT, GL_INT ...
*/
......@@ -247,6 +248,11 @@ public:
*/
static unsigned int getElementSize(const VertexElement* _pElement);
/*! Returns a string describing the vertex format for debugging purpose.
*/
QString toString() const;
private:
/*!
......
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