ManaPlus
openglgraphicsvertexes.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program 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 2 of the License, or
10  * any later version.
11  *
12  * This program 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 GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifdef USE_OPENGL
22 
24 
25 #include "render/graphics.h"
26 
27 #include "debug.h"
28 
29 unsigned int vertexBufSize = 500;
30 
32  ptr(0),
33  mFloatTexArray(nullptr),
34  mIntTexArray(nullptr),
35  mIntVertArray(nullptr),
36  mShortVertArray(nullptr),
37  mVp(),
38  mFloatTexPool(),
39  mIntVertPool(),
40  mShortVertPool(),
41  mIntTexPool(),
42  mVbo()
43 {
44  mFloatTexPool.reserve(30);
45  mIntVertPool.reserve(30);
46  mShortVertPool.reserve(30);
47  mIntTexPool.reserve(30);
48  mVp.reserve(30);
49  mVbo.reserve(30);
50 }
51 
53 {
54  clear();
55 }
56 
58 {
59  for (STD_VECTOR<GLfloat*>::iterator it = mFloatTexPool.begin();
60  it != mFloatTexPool.end(); ++ it)
61  {
62  delete [] (*it);
63  }
64  mFloatTexPool.clear();
65 
66  for (STD_VECTOR<GLint*>::iterator it = mIntVertPool.begin();
67  it != mIntVertPool.end(); ++ it)
68  {
69  delete [] (*it);
70  }
71  mIntVertPool.clear();
72 
73  for (STD_VECTOR<GLshort*>::iterator it = mShortVertPool.begin();
74  it != mShortVertPool.end(); ++ it)
75  {
76  delete [] (*it);
77  }
78  mShortVertPool.clear();
79 
80  for (STD_VECTOR<GLint*>::iterator it = mIntTexPool.begin();
81  it != mIntTexPool.end(); ++ it)
82  {
83  delete [] (*it);
84  }
85  mIntTexPool.clear();
86 
87  const int sz = CAST_S32(mVbo.size());
88  if (sz > 0)
89  {
90  mainGraphics->removeArray(sz, &mVbo[0]);
91  mVbo.clear();
92  }
93 
94  mVp.clear();
95  if (ptr != 0)
96  {
97  ptr = 0;
98  delete []mFloatTexArray;
99  mFloatTexArray = nullptr;
100  delete []mIntTexArray;
101  mIntTexArray = nullptr;
102  delete []mIntVertArray;
103  mIntVertArray = nullptr;
104  delete []mShortVertArray;
105  mShortVertArray = nullptr;
106  }
107 }
108 
110 {
111  clear();
112 }
113 
115 {
116  mFloatTexArray = new GLfloat[CAST_SIZE(vertexBufSize * 4 + 30)];
117  mFloatTexPool.push_back(mFloatTexArray);
118  return mFloatTexArray;
119 }
120 
122 {
123  mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
124  mIntVertPool.push_back(mIntVertArray);
125  return mIntVertArray;
126 }
127 
129 {
130  mShortVertArray = new GLshort[CAST_SIZE(vertexBufSize * 4 + 30)];
131  mShortVertPool.push_back(mShortVertArray);
132  return mShortVertArray;
133 }
134 
136 {
137  mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
138  mIntTexPool.push_back(mIntTexArray);
139  return mIntTexArray;
140 }
141 
143 {
144  mVp.push_back(n);
145 }
146 
148 {
149  if (mVp.empty())
150  {
151  return 0;
152  }
153  else
154  {
155  const int val = mVp.back();
156  mVp.pop_back();
157  return val;
158  }
159 }
160 
162 {
163  if (!mVp.empty())
164  mVp.pop_back();
165  mVp.push_back(n);
166 }
167 
169 {
170  if (mFloatTexPool.empty())
171  {
172  mFloatTexArray = new GLfloat[CAST_SIZE(vertexBufSize) * 4 + 30];
173  mFloatTexPool.push_back(mFloatTexArray);
174  }
175  else
176  {
177  mFloatTexArray = mFloatTexPool.back();
178  }
179  return mFloatTexArray;
180 }
181 
183 {
184  if (mIntVertPool.empty())
185  {
186  mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
187  mIntVertPool.push_back(mIntVertArray);
188  }
189  else
190  {
191  mIntVertArray = mIntVertPool.back();
192  }
193  return mIntVertArray;
194 }
195 
197 {
198  if (mShortVertPool.empty())
199  {
200  mShortVertArray = new GLshort[CAST_SIZE(vertexBufSize) * 4 + 30];
201  mShortVertPool.push_back(mShortVertArray);
202  }
203  else
204  {
206  }
207  return mShortVertArray;
208 }
209 
211 {
212  if (mIntTexPool.empty())
213  {
214  mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
215  mIntTexPool.push_back(mIntTexArray);
216  }
217  else
218  {
219  mIntTexArray = mIntTexPool.back();
220  }
221  return mIntTexArray;
222 }
223 #endif // USE_OPENGL
OpenGLGraphicsVertexes::mFloatTexPool
std::vector< GLfloat * > mFloatTexPool
Definition: openglgraphicsvertexes.h:100
restrict2
#define restrict2
Definition: localconsts.h:165
CAST_SIZE
#define CAST_SIZE
Definition: cast.h:33
OpenGLGraphicsVertexes::clear
void clear()
Definition: openglgraphicsvertexes.cpp:57
OpenGLGraphicsVertexes::switchVp
void switchVp(const int n)
Definition: openglgraphicsvertexes.cpp:142
OpenGLGraphicsVertexes::OpenGLGraphicsVertexes
OpenGLGraphicsVertexes()
Definition: openglgraphicsvertexes.cpp:31
OpenGLGraphicsVertexes::continueFloatTexArray
GLfloat * continueFloatTexArray()
Definition: openglgraphicsvertexes.cpp:168
vertexBufSize
unsigned int vertexBufSize
Definition: openglgraphicsvertexes.cpp:29
OpenGLGraphicsVertexes::continueShortVertArray
GLshort * continueShortVertArray()
Definition: openglgraphicsvertexes.cpp:196
OpenGLGraphicsVertexes::ptr
int ptr
Definition: openglgraphicsvertexes.h:93
OpenGLGraphicsVertexes::updateVp
void updateVp(const int n)
Definition: openglgraphicsvertexes.cpp:161
OpenGLGraphicsVertexes::init
void init()
Definition: openglgraphicsvertexes.cpp:109
OpenGLGraphicsVertexes::mShortVertPool
std::vector< GLshort * > mShortVertPool
Definition: openglgraphicsvertexes.h:102
OpenGLGraphicsVertexes::continueIntVertArray
GLint * continueIntVertArray()
Definition: openglgraphicsvertexes.cpp:182
OpenGLGraphicsVertexes::mIntVertArray
GLint * mIntVertArray
Definition: openglgraphicsvertexes.h:97
OpenGLGraphicsVertexes::switchIntVertArray
GLint * switchIntVertArray()
Definition: openglgraphicsvertexes.cpp:121
OpenGLGraphicsVertexes::mIntTexArray
GLint * mIntTexArray
Definition: openglgraphicsvertexes.h:96
nullptr
#define nullptr
Definition: localconsts.h:44
OpenGLGraphicsVertexes::continueIntTexArray
GLint * continueIntTexArray()
Definition: openglgraphicsvertexes.cpp:210
mainGraphics
Graphics * mainGraphics
Definition: graphics.cpp:108
OpenGLGraphicsVertexes::switchFloatTexArray
GLfloat * switchFloatTexArray()
Definition: openglgraphicsvertexes.cpp:114
OpenGLGraphicsVertexes::switchShortVertArray
GLshort * switchShortVertArray()
Definition: openglgraphicsvertexes.cpp:128
OpenGLGraphicsVertexes::mShortVertArray
GLshort * mShortVertArray
Definition: openglgraphicsvertexes.h:98
OpenGLGraphicsVertexes::~OpenGLGraphicsVertexes
~OpenGLGraphicsVertexes()
Definition: openglgraphicsvertexes.cpp:52
OpenGLGraphicsVertexes::mVbo
std::vector< GLuint > mVbo
Definition: openglgraphicsvertexes.h:104
OpenGLGraphicsVertexes::mVp
std::vector< int > mVp
Definition: openglgraphicsvertexes.h:99
openglgraphicsvertexes.h
OpenGLGraphicsVertexes::switchIntTexArray
GLint * switchIntTexArray()
Definition: openglgraphicsvertexes.cpp:135
CAST_S32
#define CAST_S32
Definition: cast.h:29
OpenGLGraphicsVertexes::mFloatTexArray
GLfloat * mFloatTexArray
Definition: openglgraphicsvertexes.h:95
Graphics::removeArray
virtual void removeArray(const uint32_t sz, uint32_t *const arr)
Definition: graphics.h:475
OpenGLGraphicsVertexes::mIntVertPool
std::vector< GLint * > mIntVertPool
Definition: openglgraphicsvertexes.h:101
OpenGLGraphicsVertexes::continueVp
int continueVp()
Definition: openglgraphicsvertexes.cpp:147
debug.h
OpenGLGraphicsVertexes::mIntTexPool
std::vector< GLint * > mIntTexPool
Definition: openglgraphicsvertexes.h:103