GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/render/safeopenglgraphics.cpp Lines: 0 309 0.0 %
Date: 2017-11-29 Branches: 0 276 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#if defined USE_OPENGL && !defined ANDROID
24
#include "render/safeopenglgraphics.h"
25
26
#ifdef DEBUG_OPENGL
27
#include "render/opengl/mgl.h"
28
#endif  // DEBUG_OPENGL
29
30
#include "resources/imagerect.h"
31
#include "resources/safeopenglimagehelper.h"
32
33
#include "resources/image/image.h"
34
35
#include "utils/sdlcheckutils.h"
36
37
#include "debug.h"
38
39
GLuint SafeOpenGLGraphics::mTextureBinded = 0;
40
41
SafeOpenGLGraphics::SafeOpenGLGraphics() :
42
    mTexture(false),
43
    mIsByteColor(false),
44
    mByteColor(),
45
    mFloatColor(1.0F),
46
    mColorAlpha(false),
47
    mFbo()
48
{
49
    mOpenGL = RENDER_SAFE_OPENGL;
50
    mName = "safe OpenGL";
51
}
52
53
SafeOpenGLGraphics::~SafeOpenGLGraphics()
54
{
55
}
56
57
void SafeOpenGLGraphics::deleteArrays() restrict2
58
{
59
}
60
61
bool SafeOpenGLGraphics::setVideoMode(const int w, const int h,
62
                                      const int scale,
63
                                      const int bpp,
64
                                      const bool fs,
65
                                      const bool hwaccel,
66
                                      const bool resize,
67
                                      const bool noFrame,
68
                                      const bool allowHighDPI) restrict2
69
{
70
    setMainFlags(w, h,
71
        scale,
72
        bpp,
73
        fs,
74
        hwaccel,
75
        resize,
76
        noFrame,
77
        allowHighDPI);
78
79
    return setOpenGLMode();
80
}
81
82
static inline void drawQuad(const Image *restrict image,
83
                            const int srcX,
84
                            const int srcY,
85
                            const int dstX,
86
                            const int dstY,
87
                            const int width,
88
                            const int height) A_NONNULL(1) A_INLINE;
89
90
static inline void drawQuad(const Image *restrict image,
91
                            const int srcX,
92
                            const int srcY,
93
                            const int dstX,
94
                            const int dstY,
95
                            const int width,
96
                            const int height)
97
{
98
    if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
99
    {
100
        const float tw = static_cast<float>(image->mTexWidth);
101
        const float th = static_cast<float>(image->mTexHeight);
102
        // Find OpenGL normalized texture coordinates.
103
        const float texX1 = static_cast<float>(srcX) / tw;
104
        const float texY1 = static_cast<float>(srcY) / th;
105
        const float texX2 = static_cast<float>(srcX + width) / tw;
106
        const float texY2 = static_cast<float>(srcY + height) / th;
107
108
        glTexCoord2f(texX1, texY1);
109
        glVertex2i(dstX, dstY);
110
        glTexCoord2f(texX2, texY1);
111
        glVertex2i(dstX + width, dstY);
112
        glTexCoord2f(texX2, texY2);
113
        glVertex2i(dstX + width, dstY + height);
114
        glTexCoord2f(texX1, texY2);
115
        glVertex2i(dstX, dstY + height);
116
    }
117
    else
118
    {
119
        glTexCoord2i(srcX, srcY);
120
        glVertex2i(dstX, dstY);
121
        glTexCoord2i(srcX + width, srcY);
122
        glVertex2i(dstX + width, dstY);
123
        glTexCoord2i(srcX + width, srcY + height);
124
        glVertex2i(dstX + width, dstY + height);
125
        glTexCoord2i(srcX, srcY + height);
126
        glVertex2i(dstX, dstY + height);
127
    }
128
}
129
130
static inline void drawRescaledQuad(const Image *restrict const image,
131
                                    const int srcX, const int srcY,
132
                                    const int dstX, const int dstY,
133
                                    const int width, const int height,
134
                                    const int desiredWidth,
135
                                    const int desiredHeight)
136
                                    A_NONNULL(1) A_INLINE;
137
138
static inline void drawRescaledQuad(const Image *restrict const image,
139
                                    const int srcX, const int srcY,
140
                                    const int dstX, const int dstY,
141
                                    const int width, const int height,
142
                                    const int desiredWidth,
143
                                    const int desiredHeight)
