GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/render/vertexes/openglgraphicsvertexes.cpp Lines: 30 100 30.0 %
Date: 2017-11-29 Branches: 12 52 23.1 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  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
536
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
3752
    mVbo()
43
{
44
536
    mFloatTexPool.reserve(30);
45
536
    mIntVertPool.reserve(30);
46
536
    mShortVertPool.reserve(30);
47
536
    mIntTexPool.reserve(30);
48
536
    mVp.reserve(30);
49
536
    mVbo.reserve(30);
50
536
}
51
52
4288
OpenGLGraphicsVertexes::~OpenGLGraphicsVertexes()
53
{
54
536
    clear();
55
536
}
56
57
536
void OpenGLGraphicsVertexes::clear() restrict2
58
{
59
1072
    for (STD_VECTOR<GLfloat*>::iterator it = mFloatTexPool.begin();
60
1608
        it != mFloatTexPool.end(); ++ it)
61
    {
62
        delete [] (*it);
63
    }
64
1072
    mFloatTexPool.clear();
65
66
1072
    for (STD_VECTOR<GLint*>::iterator it = mIntVertPool.begin();
67
1608
        it != mIntVertPool.end(); ++ it)
68
    {
69
        delete [] (*it);
70
    }
71
1072
    mIntVertPool.clear();
72
73
1072
    for (STD_VECTOR<GLshort*>::iterator it = mShortVertPool.begin();
74
1608
        it != mShortVertPool.end(); ++ it)
75
    {
76
        delete [] (*it);
77
    }
78
1072
    mShortVertPool.clear();
79
80
1072
    for (STD_VECTOR<GLint*>::iterator it = mIntTexPool.begin();
81
1608
        it != mIntTexPool.end(); ++ it)
82
    {
83
        delete [] (*it);
84
    }
85
1072
    mIntTexPool.clear();
86
87
1072
    const int sz = CAST_S32(mVbo.size());
88
536
    if (sz > 0)
89
    {
90
        mainGraphics->removeArray(sz, &mVbo[0]);
91
        mVbo.clear();
92
    }
93
94
1072
    mVp.clear();
95
536
    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
536
}
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(
173
            vertexBufSize * 4 + 30)];
174
        mFloatTexPool.push_back(mFloatTexArray);
175
    }
176
    else
177
    {
178
        mFloatTexArray = mFloatTexPool.back();
179
    }
180
    return mFloatTexArray;
181
}
182
183
GLint *OpenGLGraphicsVertexes::continueIntVertArray() restrict2
184
{
185
    if (mIntVertPool.empty())
186
    {
187
        mIntVertArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
188
        mIntVertPool.push_back(mIntVertArray);
189
    }
190
    else
191
    {
192
        mIntVertArray = mIntVertPool.back();
193
    }
194
    return mIntVertArray;
195
}
196
197
GLshort *OpenGLGraphicsVertexes::continueShortVertArray() restrict2
198
{
199
    if (mShortVertPool.empty())
200
    {
201
        mShortVertArray = new GLshort[CAST_SIZE(
202
            vertexBufSize * 4 + 30)];
203
        mShortVertPool.push_back(mShortVertArray);
204
    }
205
    else
206
    {
207
        mShortVertArray = mShortVertPool.back();
208
    }
209
    return mShortVertArray;
210
}
211
212
GLint *OpenGLGraphicsVertexes::continueIntTexArray() restrict2
213
{
214
    if (mIntTexPool.empty())
215
    {
216
        mIntTexArray = new GLint[CAST_SIZE(vertexBufSize * 4 + 30)];
217
        mIntTexPool.push_back(mIntTexArray);
218
    }
219
    else
220
    {
221
        mIntTexArray = mIntTexPool.back();
222
    }
223
    return mIntTexArray;
224
}
225
#endif  // USE_OPENGL