Commit 4b3df7ca authored by Jan Möbius's avatar Jan Möbius
Browse files

per vertex 2D texcoords (working but problem with update directly after switching)

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8459 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0b4b6f79
......@@ -79,6 +79,7 @@ TriStripNodeT(Mesh& _mesh,
enableColors_(true),
colorVertexbuffer_(0),
colorVertexBufferInitialized_(false),
enableTexCoords_(true),
lineIndexBuffer_(0),
lineIndexBufferInitialized_(false),
enabled_arrays_(0),
......@@ -173,6 +174,13 @@ availableDrawModes() const {
drawModes |= DrawModes::SOLID_FACES_COLORED_FLAT_SHADED;
}
if ( mesh_.has_vertex_texcoords2D() ) {
drawModes |= DrawModes::SOLID_TEXTURED;
// if (mesh_.has_vertex_normals())
// drawModes |= DrawModes::SOLID_TEXTURED_SHADED;
}
return drawModes;
}
......@@ -344,6 +352,19 @@ draw(GLState& _state, unsigned int _drawMode) {
}
if ( ( _drawMode & DrawModes::SOLID_TEXTURED ) && mesh_.has_vertex_texcoords2D())
{
///\todo enableTexCoords_
enable_arrays(VERTEX_ARRAY | TEXCOORD_VERTEX_ARRAY );
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glShadeModel(GL_FLAT);
glDepthRange(0.01, 1.0);
draw_faces(PER_VERTEX);
glDepthRange(0.0, 1.0);
glDisable(GL_TEXTURE_2D);
}
enable_arrays(0);
// Unbind all remaining buffers
......@@ -393,6 +414,8 @@ TriStripNodeT<Mesh>::
draw_faces(FaceMode _mode) {
if ( stripProcessor_.isValid() ) {
// If we have all properties per Vertex, we can render with index array from triangle strips!
if (_mode == PER_VERTEX) {
typename StripProcessorT<Mesh>::StripsIterator strip_it = stripProcessor_.begin();
typename StripProcessorT<Mesh>::StripsIterator strip_last = stripProcessor_.end();
......@@ -404,6 +427,7 @@ draw_faces(FaceMode _mode) {
&(strip_it->indexArray)[0] );
}
} else if ( _mode == PER_FACE ) {
// We need per face attributes so we have to use seperate vertices per face
glDrawArrays(GL_TRIANGLES, 0, stripProcessor_.perFaceVertexBufferSize() );
}
......@@ -504,6 +528,31 @@ enable_arrays(unsigned int _arrays) {
glDisableClientState(GL_COLOR_ARRAY);
}
//===================================================================
// per Vertex Texture coordinate Array
//===================================================================
// Check if we should enable the color array
if ( mesh_.has_vertex_texcoords2D() && ( _arrays & TEXCOORD_VERTEX_ARRAY )) {
// Check if its already enabled
if (!(enabled_arrays_ & TEXCOORD_VERTEX_ARRAY)) {
enabled_arrays_ |= TEXCOORD_VERTEX_ARRAY;
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
// Explicitly give the pointer as we uploaded the data ourself!
glTexCoordPointer(2, GL_FLOAT , 0 , mesh_.texcoords2D() );
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
} else if (enabled_arrays_ & TEXCOORD_VERTEX_ARRAY) {
// Disable TexCoord array
enabled_arrays_ &= ~TEXCOORD_VERTEX_ARRAY;
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
//===================================================================
// per Edge Vertex Array
//===================================================================
......@@ -1182,7 +1231,7 @@ update_geometry() {
}
}
// ==========================================================================
// unbind all buffers
// ==========================================================================
......
......@@ -246,6 +246,23 @@ private:
std::vector< ACG::Vec4f > colors_;
/** @} */
//===========================================================================
/** @name Texcoord buffer
* @{ */
//===========================================================================
public:
/// Returns if the per vertex Texture coordinates array is currently activated
bool texCoordEnabled() { return enableTexCoords_; };
/// Enable or disable the use of the per vertex Texture coordinates array
void enableTexCoords(bool _enable) { enableTexCoords_ = _enable; };
private:
bool enableTexCoords_;
/** @} */
//===========================================================================
/** @name Line buffer
......@@ -280,16 +297,18 @@ private:
/// Enum controlling which array should be used for rendering
enum ArrayType
{
NONE = 0,
VERTEX_ARRAY = 1,
NORMAL_VERTEX_ARRAY = 2,
COLOR_VERTEX_ARRAY = 4,
LINE_INDEX_ARRAY = 8,
PER_EDGE_VERTEX_ARRAY = 16,
PER_EDGE_COLOR_ARRAY = 32,
PER_FACE_VERTEX_ARRAY = 64,
PER_FACE_NORMAL_ARRAY = 128,
PER_FACE_COLOR_ARRAY = 256
NONE = 0,
VERTEX_ARRAY = 1,
NORMAL_VERTEX_ARRAY = 2,
COLOR_VERTEX_ARRAY = 4,
TEXCOORD_VERTEX_ARRAY = 8,
LINE_INDEX_ARRAY = 16,
PER_EDGE_VERTEX_ARRAY = 32,
PER_EDGE_COLOR_ARRAY = 64,
PER_FACE_VERTEX_ARRAY = 128,
PER_FACE_NORMAL_ARRAY = 256,
PER_FACE_COLOR_ARRAY = 512,
PER_FACE_TEXCOORD_ARRAY = 1024
};
/// which arrays are currently enabled?
......
......@@ -120,14 +120,6 @@ availableDrawModes() const
drawModes |= DrawModes::SOLID_1DTEXTURED_SHADED;
}
if (mesh_.has_vertex_texcoords2D())
{
drawModes |= DrawModes::SOLID_TEXTURED;
if (mesh_.has_vertex_normals())
drawModes |= DrawModes::SOLID_TEXTURED_SHADED;
}
if (mesh_.has_vertex_texcoords3D())
{
drawModes |= DrawModes::SOLID_3DTEXTURED;
......@@ -218,10 +210,6 @@ draw(GLState& _state, unsigned int _drawMode)
{
glDepthFunc(depthFunc());
// if ( ( _drawMode & DrawModes::SOLID_SMOOTH_SHADED ) && mesh_.has_vertex_normals())
// if ( ( _drawMode & DrawModes::SOLID_PHONG_SHADED ) && mesh_.has_vertex_normals() )
if ( ( _drawMode & DrawModes::SOLID_ENV_MAPPED ) && mesh_.has_vertex_normals())
{
enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
......@@ -232,19 +220,6 @@ draw(GLState& _state, unsigned int _drawMode)
glDepthRange(0.0, 1.0);
}
if ( ( _drawMode & DrawModes::SOLID_TEXTURED ) && mesh_.has_vertex_texcoords2D())
{
enable_arrays(VERTEX_ARRAY | TEXTURE_COORD_2D_ARRAY);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glShadeModel(GL_FLAT);
glDepthRange(0.01, 1.0);
draw_faces(PER_VERTEX);
glDepthRange(0.0, 1.0);
glDisable(GL_TEXTURE_2D);
}
if ( ( _drawMode & DrawModes::SOLID_TEXTURED_SHADED ) && mesh_.has_vertex_texcoords2D() && mesh_.has_vertex_normals())
{
enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY | TEXTURE_COORD_2D_ARRAY);
......
Supports Markdown
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