GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/render/vertexes/openglgraphicsvertexes.cpp Lines: 30 98 30.6 %
Date: 2018-11-12 Branches: 12 56 21.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2018  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
23
#include "render/vertexes/openglgraphicsvertexes.h"
24
25
#include "render/graphics.h"
26
27
#include "debug.h"
28
29
unsigned int vertexBufSize = 500;
30
31
269
OpenGLGraphicsVertexes::OpenGLGraphicsVertexes() :
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
1883
    mVbo()
43
{
44
269
    mFloatTexPool.reserve(30);
45
269
    mIntVertPool.reserve(30);
46
269
    mShortVertPool.reserve(30);
47
269
    mIntTexPool.reserve(30);
48
269
    mVp.reserve(30);
49
269
    mVbo.reserve(30);
50
269
}
51
52
2152
OpenGLGraphicsVertexes::~OpenGLGraphicsVertexes()
53
{
54
269
    clear();
55
269
}
56
57
269
void OpenGLGraphicsVertexes::clear() restrict2
58
{
59
807
    for (STD_VECTOR<GLfloat*>::iterator it = mFloatTexPool.begin();
60
538
        it != mFloatTexPool.end(); ++ it)
61
    {
62
        delete [] (*it);
63
    }
64
538
    mFloatTexPool.clear();
65
66
807
    for (STD_VECTOR<GLint*>::iterator it = mIntVertPool.begin();
67
538
        it != mIntVertPool.end(); ++ it)
68
    {
69
        delete [] (*it);
70
    }
71
538
    mIntVertPool.clear();
72
73
807
    for (STD_VECTOR<GLshort*>::iterator it = mShortVertPool.begin();
74
538
        it != mShortVertPool.end(); ++ it)
75
    {
76
        delete [] (*it);
77
    }
78
538
    mShortVertPool.clear();
79
80
807
    for (STD_VECTOR<GLint*>::iterator it = mIntTexPool.begin();
81
538
        it != mIntTexPool.end(); ++ it)
82
    {
83
        delete [] (*it);
84
    }
85
538
    mIntTexPool.clear();
86
87
538
    const int sz = CAST_S32(mVbo.size());
88
269
    if (sz > 0)
89
    {
90
        mainGraphics->removeArray(sz, &mVbo[0]);
91
        mVbo.clear();
92
    }
93
94
538
    mVp.clear();
95
269
    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
269
}
108
109
void OpenGLGraphicsVertexes::init() restrict2
110
{
111
    clear();
112
}
113
114
GLfloat *OpenGLGraphicsVertexes::switchFloatTexArray() restrict2
115
{
116
    mFloatTexArray = new GLfloat[CAST_SIZE(vertexBufSize * 4 + 30)];
117
    mFloatTexPool.push_back(mFloatTexArray);
118
    return mFloatTexArray;
119
}
120
121
GLint *OpenGLGraphicsVertexes::switchIntVertArray() restrict2
122
{
123
    mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
124
    mIntVertPool.push_back(mIntVertArray);
125
    return mIntVertArray;
126
}
127
128
GLshort *OpenGLGraphicsVertexes::switchShortVertArray() restrict2
129
{
130
    mShortVertArray = new GLshort[CAST_SIZE(vertexBufSize * 4 + 30)];
131
    mShortVertPool.push_back(mShortVertArray);
132
    return mShortVertArray;
133
}
134
135
GLint *OpenGLGraphicsVertexes::switchIntTexArray() restrict2
136
{
137
    mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
138
    mIntTexPool.push_back(mIntTexArray);
139
    return mIntTexArray;
140
}
141
142
void OpenGLGraphicsVertexes::switchVp(const int n) restrict2
143
{
144
    mVp.push_back(n);
145
}
146
147
int OpenGLGraphicsVertexes::continueVp() restrict2
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
161
void OpenGLGraphicsVertexes::updateVp(const int n) restrict2
162
{
163
    if (!mVp.empty())
164
        mVp.pop_back();
165
    mVp.push_back(n);
166
}
167
168
GLfloat *OpenGLGraphicsVertexes::continueFloatTexArray() restrict2
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
182
GLint *OpenGLGraphicsVertexes::continueIntVertArray() restrict2
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
196
GLshort *OpenGLGraphicsVertexes::continueShortVertArray() restrict2
197
{
198
    if (mShortVertPool.empty())
199
    {
200
        mShortVertArray = new GLshort[CAST_SIZE(vertexBufSize) * 4 + 30];
201
        mShortVertPool.push_back(mShortVertArray);
202
    }
203
    else
204
    {
205
        mShortVertArray = mShortVertPool.back();
206
    }
207
    return mShortVertArray;
208
}
209
210
GLint *OpenGLGraphicsVertexes::continueIntTexArray() restrict2
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