144
{
145
    if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
146
    {
147
        const float tw = static_cast<float>(image->mTexWidth);
148
        const float th = static_cast<float>(image->mTexHeight);
149
        // Find OpenGL normalized texture coordinates.
150
        const float texX1 = static_cast<float>(srcX) / tw;
151
        const float texY1 = static_cast<float>(srcY) / th;
152
        const float texX2 = static_cast<float>(srcX + width) / tw;
153
        const float texY2 = static_cast<float>(srcY + height) / th;
154
155
        glTexCoord2f(texX1, texY1);
156
        glVertex2i(dstX, dstY);
157
        glTexCoord2f(texX2, texY1);
158
        glVertex2i(dstX + desiredWidth, dstY);
159
        glTexCoord2f(texX2, texY2);
160
        glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
161
        glTexCoord2f(texX1, texY2);
162
        glVertex2i(dstX, dstY + desiredHeight);
163
    }
164
    else
165
    {
166
        glTexCoord2i(srcX, srcY);
167
        glVertex2i(dstX, dstY);
168
        glTexCoord2i(srcX + width, srcY);
169
        glVertex2i(dstX + desiredWidth, dstY);
170
        glTexCoord2i(srcX + width, srcY + height);
171
        glVertex2i(dstX + desiredWidth, dstY + desiredHeight);
172
        glTexCoord2i(srcX, srcY + height);
173
        glVertex2i(dstX, dstY + desiredHeight);
174
    }
175
}
176
177
void SafeOpenGLGraphics::drawImage(const Image *restrict const image,
178
                                   int dstX, int dstY) restrict2
179
{
180
    drawImageInline(image, dstX, dstY);
181
}
182
183
void SafeOpenGLGraphics::drawImageInline(const Image *restrict const image,
184
                                         int dstX, int dstY) restrict2
185
{
186
    FUNC_BLOCK("Graphics::drawImage", 1)
187
    if (image == nullptr)
188
        return;
189
190
    setColorAlpha(image->mAlpha);
191
    bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
192
    enableTexturingAndBlending();
193
194
    const SDL_Rect &bounds = image->mBounds;
195
    // Draw a textured quad.
196
    glBegin(GL_QUADS);
197
    drawQuad(image, bounds.x, bounds.y,
198
        dstX, dstY, bounds.w, bounds.h);
199
    glEnd();
200
}
201
202
void SafeOpenGLGraphics::copyImage(const Image *restrict const image,
203
                                   int dstX, int dstY) restrict2
