source: trunk/src/gpu/vbo.cpp @ 1053

Last change on this file since 1053 was 1053, checked in by sam, 10 years ago

gpu: start implementing a vertex buffer object.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "core.h"
16#include "lolgl.h"
17#include "gpu/vbo.h"
18
19using namespace std;
20
21namespace lol
22{
23
24/*
25 * GpuVbo implementation class
26 */
27
28class GpuVboData
29{
30    friend class GpuVbo;
31
32    size_t elemsize, elemcount;
33    uint8_t *alloc_buffer;
34
35    static size_t const GPU_ALIGN = 128;
36};
37
38/*
39 * Public GpuVbo class
40 */
41
42GpuVbo::GpuVbo()
43  : data(new GpuVboData())
44{
45    data->elemsize = 0;
46    data->elemcount = 0;
47    data->alloc_buffer = 0;
48}
49
50void GpuVbo::SetSize(size_t elemsize, size_t elemcount)
51{
52    size_t oldsize = data->elemsize * data->elemcount;
53    size_t newsize = elemsize * elemcount;
54
55    if (newsize == oldsize)
56        return;
57
58    if (oldsize)
59        delete[] data->alloc_buffer;
60    data->alloc_buffer = NULL;
61    if (newsize)
62        data->alloc_buffer = new uint8_t[newsize + GpuVboData::GPU_ALIGN - 1];
63
64    data->elemsize = elemsize;
65    data->elemcount = elemcount;
66}
67
68size_t GpuVbo::GetSize()
69{
70    return data->elemsize * data->elemcount;
71}
72
73uint8_t *GpuVbo::GetData()
74{
75    return (uint8_t *)(((uintptr_t)data->alloc_buffer)
76                        & ~((uintptr_t)GpuVboData::GPU_ALIGN - 1));
77}
78
79uint8_t const *GpuVbo::GetData() const
80{
81    return (uint8_t const *)(((uintptr_t)data->alloc_buffer)
82                              & ~((uintptr_t)GpuVboData::GPU_ALIGN - 1));
83}
84
85void GpuVbo::Bind()
86{
87}
88
89void GpuVbo::Unbind()
90{
91}
92
93GpuVbo::~GpuVbo()
94{
95    delete[] data->alloc_buffer;
96    delete data;
97}
98
99} /* namespace lol */
100
Note: See TracBrowser for help on using the repository browser.