ManaPlus
sdl2graphics.cpp
Go to the documentation of this file.
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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 /* _______ __ __ __ ______ __ __ _______ __ __
25  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
26  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
27  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
28  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
29  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
30  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
31  *
32  * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
33  *
34  *
35  * Per Larsson a.k.a finalman
36  * Olof Naessén a.k.a jansem/yakslem
37  *
38  * Visit: http://guichan.sourceforge.net
39  *
40  * License: (BSD)
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  * notice, this list of conditions and the following disclaimer in
48  * the documentation and/or other materials provided with the
49  * distribution.
50  * 3. Neither the name of Guichan nor the names of its contributors may
51  * be used to endorse or promote products derived from this software
52  * without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
60  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
61  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
63  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 #ifdef USE_SDL2
68 
69 #include "render/sdl2graphics.h"
70 
71 #include "graphicsmanager.h"
72 
74 
75 #include "resources/imagerect.h"
77 
78 #include "resources/image/image.h"
79 
80 #include "utils/sdlcheckutils.h"
81 
82 #include "debug.h"
83 
84 #ifdef DEBUG_SDL_SURFACES
85 
86 #define MSDL_RenderCopy(render, texture, src, dst) \
87  FakeSDL_RenderCopy(render, texture, src, dst)
88 
89 static int FakeSDL_RenderCopy(SDL_Renderer *restrict const renderer,
90  SDL_Texture *restrict const texture,
91  const SDL_Rect *restrict const srcrect,
92  const SDL_Rect *restrict const dstrect)
93 {
94  int ret = SDL_RenderCopy(renderer, texture, srcrect, dstrect);
95  if (ret)
96  {
97  logger->log("rendering error in texture %p: %s",
98  static_cast<void*>(texture), SDL_GetError());
99  }
100  return ret;
101 }
102 
103 #else // DEBUG_SDL_SURFACES
104 
105 #define MSDL_RenderCopy(render, texture, src, dst) \
106  SDL_RenderCopy(render, texture, src, dst)
107 
108 #endif // DEBUG_SDL_SURFACES
109 
110 #define setRenderDrawColor(mColor) \
111  SDL_SetRenderDrawColor(mRenderer, \
112  CAST_U8(mColor.r), \
113  CAST_U8(mColor.g), \
114  CAST_U8(mColor.b), \
115  CAST_U8(mColor.a))
116 
117 #define defRectFromArea(rect, area) \
118  const SDL_Rect rect = \
119  { \
120  CAST_S32(area.x), \
121  CAST_S32(area.y), \
122  CAST_S32(area.width), \
123  CAST_S32(area.height) \
124  }
125 
127  Graphics(),
128  mRendererFlags(SDL_RENDERER_SOFTWARE),
129  mOldPixel(0),
130  mOldAlpha(0)
131 {
132  mOpenGL = RENDER_SDL2_DEFAULT;
133  mName = "SDL2 default";
134 }
135 
137 {
138 }
139 
140 void SDLGraphics::drawRescaledImage(const Image *restrict const image,
141  int dstX, int dstY,
142  const int desiredWidth,
143  const int desiredHeight) restrict2
144 {
145  FUNC_BLOCK("Graphics::drawRescaledImage", 1)
146  // Check that preconditions for blitting are met.
147  if (!mWindow || !image || !image->mTexture)
148  return;
149 
150  const ClipRect &top = mClipStack.top();
151  const SDL_Rect &bounds = image->mBounds;
152  const SDL_Rect srcRect =
153  {
154  CAST_S32(bounds.x),
155  CAST_S32(bounds.y),
156  CAST_S32(bounds.w),
157  CAST_S32(bounds.h)
158  };
159  const SDL_Rect dstRect =
160  {
161  CAST_S32(dstX + top.xOffset),
162  CAST_S32(dstY + top.yOffset),
163  CAST_S32(desiredWidth),
164  CAST_S32(desiredHeight)
165  };
166 
167  MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
168 }
169 
170 void SDLGraphics::drawImage(const Image *restrict const image,
171  int dstX, int dstY) restrict2
172 {
173  drawImageInline(image, dstX, dstY);
174 }
175 
176 void SDLGraphics::drawImageInline(const Image *restrict const image,
177  int dstX, int dstY) restrict2
178 {
179  FUNC_BLOCK("Graphics::drawImage", 1)
180  // Check that preconditions for blitting are met.
181  if (!mWindow || !image || !image->mTexture)
182  return;
183 
184  const ClipRect &top = mClipStack.top();
185  if (!top.width || !top.height)
186  return;
187 
188  const SDL_Rect &bounds = image->mBounds;
189  const SDL_Rect srcRect =
190  {
191  CAST_S32(bounds.x),
192  CAST_S32(bounds.y),
193  CAST_S32(bounds.w),
194  CAST_S32(bounds.h)
195  };
196 
197  const SDL_Rect dstRect =
198  {
199  CAST_S32(dstX + top.xOffset),
200  CAST_S32(dstY + top.yOffset),
201  CAST_S32(bounds.w),
202  CAST_S32(bounds.h)
203  };
204 
205  MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
206 }
207 
208 void SDLGraphics::copyImage(const Image *restrict const image,
209  int dstX, int dstY) restrict2
210 {
211  drawImageInline(image, dstX, dstY);
212 }
213 
214 void SDLGraphics::drawImageCached(const Image *restrict const image,
215  int x, int y) restrict2
216 {
217  FUNC_BLOCK("Graphics::drawImageCached", 1)
218  // Check that preconditions for blitting are met.
219  if (!mWindow || !image || !image->mTexture)
220  return;
221 
222  const ClipRect &top = mClipStack.top();
223  if (!top.width || !top.height)
224  return;
225 
226  const SDL_Rect &bounds = image->mBounds;
227  const SDL_Rect srcRect =
228  {
229  CAST_S32(bounds.x),
230  CAST_S32(bounds.y),
231  CAST_S32(bounds.w),
232  CAST_S32(bounds.h)
233  };
234 
235  const SDL_Rect dstRect =
236  {
237  CAST_S32(x + top.xOffset),
238  CAST_S32(y + top.yOffset),
239  CAST_S32(bounds.w),
240  CAST_S32(bounds.h)
241  };
242 
243  MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
244 }
245 
246 void SDLGraphics::drawPatternCached(const Image *restrict const image,
247  const int x, const int y,
248  const int w, const int h) restrict2
249 {
250  FUNC_BLOCK("Graphics::drawPatternCached", 1)
251  // Check that preconditions for blitting are met.
252  if (!mWindow || !image)
253  return;
254  if (!image->mTexture)
255  return;
256 
257  const ClipRect &top = mClipStack.top();
258  if (!top.width || !top.height)
259  return;
260 
261  const SDL_Rect &bounds = image->mBounds;
262  const int iw = bounds.w;
263  const int ih = bounds.h;
264  if (iw == 0 || ih == 0)
265  return;
266 
267  const int xOffset = top.xOffset + x;
268  const int yOffset = top.yOffset + y;
269 
270  SDL_Rect dstRect;
271  SDL_Rect srcRect;
272  srcRect.x = CAST_S32(bounds.x);
273  srcRect.y = CAST_S32(bounds.y);
274  for (int py = 0; py < h; py += ih)
275  {
276  const int dh = (py + ih >= h) ? h - py : ih;
277  dstRect.y = CAST_S32(py + yOffset);
278  srcRect.h = CAST_S32(dh);
279  dstRect.h = CAST_S32(dh);
280 
281  for (int px = 0; px < w; px += iw)
282  {
283  const int dw = (px + iw >= w) ? w - px : iw;
284  dstRect.x = CAST_S32(px + xOffset);
285  srcRect.w = CAST_S32(dw);
286  dstRect.w = CAST_S32(dw);
287 
288  MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
289  }
290  }
291 }
292 
294 {
295 }
296 
297 void SDLGraphics::drawPattern(const Image *restrict const image,
298  const int x, const int y,
299  const int w, const int h) restrict2
300 {
301  drawPatternInline(image, x, y, w, h);
302 }
303 
304 void SDLGraphics::drawPatternInline(const Image *restrict const image,
305  const int x, const int y,
306  const int w, const int h) restrict2
307 {
308  FUNC_BLOCK("Graphics::drawPattern", 1)
309  // Check that preconditions for blitting are met.
310  if (!mWindow || !image)
311  return;
312  if (!image->mTexture)
313  return;
314 
315  const ClipRect &top = mClipStack.top();
316  if (!top.width || !top.height)
317  return;
318 
319  const SDL_Rect &bounds = image->mBounds;
320  const int iw = bounds.w;
321  const int ih = bounds.h;
322  if (iw == 0 || ih == 0)
323  return;
324 
325  const int xOffset = top.xOffset + x;
326  const int yOffset = top.yOffset + y;
327 
328  SDL_Rect dstRect;
329  SDL_Rect srcRect;
330  srcRect.x = CAST_S32(bounds.x);
331  srcRect.y = CAST_S32(bounds.y);
332  for (int py = 0; py < h; py += ih)
333  {
334  const int dh = (py + ih >= h) ? h - py : ih;
335  dstRect.y = CAST_S32(py + yOffset);
336  srcRect.h = CAST_S32(dh);
337  dstRect.h = CAST_S32(dh);
338 
339  for (int px = 0; px < w; px += iw)
340  {
341  const int dw = (px + iw >= w) ? w - px : iw;
342  dstRect.x = CAST_S32(px + xOffset);
343  srcRect.w = CAST_S32(dw);
344  dstRect.w = CAST_S32(dw);
345 
346  MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
347  }
348  }
349 }
350 
351 void SDLGraphics::drawRescaledPattern(const Image *restrict const image,
352  const int x, const int y,
353  const int w, const int h,
354  const int scaledWidth,
355  const int scaledHeight) restrict2
356 {
357  // Check that preconditions for blitting are met.
358  if (!mWindow || !image)
359  return;
360  if (!image->mTexture)
361  return;
362 
363  if (scaledHeight == 0 || scaledWidth == 0)
364  return;
365 
366  const ClipRect &top = mClipStack.top();
367  if (!top.width || !top.height)
368  return;
369 
370  Image *const tmpImage = image->SDLgetScaledImage(
371  scaledWidth, scaledHeight);
372  if (!tmpImage)
373  return;
374 
375  const SDL_Rect &bounds = tmpImage->mBounds;
376  const int iw = bounds.w;
377  const int ih = bounds.h;
378  if (iw == 0 || ih == 0)
379  return;
380 
381  const int xOffset = top.xOffset + x;
382  const int yOffset = top.yOffset + y;
383 
384  SDL_Rect dstRect;
385  SDL_Rect srcRect;
386  srcRect.x = CAST_S32(bounds.x);
387  srcRect.y = CAST_S32(bounds.y);
388  for (int py = 0; py < h; py += ih)
389  {
390  const int dh = (py + ih >= h) ? h - py : ih;
391  dstRect.y = CAST_S32(py + yOffset);
392  srcRect.h = CAST_S32(dh);
393  dstRect.h = CAST_S32(dh);
394 
395  for (int px = 0; px < w; px += iw)
396  {
397  const int dw = (px + iw >= w) ? w - px : iw;
398  dstRect.x = CAST_S32(px + xOffset);
399  srcRect.w = CAST_S32(dw);
400  dstRect.w = CAST_S32(dw);
401 
402  MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect);
403  }
404  }
405 
406  delete tmpImage;
407 }
408 
410  const Image *restrict const image,
411  const int x, const int y,
412  const int w, const int h) const restrict2
413 {
414  calcPatternInline(vert, image, x, y, w, h);
415 }
416 
418  const Image *restrict const image,
419  const int x, const int y,
420  const int w, const int h) const restrict2
421 {
422  // Check that preconditions for blitting are met.
423  if (!vert || !mWindow || !image || !image->mTexture)
424  return;
425 
426  const ClipRect &top = mClipStack.top();
427  if (!top.width || !top.height)
428  return;
429 
430  const SDL_Rect &bounds = image->mBounds;
431  const int iw = bounds.w;
432  const int ih = bounds.h;
433  if (iw == 0 || ih == 0)
434  return;
435 
436  const int xOffset = top.xOffset + x;
437  const int yOffset = top.yOffset + y;
438  const int srcX = bounds.x;
439  const int srcY = bounds.y;
440  for (int py = 0; py < h; py += ih)
441  {
442  const int dh = (py + ih >= h) ? h - py : ih;
443  const int dstY = py + yOffset;
444 
445  for (int px = 0; px < w; px += iw)
446  {
447  const int dw = (px + iw >= w) ? w - px : iw;
448  const int dstX = px + xOffset;
449 
450  DoubleRect *const r = new DoubleRect;
451  SDL_Rect &dstRect = r->dst;
452  SDL_Rect &srcRect = r->src;
453  srcRect.x = CAST_S32(srcX);
454  srcRect.y = CAST_S32(srcY);
455  srcRect.w = CAST_S32(dw);
456  srcRect.h = CAST_S32(dh);
457  dstRect.x = CAST_S32(dstX);
458  dstRect.y = CAST_S32(dstY);
459  dstRect.w = CAST_S32(dw);
460  dstRect.h = CAST_S32(dh);
461 
462  vert->sdl.push_back(r);
463  }
464  }
465 }
466 
468  const Image *restrict const image,
469  const int x, const int y,
470  const int w, const int h) const restrict2
471 {
472  ImageVertexes *vert = nullptr;
473  if (vertCol->currentImage != image)
474  {
475  vert = new ImageVertexes;
476  vertCol->currentImage = image;
477  vertCol->currentVert = vert;
478  vert->image = image;
479  vertCol->draws.push_back(vert);
480  }
481  else
482  {
483  vert = vertCol->currentVert;
484  }
485 
486  calcPatternInline(vert, image, x, y, w, h);
487 }
488 
490  const Image *restrict const image,
491  int x, int y) const restrict2
492 {
493  vert->image = image;
494  calcTileSDL(vert, x, y);
495 }
496 
498  const Image *restrict const image,
499  int x, int y) const restrict2
500 {
501  vert->image = image;
502  calcTileSDL(vert, x, y);
503 }
504 
506  int x, int y) const restrict2
507 {
508  // Check that preconditions for blitting are met.
509  if (!vert || !vert->image || !vert->image->mTexture)
510  return;
511 
512  const ClipRect &top = mClipStack.top();
513  if (!top.width || !top.height)
514  return;
515 
516  const Image *const image = vert->image;
517  const SDL_Rect &bounds = image->mBounds;
518 
519  x += top.xOffset;
520  y += top.yOffset;
521 
522  DoubleRect *rect = new DoubleRect;
523  SDL_Rect &dstRect = rect->dst;
524  SDL_Rect &srcRect = rect->src;
525 
526  srcRect.x = CAST_S32(bounds.x);
527  srcRect.y = CAST_S32(bounds.y);
528  srcRect.w = CAST_S32(bounds.w);
529  srcRect.h = CAST_S32(bounds.h);
530  dstRect.x = CAST_S32(x);
531  dstRect.y = CAST_S32(y);
532  dstRect.w = CAST_S32(bounds.w);
533  dstRect.h = CAST_S32(bounds.h);
534 
535  vert->sdl.push_back(rect);
536 }
537 
539  const Image *restrict const image,
540  int x, int y) restrict2
541 {
542  if (!vertCol)
543  return;
544  if (vertCol->currentImage != image)
545  {
546  ImageVertexes *const vert = new ImageVertexes;
547  vertCol->currentImage = image;
548  vertCol->currentVert = vert;
549  vert->image = image;
550  vertCol->draws.push_back(vert);
551  calcTileSDL(vert, x, y);
552  }
553  else
554  {
555  calcTileSDL(vertCol->currentVert, x, y);
556  }
557 }
558 
560  *restrict const vertCol) restrict2
561 {
562  const ImageVertexesVector &draws = vertCol->draws;
563  const ImageCollectionCIter it_end = draws.end();
564  for (ImageCollectionCIter it = draws.begin(); it != it_end; ++ it)
565  {
566  const ImageVertexes *const vert = *it;
567  const Image *const img = vert->image;
568  const DoubleRects *const rects = &vert->sdl;
569  DoubleRects::const_iterator it2 = rects->begin();
570  const DoubleRects::const_iterator it2_end = rects->end();
571  while (it2 != it2_end)
572  {
573  MSDL_RenderCopy(mRenderer, img->mTexture,
574  &(*it2)->src, &(*it2)->dst);
575  ++ it2;
576  }
577  }
578 }
579 
581  restrict2
582 {
583  if (!vert)
584  return;
585  // vert and img must be != 0
586  const Image *const img = vert->image;
587  const DoubleRects *const rects = &vert->sdl;
588  DoubleRects::const_iterator it = rects->begin();
589  const DoubleRects::const_iterator it_end = rects->end();
590  while (it != it_end)
591  {
592  MSDL_RenderCopy(mRenderer, img->mTexture, &(*it)->src, &(*it)->dst);
593  ++ it;
594  }
595 }
596 
598 {
599  BLOCK_START("Graphics::updateScreen")
600  SDL_RenderPresent(mRenderer);
601 // SDL_RenderClear(mRenderer);
603 }
604 
605 void SDLGraphics::calcWindow(ImageCollection *restrict const vertCol,
606  const int x, const int y,
607  const int w, const int h,
608  const ImageRect &restrict imgRect) restrict2
609 {
610  ImageVertexes *vert = nullptr;
611  Image *const image = imgRect.grid[4];
612  if (!image)
613  return;
614  if (vertCol->currentImage != image)
615  {
616  vert = new ImageVertexes;
617  vertCol->currentImage = image;
618  vertCol->currentVert = vert;
619  vert->image = image;
620  vertCol->draws.push_back(vert);
621  }
622  else
623  {
624  vert = vertCol->currentVert;
625  }
626  calcImageRect(vert, x, y, w, h, imgRect);
627 }
628 
629 void SDLGraphics::fillRectangle(const Rect &restrict rectangle) restrict2
630 {
631  const ClipRect &top = mClipStack.top();
632  const SDL_Rect rect =
633  {
634  CAST_S32(rectangle.x + top.xOffset),
635  CAST_S32(rectangle.y + top.yOffset),
636  CAST_S32(rectangle.width),
637  CAST_S32(rectangle.height)
638  };
639 
640  setRenderDrawColor(mColor);
641  SDL_RenderFillRects(mRenderer, &rect, 1);
642 }
643 
645 {
646  pushClipArea(Rect(0, 0, mRect.w, mRect.h));
647 }
648 
650 {
651  popClipArea();
652 }
653 
655 {
657 
658  const ClipRect &carea = mClipStack.top();
659  defRectFromArea(rect, carea);
660  SDL_RenderSetClipRect(mRenderer, &rect);
661 }
662 
664 {
666 
667  if (mClipStack.empty())
668  return;
669 
670  const ClipRect &carea = mClipStack.top();
671  defRectFromArea(rect, carea);
672  SDL_RenderSetClipRect(mRenderer, &rect);
673 }
674 
675 void SDLGraphics::drawPoint(int x, int y) restrict2
676 {
677  if (mClipStack.empty())
678  return;
679 
680  const ClipRect &top = mClipStack.top();
681 
682  x += top.xOffset;
683  y += top.yOffset;
684 
685  if (!top.isPointInRect(x, y))
686  return;
687 
688  setRenderDrawColor(mColor);
689  const SDL_Point point =
690  {
691  x,
692  y
693  };
694 
695  SDL_RenderDrawPoints(mRenderer, &point, 1);
696 }
697 
698 
699 void SDLGraphics::drawRectangle(const Rect &restrict rectangle) restrict2
700 {
701  const ClipRect &top = mClipStack.top();
702  setRenderDrawColor(mColor);
703 
704  const int x1 = rectangle.x + top.xOffset;
705  const int y1 = rectangle.y + top.yOffset;
706  const int x2 = x1 + rectangle.width - 1;
707  const int y2 = y1 + rectangle.height - 1;
708  SDL_Point points[] =
709  {
710  {x1, y1},
711  {x2, y1},
712  {x2, y2},
713  {x1, y2},
714  {x1, y1}
715  };
716 
717  SDL_RenderDrawLines(mRenderer, points, 5);
718 }
719 
720 void SDLGraphics::drawLine(int x1, int y1,
721  int x2, int y2) restrict2
722 {
723  const ClipRect &top = mClipStack.top();
724  setRenderDrawColor(mColor);
725 
726  const int x0 = top.xOffset;
727  const int y0 = top.yOffset;
728 
729  SDL_Point points[] =
730  {
731  {x1 + x0, y1 + y0},
732  {x2 + x0, y2 + y0}
733  };
734 
735  SDL_RenderDrawLines(mRenderer, points, 2);
736 }
737 
738 bool SDLGraphics::setVideoMode(const int w, const int h,
739  const int scale,
740  const int bpp,
741  const bool fs,
742  const bool hwaccel,
743  const bool resize,
744  const bool noFrame,
745  const bool allowHighDPI) restrict2
746 {
747  setMainFlags(w, h,
748  scale,
749  bpp,
750  fs,
751  hwaccel,
752  resize,
753  noFrame,
754  allowHighDPI);
755 
756  if (!(mWindow = GraphicsManager::createWindow(w, h, bpp,
757  getSoftwareFlags())))
758  {
759  mRect.w = 0;
760  mRect.h = 0;
761  return false;
762  }
763 
764  int w1 = 0;
765  int h1 = 0;
766  SDL_GetWindowSize(mWindow, &w1, &h1);
767  mRect.w = w1;
768  mRect.h = h1;
769 
770  mRenderer = graphicsManager.createRenderer(mWindow, mRendererFlags);
771  SDLImageHelper::setRenderer(mRenderer);
772  return videoInfo();
773 }
774 
775 void SDLGraphics::drawImageRect(const int x, const int y,
776  const int w, const int h,
777  const ImageRect &restrict imgRect) restrict2
778 {
780 }
781 
783  const int x, const int y,
784  const int w, const int h,
785  const ImageRect &restrict imgRect) restrict2
786 {
788 }
789 
790 #endif // USE_SDL2
#define CAST_S32
Definition: cast.h:30
static SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
virtual void updateScreen()=0
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
SDL_Rect mRect
Definition: graphics.h:543
void setMainFlags(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)
Definition: graphics.cpp:182
virtual void popClipArea()
Definition: graphics.cpp:739
virtual void drawRescaledPattern(const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)=0
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
virtual void beginDraw()
Definition: graphics.h:441
virtual bool setVideoMode(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)=0
virtual void fillRectangle(const Rect &rectangle)=0
SDL_Surface * mWindow
Definition: graphics.h:523
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
Color mColor
Definition: graphics.h:553
virtual void drawImageCached(const Image *const image, int srcX, int srcY)=0
virtual void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
virtual void endDraw()
Definition: graphics.h:453
virtual void calcTileSDL(ImageVertexes *const vert, int x, int y) const
Definition: graphics.h:224
bool videoInfo()
Definition: graphics.cpp:483
virtual void drawRectangle(const Rect &rectangle)=0
MStack< ClipRect > mClipStack
Definition: graphics.h:521
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
virtual void drawLine(int x1, int y1, int x2, int y2)=0
virtual void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const =0
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
virtual void drawPoint(int x, int y)=0
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
virtual void copyImage(const Image *const image, int dstX, int dstY)=0
virtual void pushClipArea(const Rect &area)
Definition: graphics.cpp:677
virtual void drawTileVertexes(const ImageVertexes *const vert)=0
virtual void drawPatternCached(const Image *const image, const int x, const int y, const int w, const int h)=0
virtual void completeCache()=0
int getSoftwareFlags() const
Definition: graphics.cpp:389
virtual void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
const Image * image
Definition: imagevertexes.h:48
DoubleRects sdl
Definition: imagevertexes.h:53
void log(const char *const log_text,...)
Definition: logger.cpp:269
Definition: rect.h:74
if(!vert) return
const Image *restrict const top
void calcPatternInline(ImageVertexes *restrict const vert, const Image *restrict const image, const int x, const int y, const int w, const int h) const restrict2 A_INLINE
void drawPatternInline(const Image *restrict const image, const int x, const int y, const int w, const int h) restrict2 A_INLINE
void void drawImageInline(const Image *restrict const image, int dstX, int dstY) restrict2 A_INLINE
void calcTileVertexesInline(ImageVertexes *restrict const vert, const Image *restrict const image, int x, int y) const restrict2 A_INLINE A_NONNULL(2
void calcImageRect(ImageVertexes *restrict const vert, int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 A_INLINE
GraphicsManager graphicsManager
std::vector< ImageVertexes * > ImageVertexesVector
Definition: imagevertexes.h:56
std::vector< DoubleRect * > DoubleRects
Definition: imagevertexes.h:35
ImageVertexesVector::const_iterator ImageCollectionCIter
Definition: imagevertexes.h:58
#define restrict
Definition: localconsts.h:165
#define restrict2
Definition: localconsts.h:166
Logger * logger
Definition: logger.cpp:89
#define FUNC_BLOCK(name, id)
Definition: perfomance.h:81
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
@ RENDER_SDL2_DEFAULT
Definition: rendertype.h:31
void calcTileSDL(ImageVertexes *restrict const vert, int x, int y) const restrict2 override final
SDL_Rect dst
Definition: doublerect.h:37
SDL_Rect src
Definition: doublerect.h:36
bool empty() const
Definition: mstack.h:88
T & top() const
Definition: mstack.h:73