204
{
205
    drawImageInline(image, dstX, dstY);
206
}
207
208
void SafeOpenGLGraphics::testDraw() restrict2
209
{
210
    if (SafeOpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
211
    {
212
        glBegin(GL_QUADS);
213
        glTexCoord2f(0.0f, 0.781250f);
214
        glVertex2i(0, 0);
215
        glTexCoord2f(0.0f, 0.781250f);
216
        glVertex2i(800, 0);
217
        glTexCoord2f(0.0f, 0.585938f);
218
        glVertex2i(800, 600);
219
        glTexCoord2f(0.0f, 0.585938f);
220
        glVertex2i(0, 600);
221
        glEnd();
222
    }
223
    else
224
    {
225
        glBegin(GL_QUADS);
226
        glTexCoord2i(0, 0);
227
        glVertex2i(0, 0);
228
        glTexCoord2i(800, 0);
229
        glVertex2i(800, 0);
230
        glTexCoord2i(800, 600);
231
        glVertex2i(800, 600);
232
        glTexCoord2i(0, 600);
233
        glVertex2i(0, 600);
234
        glEnd();
235
    }
236
}
237
238
void SafeOpenGLGraphics::drawImageCached(const Image *restrict const image,
239
                                         int x, int y) restrict2
240
{
241
    FUNC_BLOCK("Graphics::drawImageCached", 1)
242
    if (image == nullptr)
243
        return;
244
245
    setColorAlpha(image->mAlpha);
246
    bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
247
    enableTexturingAndBlending();
248
249
    const SDL_Rect &bounds = image->mBounds;
250
    // Draw a textured quad.
251
    glBegin(GL_QUADS);
252
    drawQuad(image, bounds.x, bounds.y, x, y, bounds.w, bounds.h);
253
    glEnd();
254
}
255
256
void SafeOpenGLGraphics::drawPatternCached(const Image *restrict const image,
257
                                           const int x, const int y,
258
                                           const int w, const int h) restrict2
259
{
260
    FUNC_BLOCK("Graphics::drawPatternCached", 1)
261
    if (image == nullptr)
262
        return;
263
264
    const SDL_Rect &imageRect = image->mBounds;
265
    const int iw = imageRect.w;
266
    const int ih = imageRect.h;
267
    if (iw == 0 || ih == 0)
268
        return;
269
270
    const int srcX = imageRect.x;
271
    const int srcY = imageRect.y;
272
273
    setColorAlpha(image->mAlpha);
274
    bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
275
    enableTexturingAndBlending();
276
277
    // Draw a set of textured rectangles
278
    glBegin(GL_QUADS);
279
280
    for (int py = 0; py < h; py += ih)
281
    {
282
        const int height = (py + ih >= h) ? h - py : ih;
283
        const int dstY = y + py;
284
        for (int px = 0; px < w; px += iw)
285
        {
286
            int width = (px + iw >= w) ? w - px : iw;
287
            int dstX = x + px;
288
            drawQuad(image, srcX, srcY, dstX, dstY, width, height);
289
        }
290
    }
291
292
    glEnd();
293
}
294
295
void SafeOpenGLGraphics::completeCache() restrict2
296
{
297
}
298
299
void SafeOpenGLGraphics::drawRescaledImage(const Image *restrict const image,
300
                                           int dstX, int dstY,
301
                                           const int desiredWidth,
302
                                           const int desiredHeight) restrict2
303
{
304
    FUNC_BLOCK("Graphics::drawRescaledImage", 1)
305
    if (image == nullptr)
306
        return;
307
308
    const SDL_Rect &imageRect = image->mBounds;
309
310
    // Just draw the image normally when no resizing is necessary,
311
    if (imageRect.w == desiredWidth && imageRect.h == desiredHeight)
312
    {
313
        drawImageInline(image, dstX, dstY);
314
        return;
315
    }
316
317
    setColorAlpha(image->mAlpha);
318
    bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
319
    enableTexturingAndBlending();
320
321
    // Draw a textured quad.
322
    glBegin(GL_QUADS);
323
    drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY,
324
        imageRect.w, imageRect.h, desiredWidth, desiredHeight);
325
    glEnd();
326
}
327
328
void SafeOpenGLGraphics::drawPattern(const Image *restrict const image,
329
                                     const int x, const int y,
330
                                     const int w, const int h) restrict2
331
{
332
    drawPatternInline(image, x, y, w, h);
333
}
334
335
void SafeOpenGLGraphics::drawPatternInline(const Image *restrict const image,
336
                                           const int x, const int y,
337
                                           const int w, const int h) restrict2
338
{
339
    FUNC_BLOCK("Graphics::drawPattern", 1)
340
    if (image == nullptr)
341
        return;
342
343
    const SDL_Rect &imageRect = image->mBounds;
344
    const int iw = imageRect.w;
345
    const int ih = imageRect.h;
346
    if (iw == 0 || ih == 0)
347
        return;
348
349
    const int srcX = imageRect.x;
350
    const int srcY = imageRect.y;
351
352
    setColorAlpha(image->mAlpha);
353
    bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
354
    enableTexturingAndBlending();
355
356
    // Draw a set of textured rectangles
357
    glBegin(GL_QUADS);
358
359
    for (int py = 0; py < h; py += ih)
360
    {
361
        const int height = (py + ih >= h) ? h - py : ih;
362
        const int dstY = y + py;
363
        for (int px = 0; px < w; px += iw)
364
        {
365
            int width = (px + iw >= w) ? w - px : iw;
366
            int dstX = x + px;
367
            drawQuad(image, srcX, srcY, dstX, dstY, width, height);
368
        }
369
    }
370
371
    glEnd();
372
}
373
374
void SafeOpenGLGraphics::drawRescaledPattern(const Image *restrict const image,
375
                                             const int x, const int y,
376
                                             const int w, const int h,
377
                                             const int scaledWidth,
378
                                             const int scaledHeight) restrict2
