GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Buffer.hh
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Tero Pulkkinen
3// Released under LGPL License.
4//
5// This file is part of Polygon.
6//
7// Polygon is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Polygon is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the Library GNU General Public License
18// along with Polygon. If not, see <http://www.gnu.org/licenses/>.
19//
20
21
22#ifndef BUFFER_HH
23#define BUFFER_HH
24
25#ifdef ANDROID
26#include "android.hh"
27#endif
28
29
30#include <algorithm>
32{
33 unsigned int *buffer;
34 unsigned int width;
35 unsigned int height;
36 unsigned int ydelta;
37 static BufferRef SubBuffer(BufferRef old, int x, int y, int width, int height)
38;
39 static BufferRef NewBufferWithoutAlloc(unsigned int *buf, unsigned int width, unsigned int height, unsigned int ydelta);
40 static BufferRef NewBuffer(int width, int height);
41 static void FreeBuffer(BufferRef &ref);
42 static void CopyBuffer(BufferRef source, BufferRef target, int x, int y, int rx, int ry, int rex, int rey);
43
44 unsigned int *operator[](int y) { return buffer+y*ydelta; }
45 BufferRef() : buffer(0) { }
46};
48{
49 float *buffer;
50 unsigned int width;
51 unsigned int height;
52 unsigned int ydelta;
53 static BufferRefF SubBuffer(BufferRefF old, int x, int y, int width, int height)
54;
55 static BufferRefF NewBuffer(int width, int height);
56
57 float *operator[](int y) const { return buffer+y*ydelta; }
58 BufferRefF() : buffer(0) { }
59};
60
62{
63 unsigned char *buffer;
64 unsigned int width;
65 unsigned int height;
66 unsigned int ydelta;
67 static BufferRefMask NewBuffer(int width, int height);
68 unsigned char *operator[](int y) const { return buffer+y*ydelta; }
70};
71
73{
74public:
75 virtual void Gen() const=0;
76 virtual BufferRef Buffer() const=0;
77 virtual ~BufferRefReq() { }
78};
79
80#if 0
81
82template<class T>
83struct Buffer
84{
85 Buffer(int count) : count(count) { buffer = new T[count]; }
86 Buffer(const Buffer<T> &buf) : buffer(new T[buf.count]), count(buf.count)
87 {
88 std::copy(buffer, buffer+count, buf.buffer);
89 }
90 void set(int index, T val)
91 {
92 buffer[index] = val;
93 }
94 T &operator[](int idx) { return buffer[idx]; }
95 void operator=(const Buffer<T> &buf)
96 {
97 buffer = new T[buf.count];
98 count = buf.count;
99 std::copy(buffer, buffer+buf.count, buf.buffer);
100 //memcpy(buffer, buf.buffer, buf.count*sizeof(T));
101 }
102 ~Buffer() { delete [] buffer; }
103 T *Array() const { return buffer; }
104 int Count() const { return count; }
105 static Buffer<T> Compose(const Buffer<T> &buf, const Buffer<T> &buf2)
106 {
107 Buffer<T> res(buf.count+buf2.count);
108 for(int i=0;i<buf.count;i++)
109 {
110 res[i]=buf[i];
111 }
112 for(int k=0;k<buf2.count;k++)
113 {
114 res[buf.count+k]=buf2[k];
115 }
116 return res;
117 }
118 int NumTris() const { return count/3/3; }
119 int NumQuads() const { return count/6/3; }
120 int NumTexCoordTris() const { return count/2/3; }
121 int NumColorTris() const { return count/1/3; }
122 int NumTexCoordQuads() const { return count/2/6; }
123 int NumColorQuads() const { return count/1/6; }
124 friend void AnimBuffer(const Buffer<float> &buf, const Buffer<float> &buf2, Buffer<float> &res, float val);
125private:
126 T *buffer;
127 int count;
128};
129inline void AnimBuffer(const Buffer<float> &buf, const Buffer<float> &buf2, Buffer<float> &res, float val)
130{
131 float m = 1.0-val;
132 float *resbuf = res.buffer;
133 float *bufbuf = buf.buffer;
134 float *buf2buf = buf2.buffer;
135 for(int i=0;i<buf.count;i++)
136 {
137 resbuf[i]=bufbuf[i]*val+buf2buf[i]*m;
138 }
139}
140#endif
141
142#endif
Definition Buffer.hh:73
virtual BufferRef Buffer() const =0
virtual void Gen() const =0
virtual ~BufferRefReq()
Definition Buffer.hh:77
size_t count(const T &t_target, const typename T::key_type &t_key)
Definition bootstrap_stl.hpp:104
float * operator[](int y) const
Definition Buffer.hh:57
static BufferRefF SubBuffer(BufferRefF old, int x, int y, int width, int height)
Definition Buffer.cc:118
static BufferRefF NewBuffer(int width, int height)
Definition Buffer.cc:108
unsigned int width
Definition Buffer.hh:50
unsigned int ydelta
Definition Buffer.hh:52
BufferRefF()
Definition Buffer.hh:58
float * buffer
Definition Buffer.hh:49
unsigned int height
Definition Buffer.hh:51
unsigned int height
Definition Buffer.hh:65
static BufferRefMask NewBuffer(int width, int height)
Definition Buffer.cc:97
unsigned int ydelta
Definition Buffer.hh:66
BufferRefMask()
Definition Buffer.hh:69
unsigned char * operator[](int y) const
Definition Buffer.hh:68
unsigned int width
Definition Buffer.hh:64
unsigned char * buffer
Definition Buffer.hh:63
Definition Buffer.hh:32
static BufferRef SubBuffer(BufferRef old, int x, int y, int width, int height)
Definition Buffer.cc:56
BufferRef()
Definition Buffer.hh:45
static void CopyBuffer(BufferRef source, BufferRef target, int x, int y, int rx, int ry, int rex, int rey)
Definition Buffer.cc:66
unsigned int width
Definition Buffer.hh:34
unsigned int * buffer
Definition Buffer.hh:33
unsigned int ydelta
Definition Buffer.hh:36
static BufferRef NewBuffer(int width, int height)
Definition Buffer.cc:36
unsigned int height
Definition Buffer.hh:35
static void FreeBuffer(BufferRef &ref)
Definition Buffer.cc:92
unsigned int * operator[](int y)
Definition Buffer.hh:44
static BufferRef NewBufferWithoutAlloc(unsigned int *buf, unsigned int width, unsigned int height, unsigned int ydelta)
Definition Buffer.cc:26