Commit 7eff637c authored by Jan Möbius's avatar Jan Möbius
Browse files

Added per face per vertex normal buffer

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9873 383ad7c9-94d9-4d36-a494-682f7c89f535
parent a6a0d7e6
......@@ -429,11 +429,11 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
if ( ( _drawMode & DrawModes::SOLID_2DTEXTURED_FACE_SHADED ) && mesh_.has_face_normals())
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
enable_arrays( PER_FACE_VERTEX_ARRAY | PER_FACE_TEXCOORD_ARRAY | PER_FACE_NORMAL_ARRAY );
glShadeModel(GL_FLAT);
enable_arrays( PER_FACE_VERTEX_ARRAY | PER_FACE_TEXCOORD_ARRAY | PER_FACE_PER_VERTEX_NORMAL_ARRAY );
glEnable(GL_LIGHTING);
glShadeModel(GL_SMOOTH);
glDepthRange(0.01, 1.0);
draw_faces(PER_FACE);
glDepthRange(0.0, 1.0);
......@@ -744,6 +744,30 @@ enable_arrays(unsigned int _arrays) {
glDisableClientState(GL_NORMAL_ARRAY);
}
//===================================================================
// per Face per vertex normal array
//===================================================================
// Check if we should enable the per face normal array
if (mesh_.has_vertex_normals() && (_arrays & PER_FACE_PER_VERTEX_NORMAL_ARRAY) ) {
// Check if its already enabled
if (!(enabled_arrays_ & PER_FACE_PER_VERTEX_NORMAL_ARRAY)) {
enabled_arrays_ |= PER_FACE_PER_VERTEX_NORMAL_ARRAY;
// For this version we load the colors directly not from vbo
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glNormalPointer( stripProcessor_.perFacePerVertexNormalBuffer() );
glEnableClientState(GL_NORMAL_ARRAY);
}
} else if (enabled_arrays_ & PER_FACE_PER_VERTEX_NORMAL_ARRAY) {
// Disable Normal array
enabled_arrays_ &= ~PER_FACE_PER_VERTEX_NORMAL_ARRAY;
glDisableClientState(GL_NORMAL_ARRAY);
}
//===================================================================
// per Face Color Array
//===================================================================
......
......@@ -308,18 +308,19 @@ 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,
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
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_PER_VERTEX_NORMAL_ARRAY = 512,
PER_FACE_COLOR_ARRAY = 1024,
PER_FACE_TEXCOORD_ARRAY = 2048
};
/// which arrays are currently enabled?
......
......@@ -820,6 +820,11 @@ updatePerFaceBuffers() {
else
perFaceNormalBuffer_.clear();
if ( mesh_.has_vertex_normals() )
perFacePerVertexNormalBuffer_.resize(n_faces * 3);
else
perFacePerVertexNormalBuffer_.clear();
if ( mesh_.has_face_colors() )
perFaceColorBuffer_.resize(n_faces * 3);
else
......@@ -868,13 +873,21 @@ updatePerFaceBuffers() {
perFaceColorBuffer_[ bufferIndex + 1 ] = color;
perFaceColorBuffer_[ bufferIndex + 2 ] = color;
}
if ( swap ) {
// Cant render triangle strips as we need one color per face and this means duplicating vertices
perFaceVertexBuffer_[ bufferIndex + 0 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
perFaceVertexBuffer_[ bufferIndex + 1 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
perFaceVertexBuffer_[ bufferIndex + 2 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
// Get the normals of all vertices at this face
if ( mesh_.has_vertex_normals() ) {
perFacePerVertexNormalBuffer_[ bufferIndex + 0 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
perFacePerVertexNormalBuffer_[ bufferIndex + 1 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
perFacePerVertexNormalBuffer_[ bufferIndex + 2 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
}
if ( usePerFaceTextureCoordinateProperty ) {
typename Mesh::ConstFaceHalfedgeIter fhe_it(mesh_.cfh_iter(strips_[ i ].faceMap[ stripIndex ]));
......@@ -903,6 +916,13 @@ updatePerFaceBuffers() {
perFaceVertexBuffer_[ bufferIndex + 1 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
perFaceVertexBuffer_[ bufferIndex + 0 ] = mesh_.point(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
// Get the normals of all vertices at this face
if ( mesh_.has_vertex_normals() ) {
perFacePerVertexNormalBuffer_[ bufferIndex + 2 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 2 ] ));
perFacePerVertexNormalBuffer_[ bufferIndex + 1 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 1 ] ));
perFacePerVertexNormalBuffer_[ bufferIndex + 0 ] = mesh_.normal(mesh_.vertex_handle( strips_[ i ].indexArray[ stripIndex - 0 ] ));
}
if ( usePerFaceTextureCoordinateProperty ) {
typename Mesh::ConstFaceHalfedgeIter fhe_it(mesh_.cfh_iter(strips_[ i ].faceMap[ stripIndex ]));
......@@ -958,6 +978,17 @@ perFaceNormalBuffer() {
return &(perFaceNormalBuffer_)[0];
};
template <class Mesh>
ACG::Vec3f *
StripProcessorT<Mesh>::
perFacePerVertexNormalBuffer() {
// Force update of the buffers if required
if (updatePerFaceBuffers_)
updatePerFaceBuffers();
return &(perFacePerVertexNormalBuffer_)[0];
};
template <class Mesh>
ACG::Vec4f *
StripProcessorT<Mesh>::
......
......@@ -275,10 +275,18 @@ public:
*
* This function will return a pointer to the first element of the per face normal buffer.
* Use updatePerFaceBuffers to update the buffer before you render it via
* glColorPointer. The buffer contains 3 equal normals per face.
* glNormalPointer. The buffer contains 3 equal normals per face.
*/
ACG::Vec3f * perFaceNormalBuffer();
/** \brief get a pointer to the per face per vertex normal buffer
*
* This function will return a pointer to the first element of the per face per vertex normal buffer.
* Use updatePerFaceBuffers to update the buffer before you render it via
* glNormalPointer. The buffer contains 3 equal normals per face.
*/
ACG::Vec3f * perFacePerVertexNormalBuffer();
/** \brief get a pointer to the per face color buffer
*
* This function will return a pointer to the first element of the per face color buffer.
......@@ -309,6 +317,7 @@ private:
std::vector< ACG::Vec3f > perFaceVertexBuffer_;
std::vector< ACG::Vec4f > perFaceColorBuffer_;
std::vector< ACG::Vec3f > perFaceNormalBuffer_;
std::vector< ACG::Vec3f > perFacePerVertexNormalBuffer_;
/// This flag controls if an update is really necessary
bool updatePerFaceBuffers_;
......
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