379
{
380
    if (image == nullptr)
381
        return;
382
383
    const int iw = scaledWidth;
384
    const int ih = scaledHeight;
385
    if (iw == 0 || ih == 0)
386
        return;
387
388
    const SDL_Rect &imageRect = image->mBounds;
389
    const int srcX = imageRect.x;
390
    const int srcY = imageRect.y;
391
392
    setColorAlpha(image->mAlpha);
393
    bindTexture(SafeOpenGLImageHelper::mTextureType, image->mGLImage);
394
    enableTexturingAndBlending();
395
396
    // Draw a set of textured rectangles
397
    glBegin(GL_QUADS);
398
399
    const float scaleFactorW = static_cast<float>(scaledWidth)
400
        / image->getWidth();
401
    const float scaleFactorH = static_cast<float>(scaledHeight)
402
        / image->getHeight();
403
404
    for (int py = 0; py < h; py += ih)
405
    {
406
        const int height = (py + ih >= h) ? h - py : ih;
407
        const int dstY = y + py;
408
        for (int px = 0; px < w; px += iw)
409
        {
410
            int width = (px + iw >= w) ? w - px : iw;
411
            int dstX = x + px;
412
413
            drawRescaledQuad(image, srcX, srcY, dstX, dstY,
414
                width / scaleFactorW, height / scaleFactorH,
415
                scaledWidth, scaledHeight);
416
        }
417
    }
418
419
    glEnd();
420
}
421
422
void SafeOpenGLGraphics::calcTileCollection(ImageCollection *restrict const
423
                                            vertCol A_UNUSED,
424
                                            const Image *restrict const image
425
                                            A_UNUSED,
426
                                            int x A_UNUSED,
427
                                            int y A_UNUSED) restrict2
428
{
429
}
430
431
void SafeOpenGLGraphics::calcTileVertexes(ImageVertexes *restrict const vert
432
                                          A_UNUSED,
433
                                          const Image *restrict const image
434
                                          A_UNUSED,
435
                                          int x A_UNUSED,
436
                                          int y A_UNUSED) const restrict2
437
{
438
}
439
440
void SafeOpenGLGraphics::calcTileVertexesInline(ImageVertexes *restrict const
441
                                                vert A_UNUSED,
442
                                                const Image *restrict const
443
                                                image A_UNUSED,
444
                                                int x A_UNUSED,
445
                                                int y A_UNUSED) const restrict2
446
{
447
}
448
449
void SafeOpenGLGraphics::calcPattern(ImageVertexes *restrict const vert
450
                                     A_UNUSED,
451
                                     const Image *restrict const image
452
                                     A_UNUSED,
453
                                     const int x A_UNUSED,
454
                                     const int y A_UNUSED,
455
                                     const int w A_UNUSED,
456
                                     const int h A_UNUSED) const restrict2
457
{
458
}
459
460
void SafeOpenGLGraphics::calcPatternInline(ImageVertexes *restrict const vert
461
                                           A_UNUSED,
462
                                           const Image *restrict const image
463
                                           A_UNUSED,
464
                                           const int x A_UNUSED,
465
                                           const int y A_UNUSED,
466
                                           const int w A_UNUSED,
467
                                           const int h A_UNUSED)
468
                                           const restrict2
469
{
470
}
471
472
void SafeOpenGLGraphics::calcPattern(ImageCollection *restrict const vert
473
                                     A_UNUSED,
474
                                     const Image *restrict const image
475
                                     A_UNUSED,
476
                                     const int x A_UNUSED,
477
                                     const int y A_UNUSED,
478
                                     const int w A_UNUSED,
479
                                     const int h A_UNUSED) const restrict2
480
{
481
}
482
483
void SafeOpenGLGraphics::drawTileVertexes(const ImageVertexes
484
                                          *restrict const vert A_UNUSED)
485
                                          restrict2
486
{
487
}
488
489
void SafeOpenGLGraphics::drawTileCollection(const ImageCollection *
490
                                            restrict const vertCol A_UNUSED)
491
                                            restrict2
492
{
493
}
494
495
void SafeOpenGLGraphics::updateScreen() restrict2
496
{
497
    BLOCK_START("Graphics::updateScreen")
498
    glFlush();
499
    glFinish();
500
#ifdef USE_SDL2
501
    SDL_GL_SwapWindow(mWindow);
502
#else
503
    SDL_GL_SwapBuffers();
504
#endif  // USE_SDL2
505
#ifdef DEBUG_OPENGL
506
    if (isGLNotNull(mglFrameTerminator))
507
        mglFrameTerminator();
508
#endif  // DEBUG_OPENGL
509
510
    BLOCK_END("Graphics::updateScreen")
511
}
512
513
void SafeOpenGLGraphics::calcWindow(ImageCollection *restrict const vertCol
514
                                    A_UNUSED,
515
                                    const int x A_UNUSED, const int y A_UNUSED,
516
                                    const int w A_UNUSED, const int h A_UNUSED,
517
                                    const ImageRect &restrict imgRect A_UNUSED)
