OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Draw.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* NewGfx interfaces */
19 #include "C4Include.h"
21 #include "graphics/C4Draw.h"
22 
23 #include "platform/C4App.h"
24 #include "graphics/C4FontLoader.h"
25 #include "platform/C4Window.h"
26 #include "graphics/C4DrawGL.h"
27 #include "graphics/C4DrawT.h"
28 #include "lib/C4Markup.h"
29 #include "lib/C4Rect.h"
30 #include "config/C4Config.h"
31 #include "lib/StdMesh.h"
32 #include "graphics/CSurface8.h"
33 #include "lib/StdColors.h"
34 
35 #include <stdio.h>
36 
37 // Instruct Optimus laptops to use nVidia GPU instead of integrated GPU
38 #if defined(_WIN32) && !defined(USE_CONSOLE)
39 extern "C" {
40  __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
41 }
42 #endif
43 
44 // Global access pointer
45 C4Draw *pDraw=nullptr;
46 
47 void C4BltTransform::SetRotate(float iAngle, float fOffX, float fOffY) // set by angle and rotation offset
48 {
49  // iAngle is in degrees (cycling from 0 to 360)
50  // determine sine and cos of reversed angle in radians
51  // fAngle = -iAngle * pi/180 = iAngle * -pi/180
52  float fAngle = iAngle * -0.0174532925f;
53  float fsin = sinf(fAngle); float fcos = cosf(fAngle);
54  // set matrix values
55  mat[0] = +fcos; mat[1] = +fsin; mat[2] = (1-fcos)*fOffX - fsin*fOffY;
56  mat[3] = -fsin; mat[4] = +fcos; mat[5] = (1-fcos)*fOffY + fsin*fOffX;
57  mat[6] = 0; mat[7] = 0; mat[8] = 1;
58  /* calculation of rotation matrix:
59  x2 = fcos*(x1-fOffX) + fsin*(y1-fOffY) + fOffX
60  = fcos*x1 - fcos*fOffX + fsin*y1 - fsin*fOffY + fOffX
61  = x1*fcos + y1*fsin + (1-fcos)*fOffX - fsin*fOffY
62 
63  y2 = -fsin*(x1-fOffX) + fcos*(y1-fOffY) + fOffY
64  = x1*-fsin + fsin*fOffX + y1*fcos - fcos*fOffY + fOffY
65  = x1*-fsin + y1*fcos + fsin*fOffX + (1-fcos)*fOffY */
66 }
67 
69 {
70  // calc inverse of matrix
71  float det = r.mat[0]*r.mat[4]*r.mat[8] + r.mat[1]*r.mat[5]*r.mat[6]
72  + r.mat[2]*r.mat[3]*r.mat[7] - r.mat[2]*r.mat[4]*r.mat[6]
73  - r.mat[0]*r.mat[5]*r.mat[7] - r.mat[1]*r.mat[3]*r.mat[8];
74  if (!det) { Set(1,0,0,0,1,0,0,0,1); return false; }
75  mat[0] = (r.mat[4] * r.mat[8] - r.mat[5] * r.mat[7]) / det;
76  mat[1] = (r.mat[2] * r.mat[7] - r.mat[1] * r.mat[8]) / det;
77  mat[2] = (r.mat[1] * r.mat[5] - r.mat[2] * r.mat[4]) / det;
78  mat[3] = (r.mat[5] * r.mat[6] - r.mat[3] * r.mat[8]) / det;
79  mat[4] = (r.mat[0] * r.mat[8] - r.mat[2] * r.mat[6]) / det;
80  mat[5] = (r.mat[2] * r.mat[3] - r.mat[0] * r.mat[5]) / det;
81  mat[6] = (r.mat[3] * r.mat[7] - r.mat[4] * r.mat[6]) / det;
82  mat[7] = (r.mat[1] * r.mat[6] - r.mat[0] * r.mat[7]) / det;
83  mat[8] = (r.mat[0] * r.mat[4] - r.mat[1] * r.mat[3]) / det;
84  return true;
85 }
86 
87 void C4BltTransform::TransformPoint(float &rX, float &rY) const
88 {
89  // apply matrix
90  float fW = mat[6] * rX + mat[7] * rY + mat[8];
91  // store in temp, so original rX is used for calculation of rY
92  float fX = (mat[0] * rX + mat[1] * rY + mat[2]) / fW;
93  rY = (mat[3] * rX + mat[4] * rY + mat[5]) / fW;
94  rX = fX; // apply temp
95 }
96 
98 {
99  sfcPattern32 = nPattern.sfcPattern32;
100  if (sfcPattern32) sfcPattern32->Lock();
101  delete [] CachedPattern;
102  if (nPattern.CachedPattern)
103  {
104  CachedPattern = new uint32_t[sfcPattern32->Wdt * sfcPattern32->Hgt];
105  memcpy(CachedPattern, nPattern.CachedPattern, sfcPattern32->Wdt * sfcPattern32->Hgt * 4);
106  }
107  else
108  {
109  CachedPattern = 0;
110  }
111  Wdt = nPattern.Wdt;
112  Hgt = nPattern.Hgt;
113  Zoom = nPattern.Zoom;
114  return *this;
115 }
116 
117 bool C4Pattern::Set(C4Surface * sfcSource, int iZoom)
118 {
119  // Safety
120  if (!sfcSource) return false;
121  // Clear existing pattern
122  Clear();
123  // new style: simply store pattern for modulation or shifting, which will be decided upon use
124  sfcPattern32=sfcSource;
125  sfcPattern32->Lock();
126  Wdt = sfcPattern32->Wdt;
127  Hgt = sfcPattern32->Hgt;
128  // set zoom
129  Zoom=iZoom;
130  // set flags
131  CachedPattern = new uint32_t[Wdt * Hgt];
132  if (!CachedPattern) return false;
133  for (int y = 0; y < Hgt; ++y)
134  for (int x = 0; x < Wdt; ++x)
135  {
136  CachedPattern[y * Wdt + x] = sfcPattern32->GetPixDw(x, y, false);
137  }
138  return true;
139 }
140 
142 {
143  // disable
144  sfcPattern32=nullptr;
145  CachedPattern = 0;
146  Zoom=0;
147 }
148 
150 {
151  // pattern assigned
152  if (sfcPattern32)
153  {
154  // unlock it
155  sfcPattern32->Unlock();
156  // clear field
157  sfcPattern32=nullptr;
158  }
159  delete[] CachedPattern; CachedPattern = 0;
160 }
161 
162 DWORD C4Pattern::PatternClr(unsigned int iX, unsigned int iY) const
163 {
164  if (!CachedPattern) return 0;
165  // wrap position
166  iX %= Wdt; iY %= Hgt;
167  return CachedPattern[iY * Wdt + iX];
168 }
169 
170 //--------------------------------------------------------------------
171 
173 {
174  RenderTarget=nullptr;
175  ClipAll=false;
176  Active=false;
177  BlitModulated=false;
178  dwBlitMode = 0;
179  ResetGamma();
180  pFoW = nullptr;
181  ZoomX = 0; ZoomY = 0; Zoom = 1;
182  MeshTransform = nullptr;
183  fUsePerspective = false;
185 }
186 
188 {
189  ResetGamma();
190  Active=BlitModulated=false;
191  dwBlitMode = 0;
192 }
193 
194 bool C4Draw::GetSurfaceSize(C4Surface * sfcSurface, int &iWdt, int &iHgt)
195 {
196  return sfcSurface->GetSurfaceSize(iWdt, iHgt);
197 }
198 
199 bool C4Draw::SubPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
200 {
201  // Set sub primary clipper
202  SetPrimaryClipper(std::max(iX1,iClipX1),std::max(iY1,iClipY1),std::min(iX2,iClipX2),std::min(iY2,iClipY2));
203  return true;
204 }
205 
207 {
208  // Store current primary clipper
210  return true;
211 }
212 
214 {
215  // Restore primary clipper
217  return true;
218 }
219 
220 bool C4Draw::SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
221 {
222  // set clipper
223  fClipX1=iX1; fClipY1=iY1; fClipX2=iX2; fClipY2=iY2;
224  iClipX1=iX1; iClipY1=iY1; iClipX2=iX2; iClipY2=iY2;
225  UpdateClipper();
226  // Done
227  return true;
228 }
229 
231 {
232  return true;
233 }
234 
236 {
237  return true;
238 }
239 
241 {
242  // apply maximum clipper
243  SetPrimaryClipper(0,0,439832,439832);
244  // Done
245  return true;
246 }
247 
248 void C4Draw::BlitLandscape(C4Surface * sfcSource, float fx, float fy,
249  C4Surface * sfcTarget, float tx, float ty, float wdt, float hgt)
250 {
251  Blit(sfcSource, fx, fy, wdt, hgt, sfcTarget, tx, ty, wdt, hgt, false);
252 }
253 
254 void C4Draw::Blit8Fast(CSurface8 * sfcSource, int fx, int fy,
255  C4Surface * sfcTarget, int tx, int ty, int wdt, int hgt)
256 {
257  // blit 8bit-sfc
258  // lock surfaces
259  assert(sfcTarget->fPrimary);
260  bool fRender = sfcTarget->IsRenderTarget();
261  if (!fRender) if (!sfcTarget->Lock())
262  { return; }
263 
264  float tfx = tx, tfy = ty, twdt = wdt, thgt = hgt;
265  if (Zoom != 1.0)
266  {
267  ApplyZoom(tfx, tfy);
268  twdt *= Zoom;
269  thgt *= Zoom;
270  }
271 
272  // blit 8 bit pix in batches of 1024 pixels
273  static const int BUF_SIZE = 1024;
274  C4BltVertex* vertices = new C4BltVertex[BUF_SIZE];
275  int bufcnt = 0;
276 
277  for (int ycnt=0; ycnt<thgt; ++ycnt)
278  {
279  for (int xcnt=0; xcnt<twdt; ++xcnt)
280  {
281  BYTE byPix = sfcSource->GetPix(fx+wdt*xcnt/twdt, fy+hgt*ycnt/thgt);
282  DWORD dwClr = byPix ? sfcSource->pPal->GetClr(byPix) : 0x00000000;
283 
284  vertices[bufcnt].ftx = (float)(tx + xcnt / Zoom);
285  vertices[bufcnt].fty = (float)(ty + ycnt / Zoom);
286  DwTo4UB(dwClr, vertices[bufcnt].color);
287  ++bufcnt;
288 
289  if(bufcnt == BUF_SIZE)
290  {
291  PerformMultiPix(sfcTarget, vertices, BUF_SIZE, nullptr);
292  bufcnt = 0;
293  }
294  }
295 
296  }
297  if(bufcnt > 0)
298  PerformMultiPix(sfcTarget, vertices, bufcnt, nullptr);
299  delete[] vertices;
300  // unlock
301  if (!fRender) sfcTarget->Unlock();
302 }
303 
304 bool C4Draw::Blit(C4Surface * sfcSource, float fx, float fy, float fwdt, float fhgt,
305  C4Surface * sfcTarget, float tx, float ty, float twdt, float thgt,
306  bool fSrcColKey, const C4BltTransform *pTransform)
307 {
308  return BlitUnscaled(sfcSource, fx * sfcSource->Scale, fy * sfcSource->Scale, fwdt * sfcSource->Scale, fhgt * sfcSource->Scale,
309  sfcTarget, tx, ty, twdt, thgt, fSrcColKey, pTransform);
310 }
311 
312 bool C4Draw::BlitUnscaled(C4Surface * sfcSource, float fx, float fy, float fwdt, float fhgt,
313  C4Surface * sfcTarget, float tx, float ty, float twdt, float thgt,
314  bool fSrcColKey, const C4BltTransform *pTransform)
315 {
316  // safety
317  if (!sfcSource || !sfcTarget || !twdt || !thgt || !fwdt || !fhgt) return false;
318  // emulated blit?
319  if (!sfcTarget->IsRenderTarget())
320  {
321  C4BltTransform t;
322  if(pTransform && Zoom != 1.0)
323  {
324  t.Set(pTransform->mat[0]*Zoom, pTransform->mat[1]*Zoom, pTransform->mat[2]*Zoom + ZoomX*(1-Zoom),
325  pTransform->mat[3]*Zoom, pTransform->mat[4]*Zoom, pTransform->mat[5]*Zoom + ZoomY*(1-Zoom),
326  pTransform->mat[6], pTransform->mat[7], pTransform->mat[8]);
327  pTransform = &t;
328  }
329  else if(Zoom != 1.0)
330  {
331  ApplyZoom(tx, ty);
332  twdt *= Zoom;
333  thgt *= Zoom;
334  }
335 
336  return Blit8(sfcSource, int(fx), int(fy), int(fwdt), int(fhgt), sfcTarget, int(tx), int(ty), int(twdt), int(thgt), fSrcColKey, pTransform);
337  }
338 
339  // calc stretch
340  float scaleX = twdt/fwdt;
341  float scaleY = thgt/fhgt;
342  // bound
343  if (ClipAll) return true;
344  // inside screen?
345  if (twdt<=0 || thgt<=0) return false;
346  // prepare rendering to surface
347  if (!PrepareRendering(sfcTarget)) return false;
348  // texture present?
349  if (!sfcSource->texture)
350  {
351  // primary surface?
352  if (sfcSource->fPrimary)
353  {
354  // blit emulated
355  return Blit8(sfcSource, int(fx), int(fy), int(fwdt), int(fhgt), sfcTarget, int(tx), int(ty), int(twdt), int(thgt), fSrcColKey);
356  }
357  return false;
358  }
359  // blit with basesfc?
360  bool fBaseSfc=false;
361  if (sfcSource->pMainSfc) if (sfcSource->pMainSfc->texture) fBaseSfc = true;
362  // get involved texture offsets
363  int iTexSizeX=sfcSource->iTexSize;
364  int iTexSizeY=sfcSource->iTexSize;
365 
366  C4TexRef *pTex = sfcSource->texture.get();
367  // set up blit data
368  C4BltVertex vertices[6];
369  vertices[0].ftx = tx; vertices[0].fty = ty;
370  vertices[1].ftx = tx + twdt; vertices[1].fty = ty;
371  vertices[2].ftx = tx + twdt; vertices[2].fty = ty + thgt;
372  vertices[3].ftx = tx; vertices[3].fty = ty + thgt;
373  vertices[0].tx = fx / pTex->iSizeX; vertices[0].ty = fy / pTex->iSizeY;
374  vertices[1].tx = (fx + fwdt) / pTex->iSizeX; vertices[1].ty = fy / pTex->iSizeY;
375  vertices[2].tx = (fx + fwdt) / pTex->iSizeX; vertices[2].ty = (fy + fhgt) / pTex->iSizeY;
376  vertices[3].tx = fx / pTex->iSizeX; vertices[3].ty = (fy + fhgt) / pTex->iSizeY;
377  DwTo4UB(0xffffffff, vertices[0].color);
378  DwTo4UB(0xffffffff, vertices[1].color);
379  DwTo4UB(0xffffffff, vertices[2].color);
380  DwTo4UB(0xffffffff, vertices[3].color);
381 
382  // duplicate vertices
383  vertices[4] = vertices[0]; vertices[5] = vertices[2];
384 
385  C4TexRef * pBaseTex = pTex;
386  // is there a base-surface to be blitted first?
387  if (fBaseSfc)
388  {
389  // then get this surface as same offset as from other surface
390  // assuming this is only valid as long as there's no texture management,
391  // organizing partially used textures together!
392  pBaseTex = sfcSource->pMainSfc->texture.get();
393  }
394 
395  C4TexRef* pNormalTex = nullptr;
396  if (sfcSource->pNormalSfc)
397  pNormalTex = sfcSource->pNormalSfc->texture.get();
398 
399  // ClrByOwner is always fully opaque
400  const DWORD dwOverlayClrMod = 0xff000000 | sfcSource->ClrByOwnerClr;
401  PerformMultiTris(sfcTarget, vertices, 6, pTransform, pBaseTex, fBaseSfc ? pTex : nullptr, pNormalTex, dwOverlayClrMod, nullptr);
402  // success
403  return true;
404 }
405 
406 bool C4Draw::RenderMesh(StdMeshInstance &instance, C4Surface * sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform* pTransform)
407 {
408  // TODO: Emulate rendering
409  if (!sfcTarget->IsRenderTarget()) return false;
410 
411  // TODO: Clip
412 
413  // prepare rendering to surface
414  if (!PrepareRendering(sfcTarget)) return false;
415  // Update bone matrices and vertex data (note this also updates attach transforms and child transforms)
416  instance.UpdateBoneTransforms();
417  // Order faces according to MeshTransformation (note pTransform does not affect Z coordinate, so does not need to be taken into account for correct ordering)
418  StdMeshMatrix mat = StdMeshMatrix::Identity();
419  if(MeshTransform) mat = *MeshTransform * mat;
420  instance.ReorderFaces(&mat);
421  // Render mesh
422  PerformMesh(instance, tx, ty, twdt, thgt, dwPlayerColor, pTransform);
423  // success
424  return true;
425 }
426 
427 bool C4Draw::Blit8(C4Surface * sfcSource, int fx, int fy, int fwdt, int fhgt,
428  C4Surface * sfcTarget, int tx, int ty, int twdt, int thgt,
429  bool fSrcColKey, const C4BltTransform *pTransform)
430 {
431  if (!pTransform) return BlitSimple(sfcSource, fx, fy, fwdt, fhgt, sfcTarget, tx, ty, twdt, thgt, fSrcColKey!=false);
432  // safety
433  if (!fwdt || !fhgt) return true;
434  // Lock the surfaces
435  if (!sfcSource->Lock())
436  return false;
437  if (!sfcTarget->Lock())
438  { sfcSource->Unlock(); return false; }
439  // transformed, emulated blit
440  // Calculate transform target rect
441  C4BltTransform Transform;
442  Transform.SetMoveScale(tx-(float)fx*twdt/fwdt, ty-(float)fy*thgt/fhgt, (float) twdt/fwdt, (float) thgt/fhgt);
443  Transform *=* pTransform;
444  C4BltTransform TransformBack;
445  TransformBack.SetAsInv(Transform);
446  float ttx0=(float)tx, tty0=(float)ty, ttx1=(float)(tx+twdt), tty1=(float)(ty+thgt);
447  float ttx2=(float)ttx0, tty2=(float)tty1, ttx3=(float)ttx1, tty3=(float)tty0;
448  pTransform->TransformPoint(ttx0, tty0);
449  pTransform->TransformPoint(ttx1, tty1);
450  pTransform->TransformPoint(ttx2, tty2);
451  pTransform->TransformPoint(ttx3, tty3);
452  int ttxMin = std::max<int>((int)floor(std::min(std::min(ttx0, ttx1), std::min(ttx2, ttx3))), 0);
453  int ttxMax = std::min<int>((int)ceil(std::max(std::max(ttx0, ttx1), std::max(ttx2, ttx3))), sfcTarget->Wdt);
454  int ttyMin = std::max<int>((int)floor(std::min(std::min(tty0, tty1), std::min(tty2, tty3))), 0);
455  int ttyMax = std::min<int>((int)ceil(std::max(std::max(tty0, tty1), std::max(tty2, tty3))), sfcTarget->Hgt);
456  // blit within target rect
457  for (int y = ttyMin; y < ttyMax; ++y)
458  for (int x = ttxMin; x < ttxMax; ++x)
459  {
460  float ffx=(float)x, ffy=(float)y;
461  TransformBack.TransformPoint(ffx, ffy);
462  int ifx=static_cast<int>(ffx), ify=static_cast<int>(ffy);
463  if (ifx<fx || ify<fy || ifx>=fx+fwdt || ify>=fy+fhgt) continue;
464  sfcTarget->BltPix(x,y, sfcSource, ifx,ify, !!fSrcColKey);
465  }
466  // Unlock the surfaces
467  sfcSource->Unlock();
468  sfcTarget->Unlock();
469  return true;
470 }
471 
472 bool C4Draw::BlitSimple(C4Surface * sfcSource, int fx, int fy, int fwdt, int fhgt,
473  C4Surface * sfcTarget, int tx, int ty, int twdt, int thgt,
474  bool fTransparency)
475 {
476  // rendertarget?
477  if (sfcTarget->IsRenderTarget())
478  {
479  return Blit(sfcSource, float(fx), float(fy), float(fwdt), float(fhgt), sfcTarget, float(tx), float(ty), float(twdt), float(thgt), true);
480  }
481  // Object is first stretched to dest rect
482  int xcnt,ycnt,tcx,tcy,cpcx,cpcy;
483  if (!fwdt || !fhgt || !twdt || !thgt) return false;
484  // Lock the surfaces
485  if (!sfcSource->Lock())
486  return false;
487  if (!sfcTarget->Lock())
488  { sfcSource->Unlock(); return false; }
489  // Rectangle centers
490  tcx=twdt/2; tcy=thgt/2;
491  for (ycnt=0; ycnt<thgt; ycnt++)
492  if (Inside(cpcy=ty+tcy-thgt/2+ycnt,0,sfcTarget->Hgt-1))
493  for (xcnt=0; xcnt<twdt; xcnt++)
494  if (Inside(cpcx=tx+tcx-twdt/2+xcnt,0,sfcTarget->Wdt-1))
495  sfcTarget->BltPix(cpcx, cpcy, sfcSource, xcnt*fwdt/twdt+fx, ycnt*fhgt/thgt+fy, fTransparency);
496  // Unlock the surfaces
497  sfcSource->Unlock();
498  sfcTarget->Unlock();
499  return true;
500 }
501 
502 
503 bool C4Draw::Error(const char *szMsg)
504 {
505  if (pApp) pApp->Error(szMsg);
506  Log(szMsg); return false;
507 }
508 
509 
510 bool C4Draw::CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
511 {
512  // simply setup primary viewport
513  // assume no zoom has been set yet
514  assert(Zoom==1.0f);
515  SetPrimaryClipper(0, 0, iXRes - 1, iYRes - 1);
517  return true;
518 }
519 
520 bool C4Draw::BlitSurface(C4Surface * sfcSurface, C4Surface * sfcTarget, int tx, int ty, bool fBlitBase)
521 {
522  if (fBlitBase)
523  {
524  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
525  return true;
526  }
527  else
528  {
529  if (!sfcSurface) return false;
530  C4Surface *pSfcBase = sfcSurface->pMainSfc;
531  sfcSurface->pMainSfc = nullptr;
532  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
533  sfcSurface->pMainSfc = pSfcBase;
534  return true;
535  }
536 }
537 
538 bool C4Draw::BlitSurfaceTile(C4Surface * sfcSurface, C4Surface * sfcTarget, float iToX, float iToY, float iToWdt, float iToHgt, float iOffsetX, float iOffsetY, C4ShaderCall* shader_call)
539 {
540  // Only direct rendering from single, tileable, texture
541  if (!sfcTarget->IsRenderTarget()) return false;
542  if ((sfcSurface->texture->iFlags & C4SF_Tileable) == 0) return false;
543 
544  // source surface dimensions
545  const float sourceWdt = sfcSurface->Wdt;
546  const float sourceHgt = sfcSurface->Hgt;
547 
548  // vertex positions
549  C4BltVertex vertices[6];
550  vertices[0].ftx = iToX; vertices[0].fty = iToY; vertices[0].ftz = 0.0f;
551  vertices[0].tx = (0.0f + iOffsetX) / sourceWdt; vertices[0].ty = (0.0f + iOffsetY) / sourceHgt;
552  DwTo4UB(0xffffffff, vertices[0].color);
553  vertices[1].ftx = iToX + iToWdt; vertices[1].fty = iToY; vertices[1].ftz = 0.0f;
554  vertices[1].tx = (iToWdt + iOffsetX) / sourceWdt; vertices[1].ty = (0.0f + iOffsetY) / sourceHgt;
555  DwTo4UB(0xffffffff, vertices[1].color);
556  vertices[2].ftx = iToX + iToWdt; vertices[2].fty = iToY + iToHgt; vertices[2].ftz = 0.0f;
557  vertices[2].tx = (iToWdt + iOffsetX) / sourceWdt; vertices[2].ty = (iToHgt + iOffsetY) / sourceHgt;
558  DwTo4UB(0xffffffff, vertices[2].color);
559  vertices[3].ftx = iToX; vertices[3].fty = iToY + iToHgt; vertices[3].ftz = 0.0f;
560  vertices[3].tx = (0.0f + iOffsetX) / sourceWdt; vertices[3].ty = (iToHgt + iOffsetY) / sourceHgt;
561  DwTo4UB(0xffffffff, vertices[3].color);
562  // duplicate vertices
563  vertices[4] = vertices[0]; vertices[5] = vertices[2];
564 
565  // Draw
566  PerformMultiTris(sfcTarget, vertices, 6, nullptr, sfcSurface->texture.get(), nullptr, nullptr, 0, shader_call);
567  return true;
568 }
569 
570 bool C4Draw::TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface * sfcDest, float iTx, float iTy, DWORD dwFCol, BYTE byForm, bool fDoMarkup)
571 {
572  C4Markup Markup(true);
573  static char szLinebuf[2500+1];
574  for (int cnt=0; SCopySegmentEx(szText,cnt,szLinebuf,fDoMarkup ? '|' : '\n','\n',2500); cnt++,iTy+=int(fZoom*rFont.GetLineHeight()))
575  if (!StringOut(szLinebuf,sfcDest,iTx,iTy,dwFCol,byForm,fDoMarkup,Markup,&rFont,fZoom)) return false;
576  return true;
577 }
578 
579 bool C4Draw::StringOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface * sfcDest, float iTx, float iTy, DWORD dwFCol, BYTE byForm, bool fDoMarkup)
580 {
581  // init markup
582  C4Markup Markup(true);
583  // output string
584  return StringOut(szText, sfcDest, iTx, iTy, dwFCol, byForm, fDoMarkup, Markup, &rFont, fZoom);
585 }
586 
587 bool C4Draw::StringOut(const char *szText, C4Surface * sfcDest, float iTx, float iTy, DWORD dwFCol, BYTE byForm, bool fDoMarkup, C4Markup &Markup, CStdFont *pFont, float fZoom)
588 {
589  // clip
590  if (ClipAll) return true;
591  // safety
592  if (!PrepareRendering(sfcDest)) return false;
593  // convert align
594  int iFlags=0;
595  switch (byForm)
596  {
597  case ACenter: iFlags |= STDFONT_CENTERED; break;
598  case ARight: iFlags |= STDFONT_RIGHTALGN; break;
599  }
600  if (!fDoMarkup) iFlags|=STDFONT_NOMARKUP;
601  // draw text
602  pFont->DrawText(sfcDest, iTx , iTy , dwFCol, szText, iFlags, Markup, fZoom);
603  // done, success
604  return true;
605 }
606 
607 void C4Draw::DrawPix(C4Surface * sfcDest, float tx, float ty, DWORD dwClr)
608 {
609  // Draw
610  C4BltVertex vtx;
611  vtx.ftx = tx;
612  vtx.fty = ty;
613  DwTo4UB(dwClr, vtx.color);
614  PerformMultiPix(sfcDest, &vtx, 1, nullptr);
615 }
616 
617 void C4Draw::DrawLineDw(C4Surface * sfcTarget, float x1, float y1, float x2, float y2, DWORD dwClr, float width)
618 {
619  C4BltVertex vertices[2];
620  vertices[0].ftx = x1; vertices[0].fty = y1;
621  vertices[1].ftx = x2; vertices[1].fty = y2;
622  DwTo4UB(dwClr, vertices[0].color);
623  DwTo4UB(dwClr, vertices[1].color);
624  PerformMultiLines(sfcTarget, vertices, 2, width, nullptr);
625 }
626 
627 void C4Draw::DrawCircleDw(C4Surface * sfcTarget, float cx, float cy, float r, DWORD dwClr, float width)
628 {
629  // Draw as line segments
630  int32_t num_lines = 12 + int32_t(r / 10);
631  std::unique_ptr<C4BltVertex[]> vertices(new C4BltVertex[num_lines * 2]);
632  for (int32_t i = 0; i < num_lines; ++i)
633  {
634  float ang = float(i) * 2 * M_PI / num_lines;
635  int32_t iv = i * 2 + 1;
636  vertices[iv].ftx = cx + sin(ang) * r;
637  vertices[iv].fty = cy + cos(ang) * r;
638  DwTo4UB(dwClr, vertices[iv].color);
639  vertices[(iv + 1) % (num_lines * 2)] = vertices[iv];
640  }
641  PerformMultiLines(sfcTarget, vertices.get(), num_lines * 2, width, nullptr);
642 }
643 
644 void C4Draw::DrawFrameDw(C4Surface * sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width) // make these parameters float...?
645 {
646  C4BltVertex vertices[8];
647  vertices[0].ftx = x1; vertices[0].fty = y1;
648  vertices[1].ftx = x2; vertices[1].fty = y1;
649  vertices[2] = vertices[1];
650  vertices[3].ftx = x2; vertices[3].fty = y2;
651  vertices[4] = vertices[3];
652  vertices[5].ftx = x1; vertices[5].fty = y2;
653  vertices[6] = vertices[5];
654  vertices[7] = vertices[0];
655 
656  for(int i = 0; i < 8; ++i)
657  DwTo4UB(dwClr, vertices[i].color);
658 
659  PerformMultiLines(sfcDest, vertices, 8, width, nullptr);
660 }
661 
662 void C4Draw::DrawQuadDw(C4Surface * sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall* shader_call)
663 {
664  C4BltVertex vertices[6];
665  vertices[0].ftx = ipVtx[0]; vertices[0].fty = ipVtx[1];
666  vertices[1].ftx = ipVtx[2]; vertices[1].fty = ipVtx[3];
667  vertices[2].ftx = ipVtx[4]; vertices[2].fty = ipVtx[5];
668  vertices[3].ftx = ipVtx[6]; vertices[3].fty = ipVtx[7];
669  DwTo4UB(dwClr1, vertices[0].color);
670  DwTo4UB(dwClr2, vertices[1].color);
671  DwTo4UB(dwClr3, vertices[2].color);
672  DwTo4UB(dwClr4, vertices[3].color);
673  vertices[4] = vertices[0];
674  vertices[5] = vertices[2];
675  PerformMultiTris(sfcTarget, vertices, 6, nullptr, nullptr, nullptr, nullptr, 0, shader_call);
676 }
677 
678 void C4Draw::DrawPatternedCircle(C4Surface * sfcDest, int x, int y, int r, BYTE col, C4Pattern & Pattern, CStdPalette &rPal)
679 {
680  bool fRenderTarget = sfcDest->IsRenderTarget();
681  if (!fRenderTarget) if (!sfcDest->Lock()) return;
682  for (int ycnt = -r; ycnt < r; ycnt++)
683  {
684  int lwdt = (int)sqrt(float(r * r - ycnt * ycnt));
685  // Set line
686  if (fRenderTarget)
687  {
688  for (int xcnt = x - lwdt; xcnt < x + lwdt; ++xcnt)
689  {
690  DrawPix(sfcDest, xcnt, y + ycnt, Pattern.PatternClr(xcnt, y + ycnt));
691  }
692  }
693  else
694  {
695  for (int xcnt = x - lwdt; xcnt < x + lwdt; ++xcnt)
696  {
697  sfcDest->SetPixDw(xcnt, y + ycnt, Pattern.PatternClr(xcnt, y + ycnt));
698  }
699  }
700  }
701  if (!fRenderTarget) sfcDest->Unlock();
702 }
703 
704 void C4Draw::Grayscale(C4Surface * sfcSfc, int32_t iOffset)
705 {
706  // safety
707  if (!sfcSfc) return;
708  // change colors
709  int xcnt,ycnt,wdt=sfcSfc->Wdt,hgt=sfcSfc->Hgt;
710  // Lock surface
711  if (!sfcSfc->Lock()) return;
712  for (ycnt=0; ycnt<hgt; ycnt++)
713  {
714  for (xcnt=0; xcnt<wdt; xcnt++)
715  {
716  DWORD dwColor = sfcSfc->GetPixDw(xcnt,ycnt,false);
717  uint32_t r = GetRedValue(dwColor), g = GetGreenValue(dwColor), b = GetBlueValue(dwColor), a = dwColor >> 24;
718  int32_t gray = Clamp<int32_t>((r + g + b) / 3 + iOffset, 0, 255);
719  sfcSfc->SetPixDw(xcnt, ycnt, RGBA(gray, gray, gray, a));
720  }
721  }
722  sfcSfc->Unlock();
723 }
724 
725 bool C4Draw::GetPrimaryClipper(int &rX1, int &rY1, int &rX2, int &rY2)
726 {
727  // Store drawing clip values
728  rX1=fClipX1; rY1=fClipY1; rX2=fClipX2; rY2=fClipY2;
729  // Done
730  return true;
731 }
732 
734 {
735  int iWdt=std::min(iClipX2, RenderTarget->Wdt-1)-iClipX1+1;
736  int iHgt=std::min(iClipY2, RenderTarget->Hgt-1)-iClipY1+1;
737  int iX=iClipX1; if (iX<0) { iWdt+=iX; iX=0; }
738  int iY=iClipY1; if (iY<0) { iHgt+=iY; iY=0; }
739  return C4Rect(iX, iY, iWdt, iHgt);
740 }
741 
743 {
744  return C4Rect(0, 0, RenderTarget->Wdt, RenderTarget->Hgt);
745 }
746 
747 void C4Draw::SetGamma(float r, float g, float b, int32_t iRampIndex)
748 {
749  // Set
750  gamma[iRampIndex][0] = r;
751  gamma[iRampIndex][1] = g;
752  gamma[iRampIndex][2] = b;
753  // Recalculate resulting gamma. Note that we flip gamma direction here,
754  // because higher gammaOut means darker.
755  gammaOut[0] = gammaOut[1] = gammaOut[2] = 1.0f;
756  for (int i = 0; i < C4MaxGammaRamps; i++) {
757  gammaOut[0] /= gamma[i][0];
758  gammaOut[1] /= gamma[i][1];
759  gammaOut[2] /= gamma[i][2];
760  }
761 }
762 
764 {
765  for (int i = 0; i < C4MaxGammaRamps; i++) {
766  gamma[i][0] = 1.0f;
767  gamma[i][1] = 1.0f;
768  gamma[i][2] = 1.0f;
769  }
770  gammaOut[0] = 1.0f;
771  gammaOut[1] = 1.0f;
772  gammaOut[2] = 1.0f;
773 }
774 
776 {
777  return C4RGB(int(pow(float(GetRedValue(dwClr)) / 255.0f, gammaOut[0]) * 255.0),
778  int(pow(float(GetGreenValue(dwClr)) / 255.0f, gammaOut[1]) * 255.0),
779  int(pow(float(GetBlueValue(dwClr)) / 255.0f, gammaOut[2]) * 255.0));
780 }
781 
782 void C4Draw::SetZoom(float X, float Y, float Zoom)
783 {
784  this->ZoomX = X; this->ZoomY = Y; this->Zoom = Zoom;
785 }
786 
787 void C4Draw::ApplyZoom(float & X, float & Y)
788 {
789  X = (X - ZoomX) * Zoom + ZoomX;
790  Y = (Y - ZoomY) * Zoom + ZoomY;
791 }
792 
793 void C4Draw::RemoveZoom(float & X, float & Y)
794 {
795  X = (X - ZoomX) / Zoom + ZoomX;
796  Y = (Y - ZoomY) / Zoom + ZoomY;
797 }
798 
799 bool DDrawInit(C4AbstractApp * pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
800 {
801  // create engine
802  #ifndef USE_CONSOLE
803  pDraw = new CStdGL();
804  #else
805  pDraw = new CStdNoGfx();
806  #endif
807  if (!pDraw) return false;
808  // init it
809  if (!pDraw->Init(pApp, iXRes, iYRes, iMonitor))
810  {
811  delete pDraw;
812  return false;
813  }
814  // done, success
815  return true;
816 }
817 
818 bool C4Draw::Init(C4AbstractApp * pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
819 {
820  this->pApp = pApp;
821 
822  pApp->pWindow->pSurface = new C4Surface(pApp, pApp->pWindow);
823 
824  if (!RestoreDeviceObjects())
825  return false;
826 
827  if (!CreatePrimaryClipper(iXRes, iYRes))
828  return Error(" Clipper failure.");
829 
830  return true;
831 }
832 
833 void C4Draw::DrawBoxFade(C4Surface * sfcDest, float iX, float iY, float iWdt, float iHgt, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall* shader_call)
834 {
835  // set vertex buffer data
836  // vertex order:
837  // 0=upper left dwClr1
838  // 1=lower left dwClr3
839  // 2=lower right dwClr4
840  // 3=upper right dwClr2
841  float vtx[8];
842  vtx[0] = iX ; vtx[1] = iY;
843  vtx[2] = iX ; vtx[3] = iY+iHgt;
844  vtx[4] = iX+iWdt; vtx[5] = iY+iHgt;
845  vtx[6] = iX+iWdt; vtx[7] = iY;
846  DrawQuadDw(sfcDest, vtx, dwClr1, dwClr3, dwClr4, dwClr2, shader_call);
847 }
848 
849 void C4Draw::DrawBoxDw(C4Surface * sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
850 {
851  if (!sfcDest->IsRenderTarget())
852  {
853  // Box on non-render target: Emulate by setting pixels
854  if (!sfcDest->Lock()) return;
855  for (int y = iY1; y <= iY2; ++y)
856  for (int x = iX1; x <= iX2; ++x)
857  sfcDest->SetPixDw(x,y, dwClr);
858  sfcDest->Unlock();
859  }
860  else
861  {
862  DrawBoxFade(sfcDest, float(iX1), float(iY1), float(iX2 - iX1 + 1), float(iY2 - iY1 + 1), dwClr, dwClr, dwClr, dwClr, nullptr);
863  }
864 }
float fty
Definition: C4Draw.h:64
bool RestorePrimaryClipper()
Definition: C4Draw.cpp:213
virtual void PerformMesh(StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)=0
void Blit8Fast(CSurface8 *sfcSource, int fx, int fy, C4Surface *sfcTarget, int tx, int ty, int wdt, int hgt)
Definition: C4Draw.cpp:254
float ftz
Definition: C4Draw.h:64
int GetLineHeight() const
Definition: C4FontLoader.h:132
void ApplyZoom(float &X, float &Y)
Definition: C4Draw.cpp:787
#define STDFONT_NOMARKUP
Definition: C4FontLoader.h:36
DWORD PatternClr(unsigned int iX, unsigned int iY) const
Definition: C4Draw.cpp:162
void DrawPix(C4Surface *sfcDest, float tx, float ty, DWORD dwCol)
Definition: C4Draw.cpp:607
bool Active
Definition: C4Draw.h:96
float fClipY2
Definition: C4Draw.h:102
virtual bool RestoreDeviceObjects()=0
void TransformPoint(float &rX, float &rY) const
float ZoomY
Definition: C4Draw.h:112
float fClipY1
Definition: C4Draw.h:102
int Wdt
Definition: C4Surface.h:67
float tx
Definition: C4Draw.h:62
C4ScriptUniform scriptUniform
Definition: C4Draw.h:100
#define GetGreenValue(rgb)
Definition: StdColors.h:30
#define b
bool GetPrimaryClipper(int &rX1, int &rY1, int &rX2, int &rY2)
Definition: C4Draw.cpp:725
unsigned char color[4]
Definition: C4Draw.h:63
float fStClipY1
Definition: C4Draw.h:103
void Grayscale(C4Surface *sfcSfc, int32_t iOffset=0)
Definition: C4Draw.cpp:704
bool Lock()
Definition: C4Surface.cpp:463
C4Surface * pSurface
Definition: C4Window.h:279
float gammaOut[3]
Definition: C4Draw.h:98
bool TextOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:570
bool Unlock()
Definition: C4Surface.cpp:474
#define STDFONT_CENTERED
Definition: C4FontLoader.h:31
int iSizeY
Definition: C4Surface.h:160
const int ARight
Definition: C4Surface.h:43
DWORD ClrByOwnerClr
Definition: C4Surface.h:83
float fStClipX2
Definition: C4Draw.h:103
const int C4MaxGammaRamps
Definition: C4Constants.h:35
bool Init(C4AbstractApp *pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
Definition: C4Draw.cpp:818
Definition: C4Rect.h:29
uint8_t BYTE
bool fUsePerspective
Definition: C4Draw.h:114
#define a
#define GetRedValue(rgb)
Definition: StdColors.h:31
float ty
Definition: C4Draw.h:62
BYTE GetPix(int iX, int iY) const
Definition: CSurface8.h:49
virtual void BlitLandscape(C4Surface *sfcSource, float fx, float fy, C4Surface *sfcTarget, float tx, float ty, float wdt, float hgt)
Definition: C4Draw.cpp:248
int Hgt
Definition: C4Surface.h:67
virtual void PerformMultiTris(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, const C4BltTransform *pTransform, C4TexRef *pTex, C4TexRef *pOverlay, C4TexRef *pNormal, DWORD dwOverlayClrMod, C4ShaderCall *shader_call)=0
void DrawLineDw(C4Surface *sfcTarget, float x1, float y1, float x2, float y2, DWORD dwClr, float width=1.0f)
Definition: C4Draw.cpp:617
int iSizeX
Definition: C4Surface.h:159
bool StringOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:579
const C4FoWRegion * pFoW
Definition: C4Draw.h:111
const StdMeshMatrix * MeshTransform
Definition: C4Draw.h:113
int Scale
Definition: C4Surface.h:68
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
Definition: C4Draw.cpp:510
DWORD GetClr(BYTE byCol)
Definition: StdColors.h:188
void DrawFrameDw(C4Surface *sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width=1.0f)
Definition: C4Draw.cpp:644
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
bool BlitSurface(C4Surface *sfcSurface, C4Surface *sfcTarget, int tx, int ty, bool fBlitBase)
Definition: C4Draw.cpp:520
C4Surface * pNormalSfc
Definition: C4Surface.h:82
bool BlitSimple(C4Surface *sfcSource, int fx, int fy, int fwdt, int fhgt, C4Surface *sfcTarget, int tx, int ty, int twdt, int thgt, bool fTransparency=true)
Definition: C4Draw.cpp:472
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
bool RenderMesh(StdMeshInstance &instance, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)
Definition: C4Draw.cpp:406
void DrawCircleDw(C4Surface *sfcTarget, float cx, float cy, float r, DWORD dwClr, float width=1.0f)
Definition: C4Draw.cpp:627
bool BlitSurfaceTile(C4Surface *sfcSurface, C4Surface *sfcTarget, float iToX, float iToY, float iToWdt, float iToHgt, float iOffsetX, float iOffsetY, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:538
void Clear()
Definition: C4Draw.cpp:149
virtual void PerformMultiPix(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call)=0
#define GetBlueValue(rgb)
Definition: StdColors.h:29
const int ACenter
Definition: C4Surface.h:43
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:586
bool GetSurfaceSize(int &irX, int &irY)
Definition: C4Surface.cpp:454
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:849
void ReorderFaces(StdMeshMatrix *global_trans)
Definition: StdMesh.cpp:1566
void DrawQuadDw(C4Surface *sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:662
const int C4SF_Tileable
Definition: C4Surface.h:51
void Error(const char *m)
Definition: C4App.h:99
bool SCopySegmentEx(const char *szString, int iSegment, char *sTarget, char cSep1, char cSep2, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:269
int iTexSize
Definition: C4Surface.h:70
C4Draw * pDraw
Definition: C4Draw.cpp:45
CStdPalette * pPal
Definition: CSurface8.h:31
virtual void PerformMultiLines(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call)=0
DWORD ApplyGammaTo(DWORD dwClr)
Definition: C4Draw.cpp:775
#define C4RGB(r, g, b)
Definition: StdColors.h:28
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:220
bool BlitUnscaled(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:312
virtual bool Error(const char *szMsg)
Definition: C4Draw.cpp:503
void SetMoveScale(float dx, float dy, float sx, float sy)
void DrawBoxFade(C4Surface *sfcDest, float iX, float iY, float iWdt, float iHgt, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:833
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:501
int32_t iClipY2
Definition: C4Draw.h:104
float ZoomX
Definition: C4Draw.h:112
void RemoveZoom(float &X, float &Y)
Definition: C4Draw.cpp:793
C4Pattern()
Definition: C4Draw.cpp:141
bool DDrawInit(C4AbstractApp *pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
Definition: C4Draw.cpp:799
float fStClipY2
Definition: C4Draw.h:103
bool BltPix(int iX, int iY, C4Surface *sfcSource, int iSrcX, int iSrcY, bool fTransparency)
Definition: C4Surface.cpp:601
float Zoom
Definition: C4Draw.h:116
std::unique_ptr< C4TexRef > texture
Definition: C4Surface.h:80
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:304
bool UpdateBoneTransforms()
Definition: StdMesh.cpp:1484
void DrawText(C4Surface *sfcDest, float iX, float iY, DWORD dwColor, const char *szText, DWORD dwFlags, C4Markup &Markup, float fZoom)
bool ApplyPrimaryClipper(C4Surface *sfcSurface)
Definition: C4Draw.cpp:230
C4Pattern & operator=(const C4Pattern &)
Definition: C4Draw.cpp:97
friend class C4Surface
Definition: C4Draw.h:213
void SetRotate(float iAngle, float fOffX, float fOffY)
virtual void Default()
Definition: C4Draw.cpp:172
float fClipX2
Definition: C4Draw.h:102
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool GetSurfaceSize(C4Surface *sfcSurface, int &iWdt, int &iHgt)
Definition: C4Draw.cpp:194
bool Log(const char *szMessage)
Definition: C4Log.cpp:195
float ftx
Definition: C4Draw.h:64
int32_t iClipY1
Definition: C4Draw.h:104
C4Rect GetOutRect() const
Definition: C4Draw.cpp:742
bool Set(class C4Surface *sfcSource, int iZoom=0)
Definition: C4Draw.cpp:117
virtual bool UpdateClipper()=0
virtual void Clear()
Definition: C4Draw.cpp:187
DWORD dwBlitMode
Definition: C4Draw.h:110
bool ClipAll
Definition: C4Draw.h:105
bool SetAsInv(C4BltTransform &rOfTransform)
int32_t iClipX1
Definition: C4Draw.h:104
bool IsRenderTarget()
Definition: C4Surface.cpp:154
void DrawPatternedCircle(C4Surface *sfcDest, int x, int y, int r, BYTE col, C4Pattern &Pattern, CStdPalette &rPal)
Definition: C4Draw.cpp:678
#define X(sdl, oc)
bool DetachPrimaryClipper(C4Surface *sfcSurface)
Definition: C4Draw.cpp:235
C4Rect GetClipRect() const
Definition: C4Draw.cpp:733
bool NoPrimaryClipper()
Definition: C4Draw.cpp:240
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:24
bool fPrimary
Definition: C4Surface.h:91
bool Blit8(C4Surface *sfcSource, int fx, int fy, int fwdt, int fhgt, C4Surface *sfcTarget, int tx, int ty, int twdt, int thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:427
bool SubPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:199
Definition: C4Draw.h:84
uint32_t DWORD
float fStClipX1
Definition: C4Draw.h:103
bool BlitModulated
Definition: C4Draw.h:108
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:782
#define STDFONT_RIGHTALGN
Definition: C4FontLoader.h:34
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:45
void SetGamma(float r, float g, float b, int32_t iRampIndex)
Definition: C4Draw.cpp:747
C4Window * pWindow
Definition: C4App.h:80
void ResetGamma()
Definition: C4Draw.cpp:763
bool StorePrimaryClipper()
Definition: C4Draw.cpp:206
float fClipX1
Definition: C4Draw.h:102
C4AbstractApp * pApp
Definition: C4Draw.h:95
C4Surface * pMainSfc
Definition: C4Surface.h:81
int32_t iClipX2
Definition: C4Draw.h:104
float gamma[C4MaxGammaRamps][3]
Definition: C4Draw.h:97