瀏覽代碼

gpu: start implementing a vertex buffer object.

legacy
Sam Hocevar sam 13 年之前
父節點
當前提交
11fb586a20
共有 4 個檔案被更改,包括 147 行新增0 行删除
  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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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__


Loading…
取消
儲存