518
                                    restrict2
519
{
520
}
521
522
void SafeOpenGLGraphics::beginDraw() restrict2
523
{
524
    glMatrixMode(GL_TEXTURE);
525
    glLoadIdentity();
526
527
    glMatrixMode(GL_PROJECTION);
528
    glLoadIdentity();
529
530
    glOrtho(0.0, static_cast<double>(mRect.w),
531
        static_cast<double>(mRect.h),
532
        0.0, -1.0, 1.0);
533
534
    glMatrixMode(GL_MODELVIEW);
535
    glLoadIdentity();
536
537
    setOpenGLFlags();
538
    glDisable(GL_LIGHTING);
539
    glDisable(GL_FOG);
540
    glDisable(GL_COLOR_MATERIAL);
541
542
    glShadeModel(GL_FLAT);
543
544
    pushClipArea(Rect(0, 0, mRect.w, mRect.h));
545
}
546
547
void SafeOpenGLGraphics::endDraw() restrict2
548
{
549
    popClipArea();
550
}
551
552
void SafeOpenGLGraphics::pushClipArea(const Rect &restrict area) restrict2
553
{
554
    int transX = 0;
555
    int transY = 0;
556
557
    if (!mClipStack.empty())
558
    {
559
        const ClipRect &clipArea = mClipStack.top();
560
        transX = -clipArea.xOffset;
561
        transY = -clipArea.yOffset;
562
    }
563
564
    Graphics::pushClipArea(area);
565
566
    const ClipRect &clipArea = mClipStack.top();
567
568
    glPushMatrix();
569
    glTranslatef(static_cast<GLfloat>(transX + clipArea.xOffset),
570
                 static_cast<GLfloat>(transY + clipArea.yOffset), 0);
571
    glScissor(clipArea.x * mScale,
572
        (mRect.h - clipArea.y - clipArea.height) * mScale,
573
        clipArea.width * mScale,
574
        clipArea.height * mScale);
575
}
576
577
void SafeOpenGLGraphics::popClipArea() restrict2
578
{
579
    Graphics::popClipArea();
580
581
    if (mClipStack.empty())
582
        return;
583
584
    glPopMatrix();
585
    const ClipRect &clipArea = mClipStack.top();
586
    glScissor(clipArea.x * mScale,
587
        (mRect.h - clipArea.y - clipArea.height) * mScale,
588
        clipArea.width * mScale,
589
        clipArea.height * mScale);
590
}
591
592
void SafeOpenGLGraphics::drawPoint(int x, int y) restrict2
593
{
594
    disableTexturingAndBlending();
595
    restoreColor();
596
597
    glBegin(GL_POINTS);
598
    glVertex2i(x, y);
599
    glEnd();
600
}
601
602
void SafeOpenGLGraphics::drawNet(const int x1, const int y1,
603
                                 const int x2, const int y2,
604
                                 const int width, const int height) restrict2
605
{
606
    disableTexturingAndBlending();
607
    restoreColor();
608
609
    glBegin(GL_LINES);
610
    for (int y = y1; y < y2; y += height)
611
    {
612
        glVertex2f(static_cast<float>(x1) + 0.5F,
613
            static_cast<float>(y) + 0.5F);
614
        glVertex2f(static_cast<float>(x2) + 0.5F,
615
            static_cast<float>(y) + 0.5F);
616
    }
617
618
    for (int x = x1; x < x2; x += width)
619
    {
620
        glVertex2f(static_cast<float>(x) + 0.5F,
621
            static_cast<float>(y1) + 0.5F);
622
        glVertex2f(static_cast<float>(x) + 0.5F,
623
            static_cast<float>(y2) + 0.5F);
624
    }
625
    glEnd();
626
}
627
628
void SafeOpenGLGraphics::drawLine(int x1, int y1,
629
                                  int x2, int y2) restrict2
