3
* Copyright (C) 2004-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2013 The ManaPlus Developers
7
* This file is part of The ManaPlus Client.
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
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.
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/>.
24
#if defined USE_OPENGL
26
#include "nullopenglgraphics.h"
28
#include "configuration.h"
29
#include "graphicsmanager.h"
30
#include "graphicsvertexes.h"
33
#include "resources/image.h"
34
#include "resources/openglimagehelper.h"
36
#include "utils/stringutils.h"
42
GLuint NullOpenGLGraphics::mLastImage = 0;
43
#ifdef DEBUG_DRAW_CALLS
44
unsigned int NullOpenGLGraphics::mDrawCalls = 0;
45
unsigned int NullOpenGLGraphics::mLastDrawCalls = 0;
48
NullOpenGLGraphics::NullOpenGLGraphics():
49
mFloatTexArray(nullptr),
50
mIntTexArray(nullptr),
51
mIntVertArray(nullptr),
58
#ifdef DEBUG_BIND_TEXTURE
65
mName = "null OpenGL";
68
NullOpenGLGraphics::~NullOpenGLGraphics()
70
delete [] mFloatTexArray;
71
delete [] mIntTexArray;
72
delete [] mIntVertArray;
75
void NullOpenGLGraphics::initArrays()
77
mMaxVertices = graphicsManager.getMaxVertices();
78
if (mMaxVertices < 500)
80
else if (mMaxVertices > 1024)
83
// need alocate small size, after if limit reached reallocate to double size
84
vertexBufSize = mMaxVertices;
85
const int sz = mMaxVertices * 4 + 30;
86
mFloatTexArray = new GLfloat[sz];
87
mIntTexArray = new GLint[sz];
88
mIntVertArray = new GLint[sz];
91
bool NullOpenGLGraphics::setVideoMode(const int w, const int h,
92
const int bpp, const bool fs,
93
const bool hwaccel, const bool resize,
96
setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame);
98
return setOpenGLMode();
101
static inline void drawQuad(const Image *const image A_UNUSED,
102
const int srcX A_UNUSED, const int srcY A_UNUSED,
103
const int dstX A_UNUSED, const int dstY A_UNUSED,
104
const int width A_UNUSED,
105
const int height A_UNUSED)
107
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
109
#ifdef DEBUG_DRAW_CALLS
110
NullOpenGLGraphics::mDrawCalls ++;
115
#ifdef DEBUG_DRAW_CALLS
116
NullOpenGLGraphics::mDrawCalls ++;
121
static inline void drawRescaledQuad(const Image *const image A_UNUSED,
122
const int srcX A_UNUSED,
123
const int srcY A_UNUSED,
124
const int dstX A_UNUSED,
125
const int dstY A_UNUSED,
126
const int width A_UNUSED,
127
const int height A_UNUSED,
128
const int desiredWidth A_UNUSED,
129
const int desiredHeight A_UNUSED)
131
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
133
#ifdef DEBUG_DRAW_CALLS
134
NullOpenGLGraphics::mDrawCalls ++;
139
#ifdef DEBUG_DRAW_CALLS
140
NullOpenGLGraphics::mDrawCalls ++;
146
bool NullOpenGLGraphics::drawImage2(const Image *const image,
149
const int width, const int height,
152
FUNC_BLOCK("Graphics::drawImage2", 1)
156
const SDL_Rect &imageRect = image->mBounds;
161
setColorAlpha(image->mAlpha);
163
#ifdef DEBUG_BIND_TEXTURE
164
debugBindTexture(image);
166
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
168
setTexturingAndBlending(true);
170
drawQuad(image, srcX, srcY, dstX, dstY, width, height);
175
bool NullOpenGLGraphics::drawRescaledImage(const Image *const image,
178
const int width, const int height,
179
const int desiredWidth,
180
const int desiredHeight,
183
return drawRescaledImage(image, srcX, srcY,
186
desiredWidth, desiredHeight,
190
bool NullOpenGLGraphics::drawRescaledImage(const Image *const image,
193
const int width, const int height,
194
const int desiredWidth,
195
const int desiredHeight,
199
FUNC_BLOCK("Graphics::drawRescaledImage", 1)
203
// Just draw the image normally when no resizing is necessary,
204
if (width == desiredWidth && height == desiredHeight)
206
return drawImage2(image, srcX, srcY, dstX, dstY,
207
width, height, useColor);
210
// When the desired image is smaller than the current one,
211
// disable smooth effect.
212
if (width > desiredWidth && height > desiredHeight)
215
const SDL_Rect &imageRect = image->mBounds;
220
setColorAlpha(image->mAlpha);
222
#ifdef DEBUG_BIND_TEXTURE
223
debugBindTexture(image);
225
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
227
setTexturingAndBlending(true);
229
// Draw a textured quad.
230
drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height,
231
desiredWidth, desiredHeight);
233
if (smooth) // A basic smooth effect...
236
drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height,
237
desiredWidth + 1, desiredHeight + 1);
238
drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height,
239
desiredWidth - 1, desiredHeight - 1);
241
drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height,
242
desiredWidth - 1, desiredHeight);
243
drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height,
244
desiredWidth, desiredHeight - 1);
250
void NullOpenGLGraphics::drawImagePattern(const Image *const image,
251
const int x, const int y,
252
const int w, const int h)
254
FUNC_BLOCK("Graphics::drawImagePattern", 1)
258
const SDL_Rect &imageRect = image->mBounds;
259
const int srcX = imageRect.x;
260
const int srcY = imageRect.y;
261
const int iw = imageRect.w;
262
const int ih = imageRect.h;
264
if (iw == 0 || ih == 0)
267
const float tw = static_cast<float>(image->mTexWidth);
268
const float th = static_cast<float>(image->mTexHeight);
270
setColorAlpha(image->mAlpha);
272
#ifdef DEBUG_BIND_TEXTURE
273
debugBindTexture(image);
275
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
277
setTexturingAndBlending(true);
280
const unsigned int vLimit = mMaxVertices * 4;
281
// Draw a set of textured rectangles
282
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
284
const float texX1 = static_cast<float>(srcX) / tw;
285
const float texY1 = static_cast<float>(srcY) / th;
287
for (int py = 0; py < h; py += ih)
289
const int height = (py + ih >= h) ? h - py : ih;
290
const int dstY = y + py;
291
const float texY2 = static_cast<float>(srcY + height) / th;
292
for (int px = 0; px < w; px += iw)
294
const int width = (px + iw >= w) ? w - px : iw;
295
const int dstX = x + px;
297
const float texX2 = static_cast<float>(srcX + width) / tw;
299
mFloatTexArray[vp + 0] = texX1;
300
mFloatTexArray[vp + 1] = texY1;
302
mFloatTexArray[vp + 2] = texX2;
303
mFloatTexArray[vp + 3] = texY1;
305
mFloatTexArray[vp + 4] = texX2;
306
mFloatTexArray[vp + 5] = texY2;
308
mFloatTexArray[vp + 6] = texX1;
309
mFloatTexArray[vp + 7] = texY2;
311
mIntVertArray[vp + 0] = dstX;
312
mIntVertArray[vp + 1] = dstY;
314
mIntVertArray[vp + 2] = dstX + width;
315
mIntVertArray[vp + 3] = dstY;
317
mIntVertArray[vp + 4] = dstX + width;
318
mIntVertArray[vp + 5] = dstY + height;
320
mIntVertArray[vp + 6] = dstX;
321
mIntVertArray[vp + 7] = dstY + height;
336
for (int py = 0; py < h; py += ih)
338
const int height = (py + ih >= h) ? h - py : ih;
339
const int dstY = y + py;
340
for (int px = 0; px < w; px += iw)
342
const int width = (px + iw >= w) ? w - px : iw;
343
const int dstX = x + px;
345
mIntTexArray[vp + 0] = srcX;
346
mIntTexArray[vp + 1] = srcY;
348
mIntTexArray[vp + 2] = srcX + width;
349
mIntTexArray[vp + 3] = srcY;
351
mIntTexArray[vp + 4] = srcX + width;
352
mIntTexArray[vp + 5] = srcY + height;
354
mIntTexArray[vp + 6] = srcX;
355
mIntTexArray[vp + 7] = srcY + height;
357
mIntVertArray[vp + 0] = dstX;
358
mIntVertArray[vp + 1] = dstY;
360
mIntVertArray[vp + 2] = dstX + width;
361
mIntVertArray[vp + 3] = dstY;
363
mIntVertArray[vp + 4] = dstX + width;
364
mIntVertArray[vp + 5] = dstY + height;
366
mIntVertArray[vp + 6] = dstX;
367
mIntVertArray[vp + 7] = dstY + height;
382
void NullOpenGLGraphics::drawRescaledImagePattern(const Image *const image,
383
const int x, const int y,
384
const int w, const int h,
385
const int scaledWidth,
386
const int scaledHeight)
391
if (scaledWidth == 0 || scaledHeight == 0)
394
const SDL_Rect &imageRect = image->mBounds;
395
const int iw = imageRect.w;
396
const int ih = imageRect.h;
397
if (iw == 0 || ih == 0)
400
const int srcX = imageRect.x;
401
const int srcY = imageRect.y;
403
setColorAlpha(image->mAlpha);
405
#ifdef DEBUG_BIND_TEXTURE
406
debugBindTexture(image);
408
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
410
setTexturingAndBlending(true);
413
const unsigned int vLimit = mMaxVertices * 4;
415
// Draw a set of textured rectangles
416
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
418
const float tw = static_cast<float>(image->mTexWidth);
419
const float th = static_cast<float>(image->mTexHeight);
421
const float texX1 = static_cast<float>(srcX) / tw;
422
const float texY1 = static_cast<float>(srcY) / th;
424
const float tFractionW = iw / tw;
425
const float tFractionH = ih / th;
427
for (int py = 0; py < h; py += scaledHeight)
429
const int height = (py + scaledHeight >= h)
430
? h - py : scaledHeight;
431
const int dstY = y + py;
432
const float visibleFractionH = static_cast<float>(height)
434
const float texY2 = texY1 + tFractionH * visibleFractionH;
435
for (int px = 0; px < w; px += scaledWidth)
437
const int width = (px + scaledWidth >= w)
438
? w - px : scaledWidth;
439
const int dstX = x + px;
440
const float visibleFractionW = static_cast<float>(width)
442
const float texX2 = texX1 + tFractionW * visibleFractionW;
444
mFloatTexArray[vp + 0] = texX1;
445
mFloatTexArray[vp + 1] = texY1;
447
mFloatTexArray[vp + 2] = texX2;
448
mFloatTexArray[vp + 3] = texY1;
450
mFloatTexArray[vp + 4] = texX2;
451
mFloatTexArray[vp + 5] = texY2;
453
mFloatTexArray[vp + 6] = texX1;
454
mFloatTexArray[vp + 7] = texY2;
456
mIntVertArray[vp + 0] = dstX;
457
mIntVertArray[vp + 1] = dstY;
459
mIntVertArray[vp + 2] = dstX + width;
460
mIntVertArray[vp + 3] = dstY;
462
mIntVertArray[vp + 4] = dstX + width;
463
mIntVertArray[vp + 5] = dstY + height;
465
mIntVertArray[vp + 6] = dstX;
466
mIntVertArray[vp + 7] = dstY + height;
481
const float scaleFactorW = static_cast<float>(scaledWidth) / iw;
482
const float scaleFactorH = static_cast<float>(scaledHeight) / ih;
484
for (int py = 0; py < h; py += scaledHeight)
486
const int height = (py + scaledHeight >= h)
487
? h - py : scaledHeight;
488
const int dstY = y + py;
489
const int scaledY = srcY + height / scaleFactorH;
490
for (int px = 0; px < w; px += scaledWidth)
492
const int width = (px + scaledWidth >= w)
493
? w - px : scaledWidth;
494
const int dstX = x + px;
495
const int scaledX = srcX + width / scaleFactorW;
497
mIntTexArray[vp + 0] = srcX;
498
mIntTexArray[vp + 1] = srcY;
500
mIntTexArray[vp + 2] = scaledX;
501
mIntTexArray[vp + 3] = srcY;
503
mIntTexArray[vp + 4] = scaledX;
504
mIntTexArray[vp + 5] = scaledY;
506
mIntTexArray[vp + 6] = srcX;
507
mIntTexArray[vp + 7] = scaledY;
509
mIntVertArray[vp + 0] = dstX;
510
mIntVertArray[vp + 1] = dstY;
512
mIntVertArray[vp + 2] = dstX + width;
513
mIntVertArray[vp + 3] = dstY;
515
mIntVertArray[vp + 4] = dstX + width;
516
mIntVertArray[vp + 5] = dstY + height;
518
mIntVertArray[vp + 6] = dstX;
519
mIntVertArray[vp + 7] = dstY + height;
534
inline void NullOpenGLGraphics::drawVertexes(const
535
NormalOpenGLGraphicsVertexes
538
const std::vector<GLint*> &intVertPool = ogl.mIntVertPool;
539
std::vector<GLint*>::const_iterator iv;
540
const std::vector<GLint*>::const_iterator iv_end = intVertPool.end();
541
const std::vector<int> &vp = ogl.mVp;
542
std::vector<int>::const_iterator ivp;
543
const std::vector<int>::const_iterator ivp_end = vp.end();
545
// Draw a set of textured rectangles
546
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
548
const std::vector<GLfloat*> &floatTexPool = ogl.mFloatTexPool;
549
std::vector<GLfloat*>::const_iterator ft;
550
const std::vector<GLfloat*>::const_iterator
551
ft_end = floatTexPool.end();
553
for (iv = intVertPool.begin(), ft = floatTexPool.begin(),
555
iv != iv_end && ft != ft_end && ivp != ivp_end;
556
++ iv, ++ ft, ++ ivp)
558
drawQuadArrayfi(*iv, *ft, *ivp);
563
const std::vector<GLint*> &intTexPool = ogl.mIntTexPool;
564
std::vector<GLint*>::const_iterator it;
565
const std::vector<GLint*>::const_iterator it_end = intTexPool.end();
567
for (iv = intVertPool.begin(), it = intTexPool.begin(),
569
iv != iv_end && it != it_end && ivp != ivp_end;
570
++ iv, ++ it, ++ ivp)
572
drawQuadArrayii(*iv, *it, *ivp);
577
void NullOpenGLGraphics::calcImagePattern(ImageVertexes* const vert,
578
const Image *const image,
579
const int x, const int y,
580
const int w, const int h) const
585
const SDL_Rect &imageRect = image->mBounds;
586
const int iw = imageRect.w;
587
const int ih = imageRect.h;
589
if (iw == 0 || ih == 0)
592
const int srcX = imageRect.x;
593
const int srcY = imageRect.y;
594
const float tw = static_cast<float>(image->mTexWidth);
595
const float th = static_cast<float>(image->mTexHeight);
597
const unsigned int vLimit = mMaxVertices * 4;
599
NormalOpenGLGraphicsVertexes &ogl = vert->ogl;
600
unsigned int vp = ogl.continueVp();
602
// Draw a set of textured rectangles
603
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
605
const float texX1 = static_cast<float>(srcX) / tw;
606
const float texY1 = static_cast<float>(srcY) / th;
608
GLfloat *floatTexArray = ogl.continueFloatTexArray();
609
GLint *intVertArray = ogl.continueIntVertArray();
611
for (int py = 0; py < h; py += ih)
613
const int height = (py + ih >= h) ? h - py : ih;
614
const int dstY = y + py;
615
const float texY2 = static_cast<float>(srcY + height) / th;
616
for (int px = 0; px < w; px += iw)
618
const int width = (px + iw >= w) ? w - px : iw;
619
const int dstX = x + px;
620
const float texX2 = static_cast<float>(srcX + width) / tw;
622
floatTexArray[vp + 0] = texX1;
623
floatTexArray[vp + 1] = texY1;
625
floatTexArray[vp + 2] = texX2;
626
floatTexArray[vp + 3] = texY1;
628
floatTexArray[vp + 4] = texX2;
629
floatTexArray[vp + 5] = texY2;
631
floatTexArray[vp + 6] = texX1;
632
floatTexArray[vp + 7] = texY2;
634
intVertArray[vp + 0] = dstX;
635
intVertArray[vp + 1] = dstY;
637
intVertArray[vp + 2] = dstX + width;
638
intVertArray[vp + 3] = dstY;
640
intVertArray[vp + 4] = dstX + width;
641
intVertArray[vp + 5] = dstY + height;
643
intVertArray[vp + 6] = dstX;
644
intVertArray[vp + 7] = dstY + height;
649
floatTexArray = ogl.switchFloatTexArray();
650
intVertArray = ogl.switchIntVertArray();
659
GLint *intTexArray = ogl.continueIntTexArray();
660
GLint *intVertArray = ogl.continueIntVertArray();
662
for (int py = 0; py < h; py += ih)
664
const int height = (py + ih >= h) ? h - py : ih;
665
const int dstY = y + py;
666
for (int px = 0; px < w; px += iw)
668
const int width = (px + iw >= w) ? w - px : iw;
669
const int dstX = x + px;
671
intTexArray[vp + 0] = srcX;
672
intTexArray[vp + 1] = srcY;
674
intTexArray[vp + 2] = srcX + width;
675
intTexArray[vp + 3] = srcY;
677
intTexArray[vp + 4] = srcX + width;
678
intTexArray[vp + 5] = srcY + height;
680
intTexArray[vp + 6] = srcX;
681
intTexArray[vp + 7] = srcY + height;
683
intVertArray[vp + 0] = dstX;
684
intVertArray[vp + 1] = dstY;
686
intVertArray[vp + 2] = dstX + width;
687
intVertArray[vp + 3] = dstY;
689
intVertArray[vp + 4] = dstX + width;
690
intVertArray[vp + 5] = dstY + height;
692
intVertArray[vp + 6] = dstX;
693
intVertArray[vp + 7] = dstY + height;
698
intTexArray = ogl.switchIntTexArray();
699
intVertArray = ogl.switchIntVertArray();
709
void NullOpenGLGraphics::calcTile(ImageCollection *const vertCol,
710
const Image *const image,
713
if (vertCol->currentGLImage != image->mGLImage)
715
ImageVertexes *const vert = new ImageVertexes();
716
vertCol->currentGLImage = image->mGLImage;
717
vertCol->currentVert = vert;
719
vertCol->draws.push_back(vert);
720
calcTile(vert, image, x, y);
724
calcTile(vertCol->currentVert, image, x, y);
728
void NullOpenGLGraphics::drawTile(const ImageCollection *const vertCol)
730
const ImageVertexesVector &draws = vertCol->draws;
731
const ImageCollectionCIter it_end = draws.end();
732
for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it)
734
const ImageVertexes *const vert = *it;
735
const Image *const image = vert->image;
737
setColorAlpha(image->mAlpha);
738
#ifdef DEBUG_BIND_TEXTURE
739
debugBindTexture(image);
741
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
742
setTexturingAndBlending(true);
743
drawVertexes(vert->ogl);
747
void NullOpenGLGraphics::calcImagePattern(ImageCollection* const vertCol,
748
const Image *const image,
749
const int x, const int y,
750
const int w, const int h) const
752
ImageVertexes *vert = nullptr;
753
if (vertCol->currentGLImage != image->mGLImage)
755
vert = new ImageVertexes();
756
vertCol->currentGLImage = image->mGLImage;
757
vertCol->currentVert = vert;
759
vertCol->draws.push_back(vert);
763
vert = vertCol->currentVert;
766
calcImagePattern(vert, image, x, y, w, h);
769
void NullOpenGLGraphics::calcTile(ImageVertexes *const vert,
770
const Image *const image,
771
int dstX, int dstY) const
776
const SDL_Rect &imageRect = image->mBounds;
777
const int w = imageRect.w;
778
const int h = imageRect.h;
780
if (w == 0 || h == 0)
783
const int srcX = imageRect.x;
784
const int srcY = imageRect.y;
786
const float tw = static_cast<float>(image->mTexWidth);
787
const float th = static_cast<float>(image->mTexHeight);
789
const unsigned int vLimit = mMaxVertices * 4;
791
NormalOpenGLGraphicsVertexes &ogl = vert->ogl;
793
// std::vector<int> *vps = ogl.getVp();
794
unsigned int vp = ogl.continueVp();
796
// Draw a set of textured rectangles
797
if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D)
799
const float texX1 = static_cast<float>(srcX) / tw;
800
const float texY1 = static_cast<float>(srcY) / th;
802
const float texX2 = static_cast<float>(srcX + w) / tw;
803
const float texY2 = static_cast<float>(srcY + h) / th;
805
GLfloat *const floatTexArray = ogl.continueFloatTexArray();
806
GLint *const intVertArray = ogl.continueIntVertArray();
808
floatTexArray[vp + 0] = texX1;
809
floatTexArray[vp + 1] = texY1;
811
floatTexArray[vp + 2] = texX2;
812
floatTexArray[vp + 3] = texY1;
814
floatTexArray[vp + 4] = texX2;
815
floatTexArray[vp + 5] = texY2;
817
floatTexArray[vp + 6] = texX1;
818
floatTexArray[vp + 7] = texY2;
820
intVertArray[vp + 0] = dstX;
821
intVertArray[vp + 1] = dstY;
823
intVertArray[vp + 2] = dstX + w;
824
intVertArray[vp + 3] = dstY;
826
intVertArray[vp + 4] = dstX + w;
827
intVertArray[vp + 5] = dstY + h;
829
intVertArray[vp + 6] = dstX;
830
intVertArray[vp + 7] = dstY + h;
835
ogl.switchFloatTexArray();
836
ogl.switchIntVertArray();
843
GLint *const intTexArray = ogl.continueIntTexArray();
844
GLint *const intVertArray = ogl.continueIntVertArray();
846
intTexArray[vp + 0] = srcX;
847
intTexArray[vp + 1] = srcY;
849
intTexArray[vp + 2] = srcX + w;
850
intTexArray[vp + 3] = srcY;
852
intTexArray[vp + 4] = srcX + w;
853
intTexArray[vp + 5] = srcY + h;
855
intTexArray[vp + 6] = srcX;
856
intTexArray[vp + 7] = srcY + h;
858
intVertArray[vp + 0] = dstX;
859
intVertArray[vp + 1] = dstY;
861
intVertArray[vp + 2] = dstX + w;
862
intVertArray[vp + 3] = dstY;
864
intVertArray[vp + 4] = dstX + w;
865
intVertArray[vp + 5] = dstY + h;
867
intVertArray[vp + 6] = dstX;
868
intVertArray[vp + 7] = dstY + h;
873
ogl.switchIntTexArray();
874
ogl.switchIntVertArray();
882
void NullOpenGLGraphics::drawTile(const ImageVertexes *const vert)
886
const Image *const image = vert->image;
888
setColorAlpha(image->mAlpha);
889
#ifdef DEBUG_BIND_TEXTURE
890
debugBindTexture(image);
892
bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage);
893
setTexturingAndBlending(true);
894
drawVertexes(vert->ogl);
897
bool NullOpenGLGraphics::calcWindow(ImageCollection *const vertCol,
898
const int x, const int y,
899
const int w, const int h,
900
const ImageRect &imgRect)
902
ImageVertexes *vert = nullptr;
903
Image *const image = imgRect.grid[4];
906
if (vertCol->currentGLImage != image->mGLImage)
908
vert = new ImageVertexes();
909
vertCol->currentGLImage = image->mGLImage;
910
vertCol->currentVert = vert;
912
vertCol->draws.push_back(vert);
916
vert = vertCol->currentVert;
919
return calcImageRect(vert, x, y, w, h,
920
imgRect.grid[0], imgRect.grid[2], imgRect.grid[6], imgRect.grid[8],
921
imgRect.grid[1], imgRect.grid[5], imgRect.grid[7], imgRect.grid[3],
925
void NullOpenGLGraphics::updateScreen()
927
BLOCK_START("Graphics::updateScreen")
928
#ifdef DEBUG_DRAW_CALLS
929
mLastDrawCalls = mDrawCalls;
932
BLOCK_END("Graphics::updateScreen")
935
void NullOpenGLGraphics::_beginDraw()
937
pushClipArea(gcn::Rectangle(0, 0, 640, 480));
940
void NullOpenGLGraphics::_endDraw()
945
void NullOpenGLGraphics::prepareScreenshot()
949
SDL_Surface* NullOpenGLGraphics::getScreenshot()
954
bool NullOpenGLGraphics::pushClipArea(gcn::Rectangle area)
959
if (!mClipStack.empty())
961
const gcn::ClipRectangle &clipArea = mClipStack.top();
962
transX = -clipArea.xOffset;
963
transY = -clipArea.yOffset;
966
const bool result = gcn::Graphics::pushClipArea(area);
968
const gcn::ClipRectangle &clipArea = mClipStack.top();
969
transX += clipArea.xOffset;
970
transY += clipArea.yOffset;
975
void NullOpenGLGraphics::popClipArea()
977
gcn::Graphics::popClipArea();
979
if (mClipStack.empty())
983
void NullOpenGLGraphics::drawPoint(int x A_UNUSED, int y A_UNUSED)
985
setTexturingAndBlending(false);
989
void NullOpenGLGraphics::drawLine(int x1, int y1,
992
setTexturingAndBlending(false);
995
mFloatTexArray[0] = static_cast<float>(x1) + 0.5f;
996
mFloatTexArray[1] = static_cast<float>(y1) + 0.5f;
997
mFloatTexArray[2] = static_cast<float>(x2) + 0.5f;
998
mFloatTexArray[3] = static_cast<float>(y2) + 0.5f;
1003
void NullOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect)
1005
drawRectangle(rect, false);
1008
void NullOpenGLGraphics::fillRectangle(const gcn::Rectangle& rect)
1010
drawRectangle(rect, true);
1013
void NullOpenGLGraphics::setTargetPlane(int width A_UNUSED,
1014
int height A_UNUSED)
1018
void NullOpenGLGraphics::setTexturingAndBlending(const bool enable)
1031
if (mAlpha && !mColorAlpha)
1033
else if (!mAlpha && mColorAlpha)
1041
void NullOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect A_UNUSED,
1042
const bool filled A_UNUSED)
1044
BLOCK_START("Graphics::drawRectangle")
1045
setTexturingAndBlending(false);
1048
#ifdef DEBUG_DRAW_CALLS
1051
BLOCK_END("Graphics::drawRectangle")
1054
bool NullOpenGLGraphics::drawNet(const int x1, const int y1,
1055
const int x2, const int y2,
1056
const int width, const int height)
1058
unsigned int vp = 0;
1059
const unsigned int vLimit = mMaxVertices * 4;
1061
setTexturingAndBlending(false);
1064
const float xf1 = static_cast<float>(x1);
1065
const float xf2 = static_cast<float>(x2);
1066
const float yf1 = static_cast<float>(y1);
1067
const float yf2 = static_cast<float>(y2);
1069
for (int y = y1; y < y2; y += height)
1071
mFloatTexArray[vp + 0] = xf1;
1072
mFloatTexArray[vp + 1] = static_cast<float>(y);
1074
mFloatTexArray[vp + 2] = xf2;
1075
mFloatTexArray[vp + 3] = static_cast<float>(y);
1085
for (int x = x1; x < x2; x += width)
1087
mFloatTexArray[vp + 0] = static_cast<float>(x);
1088
mFloatTexArray[vp + 1] = yf1;
1090
mFloatTexArray[vp + 2] = static_cast<float>(x);
1091
mFloatTexArray[vp + 3] = yf2;
1107
void NullOpenGLGraphics::bindTexture(const GLenum target A_UNUSED,
1108
const GLuint texture)
1110
if (mLastImage != texture)
1111
mLastImage = texture;
1114
inline void NullOpenGLGraphics::drawQuadArrayfi(const int size A_UNUSED)
1116
#ifdef DEBUG_DRAW_CALLS
1121
inline void NullOpenGLGraphics::drawQuadArrayfi(const GLint *const
1122
intVertArray A_UNUSED,
1123
const GLfloat *const
1124
floatTexArray A_UNUSED,
1125
const int size A_UNUSED)
1127
#ifdef DEBUG_DRAW_CALLS
1132
inline void NullOpenGLGraphics::drawQuadArrayii(const int size A_UNUSED)
1134
#ifdef DEBUG_DRAW_CALLS
1139
inline void NullOpenGLGraphics::drawQuadArrayii(const GLint *const
1140
intVertArray A_UNUSED,
1142
intTexArray A_UNUSED,
1143
const int size A_UNUSED)
1145
#ifdef DEBUG_DRAW_CALLS
1150
inline void NullOpenGLGraphics::drawLineArrayi(const int size A_UNUSED)
1152
#ifdef DEBUG_DRAW_CALLS
1157
inline void NullOpenGLGraphics::drawLineArrayf(const int size A_UNUSED)
1159
#ifdef DEBUG_DRAW_CALLS
1164
void NullOpenGLGraphics::dumpSettings()
1168
void NullOpenGLGraphics::setColorAlpha(const float alpha)
1170
if (!mIsByteColor && mFloatColor == alpha)
1173
mIsByteColor = false;
1174
mFloatColor = alpha;
1177
void NullOpenGLGraphics::restoreColor()
1179
if (mIsByteColor && mByteColor == mColor)
1182
mIsByteColor = true;
1183
mByteColor = mColor;
1186
#ifdef DEBUG_BIND_TEXTURE
1187
void NullOpenGLGraphics::debugBindTexture(const Image *const image)
1189
const std::string texture = image->getIdPath();
1190
if (mOldTexture != texture)
1192
if ((!mOldTexture.empty() || !texture.empty())
1193
&& mOldTextureId != image->mGLImage)
1195
logger->log("bind: %s (%d) to %s (%d)", mOldTexture.c_str(),
1196
mOldTextureId, texture.c_str(), image->mGLImage);
1198
mOldTextureId = image->mGLImage;
1199
mOldTexture = texture;
1203
void NullOpenGLGraphics::debugBindTexture(const Image *const image A_UNUSED)
1208
#endif // USE_OPENGL