shader-pipeline: How to append to a CVertexBuffer

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
afuzzyllama
Posts: 13
Joined: Thu Oct 10, 2013 2:20 am
Location: Tampa, FL

shader-pipeline: How to append to a CVertexBuffer

Post by afuzzyllama »

I'm using the shader-pipeline branch and I've setup a vertex descriptor in my driver.

My descriptor looks like this:

Code: Select all

 
driver->getVertexDescriptor("custom")->addAttribute("inPosition", 3, irr::video::EVAS_POSITION, irr::video::EVAT_FLOAT);
driver->getVertexDescriptor("custom")->addAttribute("inNormal", 3, irr::video::EVAS_NORMAL, irr::video::EVAT_FLOAT);
driver->getVertexDescriptor("custom")->addAttribute("inColor", 4, irr::video::EVAS_COLOR, irr::video::EVAT_UBYTE);
driver->getVertexDescriptor("custom")->addAttribute("inTexCoord0", 2, irr::video::EVAS_TEXCOORD0, irr::video::EVAT_FLOAT);
driver->getVertexDescriptor("custom")->addAttribute("inCustom", 3, irr::video::EVAS_CUSTOM, irr::video::EVAT_FLOAT);
 
If I want to create a CVertexBuffer and append a vertex like this. There are two functions to do so:

Code: Select all

 
void addVertex(const T& vertex)
void addVertex(const void* vertex)
 
The template for me is irr::s32. I'm assuming I need to use the second function call. Is there a good example of how to do this in the code base or online?
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: shader-pipeline: How to append to a CVertexBuffer

Post by Nadro »

You can check how to add new vertices in loaders eg: CB3DMeshFileLoader.cpp:

Code: Select all

MeshBuffer->getVertexBuffer()->addVertex(&YourVertex);
Anyway you don't have to add vertex one by one. If you loaded mesh from a file, you can convert vertices format in this way:

Code: Select all

MeshManipulator->convertVertices<YourNewVertex>(MeshBuffer, VertexDescriptorRelatedToYourNewVertex, falseOrTrue);
When you have converted mesh you need to apply new values to new vertex attributes (at now one by one vertex).

BTW. You can't use just irr::s32 as specialisation in this case (vertex descriptor say that your vertex structure has more than one s32 value inside). Check S3DVertex.h how to define properly vertex format. In your example you should define following vertex structure:

Code: Select all

struct YourNewVertex
{
core::vector3df Pos; // inPosition
core::vector3df Normal; // inNormal
SColor Color; // inColor
core::vector2d<f32> TCoords; // inTexCoord0
core::vector3df Custom; // inCustom
};
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
afuzzyllama
Posts: 13
Joined: Thu Oct 10, 2013 2:20 am
Location: Tampa, FL

Re: shader-pipeline: How to append to a CVertexBuffer

Post by afuzzyllama »

Looking at your example, this makes sense. Thanks!
Post Reply