Procházet zdrojové kódy

gpu: start implementing a vertex buffer object.

legacy
Sam Hocevar sam před 13 roky
rodič
revize
11fb586a20
4 změnil soubory, kde provedl 147 přidání a 0 odebrání
  1. +1
    -0
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +100
    -0
      src/gpu/vbo.cpp
  4. +45
    -0
      src/gpu/vbo.h

+ 1
- 0
src/Makefile.am Zobrazit soubor

@@ -22,6 +22,7 @@ liblol_a_SOURCES = \
$(sdl_sources) \
\
shader/shader.cpp shader/shader.h \
gpu/vbo.cpp gpu/vbo.h \
\
image/image.cpp image/image.h image/image-private.h \
image/codec/android-image.cpp \


+ 1
- 0
src/core.h Zobrazit soubor

@@ -96,6 +96,7 @@ static inline int isnan(float f)
#include "dict.h"
#include "map.h"
#include "layer.h"
#include "gpu/vbo.h"
#include "shader/shader.h"
#include "image/image.h"
#include "application/application.h"


+ 100
- 0
src/gpu/vbo.cpp Zobrazit soubor

@@ -0,0 +1,100 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include "core.h"
#include "lolgl.h"
#include "gpu/vbo.h"

using namespace std;

namespace lol
{

/*
* GpuVbo implementation class
*/

class GpuVboData
{
friend class GpuVbo;

size_t elemsize, elemcount;
uint8_t *alloc_buffer;

static size_t const GPU_ALIGN = 128;
};

/*
* Public GpuVbo class
*/

GpuVbo::GpuVbo()
: data(new GpuVboData())
{
data->elemsize = 0;
data->elemcount = 0;
data->alloc_buffer = 0;
}

void GpuVbo::SetSize(size_t elemsize, size_t elemcount)
{
size_t oldsize = data->elemsize * data->elemcount;
size_t newsize = elemsize * elemcount;

if (newsize == oldsize)
return;

if (oldsize)
delete[] data->alloc_buffer;
data->alloc_buffer = NULL;
if (newsize)
data->alloc_buffer = new uint8_t[newsize + GpuVboData::GPU_ALIGN - 1];

data->elemsize = elemsize;
data->elemcount = elemcount;
}

size_t GpuVbo::GetSize()
{
return data->elemsize * data->elemcount;
}

uint8_t *GpuVbo::GetData()
{
return (uint8_t *)(((uintptr_t)data->alloc_buffer)
& ~((uintptr_t)GpuVboData::GPU_ALIGN - 1));
}

uint8_t const *GpuVbo::GetData() const
{
return (uint8_t const *)(((uintptr_t)data->alloc_buffer)
& ~((uintptr_t)GpuVboData::GPU_ALIGN - 1));
}

void GpuVbo::Bind()
{
}

void GpuVbo::Unbind()
{
}

GpuVbo::~GpuVbo()
{
delete[] data->alloc_buffer;
delete data;
}

} /* namespace lol */


+ 45
- 0
src/gpu/vbo.h Zobrazit soubor

@@ -0,0 +1,45 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

//
// The GpuVbo class
// ----------------
//

#if !defined __LOL_VBO_H__
#define __LOL_VBO_H__

namespace lol
{

class GpuVboData;

class GpuVbo
{
public:
GpuVbo();
~GpuVbo();

void SetSize(size_t elemsize, size_t elemcount);
size_t GetSize();
uint8_t *GetData();
uint8_t const *GetData() const;

void Bind();
void Unbind();

private:
GpuVboData *data;
};

} /* namespace lol */

#endif // __LOL_VBO_H__


Načítá se…
Zrušit
Uložit