Convert code to Irrlicht

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
tinhtoitrangtay
Posts: 70
Joined: Tue Oct 28, 2008 12:59 pm

Convert code to Irrlicht

Post by tinhtoitrangtay »

struct IDirect3DDevice9;
struct IDirect3DVertexBuffer9;

class DirectXVertexBuffer : public IVertexBuffer
{
public:
DirectXVertexBuffer(IDirect3DDevice9* _device, DirectXRenderManager* _pRenderManager);
virtual ~DirectXVertexBuffer();

virtual void setVertexCount(size_t _count);
virtual size_t getVertexCount();

virtual Vertex* lock();
virtual void unlock();

/*internal:*/
virtual bool setToStream(size_t stream);

private:
bool create();
void destroy();
void resize();

private:
IDirect3DDevice9* mpD3DDevice;
IDirect3DVertexBuffer9* mpBuffer;
DirectXRenderManager* pRenderManager;

size_t mVertexCount;
size_t mNeedVertexCount;
};
#include <d3d9.h>

const size_t VERTEX_IN_QUAD = 6;
const size_t RENDER_ITEM_STEEP_REALLOCK = 5 * VERTEX_IN_QUAD;

DirectXVertexBuffer::DirectXVertexBuffer(IDirect3DDevice9* _device, DirectXRenderManager* _pRenderManager) :
mNeedVertexCount(0),
mVertexCount(RENDER_ITEM_STEEP_REALLOCK),
mpD3DDevice(_device),
pRenderManager(_pRenderManager),
mpBuffer(NULL)
{
}

DirectXVertexBuffer::~DirectXVertexBuffer()
{
destroy();
}

void DirectXVertexBuffer::setVertexCount(size_t _count)
{
if (_count != mNeedVertexCount)
{
mNeedVertexCount = _count;
resize();
}
}

size_t DirectXVertexBuffer::getVertexCount()
{
return mNeedVertexCount;
}

Vertex* DirectXVertexBuffer::lock()
{
//assert(!mpBuffer && __FUNCTION__);
void* lockPtr = nullptr;
if (SUCCEEDED(mpBuffer->Lock(0, 0, (void**)&lockPtr, 0)))
{
return (Vertex*)lockPtr;
}
return nullptr;
}

void DirectXVertexBuffer::unlock()
{
//assert(!mpBuffer && __FUNCTION__);
if (FAILED(mpBuffer->Unlock()))
{
//exception
}
}

bool DirectXVertexBuffer::setToStream(size_t stream)
{
//assert(!mpBuffer && __FUNCTION__);
if (SUCCEEDED(mpD3DDevice->SetStreamSource(stream, mpBuffer, 0, sizeof(MyGUI::Vertex))))
return true;
return false;
}

bool DirectXVertexBuffer::create()
{
DWORD length = mNeedVertexCount * sizeof(MyGUI::Vertex);
if (SUCCEEDED(mpD3DDevice->CreateVertexBuffer(length, 0, 0, D3DPOOL_MANAGED, &mpBuffer, nullptr)))
return false;
return false;
}

void DirectXVertexBuffer::destroy()
{
if (mpBuffer)
{
mpBuffer->Release();
mpBuffer = nullptr;
}
}

void DirectXVertexBuffer::resize()
{
if (mpD3DDevice)
{
destroy();
create();
}
}
Please help me convert code to Irrlicht. Thanks
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: Convert code to Irrlicht

Post by Radikalizm »

So basically you're asking someone to write code for you? I'd say figure it out yourself, that's what programming is all about, if you can't do that you should practice and learn some more
Don't be lazy
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Convert code to Irrlicht

Post by hybrid »

Just vertices? Simply create an SMesh containing an SMeshBuffer, add the vertices to mb->Vertices, add a trivial index list (or a better one, depending on your needs), set hwmappinghint of the buffer to static or whatever you want. If you need to change the vertex buffer, you have to change the vertex array and call setDirty on the mesh/buffer. I don't think that anything else happens here.
Post Reply