Sign in to follow this  

VertexBuffer!! arfgh!!!

This topic is 4580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

They aren't being drawn. Can anyone find the problem in the code? They are created using:
VertexBuffer *RenderWindow::CreateVertexBuffer( const string &name, long numVerts,
    long vertSize, DWORD descriptor )
  {
    VertexBuffer           *buffer;
    IDirect3DVertexBuffer8 *vertexBuffer;
    
    if ( FAILED( mDevice->CreateVertexBuffer( vertSize * numVerts, NULL, descriptor, 
      D3DPOOL_MANAGED, &vertexBuffer ) ) )
    {
      return NULL;
    }
    
    
    try
    {
      buffer = new VertexBuffer( name, numVerts, vertSize, descriptor, vertexBuffer );
    }
    catch( ... )
    {
      delete buffer;
      
      return NULL;
    }
    
    buffer->AddNode( VertexBuffer::mRoot );
    
    return buffer;
  }
Rendered using:
void RenderWindow::RenderVertexBuffer( VertexBuffer *buffer, int firstVertex, int numTris )
  {
    mDevice->SetStreamSource( 0, buffer->mBuffer, buffer->mVertSize );
    mDevice->SetVertexShader( buffer->mFVF );
    
    mDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, firstVertex, numTris );
  }
And manipulated using:
VertexBuffer::VertexBuffer( const string &value, long numVerts, long vertSize, 
    DWORD descriptor, IDirect3DVertexBuffer8 *vb ) : Node( value ), mNumVerts( numVerts ), 
    mVertSize( vertSize ), mFVF( descriptor ), mDataPtr( NULL ), mBuffer( vb )
  {
    
  }
  
  
  VertexBuffer::~VertexBuffer()
  {
    
  }
  
  
  bool VertexBuffer::Lock( int firstVertex )
  {    
    if ( FAILED( mBuffer->Lock( firstVertex * mVertSize, mNumVerts * mVertSize, 
      (BYTE**)&mDataPtr, D3DLOCK_NOSYSLOCK | D3DLOCK_DISCARD ) ) )
    {
      return false;
    }
    
    return true;
  }
  
  
  void VertexBuffer::Unlock()
  {
    mBuffer->Unlock(); 
  }
  
  
  bool VertexBuffer::Fill( int firstVertex, void *data )
  {
    if( !Lock( firstVertex ) )
    {
      return false;
    } 
    
    memcpy( mDataPtr, data, mNumVerts * mVertSize );
    
    Unlock();
    
    return true;
  }

Share this post


Link to post
Share on other sites
The vbuffer is rendered using the following vertex data. No changes have been made to the default D3D settings. (no perspective translations etc...)

Vertex verts[4] = { 
{ 0.0f, 0.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f },
{ 1.0f, 0.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f },
{ 0.0f, 1.0f, 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f } };

Share this post


Link to post
Share on other sites
Hello,

HRESULT SetStreamSource( UINT StreamNumber,
IDirect3DVertexBuffer9 *pStreamData,
UINT OffsetInBytes,
UINT Stride
);

as you can se the third parameter is an offset, you se your fvf size as taht offset, i suggest 0 instead..
hmm maybe i'm wrong, which Dx version do you use?

Share this post


Link to post
Share on other sites
Hi again,

I can't test it out, because my dev-machine currently isn't working, so I can only bet!

In your VertexBuffer-constructor you don't do anything, do you?! If this is the code you use then this might be the problem, because there are no information saved then. So if you write

buffer = new VertexBuffer( name, numVerts, vertSize, descriptor, vertexBuffer );

in your VertexBuffer-creating-function, the information isn't saved in the new buffer.


cu

Share this post


Link to post
Share on other sites

This topic is 4580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this