Deallocating Vertex/Index Arrays

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Riktovitch
Posts: 15
Joined: Tue Mar 05, 2013 12:36 am

Deallocating Vertex/Index Arrays

Post by Riktovitch »

Hi,

I was wondering if it's possible to move the vertices and indices into the GPU and then remove it from memory locally.
You probably know that in OpenGL you can, for example, do this:

Code: Select all

Vertex *vertices = new Vertex[147456];
 
// Generate vertices ...
 
glBindBuffer(...)
glBufferData(...)
 
delete[] vertices;
So the data remains on the GPU and you can render like normal, without having two copies of the data unnecessarily.

Code: Select all

#include <irrlicht/irrlicht.h>
 
int main()
{
    irr::IrrlichtDevice *device = irr::createDevice(irr::video::E_DRIVER_TYPE::EDT_OPENGL, irr::core::dimension2du(1280, 720), 32U, false, false, false, 0);
 
    if (device)
    {
        device->setResizable(true);
 
        irr::video::IVideoDriver *driver = device->getVideoDriver();
 
        irr::scene::CDynamicMeshBuffer *buffer = new irr::scene::CDynamicMeshBuffer(irr::video::E_VERTEX_TYPE::EVT_STANDARD, irr::video::E_INDEX_TYPE::EIT_16BIT);
 
        buffer->Material.Lighting = false;
        buffer->Material.UseMipMaps = false;
        buffer->Material.BackfaceCulling = true;
        buffer->Material.TextureLayer[0].BilinearFilter = false;
        buffer->Material.TextureLayer[0].AnisotropicFilter = 16;
 
        {
            irr::core::rectf uv(0.0f, 0.0f, 1.0f, 1.0f);
            irr::scene::IVertexBuffer &vertices = buffer->getVertexBuffer();
            irr::scene::IIndexBuffer &indices = buffer->getIndexBuffer();
 
            vertices.push_back(irr::video::S3DVertex(-1, 1, 0, 0, 0, 0, irr::video::SColor(255, 255, 255, 255), uv.UpperLeftCorner.X, uv.UpperLeftCorner.Y));
            vertices.push_back(irr::video::S3DVertex(1, 1, 0, 0, 0, 0, irr::video::SColor(255, 255, 255, 255), uv.LowerRightCorner.X, uv.UpperLeftCorner.Y));
            vertices.push_back(irr::video::S3DVertex(-1, -1, 0, 0, 0, 0, irr::video::SColor(255, 255, 255, 255), uv.UpperLeftCorner.X, uv.LowerRightCorner.Y));
 
            vertices.push_back(irr::video::S3DVertex(1, 1, 0, 0, 0, 0, irr::video::SColor(255, 255, 255, 255), uv.LowerRightCorner.X, uv.UpperLeftCorner.Y));
            vertices.push_back(irr::video::S3DVertex(1, -1, 0, 0, 0, 0, irr::video::SColor(255, 255, 255, 255), uv.LowerRightCorner.X, uv.LowerRightCorner.Y));
            vertices.push_back(irr::video::S3DVertex(-1, -1, 0, 0, 0, 0, irr::video::SColor(255, 255, 255, 255), uv.UpperLeftCorner.X, uv.LowerRightCorner.Y));
 
            indices.push_back(0);
            indices.push_back(1);
            indices.push_back(2);
            indices.push_back(3);
            indices.push_back(4);
            indices.push_back(5);
        }
 
        while (device->run())
        {
            driver->beginScene();
 
            irr::core::matrix4 matrix;
 
            matrix.setScale(irr::core::vector3df(0.5f, 0.5f, 0.5f));
 
            driver->setTransform(irr::video::E_TRANSFORMATION_STATE::ETS_WORLD, matrix);
            driver->setMaterial(buffer->Material);
            driver->drawMeshBuffer(buffer);
 
            driver->endScene();
        }
    }
}
Replies are very much appreciated, thanks.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Deallocating Vertex/Index Arrays

Post by hendu »

No, irr doesn't allow that, as to keep the abstraction of how to send them over.

FYI, in most cases the driver will still keep a copy, so you're talking 1x gpu + 1x ram vs 1x gpu + 2x ram.
Post Reply