Texture::Texture( const Surface32f &surface, Format format ) : mObj( shared_ptr<Obj>( new Obj( surface.getWidth(), surface.getHeight() ) ) ) { if( format.mInternalFormat < 0 ) { #if ! defined( CINDER_GLES ) if( GLEE_ARB_texture_float ) format.mInternalFormat = surface.hasAlpha() ? GL_RGBA32F_ARB : GL_RGB32F_ARB; else format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB; #else format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB; #endif } mObj->mInternalFormat = format.mInternalFormat; mObj->mTarget = format.mTarget; init( surface.getData(), surface.hasAlpha()?GL_RGBA:GL_RGB, format ); }
Texture::Texture( const Surface32f &surface, Format format ) : mObj( shared_ptr<Obj>( new Obj( surface.getWidth(), surface.getHeight() ) ) ) { #if defined( CINDER_MAC ) bool supportsTextureFloat = gl::isExtensionAvailable( "GL_ARB_texture_float" ); #elif defined( CINDER_MSW ) bool supportsTextureFloat = GLEE_ARB_texture_float != 0; #endif if( format.mInternalFormat < 0 ) { #if ! defined( CINDER_GLES ) if( supportsTextureFloat ) format.mInternalFormat = surface.hasAlpha() ? GL_RGBA32F_ARB : GL_RGB32F_ARB; else format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB; #else format.mInternalFormat = surface.hasAlpha() ? GL_RGBA : GL_RGB; #endif } mObj->mInternalFormat = format.mInternalFormat; mObj->mTarget = format.mTarget; init( surface.getData(), surface.hasAlpha()?GL_RGBA:GL_RGB, format ); }
void fsExperiments::setupVbo() { GlobalData& data = GlobalData::get(); TriMesh neutralMesh = data.mFaceShift.getNeutralMesh(); size_t numVertices = neutralMesh.getNumVertices(); size_t numBlendShapes = data.mFaceShift.getNumBlendshapes(); gl::VboMesh::Layout layout; layout.setStaticPositions(); layout.setStaticIndices(); layout.setStaticNormals(); layout.setStaticTexCoords2d(); // TODO: int attribute layout.mCustomStatic.push_back( std::make_pair( gl::VboMesh::Layout::CUSTOM_ATTR_FLOAT, 0 ) ); data.mVboMesh = gl::VboMesh( neutralMesh.getNumVertices(), neutralMesh.getNumIndices(), layout, GL_TRIANGLES ); data.mVboMesh.bufferPositions( neutralMesh.getVertices() ); data.mVboMesh.bufferIndices( neutralMesh.getIndices() ); if ( !neutralMesh.hasNormals() ) neutralMesh.recalculateNormals(); data.mVboMesh.bufferNormals( neutralMesh.getNormals() ); data.mVboMesh.bufferTexCoords2d( 0, neutralMesh.getTexCoords() ); data.mVboMesh.unbindBuffers(); vector< float > vertexIndices( numVertices, 0.f ); for ( uint32_t i = 0; i < numVertices; ++i ) vertexIndices[ i ] = static_cast< float >( i ); data.mVboMesh.getStaticVbo().bind(); size_t offset = sizeof( GLfloat ) * ( 3 + 3 + 2 ) * neutralMesh.getNumVertices(); data.mVboMesh.getStaticVbo().bufferSubData( offset, numVertices * sizeof( float ), &vertexIndices[ 0 ] ); data.mVboMesh.getStaticVbo().unbind(); // blendshapes texture gl::Texture::Format format; format.setTargetRect(); format.setWrap( GL_CLAMP, GL_CLAMP ); format.setMinFilter( GL_NEAREST ); format.setMagFilter( GL_NEAREST ); format.setInternalFormat( GL_RGB32F_ARB ); int verticesPerRow = 32; int txtWidth = verticesPerRow * numBlendShapes; int txtHeight = math< float >::ceil( numVertices / (float)verticesPerRow ); Surface32f blendshapeSurface = Surface32f( txtWidth, txtHeight, false ); float *ptr = blendshapeSurface.getData(); size_t idx = 0; for ( int j = 0; j < txtHeight; j++ ) { for ( int s = 0; s < verticesPerRow; s++ ) { for ( size_t i = 0; i < numBlendShapes; i++ ) { *( reinterpret_cast< Vec3f * >( ptr ) ) = data.mFaceShift.getBlendshapeMesh( i ).getVertices()[ idx ] - neutralMesh.getVertices()[ idx ]; ptr += 3; } idx++; } } data.mBlendshapeTexture = gl::Texture( blendshapeSurface, format ); }