630
{
631
    disableTexturingAndBlending();
632
    restoreColor();
633
634
    glBegin(GL_LINES);
635
    glVertex2f(static_cast<float>(x1) + 0.5F, static_cast<float>(y1) + 0.5F);
636
    glVertex2f(static_cast<float>(x2) + 0.5F, static_cast<float>(y2) + 0.5F);
637
    glEnd();
638
}
639
640
void SafeOpenGLGraphics::drawRectangle(const Rect &restrict rect) restrict2
641
{
642
    drawRectangle(rect, false);
643
}
644
645
void SafeOpenGLGraphics::fillRectangle(const Rect &restrict rect) restrict2
646
{
647
    drawRectangle(rect, true);
648
}
649
650
void SafeOpenGLGraphics::enableTexturingAndBlending() restrict2
651
{
652
    if (!mTexture)
653
    {
654
        glEnable(SafeOpenGLImageHelper::mTextureType);
655
        mTexture = true;
656
    }
657
658
    if (!mAlpha)
659
    {
660
        glEnable(GL_BLEND);
661
        mAlpha = true;
662
    }
663
}
664
665
void SafeOpenGLGraphics::disableTexturingAndBlending() restrict2
666
{
667
    mTextureBinded = 0;
668
    if (mAlpha && !mColorAlpha)
669
    {
670
        glDisable(GL_BLEND);
671
        mAlpha = false;
672
    }
673
    else if (!mAlpha && mColorAlpha)
674
    {
675
        glEnable(GL_BLEND);
676
        mAlpha = true;
677
    }
678
679
    if (mTexture)
680
    {
681
        glDisable(SafeOpenGLImageHelper::mTextureType);
682
        mTexture = false;
683
    }
684
}
685
686
void SafeOpenGLGraphics::drawRectangle(const Rect &restrict rect,
687
                                       const bool filled) restrict2
688
{
689
    BLOCK_START("Graphics::drawRectangle")
690
    const float offset = filled ? 0 : 0.5F;
691
692
    disableTexturingAndBlending();
693
    restoreColor();
694
695
    glBegin(filled ? GL_QUADS : GL_LINE_LOOP);
696
    glVertex2f(static_cast<float>(rect.x) + offset,
697
        static_cast<float>(rect.y) + offset);
698
    glVertex2f(static_cast<float>(rect.x + rect.width) - offset,
699
        static_cast<float>(rect.y) + offset);
700
    glVertex2f(static_cast<float>(rect.x + rect.width) - offset,
701
        static_cast<float>(rect.y + rect.height) - offset);
702
    glVertex2f(static_cast<float>(rect.x) + offset,
703
        static_cast<float>(rect.y + rect.height) - offset);
704
    glEnd();
705
    BLOCK_END("Graphics::drawRectangle")
706
}
707
708
void SafeOpenGLGraphics::bindTexture(const GLenum target,
709
                                     const GLuint texture)
710
{
711
    if (mTextureBinded != texture)
712
    {
713
        mTextureBinded = texture;
714
        glBindTexture(target, texture);
715
    }
716
}
717
718
void SafeOpenGLGraphics::setColorAlpha(const float alpha) restrict2
719
{
720
    if (!mIsByteColor && mFloatColor == alpha)
721
        return;
722
723
    glColor4f(1.0F, 1.0F, 1.0F, alpha);
724
    mIsByteColor = false;
725
    mFloatColor = alpha;
726
}
727
728
void SafeOpenGLGraphics::restoreColor() restrict2
729
{
730
    if (mIsByteColor && mByteColor == mColor)
731
        return;
732
733
    glColor4ub(static_cast<GLubyte>(mColor.r),
734
               static_cast<GLubyte>(mColor.g),
735
               static_cast<GLubyte>(mColor.b),
736
               static_cast<GLubyte>(mColor.a));
737
    mIsByteColor = true;
738
    mByteColor = mColor;
739
}
740
741
void SafeOpenGLGraphics::clearScreen() const restrict2
742
{
743
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
744
}
745
746
void SafeOpenGLGraphics::drawImageRect(const int x, const int y,
747
                                       const int w, const int h,
748
                                       const ImageRect &restrict imgRect)
749
                                       restrict2
750
{
751
    #include "render/graphics_drawImageRect.hpp"
752
}
753
754
void SafeOpenGLGraphics::calcImageRect(ImageVertexes *restrict const vert,
755
                                       const int x, const int y,
756
                                       const int w, const int h,
757
                                       const ImageRect &restrict imgRect)
758
                                       restrict2
759
{
760
    #include "render/graphics_calcImageRect.hpp"
761
}
762
763
#endif  // USE_OPENGL