OpenClonk
CStdGL Class Reference

#include <C4DrawGL.h>

Inheritance diagram for CStdGL:
[legend]
Collaboration diagram for CStdGL:
[legend]

Public Types

enum  DrawOperation { OP_POINTS , OP_TRIANGLES }
 
enum  { DEFAULT_MESSAGE_COLOR = 0xffffffff }
 

Public Member Functions

 CStdGL ()
 
 ~CStdGL () override
 
unsigned int GenVAOID ()
 
void FreeVAOID (unsigned int vaoid)
 
bool GetVAO (unsigned int vaoid, GLuint &vao)
 
void Clear () override
 
void Default () override
 
bool OnResolutionChanged (unsigned int iXRes, unsigned int iYRes) override
 
bool UpdateClipper () override
 
const StdProjectionMatrixGetProjectionMatrix () const
 
bool PrepareMaterial (StdMeshMatManager &mat_manager, StdMeshMaterialLoader &loader, StdMeshMaterial &mat) override
 
bool PrepareRendering (C4Surface *sfcToSurface) override
 
bool PrepareSpriteShader (C4Shader &shader, const char *name, int ssc, C4GroupSet *pGroups, const char *const *additionalDefines, const char *const *additionalSlices) override
 
bool EnsureMainContextSelected () override
 
CStdGLCtxCreateContext (C4Window *pWindow, C4AbstractApp *pApp) override
 
void SetupMultiBlt (C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
 
void PerformMesh (StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform) override
 
void FillBG (DWORD dwClr=0) override
 
void PerformMultiPix (C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call) override
 
void PerformMultiLines (C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call) override
 
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) override
 
void PerformMultiBlt (C4Surface *sfcTarget, DrawOperation op, const C4BltVertex *vertices, unsigned int n_vertices, bool has_tex, C4ShaderCall *shader_call)
 
bool RestoreDeviceObjects () override
 
bool InvalidateDeviceObjects () override
 
bool DeviceReady () override
 
bool InitShaders (C4GroupSet *pGroups)
 
C4ShaderGetSpriteShader (int ssc)
 
C4ShaderGetSpriteShader (bool haveBase, bool haveOverlay, bool haveNormal)
 
void ObjectLabel (uint32_t identifier, uint32_t name, int32_t length, const char *label)
 
bool Init (C4AbstractApp *pApp, unsigned int iXRes, unsigned int iYRes, unsigned int iMonitor)
 
bool GetPrimaryClipper (int &rX1, int &rY1, int &rX2, int &rY2)
 
bool SetPrimaryClipper (int iX1, int iY1, int iX2, int iY2)
 
bool SubPrimaryClipper (int iX1, int iY1, int iX2, int iY2)
 
C4Rect GetClipRect () const
 
C4Rect GetOutRect () const
 
bool StorePrimaryClipper ()
 
bool RestorePrimaryClipper ()
 
bool NoPrimaryClipper ()
 
bool ApplyPrimaryClipper (C4Surface *sfcSurface)
 
bool DetachPrimaryClipper (C4Surface *sfcSurface)
 
bool GetSurfaceSize (C4Surface *sfcSurface, int &iWdt, int &iHgt)
 
void Grayscale (C4Surface *sfcSfc, int32_t iOffset=0)
 
void LockingPrimary ()
 
void PrimaryUnlocked ()
 
virtual void BlitLandscape (C4Surface *sfcSource, float fx, float fy, C4Surface *sfcTarget, float tx, float ty, float wdt, float hgt)
 
void Blit8Fast (CSurface8 *sfcSource, int fx, int fy, C4Surface *sfcTarget, int tx, int ty, int wdt, int hgt)
 
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)
 
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)
 
bool RenderMesh (StdMeshInstance &instance, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)
 
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)
 
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)
 
bool BlitSurface (C4Surface *sfcSurface, C4Surface *sfcTarget, int tx, int ty, bool fBlitBase)
 
bool BlitSurfaceTile (C4Surface *sfcSurface, C4Surface *sfcTarget, float iToX, float iToY, float iToWdt, float iToHgt, float iOffsetX, float iOffsetY, C4ShaderCall *shader_call)
 
bool TextOut (const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
 
bool StringOut (const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
 
void DrawBoxDw (C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
 
void DrawBoxFade (C4Surface *sfcDest, float iX, float iY, float iWdt, float iHgt, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
 
void DrawPatternedCircle (C4Surface *sfcDest, int x, int y, int r, BYTE col, C4Pattern &Pattern, CStdPalette &rPal)
 
void DrawFrameDw (C4Surface *sfcDest, int x1, int y1, int x2, int y2, DWORD dwClr, float width=1.0f)
 
void DrawQuadDw (C4Surface *sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
 
void DrawPix (C4Surface *sfcDest, float tx, float ty, DWORD dwCol)
 
void DrawLineDw (C4Surface *sfcTarget, float x1, float y1, float x2, float y2, DWORD dwClr, float width=1.0f)
 
void DrawCircleDw (C4Surface *sfcTarget, float cx, float cy, float r, DWORD dwClr, float width=1.0f)
 
void SetGamma (float r, float g, float b, int32_t iRampIndex)
 
void ResetGamma ()
 
DWORD ApplyGammaTo (DWORD dwClr)
 
void ActivateBlitModulation (DWORD dwWithClr)
 
void DeactivateBlitModulation ()
 
bool GetBlitModulation (DWORD &rdwColor)
 
void SetBlitMode (DWORD dwBlitMode)
 
void ResetBlitMode ()
 
void SetFoW (const C4FoWRegion *fow)
 
const C4FoWRegionGetFoW () const
 
void SetZoom (float X, float Y, float Zoom)
 
void SetZoom (const ZoomData &zoom)
 
void GetZoom (ZoomData *r)
 
void ApplyZoom (float &X, float &Y)
 
void RemoveZoom (float &X, float &Y)
 
void SetMeshTransform (const StdMeshMatrix *Transform)
 
void SetPerspective (bool fSet)
 

Public Attributes

struct {
bool LowMaxVertexUniformCount
 
bool ForceSoftwareTransform
 
Workarounds
 
C4AbstractApppApp
 
bool Active
 
float gamma [C4MaxGammaRamps][3]
 
float gammaOut [3]
 
int MaxTexSize {0}
 
C4ScriptUniform scriptUniform
 
float Zoom
 

Static Public Attributes

static constexpr int COLOR_DEPTH = 32
 
static constexpr int COLOR_DEPTH_BYTES = COLOR_DEPTH / 8
 

Protected Member Functions

bool CheckGLError (const char *szAtOp)
 
const char * GLErrorString (GLenum code)
 
bool Error (const char *szMsg) override
 
bool StringOut (const char *szText, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol, BYTE byForm, bool fDoMarkup, C4Markup &Markup, CStdFont *pFont, float fZoom)
 
bool CreatePrimaryClipper (unsigned int iXRes, unsigned int iYRes)
 

Protected Attributes

int iPixelFormat
 
GLenum sfcFmt
 
CStdGLCtxpMainCtx {nullptr}
 
CStdGLCtxpCurrCtx
 
GLuint lines_tex
 
StdProjectionMatrix ProjectionMatrix
 
C4Shader SpriteShader
 
C4Shader SpriteShaderMod2
 
C4Shader SpriteShaderBase
 
C4Shader SpriteShaderBaseMod2
 
C4Shader SpriteShaderBaseOverlay
 
C4Shader SpriteShaderBaseOverlayMod2
 
C4Shader SpriteShaderLight
 
C4Shader SpriteShaderLightMod2
 
C4Shader SpriteShaderLightBase
 
C4Shader SpriteShaderLightBaseMod2
 
C4Shader SpriteShaderLightBaseOverlay
 
C4Shader SpriteShaderLightBaseOverlayMod2
 
C4Shader SpriteShaderLightBaseNormal
 
C4Shader SpriteShaderLightBaseNormalMod2
 
C4Shader SpriteShaderLightBaseNormalOverlay
 
C4Shader SpriteShaderLightBaseNormalOverlayMod2
 
GLuint GenericVBOs [N_GENERIC_VBOS]
 
unsigned int GenericVBOSizes [N_GENERIC_VBOS]
 
unsigned int CurrentVBO {0}
 
unsigned int GenericVAOs [N_GENERIC_VBOS *2]
 
std::set< unsigned int > VAOIDs
 
std::set< unsigned int >::iterator NextVAOID
 
bool has_khr_debug
 
float fClipX1
 
float fClipY1
 
float fClipX2
 
float fClipY2
 
float fStClipX1
 
float fStClipY1
 
float fStClipX2
 
float fStClipY2
 
int32_t iClipX1
 
int32_t iClipY1
 
int32_t iClipX2
 
int32_t iClipY2
 
bool ClipAll
 
bool PrimaryLocked
 
C4SurfaceRenderTarget
 
bool BlitModulated
 
DWORD BlitModulateClr
 
DWORD dwBlitMode
 
const C4FoWRegionpFoW
 
float ZoomX
 
float ZoomY
 
const StdMeshMatrixMeshTransform
 
bool fUsePerspective
 

Static Protected Attributes

static const unsigned int N_GENERIC_VBOS = 16
 
static const unsigned int GENERIC_VBO_SIZE = 3 * 64
 

Friends

class C4Surface
 
class C4TexRef
 
class C4Pattern
 
class CStdGLCtx
 
class C4StartupOptionsDlg
 
class C4FullScreen
 
class C4Window
 
class C4ShaderCall
 
class C4FoWRegion
 

Detailed Description

Definition at line 169 of file C4DrawGL.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
inherited
Enumerator
DEFAULT_MESSAGE_COLOR 

Definition at line 167 of file C4Draw.h.

167 { DEFAULT_MESSAGE_COLOR = 0xffffffff };
@ DEFAULT_MESSAGE_COLOR
Definition: C4Draw.h:167

◆ DrawOperation

enum C4Draw::DrawOperation
inherited
Enumerator
OP_POINTS 
OP_TRIANGLES 

Definition at line 87 of file C4Draw.h.

@ OP_TRIANGLES
Definition: C4Draw.h:87
@ OP_POINTS
Definition: C4Draw.h:87

Constructor & Destructor Documentation

◆ CStdGL()

CStdGL::CStdGL ( )

Definition at line 90 of file C4DrawGL.cpp.

90  :
91  NextVAOID(VAOIDs.end())
92 {
93  GenericVBOs[0] = 0;
94  Default();
95  // global ptr
96  pGL = this;
97  lines_tex = 0;
98 }
CStdGL * pGL
Definition: C4DrawGL.cpp:907
std::set< unsigned int > VAOIDs
Definition: C4DrawGL.h:227
GLuint GenericVBOs[N_GENERIC_VBOS]
Definition: C4DrawGL.h:218
void Default() override
Definition: C4DrawGL.cpp:917
std::set< unsigned int >::iterator NextVAOID
Definition: C4DrawGL.h:228
GLuint lines_tex
Definition: C4DrawGL.h:182

References Default(), GenericVBOs, lines_tex, and pGL.

Here is the call graph for this function:

◆ ~CStdGL()

CStdGL::~CStdGL ( )
override

Definition at line 100 of file C4DrawGL.cpp.

101 {
102  Clear();
103  pGL=nullptr;
104 }
void Clear() override
Definition: C4DrawGL.cpp:106

References Clear(), and pGL.

Here is the call graph for this function:

Member Function Documentation

◆ ActivateBlitModulation()

void C4Draw::ActivateBlitModulation ( DWORD  dwWithClr)
inlineinherited

Definition at line 188 of file C4Draw.h.

188 { BlitModulated=true; BlitModulateClr=dwWithClr; } // modulate following blits with a given color
bool BlitModulated
Definition: C4Draw.h:108
DWORD BlitModulateClr
Definition: C4Draw.h:109

References C4Draw::BlitModulateClr, and C4Draw::BlitModulated.

Referenced by C4Sky::Draw(), C4GUI::Dialog::Draw(), C4GraphicsOverlay::Draw(), C4Landscape::Draw(), C4MouseControl::Draw(), C4GUI::Tabular::Sheet::DrawCaption(), C4Viewport::DrawMenu(), C4GraphicsOverlay::DrawPicture(), CStdFont::DrawText(), and C4Object::PrepareDrawing().

Here is the caller graph for this function:

◆ ApplyGammaTo()

DWORD C4Draw::ApplyGammaTo ( DWORD  dwClr)
inherited

Definition at line 766 of file C4Draw.cpp.

767 {
768  return C4RGB(int(pow(float(GetRedValue(dwClr)) / 255.0f, gammaOut[0]) * 255.0),
769  int(pow(float(GetGreenValue(dwClr)) / 255.0f, gammaOut[1]) * 255.0),
770  int(pow(float(GetBlueValue(dwClr)) / 255.0f, gammaOut[2]) * 255.0));
771 }
#define C4RGB(r, g, b)
Definition: StdColors.h:26
#define GetRedValue(rgb)
Definition: StdColors.h:29
#define GetGreenValue(rgb)
Definition: StdColors.h:28
#define GetBlueValue(rgb)
Definition: StdColors.h:27
float gammaOut[3]
Definition: C4Draw.h:98

References C4RGB, C4Draw::gammaOut, GetBlueValue, GetGreenValue, and GetRedValue.

◆ ApplyPrimaryClipper()

bool C4Draw::ApplyPrimaryClipper ( C4Surface sfcSurface)
inherited

Definition at line 227 of file C4Draw.cpp.

228 {
229  return true;
230 }

◆ ApplyZoom()

void C4Draw::ApplyZoom ( float &  X,
float &  Y 
)
inherited

Definition at line 778 of file C4Draw.cpp.

779 {
780  X = (X - ZoomX) * Zoom + ZoomX;
781  Y = (Y - ZoomY) * Zoom + ZoomY;
782 }
#define X(sdl, oc)
float ZoomY
Definition: C4Draw.h:112
float ZoomX
Definition: C4Draw.h:112
float Zoom
Definition: C4Draw.h:116

References X, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

Referenced by C4Draw::Blit8Fast(), C4Draw::BlitUnscaled(), C4GUI::Window::Draw(), C4LandscapeRenderGL::Draw(), and C4GUI::Edit::DrawElement().

Here is the caller graph for this function:

◆ Blit()

bool C4Draw::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 
)
inherited

Definition at line 301 of file C4Draw.cpp.

304 {
305  return BlitUnscaled(sfcSource, fx * sfcSource->Scale, fy * sfcSource->Scale, fwdt * sfcSource->Scale, fhgt * sfcSource->Scale,
306  sfcTarget, tx, ty, twdt, thgt, fSrcColKey, pTransform);
307 }
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:309
int Scale
Definition: C4Surface.h:66

References C4Draw::BlitUnscaled(), and C4Surface::Scale.

Referenced by C4Draw::BlitLandscape(), C4Draw::BlitSimple(), C4Draw::BlitSurface(), C4FacetSurface::CopyFromSfcMaxSize(), C4Facet::Draw(), C4Object::Draw(), C4Object::DrawFaceImpl(), C4Facet::DrawFullScreen(), C4Facet::DrawT(), CStdFont::DrawText(), C4Object::DrawTopFace(), C4Facet::DrawX(), C4Facet::DrawXFloat(), C4Facet::DrawXR(), C4Facet::DrawXT(), C4MapFolderData::Load(), and C4Game::SaveGameTitle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Blit8()

bool C4Draw::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 
)
inherited

Definition at line 418 of file C4Draw.cpp.

421 {
422  if (!pTransform) return BlitSimple(sfcSource, fx, fy, fwdt, fhgt, sfcTarget, tx, ty, twdt, thgt, fSrcColKey!=false);
423  // safety
424  if (!fwdt || !fhgt) return true;
425  // Lock the surfaces
426  if (!sfcSource->Lock())
427  return false;
428  if (!sfcTarget->Lock())
429  { sfcSource->Unlock(); return false; }
430  // transformed, emulated blit
431  // Calculate transform target rect
432  C4BltTransform Transform;
433  Transform.SetMoveScale(tx-(float)fx*twdt/fwdt, ty-(float)fy*thgt/fhgt, (float) twdt/fwdt, (float) thgt/fhgt);
434  Transform *=* pTransform;
435  C4BltTransform TransformBack;
436  TransformBack.SetAsInv(Transform);
437  auto ttx0=(float)tx, tty0=(float)ty, ttx1=(float)(tx+twdt), tty1=(float)(ty+thgt);
438  auto ttx2=(float)ttx0, tty2=(float)tty1, ttx3=(float)ttx1, tty3=(float)tty0;
439  pTransform->TransformPoint(ttx0, tty0);
440  pTransform->TransformPoint(ttx1, tty1);
441  pTransform->TransformPoint(ttx2, tty2);
442  pTransform->TransformPoint(ttx3, tty3);
443  int ttxMin = std::max<int>((int)floor(std::min(std::min(ttx0, ttx1), std::min(ttx2, ttx3))), 0);
444  int ttxMax = std::min<int>((int)ceil(std::max(std::max(ttx0, ttx1), std::max(ttx2, ttx3))), sfcTarget->Wdt);
445  int ttyMin = std::max<int>((int)floor(std::min(std::min(tty0, tty1), std::min(tty2, tty3))), 0);
446  int ttyMax = std::min<int>((int)ceil(std::max(std::max(tty0, tty1), std::max(tty2, tty3))), sfcTarget->Hgt);
447  // blit within target rect
448  for (int y = ttyMin; y < ttyMax; ++y)
449  for (int x = ttxMin; x < ttxMax; ++x)
450  {
451  float ffx=(float)x, ffy=(float)y;
452  TransformBack.TransformPoint(ffx, ffy);
453  int ifx=static_cast<int>(ffx), ify=static_cast<int>(ffy);
454  if (ifx<fx || ify<fy || ifx>=fx+fwdt || ify>=fy+fhgt) continue;
455  sfcTarget->BltPix(x,y, sfcSource, ifx,ify, !!fSrcColKey);
456  }
457  // Unlock the surfaces
458  sfcSource->Unlock();
459  sfcTarget->Unlock();
460  return true;
461 }
void SetMoveScale(float dx, float dy, float sx, float sy)
bool SetAsInv(C4BltTransform &rOfTransform)
void TransformPoint(float &rX, float &rY) const
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:463
int Wdt
Definition: C4Surface.h:65
bool Unlock()
Definition: C4Surface.cpp:464
bool Lock()
Definition: C4Surface.cpp:453
bool BltPix(int iX, int iY, C4Surface *sfcSource, int iSrcX, int iSrcY, bool fTransparency)
Definition: C4Surface.cpp:591
int Hgt
Definition: C4Surface.h:65

References C4Draw::BlitSimple(), C4Surface::BltPix(), C4Surface::Hgt, C4Surface::Lock(), C4BltTransform::SetAsInv(), C4BltTransform::SetMoveScale(), C4BltTransform::TransformPoint(), C4Surface::Unlock(), and C4Surface::Wdt.

Referenced by C4Draw::BlitUnscaled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Blit8Fast()

void C4Draw::Blit8Fast ( CSurface8 sfcSource,
int  fx,
int  fy,
C4Surface sfcTarget,
int  tx,
int  ty,
int  wdt,
int  hgt 
)
inherited

Definition at line 251 of file C4Draw.cpp.

253 {
254  // blit 8bit-sfc
255  // lock surfaces
256  assert(sfcTarget->fPrimary);
257  bool fRender = sfcTarget->IsRenderTarget();
258  if (!fRender) if (!sfcTarget->Lock())
259  { return; }
260 
261  float tfx = tx, tfy = ty, twdt = wdt, thgt = hgt;
262  if (Zoom != 1.0)
263  {
264  ApplyZoom(tfx, tfy);
265  twdt *= Zoom;
266  thgt *= Zoom;
267  }
268 
269  // blit 8 bit pix in batches of 1024 pixels
270  static const int BUF_SIZE = 1024;
271  C4BltVertex* vertices = new C4BltVertex[BUF_SIZE];
272  int bufcnt = 0;
273 
274  for (int ycnt=0; ycnt<thgt; ++ycnt)
275  {
276  for (int xcnt=0; xcnt<twdt; ++xcnt)
277  {
278  BYTE byPix = sfcSource->GetPix(fx+wdt*xcnt/twdt, fy+hgt*ycnt/thgt);
279  DWORD dwClr = byPix ? sfcSource->pPal->GetClr(byPix) : 0x00000000;
280 
281  vertices[bufcnt].ftx = (float)(tx + xcnt / Zoom);
282  vertices[bufcnt].fty = (float)(ty + ycnt / Zoom);
283  DwTo4UB(dwClr, vertices[bufcnt].color);
284  ++bufcnt;
285 
286  if(bufcnt == BUF_SIZE)
287  {
288  PerformMultiPix(sfcTarget, vertices, BUF_SIZE, nullptr);
289  bufcnt = 0;
290  }
291  }
292 
293  }
294  if(bufcnt > 0)
295  PerformMultiPix(sfcTarget, vertices, bufcnt, nullptr);
296  delete[] vertices;
297  // unlock
298  if (!fRender) sfcTarget->Unlock();
299 }
float ftx
Definition: C4Draw.h:64
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
float fty
Definition: C4Draw.h:64
uint8_t BYTE
uint32_t DWORD
void ApplyZoom(float &X, float &Y)
Definition: C4Draw.cpp:778
virtual void PerformMultiPix(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call)=0
bool fPrimary
Definition: C4Surface.h:89
bool IsRenderTarget()
Definition: C4Surface.cpp:144
CStdPalette * pPal
Definition: CSurface8.h:31
BYTE GetPix(int iX, int iY) const
Definition: CSurface8.h:49
DWORD GetClr(BYTE byCol)
Definition: StdColors.h:188

References C4Draw::ApplyZoom(), DwTo4UB(), C4Surface::fPrimary, C4BltVertex::ftx, C4BltVertex::fty, CStdPalette::GetClr(), CSurface8::GetPix(), C4Surface::IsRenderTarget(), C4Surface::Lock(), C4Draw::PerformMultiPix(), CSurface8::pPal, C4Surface::Unlock(), and C4Draw::Zoom.

Referenced by C4Landscape::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlitLandscape()

void C4Draw::BlitLandscape ( C4Surface sfcSource,
float  fx,
float  fy,
C4Surface sfcTarget,
float  tx,
float  ty,
float  wdt,
float  hgt 
)
virtualinherited

Definition at line 245 of file C4Draw.cpp.

247 {
248  Blit(sfcSource, fx, fy, wdt, hgt, sfcTarget, tx, ty, wdt, hgt, false);
249 }
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:301

References C4Draw::Blit().

Here is the call graph for this function:

◆ BlitSimple()

bool C4Draw::BlitSimple ( C4Surface sfcSource,
int  fx,
int  fy,
int  fwdt,
int  fhgt,
C4Surface sfcTarget,
int  tx,
int  ty,
int  twdt,
int  thgt,
bool  fTransparency = true 
)
inherited

Definition at line 463 of file C4Draw.cpp.

466 {
467  // rendertarget?
468  if (sfcTarget->IsRenderTarget())
469  {
470  return Blit(sfcSource, float(fx), float(fy), float(fwdt), float(fhgt), sfcTarget, float(tx), float(ty), float(twdt), float(thgt), true);
471  }
472  // Object is first stretched to dest rect
473  int xcnt,ycnt,tcx,tcy,cpcx,cpcy;
474  if (!fwdt || !fhgt || !twdt || !thgt) return false;
475  // Lock the surfaces
476  if (!sfcSource->Lock())
477  return false;
478  if (!sfcTarget->Lock())
479  { sfcSource->Unlock(); return false; }
480  // Rectangle centers
481  tcx=twdt/2; tcy=thgt/2;
482  for (ycnt=0; ycnt<thgt; ycnt++)
483  if (Inside(cpcy=ty+tcy-thgt/2+ycnt,0,sfcTarget->Hgt-1))
484  for (xcnt=0; xcnt<twdt; xcnt++)
485  if (Inside(cpcx=tx+tcx-twdt/2+xcnt,0,sfcTarget->Wdt-1))
486  sfcTarget->BltPix(cpcx, cpcy, sfcSource, xcnt*fwdt/twdt+fx, ycnt*fhgt/thgt+fy, fTransparency);
487  // Unlock the surfaces
488  sfcSource->Unlock();
489  sfcTarget->Unlock();
490  return true;
491 }
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

References C4Draw::Blit(), C4Surface::BltPix(), C4Surface::Hgt, Inside(), C4Surface::IsRenderTarget(), C4Surface::Lock(), C4Surface::Unlock(), and C4Surface::Wdt.

Referenced by C4Draw::Blit8().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlitSurface()

bool C4Draw::BlitSurface ( C4Surface sfcSurface,
C4Surface sfcTarget,
int  tx,
int  ty,
bool  fBlitBase 
)
inherited

Definition at line 511 of file C4Draw.cpp.

512 {
513  if (fBlitBase)
514  {
515  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
516  return true;
517  }
518  else
519  {
520  if (!sfcSurface) return false;
521  C4Surface *pSfcBase = sfcSurface->pMainSfc;
522  sfcSurface->pMainSfc = nullptr;
523  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
524  sfcSurface->pMainSfc = pSfcBase;
525  return true;
526  }
527 }
C4Surface * pMainSfc
Definition: C4Surface.h:79

References C4Draw::Blit(), C4Surface::Hgt, C4Surface::pMainSfc, and C4Surface::Wdt.

Referenced by C4Surface::Copy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlitSurfaceTile()

bool C4Draw::BlitSurfaceTile ( C4Surface sfcSurface,
C4Surface sfcTarget,
float  iToX,
float  iToY,
float  iToWdt,
float  iToHgt,
float  iOffsetX,
float  iOffsetY,
C4ShaderCall shader_call 
)
inherited

Definition at line 529 of file C4Draw.cpp.

530 {
531  // Only direct rendering from single, tileable, texture
532  if (!sfcTarget->IsRenderTarget()) return false;
533  if ((sfcSurface->texture->iFlags & C4SF_Tileable) == 0) return false;
534 
535  // source surface dimensions
536  const float sourceWdt = sfcSurface->Wdt;
537  const float sourceHgt = sfcSurface->Hgt;
538 
539  // vertex positions
540  C4BltVertex vertices[6];
541  vertices[0].ftx = iToX; vertices[0].fty = iToY; vertices[0].ftz = 0.0f;
542  vertices[0].tx = (0.0f + iOffsetX) / sourceWdt; vertices[0].ty = (0.0f + iOffsetY) / sourceHgt;
543  DwTo4UB(0xffffffff, vertices[0].color);
544  vertices[1].ftx = iToX + iToWdt; vertices[1].fty = iToY; vertices[1].ftz = 0.0f;
545  vertices[1].tx = (iToWdt + iOffsetX) / sourceWdt; vertices[1].ty = (0.0f + iOffsetY) / sourceHgt;
546  DwTo4UB(0xffffffff, vertices[1].color);
547  vertices[2].ftx = iToX + iToWdt; vertices[2].fty = iToY + iToHgt; vertices[2].ftz = 0.0f;
548  vertices[2].tx = (iToWdt + iOffsetX) / sourceWdt; vertices[2].ty = (iToHgt + iOffsetY) / sourceHgt;
549  DwTo4UB(0xffffffff, vertices[2].color);
550  vertices[3].ftx = iToX; vertices[3].fty = iToY + iToHgt; vertices[3].ftz = 0.0f;
551  vertices[3].tx = (0.0f + iOffsetX) / sourceWdt; vertices[3].ty = (iToHgt + iOffsetY) / sourceHgt;
552  DwTo4UB(0xffffffff, vertices[3].color);
553  // duplicate vertices
554  vertices[4] = vertices[0]; vertices[5] = vertices[2];
555 
556  // Draw
557  PerformMultiTris(sfcTarget, vertices, 6, nullptr, sfcSurface->texture.get(), nullptr, nullptr, 0, shader_call);
558  return true;
559 }
float tx
Definition: C4Draw.h:62
float ty
Definition: C4Draw.h:62
float ftz
Definition: C4Draw.h:64
const int C4SF_Tileable
Definition: C4Surface.h:49
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
std::unique_ptr< C4TexRef > texture
Definition: C4Surface.h:78

References C4SF_Tileable, DwTo4UB(), C4BltVertex::ftx, C4BltVertex::fty, C4BltVertex::ftz, C4Surface::Hgt, C4Surface::IsRenderTarget(), C4Draw::PerformMultiTris(), C4Surface::texture, C4BltVertex::tx, C4BltVertex::ty, and C4Surface::Wdt.

Referenced by C4UpperBoard::Draw(), C4Sky::Draw(), C4Viewport::Draw(), C4GUI::FullscreenDialog::DrawElement(), and C4ViewportList::DrawFullscreenBackground().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlitUnscaled()

bool C4Draw::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 
)
inherited

Definition at line 309 of file C4Draw.cpp.

312 {
313  // safety
314  if (!sfcSource || !sfcTarget || !twdt || !thgt || !fwdt || !fhgt) return false;
315  // emulated blit?
316  if (!sfcTarget->IsRenderTarget())
317  {
318  C4BltTransform t;
319  if(pTransform && Zoom != 1.0)
320  {
321  t.Set(pTransform->mat[0]*Zoom, pTransform->mat[1]*Zoom, pTransform->mat[2]*Zoom + ZoomX*(1-Zoom),
322  pTransform->mat[3]*Zoom, pTransform->mat[4]*Zoom, pTransform->mat[5]*Zoom + ZoomY*(1-Zoom),
323  pTransform->mat[6], pTransform->mat[7], pTransform->mat[8]);
324  pTransform = &t;
325  }
326  else if(Zoom != 1.0)
327  {
328  ApplyZoom(tx, ty);
329  twdt *= Zoom;
330  thgt *= Zoom;
331  }
332 
333  return Blit8(sfcSource, int(fx), int(fy), int(fwdt), int(fhgt), sfcTarget, int(tx), int(ty), int(twdt), int(thgt), fSrcColKey, pTransform);
334  }
335 
336  // bound
337  if (ClipAll) return true;
338  // inside screen?
339  if (twdt<=0 || thgt<=0) return false;
340  // prepare rendering to surface
341  if (!PrepareRendering(sfcTarget)) return false;
342  // texture present?
343  if (!sfcSource->texture)
344  {
345  // primary surface?
346  if (sfcSource->fPrimary)
347  {
348  // blit emulated
349  return Blit8(sfcSource, int(fx), int(fy), int(fwdt), int(fhgt), sfcTarget, int(tx), int(ty), int(twdt), int(thgt), fSrcColKey);
350  }
351  return false;
352  }
353  // blit with basesfc?
354  bool fBaseSfc=false;
355  if (sfcSource->pMainSfc) if (sfcSource->pMainSfc->texture) fBaseSfc = true;
356 
357  C4TexRef *pTex = sfcSource->texture.get();
358  // set up blit data
359  C4BltVertex vertices[6];
360  vertices[0].ftx = tx; vertices[0].fty = ty;
361  vertices[1].ftx = tx + twdt; vertices[1].fty = ty;
362  vertices[2].ftx = tx + twdt; vertices[2].fty = ty + thgt;
363  vertices[3].ftx = tx; vertices[3].fty = ty + thgt;
364  vertices[0].tx = fx / pTex->iSizeX; vertices[0].ty = fy / pTex->iSizeY;
365  vertices[1].tx = (fx + fwdt) / pTex->iSizeX; vertices[1].ty = fy / pTex->iSizeY;
366  vertices[2].tx = (fx + fwdt) / pTex->iSizeX; vertices[2].ty = (fy + fhgt) / pTex->iSizeY;
367  vertices[3].tx = fx / pTex->iSizeX; vertices[3].ty = (fy + fhgt) / pTex->iSizeY;
368  DwTo4UB(0xffffffff, vertices[0].color);
369  DwTo4UB(0xffffffff, vertices[1].color);
370  DwTo4UB(0xffffffff, vertices[2].color);
371  DwTo4UB(0xffffffff, vertices[3].color);
372 
373  // duplicate vertices
374  vertices[4] = vertices[0]; vertices[5] = vertices[2];
375 
376  C4TexRef * pBaseTex = pTex;
377  // is there a base-surface to be blitted first?
378  if (fBaseSfc)
379  {
380  // then get this surface as same offset as from other surface
381  // assuming this is only valid as long as there's no texture management,
382  // organizing partially used textures together!
383  pBaseTex = sfcSource->pMainSfc->texture.get();
384  }
385 
386  C4TexRef* pNormalTex = nullptr;
387  if (sfcSource->pNormalSfc)
388  pNormalTex = sfcSource->pNormalSfc->texture.get();
389 
390  // ClrByOwner is always fully opaque
391  const DWORD dwOverlayClrMod = 0xff000000 | sfcSource->ClrByOwnerClr;
392  PerformMultiTris(sfcTarget, vertices, 6, pTransform, pBaseTex, fBaseSfc ? pTex : nullptr, pNormalTex, dwOverlayClrMod, nullptr);
393  // success
394  return true;
395 }
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
bool ClipAll
Definition: C4Draw.h:105
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:418
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
C4Surface * pNormalSfc
Definition: C4Surface.h:80
DWORD ClrByOwnerClr
Definition: C4Surface.h:81
int iSizeX
Definition: C4Surface.h:157
int iSizeY
Definition: C4Surface.h:158

References C4Draw::ApplyZoom(), C4Draw::Blit8(), C4Draw::ClipAll, C4Surface::ClrByOwnerClr, DwTo4UB(), C4Surface::fPrimary, C4BltVertex::ftx, C4BltVertex::fty, C4TexRef::iSizeX, C4TexRef::iSizeY, C4Surface::IsRenderTarget(), C4BltTransform::mat, C4Draw::PerformMultiTris(), C4Surface::pMainSfc, C4Surface::pNormalSfc, C4Draw::PrepareRendering(), C4BltTransform::Set(), C4Surface::texture, C4BltVertex::tx, C4BltVertex::ty, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

Referenced by C4Draw::Blit(), and C4Facet::DrawTUnscaled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckGLError()

bool CStdGL::CheckGLError ( const char *  szAtOp)
protected

Definition at line 898 of file C4DrawGL.cpp.

899 {
900  GLenum err = glGetError();
901  if (!err) return true;
902 
903  LogF("GL error with %s: %d - %s", szAtOp, err, GLErrorString(err));
904  return false;
905 }
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
const char * GLErrorString(GLenum code)
Definition: C4DrawGL.cpp:882

References GLErrorString(), and LogF().

Here is the call graph for this function:

◆ Clear()

void CStdGL::Clear ( )
overridevirtual

Reimplemented from C4Draw.

Definition at line 106 of file C4DrawGL.cpp.

107 {
109  // cannot unlock TexMgr here or we can't preserve textures across GL reinitialization as required when changing multisampling
112  RenderTarget = nullptr;
113  // Clear all shaders
130  // clear context
131  if (pCurrCtx) pCurrCtx->Deselect();
132  pMainCtx=nullptr;
133  C4Draw::Clear();
134 }
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool NoPrimaryClipper()
Definition: C4Draw.cpp:237
virtual void Clear()
Definition: C4Draw.cpp:184
void Clear()
Definition: C4Shader.cpp:335
virtual void Deselect()
C4Shader SpriteShaderLightBaseNormalMod2
Definition: C4DrawGL.h:205
C4Shader SpriteShaderLightBase
Definition: C4DrawGL.h:200
C4Shader SpriteShaderBaseOverlayMod2
Definition: C4DrawGL.h:196
C4Shader SpriteShaderBaseOverlay
Definition: C4DrawGL.h:195
C4Shader SpriteShaderLightMod2
Definition: C4DrawGL.h:199
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:180
bool InvalidateDeviceObjects() override
Definition: C4DrawGL.cpp:808
C4Shader SpriteShaderBaseMod2
Definition: C4DrawGL.h:194
C4Shader SpriteShaderMod2
Definition: C4DrawGL.h:192
C4Shader SpriteShaderLightBaseNormal
Definition: C4DrawGL.h:204
C4Shader SpriteShader
Definition: C4DrawGL.h:191
C4Shader SpriteShaderLightBaseOverlay
Definition: C4DrawGL.h:202
C4Shader SpriteShaderLightBaseMod2
Definition: C4DrawGL.h:201
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:179
C4Shader SpriteShaderBase
Definition: C4DrawGL.h:193
C4Shader SpriteShaderLightBaseNormalOverlay
Definition: C4DrawGL.h:206
C4Shader SpriteShaderLight
Definition: C4DrawGL.h:198
C4Shader SpriteShaderLightBaseOverlayMod2
Definition: C4DrawGL.h:203
C4Shader SpriteShaderLightBaseNormalOverlayMod2
Definition: C4DrawGL.h:207

References C4Draw::Clear(), C4Shader::Clear(), CStdGLCtx::Deselect(), InvalidateDeviceObjects(), C4Draw::NoPrimaryClipper(), pCurrCtx, pMainCtx, C4Draw::RenderTarget, SpriteShader, SpriteShaderBase, SpriteShaderBaseMod2, SpriteShaderBaseOverlay, SpriteShaderBaseOverlayMod2, SpriteShaderLight, SpriteShaderLightBase, SpriteShaderLightBaseMod2, SpriteShaderLightBaseNormal, SpriteShaderLightBaseNormalMod2, SpriteShaderLightBaseNormalOverlay, SpriteShaderLightBaseNormalOverlayMod2, SpriteShaderLightBaseOverlay, SpriteShaderLightBaseOverlayMod2, SpriteShaderLightMod2, and SpriteShaderMod2.

Referenced by ~CStdGL().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateContext()

CStdGLCtx * CStdGL::CreateContext ( C4Window pWindow,
C4AbstractApp pApp 
)
overridevirtual

Reimplemented from C4Draw.

Definition at line 273 of file C4DrawGL.cpp.

274 {
275  // safety
276  if (!pWindow) return nullptr;
277 
278  // create it
279  CStdGLCtx *pCtx;
280 #ifdef WITH_QT_EDITOR
281  auto app = dynamic_cast<C4Application*>(pApp);
282  if (app->isEditor)
283  pCtx = new CStdGLCtxQt();
284  else
285 #endif
286  pCtx = new CStdGLCtx();
287  bool first_ctx = !pMainCtx;
288  if (first_ctx)
289  {
290  pMainCtx = pCtx;
291  LogF(" gl: Create first %scontext...", Config.Graphics.DebugOpenGL ? "debug " : "");
292  }
293  if (!pCtx->Init(pWindow, pApp))
294  {
295  Log(" gl: failed to create context.");
296  delete pCtx;
297  return NULL;
298  }
299  has_khr_debug = epoxy_has_gl_extension("GL_KHR_debug") || epoxy_gl_version() >= 43;
300  if (Config.Graphics.DebugOpenGL && (has_khr_debug || epoxy_has_gl_extension("GL_ARB_debug_output")))
301  {
302  if (first_ctx) Log(" gl: Setting OpenGLDebugProc callback");
303  glDebugMessageCallback(&OpenGLDebugProc, nullptr);
304  glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
305  if (has_khr_debug)
306  glEnable(GL_DEBUG_OUTPUT);
307  }
308  // First context: Log some information about hardware/drivers
309  // Must log after context creation to get valid results
310  if (first_ctx)
311  {
312  const auto *gl_vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
313  const auto *gl_renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
314  const auto *gl_version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
315  LogF("GL %s on %s (%s)", gl_version ? gl_version : "", gl_renderer ? gl_renderer : "", gl_vendor ? gl_vendor : "");
316 
318  {
319  // Dump extension list
320  if (epoxy_is_desktop_gl() && epoxy_gl_version() >= 30)
321  {
322  GLint gl_extension_count = 0;
323  glGetIntegerv(GL_NUM_EXTENSIONS, &gl_extension_count);
324  if (gl_extension_count == 0)
325  {
326  LogSilentF("No available extensions.");
327  }
328  else
329  {
330  LogSilentF("%d available extensions:", gl_extension_count);
331  for (GLint i = 0; i < gl_extension_count; ++i)
332  {
333  const char *gl_extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
334  LogSilentF(" %4d: %s", i, gl_extension);
335  }
336  }
337  }
338  else
339  {
340  const char *gl_extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
341  LogSilentF("GLExt: %s", gl_extensions ? gl_extensions : "");
342  }
343  }
344  }
345  // creation selected the new context - switch back to previous context
346  RenderTarget = nullptr;
347 #ifdef WITH_QT_EDITOR
348  // FIXME This is a hackfix for #1813 / #1956. The proper way to fix them would probably be to select a drawing context before invoking C4Player::FinalInit
349  if (!app->isEditor)
350 #endif
351  pCurrCtx = nullptr;
352  // done
353  return pCtx;
354 }
C4Config Config
Definition: C4Config.cpp:930
bool Log(const char *szMessage)
Definition: C4Log.cpp:204
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:272
int32_t DebugOpenGL
Definition: C4Config.h:117
C4ConfigGraphics Graphics
Definition: C4Config.h:257
C4AbstractApp * pApp
Definition: C4Draw.h:95
virtual bool Init(C4Window *pWindow, C4AbstractApp *pApp)
bool has_khr_debug
Definition: C4DrawGL.h:230
friend class CStdGLCtx
Definition: C4DrawGL.h:294

References Config, CStdGLCtx, C4ConfigGraphics::DebugOpenGL, C4Config::Graphics, has_khr_debug, CStdGLCtx::Init(), Log(), LogF(), LogSilentF(), C4Draw::pApp, pCurrCtx, pMainCtx, and C4Draw::RenderTarget.

Referenced by C4Surface::C4Surface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreatePrimaryClipper()

bool C4Draw::CreatePrimaryClipper ( unsigned int  iXRes,
unsigned int  iYRes 
)
protectedinherited

Definition at line 501 of file C4Draw.cpp.

502 {
503  // simply setup primary viewport
504  // assume no zoom has been set yet
505  assert(Zoom==1.0f);
506  SetPrimaryClipper(0, 0, iXRes - 1, iYRes - 1);
508  return true;
509 }
bool StorePrimaryClipper()
Definition: C4Draw.cpp:203
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217

References C4Draw::SetPrimaryClipper(), C4Draw::StorePrimaryClipper(), and C4Draw::Zoom.

Referenced by C4Draw::Init(), and OnResolutionChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeactivateBlitModulation()

void C4Draw::DeactivateBlitModulation ( )
inlineinherited

Definition at line 189 of file C4Draw.h.

189 { BlitModulated=false; } // stop color modulation of blits

References C4Draw::BlitModulated.

Referenced by C4Sky::Draw(), C4GUI::Dialog::Draw(), C4GraphicsOverlay::Draw(), C4Landscape::Draw(), C4MouseControl::Draw(), C4ParticleList::Draw(), C4GUI::Tabular::Sheet::DrawCaption(), C4Viewport::DrawMenu(), C4GraphicsOverlay::DrawPicture(), CStdFont::DrawText(), and C4Object::FinishedDrawing().

Here is the caller graph for this function:

◆ Default()

void CStdGL::Default ( )
overridevirtual

Reimplemented from C4Draw.

Definition at line 917 of file C4DrawGL.cpp.

918 {
919  C4Draw::Default();
920  pCurrCtx = nullptr;
921  iPixelFormat=0;
922  sfcFmt=0;
923  Workarounds.LowMaxVertexUniformCount = false;
924  Workarounds.ForceSoftwareTransform = false;
925 }
virtual void Default()
Definition: C4Draw.cpp:169
int iPixelFormat
Definition: C4DrawGL.h:176
GLenum sfcFmt
Definition: C4DrawGL.h:178
struct CStdGL::@10 Workarounds

References C4Draw::Default(), iPixelFormat, pCurrCtx, sfcFmt, and Workarounds.

Referenced by CStdGL().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DetachPrimaryClipper()

bool C4Draw::DetachPrimaryClipper ( C4Surface sfcSurface)
inherited

Definition at line 232 of file C4Draw.cpp.

233 {
234  return true;
235 }

◆ DeviceReady()

bool CStdGL::DeviceReady ( )
inlineoverridevirtual

Implements C4Draw.

Definition at line 274 of file C4DrawGL.h.

274 { return !!pMainCtx; }

References pMainCtx.

◆ DrawBoxDw()

void C4Draw::DrawBoxDw ( C4Surface sfcDest,
int  iX1,
int  iY1,
int  iX2,
int  iY2,
DWORD  dwClr 
)
inherited

Definition at line 840 of file C4Draw.cpp.

841 {
842  if (!sfcDest->IsRenderTarget())
843  {
844  // Box on non-render target: Emulate by setting pixels
845  if (!sfcDest->Lock()) return;
846  for (int y = iY1; y <= iY2; ++y)
847  for (int x = iX1; x <= iX2; ++x)
848  sfcDest->SetPixDw(x,y, dwClr);
849  sfcDest->Unlock();
850  }
851  else
852  {
853  DrawBoxFade(sfcDest, float(iX1), float(iY1), float(iX2 - iX1 + 1), float(iY2 - iY1 + 1), dwClr, dwClr, dwClr, dwClr, nullptr);
854  }
855 }
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:824
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:576

References C4Draw::DrawBoxFade(), C4Surface::IsRenderTarget(), C4Surface::Lock(), C4Surface::SetPixDw(), and C4Surface::Unlock().

Referenced by C4MessageBoard::Draw(), C4Def::Draw(), C4LoaderScreen::Draw(), C4Sky::Draw(), C4GUI::Dialog::Draw(), C4Viewport::Draw(), C4GUI::Screen::Draw(), C4GUI::FrameDecoration::Draw(), C4ScriptGuiWindow::Draw(), C4GUI::GroupBox::DrawElement(), C4GUI::Edit::DrawElement(), C4GUI::ListBox::DrawElement(), C4GUI::Tabular::DrawElement(), C4GUI::TextWindow::DrawElement(), C4GUI::ContextMenu::DrawElement(), C4GUI::ComboBox::DrawElement(), C4GUI::Dialog::DrawElement(), C4MenuItem::DrawElement(), C4StartupNetListEntry::DrawElement(), and C4GUI::Screen::DrawToolTip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawBoxFade()

void C4Draw::DrawBoxFade ( C4Surface sfcDest,
float  iX,
float  iY,
float  iWdt,
float  iHgt,
DWORD  dwClr1,
DWORD  dwClr2,
DWORD  dwClr3,
DWORD  dwClr4,
C4ShaderCall shader_call 
)
inherited

Definition at line 824 of file C4Draw.cpp.

825 {
826  // set vertex buffer data
827  // vertex order:
828  // 0=upper left dwClr1
829  // 1=lower left dwClr3
830  // 2=lower right dwClr4
831  // 3=upper right dwClr2
832  float vtx[8];
833  vtx[0] = iX ; vtx[1] = iY;
834  vtx[2] = iX ; vtx[3] = iY+iHgt;
835  vtx[4] = iX+iWdt; vtx[5] = iY+iHgt;
836  vtx[6] = iX+iWdt; vtx[7] = iY;
837  DrawQuadDw(sfcDest, vtx, dwClr1, dwClr3, dwClr4, dwClr2, shader_call);
838 }
void DrawQuadDw(C4Surface *sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:653

References C4Draw::DrawQuadDw().

Referenced by C4Sky::Draw(), and C4Draw::DrawBoxDw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawCircleDw()

void C4Draw::DrawCircleDw ( C4Surface sfcTarget,
float  cx,
float  cy,
float  r,
DWORD  dwClr,
float  width = 1.0f 
)
inherited

Definition at line 618 of file C4Draw.cpp.

619 {
620  // Draw as line segments
621  int32_t num_lines = 12 + int32_t(r / 10);
622  std::unique_ptr<C4BltVertex[]> vertices(new C4BltVertex[num_lines * 2]);
623  for (int32_t i = 0; i < num_lines; ++i)
624  {
625  float ang = float(i) * 2 * M_PI / num_lines;
626  int32_t iv = i * 2 + 1;
627  vertices[iv].ftx = cx + sin(ang) * r;
628  vertices[iv].fty = cy + cos(ang) * r;
629  DwTo4UB(dwClr, vertices[iv].color);
630  vertices[(iv + 1) % (num_lines * 2)] = vertices[iv];
631  }
632  PerformMultiLines(sfcTarget, vertices.get(), num_lines * 2, width, nullptr);
633 }
virtual void PerformMultiLines(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call)=0

References DwTo4UB(), and C4Draw::PerformMultiLines().

Referenced by C4EditCursor::Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawFrameDw()

void C4Draw::DrawFrameDw ( C4Surface sfcDest,
int  x1,
int  y1,
int  x2,
int  y2,
DWORD  dwClr,
float  width = 1.0f 
)
inherited

Definition at line 635 of file C4Draw.cpp.

636 {
637  C4BltVertex vertices[8];
638  vertices[0].ftx = x1; vertices[0].fty = y1;
639  vertices[1].ftx = x2; vertices[1].fty = y1;
640  vertices[2] = vertices[1];
641  vertices[3].ftx = x2; vertices[3].fty = y2;
642  vertices[4] = vertices[3];
643  vertices[5].ftx = x1; vertices[5].fty = y2;
644  vertices[6] = vertices[5];
645  vertices[7] = vertices[0];
646 
647  for(auto & vertex : vertices)
648  DwTo4UB(dwClr, vertex.color);
649 
650  PerformMultiLines(sfcDest, vertices, 8, width, nullptr);
651 }

References DwTo4UB(), C4BltVertex::ftx, C4BltVertex::fty, and C4Draw::PerformMultiLines().

Referenced by C4EditCursor::Draw(), C4PathFinderRay::Draw(), C4TransferZone::Draw(), C4Object::Draw(), C4ScriptGuiWindow::Draw(), C4GUI::GroupBox::DrawElement(), C4GUI::Edit::DrawElement(), C4GUI::ComboBox::DrawElement(), C4Menu::DrawFrame(), and C4GUI::Screen::DrawToolTip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawLineDw()

void C4Draw::DrawLineDw ( C4Surface sfcTarget,
float  x1,
float  y1,
float  x2,
float  y2,
DWORD  dwClr,
float  width = 1.0f 
)
inherited

Definition at line 608 of file C4Draw.cpp.

609 {
610  C4BltVertex vertices[2];
611  vertices[0].ftx = x1; vertices[0].fty = y1;
612  vertices[1].ftx = x2; vertices[1].fty = y2;
613  DwTo4UB(dwClr, vertices[0].color);
614  DwTo4UB(dwClr, vertices[1].color);
615  PerformMultiLines(sfcTarget, vertices, 2, width, nullptr);
616 }

References DwTo4UB(), C4BltVertex::ftx, C4BltVertex::fty, and C4Draw::PerformMultiLines().

Referenced by C4EditCursor::Draw(), C4PathFinderRay::Draw(), C4Object::Draw(), C4GUI::Element::Draw3DFrame(), C4GUI::HorizontalLine::DrawElement(), C4GUI::GroupBox::DrawElement(), C4GUI::ListBox::DrawElement(), C4GUI::Tabular::DrawElement(), and C4Chart::DrawElement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawPatternedCircle()

void C4Draw::DrawPatternedCircle ( C4Surface sfcDest,
int  x,
int  y,
int  r,
BYTE  col,
C4Pattern Pattern,
CStdPalette rPal 
)
inherited

Definition at line 669 of file C4Draw.cpp.

670 {
671  bool fRenderTarget = sfcDest->IsRenderTarget();
672  if (!fRenderTarget) if (!sfcDest->Lock()) return;
673  for (int ycnt = -r; ycnt < r; ycnt++)
674  {
675  int lwdt = (int)sqrt(float(r * r - ycnt * ycnt));
676  // Set line
677  if (fRenderTarget)
678  {
679  for (int xcnt = x - lwdt; xcnt < x + lwdt; ++xcnt)
680  {
681  DrawPix(sfcDest, xcnt, y + ycnt, Pattern.PatternClr(xcnt, y + ycnt));
682  }
683  }
684  else
685  {
686  for (int xcnt = x - lwdt; xcnt < x + lwdt; ++xcnt)
687  {
688  sfcDest->SetPixDw(xcnt, y + ycnt, Pattern.PatternClr(xcnt, y + ycnt));
689  }
690  }
691  }
692  if (!fRenderTarget) sfcDest->Unlock();
693 }
void DrawPix(C4Surface *sfcDest, float tx, float ty, DWORD dwCol)
Definition: C4Draw.cpp:598
DWORD PatternClr(unsigned int iX, unsigned int iY) const
Definition: C4Draw.cpp:159

References C4Draw::DrawPix(), C4Surface::IsRenderTarget(), C4Surface::Lock(), C4Pattern::PatternClr(), C4Surface::SetPixDw(), and C4Surface::Unlock().

Here is the call graph for this function:

◆ DrawPix()

void C4Draw::DrawPix ( C4Surface sfcDest,
float  tx,
float  ty,
DWORD  dwCol 
)
inherited

Definition at line 598 of file C4Draw.cpp.

599 {
600  // Draw
601  C4BltVertex vtx;
602  vtx.ftx = tx;
603  vtx.fty = ty;
604  DwTo4UB(dwClr, vtx.color);
605  PerformMultiPix(sfcDest, &vtx, 1, nullptr);
606 }
unsigned char color[4]
Definition: C4Draw.h:63

References C4BltVertex::color, DwTo4UB(), C4BltVertex::ftx, C4BltVertex::fty, and C4Draw::PerformMultiPix().

Referenced by C4Draw::DrawPatternedCircle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawQuadDw()

void C4Draw::DrawQuadDw ( C4Surface sfcTarget,
float *  ipVtx,
DWORD  dwClr1,
DWORD  dwClr2,
DWORD  dwClr3,
DWORD  dwClr4,
C4ShaderCall shader_call 
)
inherited

Definition at line 653 of file C4Draw.cpp.

654 {
655  C4BltVertex vertices[6];
656  vertices[0].ftx = ipVtx[0]; vertices[0].fty = ipVtx[1];
657  vertices[1].ftx = ipVtx[2]; vertices[1].fty = ipVtx[3];
658  vertices[2].ftx = ipVtx[4]; vertices[2].fty = ipVtx[5];
659  vertices[3].ftx = ipVtx[6]; vertices[3].fty = ipVtx[7];
660  DwTo4UB(dwClr1, vertices[0].color);
661  DwTo4UB(dwClr2, vertices[1].color);
662  DwTo4UB(dwClr3, vertices[2].color);
663  DwTo4UB(dwClr4, vertices[3].color);
664  vertices[4] = vertices[0];
665  vertices[5] = vertices[2];
666  PerformMultiTris(sfcTarget, vertices, 6, nullptr, nullptr, nullptr, nullptr, 0, shader_call);
667 }

References DwTo4UB(), C4BltVertex::ftx, C4BltVertex::fty, and C4Draw::PerformMultiTris().

Referenced by C4Draw::DrawBoxFade(), and C4GUI::Tabular::DrawElement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureMainContextSelected()

bool CStdGL::EnsureMainContextSelected ( )
overridevirtual

Implements C4Draw.

Definition at line 757 of file C4DrawGL.cpp.

758 {
759  return pMainCtx->Select();
760 }
virtual bool Select(bool verbose=false)

References pMainCtx, and CStdGLCtx::Select().

Referenced by InitShaders().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Error()

bool CStdGL::Error ( const char *  szMsg)
overrideprotectedvirtual

Reimplemented from C4Draw.

Definition at line 855 of file C4DrawGL.cpp.

856 {
857 #ifdef USE_WIN32_WINDOWS
858  DWORD err = GetLastError();
859 #endif
860  bool r = C4Draw::Error(szMsg);
861 #ifdef USE_WIN32_WINDOWS
862  wchar_t * lpMsgBuf;
863  FormatMessage(
864  FORMAT_MESSAGE_ALLOCATE_BUFFER |
865  FORMAT_MESSAGE_FROM_SYSTEM |
866  FORMAT_MESSAGE_IGNORE_INSERTS,
867  nullptr,
868  err,
869  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
870  (LPTSTR) &lpMsgBuf,
871  0, nullptr );
872  LogF(" gl: GetLastError() = %d - %s", err, StdStrBuf(lpMsgBuf).getData());
873  LocalFree(lpMsgBuf);
874 #endif
875  LogF(" gl: %s", glGetString(GL_VENDOR));
876  LogF(" gl: %s", glGetString(GL_RENDERER));
877  LogF(" gl: %s", glGetString(GL_VERSION));
878  LogF(" gl: %s", glGetString(GL_EXTENSIONS));
879  return r;
880 }
virtual bool Error(const char *szMsg)
Definition: C4Draw.cpp:494

References C4Draw::Error(), and LogF().

Here is the call graph for this function:

◆ FillBG()

void CStdGL::FillBG ( DWORD  dwClr = 0)
overridevirtual

Implements C4Draw.

Definition at line 136 of file C4DrawGL.cpp.

137 {
138  if (!pCurrCtx) return;
139  glClearColor((float)GetRedValue(dwClr)/255.0f, (float)GetGreenValue(dwClr)/255.0f, (float)GetBlueValue(dwClr)/255.0f, 0.0f);
140  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
141 }

References GetBlueValue, GetGreenValue, GetRedValue, and pCurrCtx.

◆ FreeVAOID()

void CStdGL::FreeVAOID ( unsigned int  vaoid)

Definition at line 969 of file C4DrawGL.cpp.

970 {
971  std::set<unsigned int>::iterator iter = VAOIDs.find(vaoid);
972  assert(iter != VAOIDs.end());
973 
974  // Delete this VAO in the current context
975  if (pCurrCtx)
976  {
977  if (vaoid < pCurrCtx->hVAOs.size() && pCurrCtx->hVAOs[vaoid] != 0)
978  {
979  glDeleteVertexArrays(1, &pCurrCtx->hVAOs[vaoid]);
980  pCurrCtx->hVAOs[vaoid] = 0;
981  }
982  }
983 
984  // For all other contexts, mark it to be deleted as soon as we select
985  // that context. Otherwise we would need to do a lot of context
986  // switching at this point.
987  for (auto ctx : CStdGLCtx::contexts)
988  {
989  if (ctx != pCurrCtx && vaoid < ctx->hVAOs.size() && ctx->hVAOs[vaoid] != 0)
990  if (std::find(ctx->VAOsToBeDeleted.begin(), ctx->VAOsToBeDeleted.end(), vaoid) == ctx->VAOsToBeDeleted.end())
991  ctx->VAOsToBeDeleted.push_back(vaoid);
992  }
993 
994  // Delete the VAO ID from our list of VAO IDs in use
995  // If the Next VAO ID is 1, then no matter what we delete we don't need
996  // to update anything. If it is not at the beginning, then move it to the
997  // gap we just created if it was at a higher place, to make sure we keep
998  // the numbers as sequential as possible.
999  unsigned int nextVaoID = 1;
1000  if (NextVAOID != VAOIDs.begin())
1001  {
1002  std::set<unsigned int>::iterator next_vao_iter = NextVAOID;
1003  --next_vao_iter;
1004  nextVaoID = *next_vao_iter + 1;
1005  }
1006 
1007  assert(vaoid != nextVaoID);
1008 
1009  if (vaoid < nextVaoID || iter == NextVAOID)
1010  NextVAOID = VAOIDs.erase(iter);
1011  else
1012  VAOIDs.erase(iter);
1013 }
std::vector< GLuint > hVAOs
Definition: C4DrawGL.h:140
static std::list< CStdGLCtx * > contexts
Definition: C4DrawGL.h:136

References CStdGLCtx::contexts, CStdGLCtx::hVAOs, NextVAOID, pCurrCtx, and VAOIDs.

Referenced by C4LandscapeRenderGL::Clear(), InvalidateDeviceObjects(), StdMeshInstance::UpdateIBO(), C4FoWDrawLightTextureStrategy::~C4FoWDrawLightTextureStrategy(), C4FoWDrawWireframeStrategy::~C4FoWDrawWireframeStrategy(), C4FoWRegion::~C4FoWRegion(), StdMesh::~StdMesh(), and StdMeshInstance::~StdMeshInstance().

Here is the caller graph for this function:

◆ GenVAOID()

unsigned int CStdGL::GenVAOID ( )

Definition at line 927 of file C4DrawGL.cpp.

928 {
929  // Generate a new VAO ID. Make them sequential so that the actual
930  // VAOs in the context can be simply maintained with a lookup table.
931  unsigned int id;
932  if (NextVAOID == VAOIDs.begin())
933  {
934  // Insert at the beginning
935  id = 1;
936  }
937  else
938  {
939  // Insert at the end, or somewhere in the middle
940  std::set<unsigned int>::iterator iter = NextVAOID;
941  --iter;
942 
943  id = *iter + 1;
944  }
945 
946  // Actually insert the ID
947 #ifdef NDEBUG
948  std::set<unsigned int>::iterator inserted_iter = VAOIDs.insert(NextVAOID, id);
949 #else
950  std::pair<std::set<unsigned int>::iterator, bool> inserted = VAOIDs.insert(id);
951  assert(inserted.second == true);
952  std::set<unsigned int>::iterator inserted_iter = inserted.first;
953 #endif
954 
955  // Update next VAO ID: increment iterator until we find a gap
956  // in the sequence.
957  NextVAOID = inserted_iter;
958  unsigned int prev_id = id;
959  ++NextVAOID;
960  while(NextVAOID != VAOIDs.end() && prev_id + 1 == *NextVAOID)
961  {
962  prev_id = *NextVAOID;
963  ++NextVAOID;
964  }
965 
966  return id;
967 }

References NextVAOID, and VAOIDs.

Referenced by C4FoWDrawLightTextureStrategy::Begin(), C4FoWDrawWireframeStrategy::C4FoWDrawWireframeStrategy(), C4ParticleChunk::Draw(), StdMesh::PostInit(), C4FoWRegion::Render(), RestoreDeviceObjects(), and StdMeshInstance::UpdateIBO().

Here is the caller graph for this function:

◆ GetBlitModulation()

bool C4Draw::GetBlitModulation ( DWORD rdwColor)
inlineinherited

Definition at line 190 of file C4Draw.h.

190 { rdwColor=BlitModulateClr; return BlitModulated; }

References C4Draw::BlitModulateClr, and C4Draw::BlitModulated.

Referenced by CStdFont::DrawText().

Here is the caller graph for this function:

◆ GetClipRect()

C4Rect C4Draw::GetClipRect ( ) const
inherited

Definition at line 724 of file C4Draw.cpp.

725 {
726  int iWdt=std::min(iClipX2, RenderTarget->Wdt-1)-iClipX1+1;
727  int iHgt=std::min(iClipY2, RenderTarget->Hgt-1)-iClipY1+1;
728  int iX=iClipX1; if (iX<0) { iWdt+=iX; iX=0; }
729  int iY=iClipY1; if (iY<0) { iHgt+=iY; iY=0; }
730  return C4Rect(iX, iY, iWdt, iHgt);
731 }
int32_t iClipY2
Definition: C4Draw.h:104
int32_t iClipX1
Definition: C4Draw.h:104
int32_t iClipX2
Definition: C4Draw.h:104
int32_t iClipY1
Definition: C4Draw.h:104
Definition: C4Rect.h:28

References C4Surface::Hgt, C4Draw::iClipX1, C4Draw::iClipX2, C4Draw::iClipY1, C4Draw::iClipY2, C4Draw::RenderTarget, and C4Surface::Wdt.

Referenced by C4LandscapeRenderGL::Draw(), PerformMesh(), SetupMultiBlt(), and UpdateClipper().

Here is the caller graph for this function:

◆ GetFoW()

const C4FoWRegion* C4Draw::GetFoW ( ) const
inlineinherited

Definition at line 194 of file C4Draw.h.

194 { return pFoW; }
const C4FoWRegion * pFoW
Definition: C4Draw.h:111

References C4Draw::pFoW.

Referenced by C4Sky::Draw(), and C4Object::Draw().

Here is the caller graph for this function:

◆ GetOutRect()

C4Rect C4Draw::GetOutRect ( ) const
inherited

Definition at line 733 of file C4Draw.cpp.

734 {
735  return C4Rect(0, 0, RenderTarget->Wdt, RenderTarget->Hgt);
736 }

References C4Surface::Hgt, C4Draw::RenderTarget, and C4Surface::Wdt.

Referenced by C4LandscapeRenderGL::Draw(), PerformMesh(), and SetupMultiBlt().

Here is the caller graph for this function:

◆ GetPrimaryClipper()

bool C4Draw::GetPrimaryClipper ( int &  rX1,
int &  rY1,
int &  rX2,
int &  rY2 
)
inherited

Definition at line 716 of file C4Draw.cpp.

717 {
718  // Store drawing clip values
719  rX1=fClipX1; rY1=fClipY1; rX2=fClipX2; rY2=fClipY2;
720  // Done
721  return true;
722 }
float fClipX2
Definition: C4Draw.h:102
float fClipY1
Definition: C4Draw.h:102
float fClipY2
Definition: C4Draw.h:102
float fClipX1
Definition: C4Draw.h:102

References C4Draw::fClipX1, C4Draw::fClipX2, C4Draw::fClipY1, and C4Draw::fClipY2.

Referenced by C4GUI::Window::Draw(), C4GUI::MultilineLabel::DrawElement(), and C4GUI::Edit::DrawElement().

Here is the caller graph for this function:

◆ GetProjectionMatrix()

const StdProjectionMatrix& CStdGL::GetProjectionMatrix ( ) const
inline

Definition at line 254 of file C4DrawGL.h.

254 { return ProjectionMatrix; }
StdProjectionMatrix ProjectionMatrix
Definition: C4DrawGL.h:185

References ProjectionMatrix.

Referenced by C4LandscapeRenderGL::Draw(), and C4FoWRegion::Render().

Here is the caller graph for this function:

◆ GetSpriteShader() [1/2]

C4Shader * CStdGL::GetSpriteShader ( bool  haveBase,
bool  haveOverlay,
bool  haveNormal 
)

Definition at line 662 of file C4DrawGL.cpp.

663 {
664  int ssc = 0;
665  if(dwBlitMode & C4GFXBLIT_MOD2) ssc |= C4SSC_MOD2;
666  if(haveBase) ssc |= C4SSC_BASE;
667  if(haveBase && haveOverlay) ssc |= C4SSC_OVERLAY;
668  if(pFoW != nullptr) ssc |= C4SSC_LIGHT;
669  if(pFoW != nullptr && haveBase && haveNormal) ssc |= C4SSC_NORMAL;
670  return GetSpriteShader(ssc);
671 }
#define C4GFXBLIT_MOD2
Definition: C4Surface.h:27
DWORD dwBlitMode
Definition: C4Draw.h:110
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:673

References C4GFXBLIT_MOD2, and C4Draw::dwBlitMode.

◆ GetSpriteShader() [2/2]

C4Shader * CStdGL::GetSpriteShader ( int  ssc)

Definition at line 673 of file C4DrawGL.cpp.

674 {
675  C4Shader* shaders[16] = {
676  &SpriteShader,
682 
693  };
694 
695  int index = 0;
696  if(ssc & C4SSC_LIGHT) index += 6;
697 
698  if(ssc & C4SSC_BASE)
699  {
700  index += 2;
701  if(ssc & C4SSC_OVERLAY)
702  index += 2;
703  if( (ssc & C4SSC_NORMAL) && (ssc & C4SSC_LIGHT))
704  index += 4;
705  }
706 
707  if(ssc & C4SSC_MOD2)
708  index += 1;
709 
710  assert(index < 16);
711  return shaders[index];
712 }

References SpriteShader, SpriteShaderBase, SpriteShaderBaseMod2, SpriteShaderBaseOverlay, SpriteShaderBaseOverlayMod2, SpriteShaderLight, SpriteShaderLightBase, SpriteShaderLightBaseMod2, SpriteShaderLightBaseNormal, SpriteShaderLightBaseNormalMod2, SpriteShaderLightBaseNormalOverlay, SpriteShaderLightBaseNormalOverlayMod2, SpriteShaderLightBaseOverlay, SpriteShaderLightBaseOverlayMod2, SpriteShaderLightMod2, and SpriteShaderMod2.

Referenced by C4ParticleList::Draw(), PerformMultiLines(), PerformMultiPix(), and PerformMultiTris().

Here is the caller graph for this function:

◆ GetSurfaceSize()

bool C4Draw::GetSurfaceSize ( C4Surface sfcSurface,
int &  iWdt,
int &  iHgt 
)
inherited

Definition at line 191 of file C4Draw.cpp.

192 {
193  return sfcSurface->GetSurfaceSize(iWdt, iHgt);
194 }
bool GetSurfaceSize(int &irX, int &irY)
Definition: C4Surface.cpp:444

References C4Surface::GetSurfaceSize().

Here is the call graph for this function:

◆ GetVAO()

bool CStdGL::GetVAO ( unsigned int  vaoid,
GLuint &  vao 
)

Definition at line 1015 of file C4DrawGL.cpp.

1016 {
1017  assert(pCurrCtx != nullptr);
1018 
1019  if (vaoid >= pCurrCtx->hVAOs.size())
1020  {
1021  // Resize the VAO array so that all generated VAO IDs fit
1022  // in it, and not only the one requested in this call.
1023  // We hope to get away with fewer reallocations this way.
1024  assert(VAOIDs.find(vaoid) != VAOIDs.end());
1025  std::set<unsigned int>::iterator iter = VAOIDs.end();
1026  --iter;
1027 
1028  pCurrCtx->hVAOs.resize(*iter + 1);
1029  }
1030 
1031  if (pCurrCtx->hVAOs[vaoid] == 0)
1032  {
1033  glGenVertexArrays(1, &pCurrCtx->hVAOs[vaoid]);
1034  vao = pCurrCtx->hVAOs[vaoid];
1035  return false;
1036  }
1037 
1038  vao = pCurrCtx->hVAOs[vaoid];
1039  return true;
1040 }

References CStdGLCtx::hVAOs, pCurrCtx, and VAOIDs.

Referenced by C4ParticleChunk::Draw(), C4LandscapeRenderGL::Draw(), C4FoWDrawLightTextureStrategy::End(), C4FoWDrawWireframeStrategy::End(), PerformMultiBlt(), and C4FoWRegion::Render().

Here is the caller graph for this function:

◆ GetZoom()

void C4Draw::GetZoom ( ZoomData r)
inlineinherited

Definition at line 197 of file C4Draw.h.

197 { r->Zoom=Zoom; r->X=ZoomX; r->Y=ZoomY; }
float Zoom
Definition: C4Draw.h:70
float X
Definition: C4Draw.h:71
float Y
Definition: C4Draw.h:71

References ZoomData::X, ZoomData::Y, ZoomData::Zoom, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

Referenced by C4MouseControl::Draw(), C4GUI::CMouse::Draw(), C4Game::DrawCrewOverheadText(), and ZoomDataStackItem::ZoomDataStackItem().

Here is the caller graph for this function:

◆ GLErrorString()

const char * CStdGL::GLErrorString ( GLenum  code)
protected

Definition at line 882 of file C4DrawGL.cpp.

883 {
884  switch (code)
885  {
886  case GL_NO_ERROR: return "No error";
887  case GL_INVALID_ENUM: return "An unacceptable value is specified for an enumerated argument";
888  case GL_INVALID_VALUE: return "A numeric argument is out of range";
889  case GL_INVALID_OPERATION: return "The specified operation is not allowed in the current state";
890  case GL_INVALID_FRAMEBUFFER_OPERATION: return "The framebuffer object is not complete";
891  case GL_OUT_OF_MEMORY: return "There is not enough memory left to execute the command";
892  case GL_STACK_UNDERFLOW: return "An attempt has been made to perform an operation that would cause an internal stack to underflow";
893  case GL_STACK_OVERFLOW: return "An attempt has been made to perform an operation that would cause an internal stack to overflow";
894  default: assert(false); return "";
895  }
896 }

Referenced by CheckGLError().

Here is the caller graph for this function:

◆ Grayscale()

void C4Draw::Grayscale ( C4Surface sfcSfc,
int32_t  iOffset = 0 
)
inherited

Definition at line 695 of file C4Draw.cpp.

696 {
697  // safety
698  if (!sfcSfc) return;
699  // change colors
700  int xcnt,ycnt,wdt=sfcSfc->Wdt,hgt=sfcSfc->Hgt;
701  // Lock surface
702  if (!sfcSfc->Lock()) return;
703  for (ycnt=0; ycnt<hgt; ycnt++)
704  {
705  for (xcnt=0; xcnt<wdt; xcnt++)
706  {
707  DWORD dwColor = sfcSfc->GetPixDw(xcnt,ycnt,false);
708  uint32_t r = GetRedValue(dwColor), g = GetGreenValue(dwColor), b = GetBlueValue(dwColor), a = dwColor >> 24;
709  int32_t gray = Clamp<int32_t>((r + g + b) / 3 + iOffset, 0, 255);
710  sfcSfc->SetPixDw(xcnt, ycnt, RGBA(gray, gray, gray, a));
711  }
712  }
713  sfcSfc->Unlock();
714 }
#define a
#define b
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:22
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:491

References a, b, GetBlueValue, GetGreenValue, C4Surface::GetPixDw(), GetRedValue, C4Surface::Hgt, C4Surface::Lock(), RGBA(), C4Surface::SetPixDw(), C4Surface::Unlock(), and C4Surface::Wdt.

Referenced by C4FacetSurface::Grayscale().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

bool C4Draw::Init ( C4AbstractApp pApp,
unsigned int  iXRes,
unsigned int  iYRes,
unsigned int  iMonitor 
)
inherited

Definition at line 809 of file C4Draw.cpp.

810 {
811  this->pApp = pApp;
812 
814 
815  if (!RestoreDeviceObjects())
816  return false;
817 
818  if (!CreatePrimaryClipper(iXRes, iYRes))
819  return Error(" Clipper failure.");
820 
821  return true;
822 }
C4Window * pWindow
Definition: C4App.h:80
friend class C4Surface
Definition: C4Draw.h:213
virtual bool RestoreDeviceObjects()=0
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
Definition: C4Draw.cpp:501
C4Surface * pSurface
Definition: C4Window.h:275

References C4Draw::C4Surface, C4Draw::CreatePrimaryClipper(), C4Draw::Error(), C4Draw::pApp, C4Window::pSurface, C4AbstractApp::pWindow, and C4Draw::RestoreDeviceObjects().

Referenced by DDrawInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitShaders()

bool CStdGL::InitShaders ( C4GroupSet pGroups)

Definition at line 714 of file C4DrawGL.cpp.

715 {
716  if (!pCurrCtx)
718 
719  // Create sprite blitting shaders
720  if(!PrepareSpriteShader(SpriteShader, "sprite", 0, pGroups, nullptr, nullptr))
721  return false;
722  if(!PrepareSpriteShader(SpriteShaderMod2, "spriteMod2", C4SSC_MOD2, pGroups, nullptr, nullptr))
723  return false;
724  if(!PrepareSpriteShader(SpriteShaderBase, "spriteBase", C4SSC_BASE, pGroups, nullptr, nullptr))
725  return false;
726  if(!PrepareSpriteShader(SpriteShaderBaseMod2, "spriteBaseMod2", C4SSC_MOD2 | C4SSC_BASE, pGroups, nullptr, nullptr))
727  return false;
728  if(!PrepareSpriteShader(SpriteShaderBaseOverlay, "spriteBaseOverlay", C4SSC_BASE | C4SSC_OVERLAY, pGroups, nullptr, nullptr))
729  return false;
730  if(!PrepareSpriteShader(SpriteShaderBaseOverlayMod2, "spriteBaseOverlayMod2", C4SSC_MOD2 | C4SSC_BASE | C4SSC_OVERLAY, pGroups, nullptr, nullptr))
731  return false;
732 
733  if(!PrepareSpriteShader(SpriteShaderLight, "spriteLight", C4SSC_LIGHT, pGroups, nullptr, nullptr))
734  return false;
735  if(!PrepareSpriteShader(SpriteShaderLightMod2, "spriteLightMod2", C4SSC_LIGHT | C4SSC_MOD2, pGroups, nullptr, nullptr))
736  return false;
737  if(!PrepareSpriteShader(SpriteShaderLightBase, "spriteLightBase", C4SSC_LIGHT | C4SSC_BASE, pGroups, nullptr, nullptr))
738  return false;
739  if(!PrepareSpriteShader(SpriteShaderLightBaseMod2, "spriteLightBaseMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_MOD2, pGroups, nullptr, nullptr))
740  return false;
741  if(!PrepareSpriteShader(SpriteShaderLightBaseOverlay, "spriteLightBaseOverlay", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY, pGroups, nullptr, nullptr))
742  return false;
743  if(!PrepareSpriteShader(SpriteShaderLightBaseOverlayMod2, "spriteLightBaseOverlayMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY | C4SSC_MOD2, pGroups, nullptr, nullptr))
744  return false;
745  if(!PrepareSpriteShader(SpriteShaderLightBaseNormal, "spriteLightBaseNormal", C4SSC_LIGHT | C4SSC_BASE | C4SSC_NORMAL, pGroups, nullptr, nullptr))
746  return false;
747  if(!PrepareSpriteShader(SpriteShaderLightBaseNormalMod2, "spriteLightBaseNormalMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_NORMAL | C4SSC_MOD2, pGroups, nullptr, nullptr))
748  return false;
749  if(!PrepareSpriteShader(SpriteShaderLightBaseNormalOverlay, "spriteLightBaseNormalOverlay", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY | C4SSC_NORMAL, pGroups, nullptr, nullptr))
750  return false;
751  if(!PrepareSpriteShader(SpriteShaderLightBaseNormalOverlayMod2, "spriteLightBaseNormalOverlayMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY | C4SSC_NORMAL | C4SSC_MOD2, pGroups, nullptr, nullptr))
752  return false;
753 
754  return true;
755 }
bool EnsureMainContextSelected() override
Definition: C4DrawGL.cpp:757
bool PrepareSpriteShader(C4Shader &shader, const char *name, int ssc, C4GroupSet *pGroups, const char *const *additionalDefines, const char *const *additionalSlices) override
Definition: C4DrawGL.cpp:190

References EnsureMainContextSelected(), pCurrCtx, PrepareSpriteShader(), SpriteShader, and SpriteShaderMod2.

Referenced by C4GraphicsResource::Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InvalidateDeviceObjects()

bool CStdGL::InvalidateDeviceObjects ( )
overridevirtual

Implements C4Draw.

Definition at line 808 of file C4DrawGL.cpp.

809 {
810  bool fSuccess=true;
811  // deactivate
812  Active=false;
813  // invalidate font objects
814  // invalidate primary surfaces
815  if (lines_tex)
816  {
817  glDeleteTextures(1, &lines_tex);
818  lines_tex = 0;
819  }
820 
821  // invalidate generic VBOs
822  if (GenericVBOs[0] != 0)
823  {
824  glDeleteBuffers(N_GENERIC_VBOS, GenericVBOs);
825  GenericVBOs[0] = 0;
826  CurrentVBO = 0;
827  for (unsigned int GenericVAO : GenericVAOs)
828  FreeVAOID(GenericVAO);
829  }
830 
831  // invalidate shaders
832 
833  // TODO: We don't do this here because we cannot re-validate them in
834  // RestoreDeviceObjects. This should be refactored.
835 
836  /*SpriteShader.Clear();
837  SpriteShaderMod2.Clear();
838  SpriteShaderBase.Clear();
839  SpriteShaderBaseMod2.Clear();
840  SpriteShaderBaseOverlay.Clear();
841  SpriteShaderBaseOverlayMod2.Clear();
842  SpriteShaderLight.Clear();
843  SpriteShaderLightMod2.Clear();
844  SpriteShaderLightBase.Clear();
845  SpriteShaderLightBaseMod2.Clear();
846  SpriteShaderLightBaseOverlay.Clear();
847  SpriteShaderLightBaseOverlayMod2.Clear();
848  SpriteShaderLightBaseNormal.Clear();
849  SpriteShaderLightBaseNormalMod2.Clear();
850  SpriteShaderLightBaseNormalOverlay.Clear();
851  SpriteShaderLightBaseNormalOverlayMod2.Clear();*/
852  return fSuccess;
853 }
bool Active
Definition: C4Draw.h:96
unsigned int CurrentVBO
Definition: C4DrawGL.h:220
unsigned int GenericVAOs[N_GENERIC_VBOS *2]
Definition: C4DrawGL.h:224
static const unsigned int N_GENERIC_VBOS
Definition: C4DrawGL.h:216
void FreeVAOID(unsigned int vaoid)
Definition: C4DrawGL.cpp:969

References C4Draw::Active, CurrentVBO, FreeVAOID(), GenericVAOs, GenericVBOs, lines_tex, and N_GENERIC_VBOS.

Referenced by Clear(), and RestoreDeviceObjects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LockingPrimary()

void C4Draw::LockingPrimary ( )
inlineinherited

Definition at line 138 of file C4Draw.h.

138 { PrimaryLocked=true; }
bool PrimaryLocked
Definition: C4Draw.h:106

References C4Draw::PrimaryLocked.

◆ NoPrimaryClipper()

bool C4Draw::NoPrimaryClipper ( )
inherited

Definition at line 237 of file C4Draw.cpp.

238 {
239  // apply maximum clipper
240  SetPrimaryClipper(0,0,439832,439832);
241  // Done
242  return true;
243 }

References C4Draw::SetPrimaryClipper().

Referenced by Clear(), C4Viewport::Draw(), C4Landscape::DrawChunks(), C4GUI::Edit::DrawElement(), and C4Landscape::P::MapToSurface().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ObjectLabel()

void CStdGL::ObjectLabel ( uint32_t  identifier,
uint32_t  name,
int32_t  length,
const char *  label 
)

Definition at line 267 of file C4DrawGL.cpp.

268 {
269  if (has_khr_debug)
270  glObjectLabel(identifier, name, length, label);
271 }

References has_khr_debug.

Referenced by C4ParticleChunk::Draw(), and C4Shader::Init().

Here is the caller graph for this function:

◆ OnResolutionChanged()

bool CStdGL::OnResolutionChanged ( unsigned int  iXRes,
unsigned int  iYRes 
)
overridevirtual

Implements C4Draw.

Definition at line 909 of file C4DrawGL.cpp.

910 {
911  // Re-create primary clipper to adapt to new size.
912  CreatePrimaryClipper(iXRes, iYRes);
914  return true;
915 }
bool RestoreDeviceObjects() override
Definition: C4DrawGL.cpp:762

References C4Draw::CreatePrimaryClipper(), and RestoreDeviceObjects().

Here is the call graph for this function:

◆ PerformMesh()

void CStdGL::PerformMesh ( StdMeshInstance instance,
float  tx,
float  ty,
float  twdt,
float  thgt,
DWORD  dwPlayerColor,
C4BltTransform pTransform 
)
overridevirtual

Implements C4Draw.

Definition at line 1025 of file C4DrawMeshGL.cpp.

1026 {
1027  // Field of View for perspective projection, in degrees
1028  static const float FOV = 60.0f;
1029  static const float TAN_FOV = tan(FOV / 2.0f / 180.0f * M_PI);
1030 
1031  // Check mesh transformation; abort when it is degenerate.
1032  bool mesh_transform_parity = false;
1033  if (MeshTransform)
1034  {
1035  const float det = MeshTransform->Determinant();
1036  if (fabs(det) < 1e-6)
1037  return;
1038  else if (det < 0.0f)
1039  mesh_transform_parity = true;
1040  }
1041 
1042  const StdMesh& mesh = instance.GetMesh();
1043 
1044  bool parity = false;
1045 
1046  // Convert bounding box to clonk coordinate system
1047  // (TODO: We should cache this, not sure where though)
1048  const StdMeshBox& box = mesh.GetBoundingBox();
1049  StdMeshVector v1, v2;
1050  v1.x = box.x1; v1.y = box.y1; v1.z = box.z1;
1051  v2.x = box.x2; v2.y = box.y2; v2.z = box.z2;
1052 
1053  // Vector from origin of mesh to center of mesh
1054  const StdMeshVector MeshCenter = (v1 + v2)/2.0f;
1055 
1056  glEnable(GL_DEPTH_TEST);
1057  glEnable(GL_BLEND); // TODO: Shouldn't this always be enabled? - blending does not work for meshes without this though.
1058 
1059  // TODO: We ignore the additive drawing flag for meshes but instead
1060  // set the blending mode of the corresponding material. I'm not sure
1061  // how the two could be combined.
1062  // TODO: Maybe they can be combined using a pixel shader which does
1063  // ftransform() and then applies colormod, additive and mod2
1064  // on the result (with alpha blending).
1065  //int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE;
1066  //glBlendFunc(GL_SRC_ALPHA, iAdditive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA);
1067 
1068  // Mesh extents
1069  const float b = fabs(v2.x - v1.x)/2.0f;
1070  const float h = fabs(v2.y - v1.y)/2.0f;
1071  const float l = fabs(v2.z - v1.z)/2.0f;
1072 
1073  // Set up projection matrix first. We do transform and Zoom with the
1074  // projection matrix, so that lighting is applied to the untransformed/unzoomed
1075  // mesh.
1076  StdProjectionMatrix projectionMatrix;
1077  if (!fUsePerspective)
1078  {
1079  // Load the orthographic projection
1080  projectionMatrix = ProjectionMatrix;
1081 
1082  if (!ApplyZoomAndTransform(ZoomX, ZoomY, Zoom, pTransform, projectionMatrix))
1083  parity = !parity;
1084 
1085  // Scale so that the mesh fits in (tx,ty,twdt,thgt)
1086  const float rx = -std::min(v1.x,v2.x) / fabs(v2.x - v1.x);
1087  const float ry = -std::min(v1.y,v2.y) / fabs(v2.y - v1.y);
1088  const float dx = tx + rx*twdt;
1089  const float dy = ty + ry*thgt;
1090 
1091  // Scale so that Z coordinate is between -1 and 1, otherwise parts of
1092  // the mesh could be clipped away by the near or far clipping plane.
1093  // Note that this only works for the projection matrix, otherwise
1094  // lighting is screwed up.
1095 
1096  // This technique might also enable us not to clear the depth buffer
1097  // after every mesh rendering - we could simply scale the first mesh
1098  // of the scene so that it's Z coordinate is between 0 and 1, scale
1099  // the second mesh that it is between 1 and 2, and so on.
1100  // This of course requires an orthogonal projection so that the
1101  // meshes don't look distorted - if we should ever decide to use
1102  // a perspective projection we need to think of something different.
1103  // Take also into account that the depth is not linear but linear
1104  // in the logarithm (if I am not mistaken), so goes as 1/z
1105 
1106  // Don't scale by Z extents since mesh might be transformed
1107  // by MeshTransformation, so use GetBoundingRadius to be safe.
1108  // Note this still fails if mesh is scaled in Z direction or
1109  // there are attached meshes.
1110  const float scz = 1.0/(mesh.GetBoundingRadius());
1111 
1112  Translate(projectionMatrix, dx, dy, 0.0f);
1113  Scale(projectionMatrix, 1.0f, 1.0f, scz);
1114  }
1115  else
1116  {
1117  // Perspective projection. This code transforms the projected
1118  // 3D model into the target area.
1119  const C4Rect clipRect = GetClipRect();
1120  projectionMatrix = StdProjectionMatrix::Identity();
1121 
1122  // Back to GL device coordinates
1123  Translate(projectionMatrix, -1.0f, 1.0f, 0.0f);
1124  Scale(projectionMatrix, 2.0f/clipRect.Wdt, -2.0f/clipRect.Hgt, 1.0f);
1125 
1126  Translate(projectionMatrix, -clipRect.x, -clipRect.y, 0.0f);
1127  if (!ApplyZoomAndTransform(ZoomX, ZoomY, Zoom, pTransform, projectionMatrix))
1128  parity = !parity;
1129 
1130  // Move to target location and compensate for 1.0f aspect
1131  float ttx = tx, tty = ty, ttwdt = twdt, tthgt = thgt;
1132  if(twdt > thgt)
1133  {
1134  tty += (thgt-twdt)/2.0;
1135  tthgt = twdt;
1136  }
1137  else
1138  {
1139  ttx += (twdt-thgt)/2.0;
1140  ttwdt = thgt;
1141  }
1142 
1143  Translate(projectionMatrix, ttx, tty, 0.0f);
1144  Scale(projectionMatrix, ((float)ttwdt)/clipRect.Wdt, ((float)tthgt)/clipRect.Hgt, 1.0f);
1145 
1146  // Return to Clonk coordinate frame
1147  Scale(projectionMatrix, clipRect.Wdt/2.0, -clipRect.Hgt/2.0, 1.0f);
1148  Translate(projectionMatrix, 1.0f, -1.0f, 0.0f);
1149 
1150  // Fix for the case when we have different aspect ratios
1151  const float ta = twdt / thgt;
1152  const float ma = b / h;
1153  if(ta <= 1 && ta/ma <= 1)
1154  Scale(projectionMatrix, std::max(ta, ta/ma), std::max(ta, ta/ma), 1.0f);
1155  else if(ta >= 1 && ta/ma >= 1)
1156  Scale(projectionMatrix, std::max(1.0f/ta, ma/ta), std::max(1.0f/ta, ma/ta), 1.0f);
1157 
1158  // Apply perspective projection. After this, x and y range from
1159  // -1 to 1, and this is mapped into tx/ty/twdt/thgt by the above code.
1160  // Aspect is 1.0f which is changed above as well.
1161  Perspective(projectionMatrix, 1.0f/TAN_FOV, 1.0f, 0.1f, 100.0f);
1162  }
1163 
1164  // Now set up the modelview matrix
1165  StdMeshMatrix modelviewMatrix;
1166  if (fUsePerspective)
1167  {
1168  // Setup camera position so that the mesh with uniform transformation
1169  // fits well into a square target (without distortion).
1170  const float EyeR = l + std::max(b/TAN_FOV, h/TAN_FOV);
1171  const StdMeshVector Eye = StdMeshVector::Translate(MeshCenter.x, MeshCenter.y, MeshCenter.z + EyeR);
1172 
1173  // Up vector is unit vector in theta direction
1174  const StdMeshVector Up = StdMeshVector::Translate(0.0f, -1.0f, 0.0f);
1175 
1176  // Fix X axis (???)
1177  modelviewMatrix = StdMeshMatrix::Scale(-1.0f, 1.0f, 1.0f);
1178 
1179  // center on mesh's bounding box, so that the mesh is really in the center of the viewport
1180  modelviewMatrix *= StdMeshMatrix::LookAt(Eye, MeshCenter, Up);
1181  }
1182  else
1183  {
1184  modelviewMatrix = StdMeshMatrix::Identity();
1185  }
1186 
1187  // Apply mesh transformation matrix
1188  if (MeshTransform)
1189  {
1190  // Apply MeshTransformation (in the Mesh's coordinate system)
1191  modelviewMatrix *= *MeshTransform;
1192  // Keep track of parity
1193  if (mesh_transform_parity) parity = !parity;
1194  }
1195 
1196  DWORD dwModClr = BlitModulated ? BlitModulateClr : 0xffffffff;
1197 
1198  const C4Rect clipRect = GetClipRect();
1199  const C4Rect outRect = GetOutRect();
1200 
1201  RenderMeshImpl(projectionMatrix, modelviewMatrix, instance, dwModClr, dwBlitMode, dwPlayerColor, pFoW, clipRect, outRect, parity);
1202 
1203  // Reset state
1204  //glActiveTexture(GL_TEXTURE0);
1205  glDepthMask(GL_TRUE);
1206  glDisable(GL_DEPTH_TEST);
1207  glDisable(GL_CULL_FACE);
1208  glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
1209 
1210  // TODO: glScissor, so that we only clear the area the mesh covered.
1211  glClear(GL_DEPTH_BUFFER_BIT);
1212 }
void Perspective(MatrixType &mat, float cot_fovy2, float aspect, float nearVal, float farVal)
Definition: StdMeshMath.h:216
void Scale(MatrixType &mat, float sx, float sy, float sz)
Definition: StdMeshMath.h:195
void Translate(MatrixType &mat, float dx, float dy, float dz)
Definition: StdMeshMath.h:185
bool fUsePerspective
Definition: C4Draw.h:114
const StdMeshMatrix * MeshTransform
Definition: C4Draw.h:113
C4Rect GetClipRect() const
Definition: C4Draw.cpp:724
C4Rect GetOutRect() const
Definition: C4Draw.cpp:733
int32_t y
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30
int32_t Wdt
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30
float GetBoundingRadius() const
Definition: StdMesh.h:207
const StdMeshBox & GetBoundingBox() const
Definition: StdMesh.h:206
const StdMesh & GetMesh() const
Definition: StdMesh.h:622
static StdMeshMatrix Identity()
static StdMeshMatrix LookAt(const StdMeshVector &eye, const StdMeshVector &center, const StdMeshVector &up)
static StdMeshMatrix Scale(float sx, float sy, float sz)
float Determinant() const
static StdProjectionMatrix Identity()
void Up(T &keys)
float y2
Definition: StdMesh.h:147
float z1
Definition: StdMesh.h:146
float z2
Definition: StdMesh.h:147
float x2
Definition: StdMesh.h:147
float y1
Definition: StdMesh.h:146
float x1
Definition: StdMesh.h:146
static StdMeshVector Translate(float dx, float dy, float dz)
Definition: StdMeshMath.cpp:38

References b, C4Draw::BlitModulateClr, C4Draw::BlitModulated, StdMeshMatrix::Determinant(), C4Draw::dwBlitMode, C4Draw::fUsePerspective, StdMesh::GetBoundingBox(), StdMesh::GetBoundingRadius(), C4Draw::GetClipRect(), StdMeshInstance::GetMesh(), C4Draw::GetOutRect(), C4Rect::Hgt, StdMeshMatrix::Identity(), StdProjectionMatrix::Identity(), StdMeshMatrix::LookAt(), C4Draw::MeshTransform, Perspective(), C4Draw::pFoW, ProjectionMatrix, StdMeshMatrix::Scale(), Scale(), StdMeshVector::Translate(), Translate(), ControllerKeys::Up(), C4Rect::Wdt, C4Rect::x, StdMeshVector::x, StdMeshBox::x1, StdMeshBox::x2, C4Rect::y, StdMeshVector::y, StdMeshBox::y1, StdMeshBox::y2, StdMeshVector::z, StdMeshBox::z1, StdMeshBox::z2, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

Here is the call graph for this function:

◆ PerformMultiBlt()

void CStdGL::PerformMultiBlt ( C4Surface sfcTarget,
DrawOperation  op,
const C4BltVertex vertices,
unsigned int  n_vertices,
bool  has_tex,
C4ShaderCall shader_call 
)

Definition at line 593 of file C4DrawGL.cpp.

594 {
595  // Only direct rendering
596  assert(sfcTarget->IsRenderTarget());
597  if(!PrepareRendering(sfcTarget)) return;
598 
599  // Set resolution. The other uniforms are set in SetupMultiBlt, but the
600  // surface size is still unknown there.
601  shader_call->SetUniform2f(C4SSU_Resolution, sfcTarget->Wdt, sfcTarget->Hgt);
602 
603  // Select a buffer
604  const unsigned int vbo_index = CurrentVBO;
606 
607  // Upload data into the buffer, resize buffer if necessary
608  glBindBuffer(GL_ARRAY_BUFFER, GenericVBOs[vbo_index]);
609  if (GenericVBOSizes[vbo_index] < n_vertices)
610  {
611  GenericVBOSizes[vbo_index] = n_vertices;
612  glBufferData(GL_ARRAY_BUFFER, n_vertices * sizeof(C4BltVertex), vertices, GL_STREAM_DRAW);
613  }
614  else
615  {
616  glBufferSubData(GL_ARRAY_BUFFER, 0, n_vertices * sizeof(C4BltVertex), vertices);
617  }
618 
619  // Choose the VAO that corresponds to the chosen VBO. Also, use one
620  // that supplies texture coordinates if we have texturing enabled.
621  GLuint vao;
622  const unsigned int vao_index = vbo_index + (has_tex ? N_GENERIC_VBOS : 0);
623  const unsigned int vao_id = GenericVAOs[vao_index];
624  const bool has_vao = GetVAO(vao_id, vao);
625  glBindVertexArray(vao);
626  if (!has_vao)
627  {
628  // Initialize VAO for this context
629  const GLuint position = shader_call->GetAttribute(C4SSA_Position);
630  const GLuint color = shader_call->GetAttribute(C4SSA_Color);
631  const GLuint texcoord = has_tex ? shader_call->GetAttribute(C4SSA_TexCoord) : 0;
632 
633  glEnableVertexAttribArray(position);
634  glEnableVertexAttribArray(color);
635  if (has_tex)
636  glEnableVertexAttribArray(texcoord);
637 
638 
639  glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, sizeof(C4BltVertex), reinterpret_cast<const uint8_t*>(offsetof(C4BltVertex, ftx)));
640  glVertexAttribPointer(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(C4BltVertex), reinterpret_cast<const uint8_t*>(offsetof(C4BltVertex, color)));
641  if (has_tex)
642  glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(C4BltVertex), reinterpret_cast<const uint8_t*>(offsetof(C4BltVertex, tx)));
643  }
644 
645  switch (op)
646  {
647  case OP_POINTS:
648  glDrawArrays(GL_POINTS, 0, n_vertices);
649  break;
650  case OP_TRIANGLES:
651  glDrawArrays(GL_TRIANGLES, 0, n_vertices);
652  break;
653  default:
654  assert(false);
655  break;
656  }
657 
658  glBindVertexArray(0);
659  glBindBuffer(GL_ARRAY_BUFFER, 0);
660 }
@ C4SSA_TexCoord
Definition: C4DrawGL.h:91
@ C4SSA_Color
Definition: C4DrawGL.h:92
@ C4SSA_Position
Definition: C4DrawGL.h:89
@ C4SSU_Resolution
Definition: C4DrawGL.h:58
GLint GetAttribute(int iAttribute) const
Definition: C4Shader.h:194
void SetUniform2f(int iUniform, float gX, float gY) const
Definition: C4Shader.h:245
unsigned int GenericVBOSizes[N_GENERIC_VBOS]
Definition: C4DrawGL.h:219
bool PrepareRendering(C4Surface *sfcToSurface) override
Definition: C4DrawGL.cpp:161
bool GetVAO(unsigned int vaoid, GLuint &vao)
Definition: C4DrawGL.cpp:1015

References C4SSA_Color, C4SSA_Position, C4SSA_TexCoord, C4SSU_Resolution, CurrentVBO, GenericVAOs, GenericVBOs, GenericVBOSizes, C4ShaderCall::GetAttribute(), GetVAO(), C4Surface::Hgt, C4Surface::IsRenderTarget(), N_GENERIC_VBOS, C4Draw::OP_POINTS, C4Draw::OP_TRIANGLES, PrepareRendering(), C4ShaderCall::SetUniform2f(), and C4Surface::Wdt.

Referenced by PerformMultiLines(), PerformMultiPix(), and PerformMultiTris().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PerformMultiLines()

void CStdGL::PerformMultiLines ( C4Surface sfcTarget,
const C4BltVertex vertices,
unsigned int  n_vertices,
float  width,
C4ShaderCall shader_call 
)
overridevirtual

Implements C4Draw.

Definition at line 517 of file C4DrawGL.cpp.

518 {
519  // In a first step, we transform the lines array to a triangle array, so that we can draw
520  // the lines with some thickness.
521  // In principle, this step could be easily (and probably much more efficiently) performed
522  // by a geometry shader as well, however that would require OpenGL 3.2.
523  C4BltVertex* tri_vertices = new C4BltVertex[n_vertices * 3];
524  for(unsigned int i = 0; i < n_vertices; i += 2)
525  {
526  const float x1 = vertices[i].ftx;
527  const float y1 = vertices[i].fty;
528  const float x2 = vertices[i+1].ftx;
529  const float y2 = vertices[i+1].fty;
530 
531  float offx = y1 - y2;
532  float offy = x2 - x1;
533  float l = sqrtf(offx * offx + offy * offy);
534  // avoid division by zero
535  l += 0.000000005f;
536  offx *= width/l;
537  offy *= width/l;
538 
539  tri_vertices[3*i + 0].ftx = x1 + offx; tri_vertices[3*i + 0].fty = y1 + offy;
540  tri_vertices[3*i + 1].ftx = x1 - offx; tri_vertices[3*i + 1].fty = y1 - offy;
541  tri_vertices[3*i + 2].ftx = x2 - offx; tri_vertices[3*i + 2].fty = y2 - offy;
542  tri_vertices[3*i + 3].ftx = x2 + offx; tri_vertices[3*i + 3].fty = y2 + offy;
543 
544  for(int j = 0; j < 4; ++j)
545  {
546  tri_vertices[3*i + 0].color[j] = vertices[i].color[j];
547  tri_vertices[3*i + 1].color[j] = vertices[i].color[j];
548  tri_vertices[3*i + 2].color[j] = vertices[i + 1].color[j];
549  tri_vertices[3*i + 3].color[j] = vertices[i + 1].color[j];
550  }
551 
552  tri_vertices[3*i + 0].tx = 0.f; tri_vertices[3*i + 0].ty = 0.f;
553  tri_vertices[3*i + 1].tx = 0.f; tri_vertices[3*i + 1].ty = 2.f;
554  tri_vertices[3*i + 2].tx = 1.f; tri_vertices[3*i + 2].ty = 2.f;
555  tri_vertices[3*i + 3].tx = 1.f; tri_vertices[3*i + 3].ty = 0.f;
556 
557  tri_vertices[3*i + 4] = tri_vertices[3*i + 2]; // duplicate vertex
558  tri_vertices[3*i + 5] = tri_vertices[3*i + 0]; // duplicate vertex
559  }
560 
561  // Then, feed the vertices to the GL
562  if (!shader_call)
563  {
564  C4ShaderCall call(GetSpriteShader(true, false, false));
565  SetupMultiBlt(call, nullptr, lines_tex, 0, 0, 0, nullptr);
566  PerformMultiBlt(sfcTarget, OP_TRIANGLES, tri_vertices, n_vertices * 3, true, &call);
567  }
568  else
569  {
570  SetupMultiBlt(*shader_call, nullptr, lines_tex, 0, 0, 0, nullptr);
571  PerformMultiBlt(sfcTarget, OP_TRIANGLES, tri_vertices, n_vertices * 3, true, shader_call);
572  }
573 
574  delete[] tri_vertices;
575 }
void SetupMultiBlt(C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
Definition: C4DrawGL.cpp:356
void PerformMultiBlt(C4Surface *sfcTarget, DrawOperation op, const C4BltVertex *vertices, unsigned int n_vertices, bool has_tex, C4ShaderCall *shader_call)
Definition: C4DrawGL.cpp:593

References C4BltVertex::color, C4BltVertex::ftx, C4BltVertex::fty, GetSpriteShader(), lines_tex, C4Draw::OP_TRIANGLES, PerformMultiBlt(), SetupMultiBlt(), C4BltVertex::tx, and C4BltVertex::ty.

Here is the call graph for this function:

◆ PerformMultiPix()

void CStdGL::PerformMultiPix ( C4Surface sfcTarget,
const C4BltVertex vertices,
unsigned int  n_vertices,
C4ShaderCall shader_call 
)
overridevirtual

Implements C4Draw.

Definition at line 490 of file C4DrawGL.cpp.

491 {
492  // Draw on pixel center:
493  StdProjectionMatrix transform = StdProjectionMatrix::Translate(0.5f, 0.5f, 0.0f);
494 
495  // This is a workaround. Instead of submitting the whole vertex array to the GL, we do it
496  // in batches of 256 vertices. The intel graphics driver on Linux crashes with
497  // significantly larger arrays, such as 400. It's not clear to me why, maybe POINT drawing
498  // is just not very well tested.
499  const unsigned int BATCH_SIZE = 256;
500 
501  // Feed the vertices to the GL
502  if (!shader_call)
503  {
504  C4ShaderCall call(GetSpriteShader(false, false, false));
505  SetupMultiBlt(call, nullptr, 0, 0, 0, 0, &transform);
506  for(unsigned int i = 0; i < n_vertices; i += BATCH_SIZE)
507  PerformMultiBlt(sfcTarget, OP_POINTS, &vertices[i], std::min(n_vertices - i, BATCH_SIZE), false, &call);
508  }
509  else
510  {
511  SetupMultiBlt(*shader_call, nullptr, 0, 0, 0, 0, &transform);
512  for(unsigned int i = 0; i < n_vertices; i += BATCH_SIZE)
513  PerformMultiBlt(sfcTarget, OP_POINTS, &vertices[i], std::min(n_vertices - i, BATCH_SIZE), false, shader_call);
514  }
515 }
static StdProjectionMatrix Translate(float dx, float dy, float dz)

References GetSpriteShader(), C4Draw::OP_POINTS, PerformMultiBlt(), SetupMultiBlt(), and StdProjectionMatrix::Translate().

Here is the call graph for this function:

◆ PerformMultiTris()

void CStdGL::PerformMultiTris ( C4Surface sfcTarget,
const C4BltVertex vertices,
unsigned int  n_vertices,
const C4BltTransform pTransform,
C4TexRef pTex,
C4TexRef pOverlay,
C4TexRef pNormal,
DWORD  dwOverlayClrMod,
C4ShaderCall shader_call 
)
overridevirtual

Implements C4Draw.

Definition at line 577 of file C4DrawGL.cpp.

578 {
579  // Feed the vertices to the GL
580  if (!shader_call)
581  {
582  C4ShaderCall call(GetSpriteShader(pTex != nullptr, pOverlay != nullptr, pNormal != nullptr));
583  SetupMultiBlt(call, pTransform, pTex ? pTex->texName : 0, pOverlay ? pOverlay->texName : 0, pNormal ? pNormal->texName : 0, dwOverlayModClr, nullptr);
584  PerformMultiBlt(sfcTarget, OP_TRIANGLES, vertices, n_vertices, pTex != nullptr, &call);
585  }
586  else
587  {
588  SetupMultiBlt(*shader_call, pTransform, pTex ? pTex->texName : 0, pOverlay ? pOverlay->texName : 0, pNormal ? pNormal->texName : 0, dwOverlayModClr, nullptr);
589  PerformMultiBlt(sfcTarget, OP_TRIANGLES, vertices, n_vertices, pTex != nullptr, shader_call);
590  }
591 }
unsigned int texName
Definition: C4Surface.h:155

References GetSpriteShader(), C4Draw::OP_TRIANGLES, PerformMultiBlt(), SetupMultiBlt(), and C4TexRef::texName.

Here is the call graph for this function:

◆ PrepareMaterial()

bool CStdGL::PrepareMaterial ( StdMeshMatManager mat_manager,
StdMeshMaterialLoader loader,
StdMeshMaterial mat 
)
overridevirtual

Implements C4Draw.

Definition at line 272 of file C4DrawMeshGL.cpp.

273 {
274  // TODO: If a technique is not available, show an error message what the problem is
275 
276  // select context, if not already done
277  if (!pCurrCtx) return false;
278 
279  for (unsigned int i = 0; i < mat.Techniques.size(); ++i)
280  {
281  StdMeshMaterialTechnique& technique = mat.Techniques[i];
282  technique.Available = true;
283  for (unsigned int j = 0; j < technique.Passes.size(); ++j)
284  {
285  StdMeshMaterialPass& pass = technique.Passes[j];
286 
287  GLint max_texture_units;
288  glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
289 
290  // OpenGL 3.x guarantees at least 16 TIUs. If the above returns
291  // less it's probably a driver bug. So just keep going.
292  assert(max_texture_units >= 16);
293  max_texture_units = std::min<GLint>(max_texture_units, 16);
294 
295  unsigned int active_texture_units = 0;
296  for(auto & TextureUnit : pass.TextureUnits)
297  if(TextureUnit.HasTexture())
298  ++active_texture_units;
299 
300  if (active_texture_units > static_cast<unsigned int>(max_texture_units))
301  technique.Available = false;
302 
303  for (auto & texunit : pass.TextureUnits)
304  {
305  for (unsigned int l = 0; l < texunit.GetNumTextures(); ++l)
306  {
307  const C4TexRef& texture = texunit.GetTexture(l);
308  glBindTexture(GL_TEXTURE_2D, texture.texName);
309  switch (texunit.TexAddressMode)
310  {
312  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
313  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
314  break;
316  glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, texunit.TexBorderColor);
317  // fallthrough
319  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
320  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
321  break;
323  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
324  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
325  break;
326  }
327 
328  switch (texunit.Filtering[0]) // min
329  {
331  technique.Available = false;
332  break;
334  switch (texunit.Filtering[2]) // mip
335  {
337  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
338  break;
340  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
341  break;
343  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
344  break;
346  technique.Available = false; // invalid
347  break;
348  }
349  break;
351  switch (texunit.Filtering[2]) // mip
352  {
354  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
355  break;
357  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
358  break;
360  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
361  break;
363  technique.Available = false; // invalid
364  break;
365  }
366  break;
368  // unsupported
369  technique.Available = false;
370  break;
371  }
372 
373  switch (texunit.Filtering[1]) // max
374  {
376  technique.Available = false; // invalid
377  break;
379  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
380  break;
382  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
383  break;
385  // unsupported
386  technique.Available = false;
387  break;
388  }
389  } // loop over textures
390  } // loop over texture units
391 
392  // Create fragment and/or vertex shader
393  // if a custom shader is not provided.
394  // Re-use existing programs if the generated
395  // code is the same (determined by SHA1 hash).
396  bool custom_shader = true;
397  if(!pass.VertexShader.Shader)
398  {
399  StdStrBuf buf = GetVertexShaderCodeForPass(pass, Workarounds.LowMaxVertexUniformCount);
400  StdStrBuf hash = GetSHA1HexDigest(buf.getData(), buf.getLength());
401  pass.VertexShader.Shader = mat_manager.AddShader("auto-generated vertex shader", hash.getData(), "glsl", SMMS_VERTEX, buf.getData(), StdMeshMatManager::SMM_AcceptExisting);
402  custom_shader = false;
403  }
404 
405  if(!pass.FragmentShader.Shader)
406  {
407  // TODO: Should use shared_params once we introduce them
408  StdStrBuf buf = GetFragmentShaderCodeForPass(pass, pass.FragmentShader.Parameters);
409  StdStrBuf hash = GetSHA1HexDigest(buf.getData(), buf.getLength());
410  pass.FragmentShader.Shader = mat_manager.AddShader("auto-generated fragment shader", hash.getData(), "glsl", SMMS_FRAGMENT, buf.getData(), StdMeshMatManager::SMM_AcceptExisting);
411  }
412 
413  // Then, link the program, and resolve parameter locations
414  StdStrBuf name(FormatString("%s:%s:%s", mat.Name.getData(), technique.Name.getData(), pass.Name.getData()));
415  const StdMeshMaterialProgram* added_program = mat_manager.AddProgram(name.getData(), loader, pass.FragmentShader, pass.VertexShader, pass.GeometryShader);
416  if(!added_program)
417  {
418  // If the program could not be compiled, try again with the LowMaxVertexUniformCount workaround.
419  // See bug #1368.
420  if (!custom_shader && !Workarounds.LowMaxVertexUniformCount)
421  {
422  StdStrBuf buf = GetVertexShaderCodeForPass(pass, true);
423  StdStrBuf hash = GetSHA1HexDigest(buf.getData(), buf.getLength());
424  pass.VertexShader.Shader = mat_manager.AddShader("auto-generated vertex shader", hash.getData(), "glsl", SMMS_VERTEX, buf.getData(), StdMeshMatManager::SMM_AcceptExisting);
425 
426  added_program = mat_manager.AddProgram(name.getData(), loader, pass.FragmentShader, pass.VertexShader, pass.GeometryShader);
427  if(added_program)
428  {
429  // If this actually work, cache the result, so we don't
430  // need to fail again next time before trying the workaround.
431  Workarounds.LowMaxVertexUniformCount = true;
432  Log(" gl: Enabling low max vertex uniform workaround");
433  }
434  }
435  }
436 
437  if (!added_program)
438  {
439  technique.Available = false;
440  }
441  else
442  {
443  std::unique_ptr<StdMeshMaterialPass::ProgramInstance> program_instance(new StdMeshMaterialPass::ProgramInstance(added_program, &pass.FragmentShader, &pass.VertexShader, &pass.GeometryShader));
444  pass.Program = std::move(program_instance);
445  }
446  }
447 
448  if (technique.Available && mat.BestTechniqueIndex == -1)
449  mat.BestTechniqueIndex = i;
450  }
451 
452  return mat.BestTechniqueIndex != -1;
453 }
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
@ SMMS_VERTEX
@ SMMS_FRAGMENT
const StdMeshMaterialProgram * AddProgram(const char *name, StdMeshMaterialLoader &loader, const StdMeshMaterialPass::ShaderInstance &fragment_shader, const StdMeshMaterialPass::ShaderInstance &vertex_shader, const StdMeshMaterialPass::ShaderInstance &geometry_shader)
const StdMeshMaterialShader * AddShader(const char *filename, const char *name, const char *language, StdMeshMaterialShaderType type, const char *text, uint32_t load_flags)
StdCopyStrBuf Name
std::vector< StdMeshMaterialTechnique > Techniques
const StdMeshMaterialShader * Shader
std::shared_ptr< ProgramInstance > Program
StdMeshMaterialShaderParameters Parameters
ShaderInstance GeometryShader
ShaderInstance FragmentShader
std::vector< StdMeshMaterialTextureUnit > TextureUnits
ShaderInstance VertexShader
std::vector< StdMeshMaterialPass > Passes
const char * getData() const
Definition: StdBuf.h:442
size_t getLength() const
Definition: StdBuf.h:445

References StdMeshMatManager::AddProgram(), StdMeshMatManager::AddShader(), StdMeshMaterialTextureUnit::AM_Border, StdMeshMaterialTextureUnit::AM_Clamp, StdMeshMaterialTextureUnit::AM_Mirror, StdMeshMaterialTextureUnit::AM_Wrap, StdMeshMaterialTechnique::Available, StdMeshMaterial::BestTechniqueIndex, StdMeshMaterialTextureUnit::F_Anisotropic, StdMeshMaterialTextureUnit::F_Linear, StdMeshMaterialTextureUnit::F_None, StdMeshMaterialTextureUnit::F_Point, StdMeshMaterialTextureUnit::Filtering, FormatString(), StdMeshMaterialPass::FragmentShader, StdMeshMaterialPass::GeometryShader, StdStrBuf::getData(), StdStrBuf::getLength(), StdMeshMaterialTextureUnit::GetNumTextures(), StdMeshMaterialTextureUnit::GetTexture(), Log(), StdMeshMaterialPass::Name, StdMeshMaterialTechnique::Name, StdMeshMaterial::Name, StdMeshMaterialPass::ShaderInstance::Parameters, StdMeshMaterialTechnique::Passes, pCurrCtx, StdMeshMaterialPass::Program, StdMeshMaterialPass::ShaderInstance::Shader, StdMeshMatManager::SMM_AcceptExisting, SMMS_FRAGMENT, SMMS_VERTEX, StdMeshMaterial::Techniques, StdMeshMaterialTextureUnit::TexAddressMode, StdMeshMaterialTextureUnit::TexBorderColor, C4TexRef::texName, StdMeshMaterialPass::TextureUnits, StdMeshMaterialPass::VertexShader, and Workarounds.

Here is the call graph for this function:

◆ PrepareRendering()

bool CStdGL::PrepareRendering ( C4Surface sfcToSurface)
overridevirtual

Implements C4Draw.

Definition at line 161 of file C4DrawGL.cpp.

162 {
163  // call from gfx thread only!
164  if (!pApp || !pApp->AssertMainThread()) return false;
165  // not ready?
166  if (!Active)
167  return false;
168  // target?
169  if (!sfcToSurface) return false;
170  // target locked?
171  if (sfcToSurface->Locked) return false;
172  // target is already set as render target?
173  if (sfcToSurface != RenderTarget)
174  {
175  // target is a render-target?
176  if (!sfcToSurface->IsRenderTarget()) return false;
177  // context
178  if (sfcToSurface->pCtx && sfcToSurface->pCtx != pCurrCtx)
179  if (!sfcToSurface->pCtx->Select()) return false;
180  // set target
181  RenderTarget=sfcToSurface;
182  // new target has different size; needs other clipping rect
183  UpdateClipper();
184  }
185  // done
186  return true;
187 }
bool AssertMainThread()
Definition: C4App.h:123
int Locked
Definition: C4Surface.h:87
CStdGLCtx * pCtx
Definition: C4Surface.h:76
bool UpdateClipper() override
Definition: C4DrawGL.cpp:143

References C4Draw::Active, C4AbstractApp::AssertMainThread(), C4Surface::IsRenderTarget(), C4Surface::Locked, C4Draw::pApp, C4Surface::pCtx, pCurrCtx, C4Draw::RenderTarget, CStdGLCtx::Select(), and UpdateClipper().

Referenced by C4LandscapeRenderGL::Draw(), PerformMultiBlt(), and C4GUI::DialogWindow::PerformUpdate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareSpriteShader()

bool CStdGL::PrepareSpriteShader ( C4Shader shader,
const char *  name,
int  ssc,
C4GroupSet pGroups,
const char *const *  additionalDefines,
const char *const *  additionalSlices 
)
overridevirtual

Implements C4Draw.

Definition at line 190 of file C4DrawGL.cpp.

191 {
192  const char* uniformNames[C4SSU_Count + 1];
193  uniformNames[C4SSU_ProjectionMatrix] = "projectionMatrix";
194  uniformNames[C4SSU_ModelViewMatrix] = "modelviewMatrix";
195  uniformNames[C4SSU_NormalMatrix] = "normalMatrix";
196  uniformNames[C4SSU_ClrMod] = "clrMod";
197  uniformNames[C4SSU_Gamma] = "gamma";
198  uniformNames[C4SSU_Resolution] = "resolution";
199  uniformNames[C4SSU_BaseTex] = "baseTex";
200  uniformNames[C4SSU_OverlayTex] = "overlayTex";
201  uniformNames[C4SSU_OverlayClr] = "overlayClr";
202  uniformNames[C4SSU_LightTex] = "lightTex";
203  uniformNames[C4SSU_LightTransform] = "lightTransform";
204  uniformNames[C4SSU_NormalTex] = "normalTex";
205  uniformNames[C4SSU_AmbientTex] = "ambientTex";
206  uniformNames[C4SSU_AmbientTransform] = "ambientTransform";
207  uniformNames[C4SSU_AmbientBrightness] = "ambientBrightness";
208  uniformNames[C4SSU_MaterialAmbient] = "materialAmbient"; // unused
209  uniformNames[C4SSU_MaterialDiffuse] = "materialDiffuse"; // unused
210  uniformNames[C4SSU_MaterialSpecular] = "materialSpecular"; // unused
211  uniformNames[C4SSU_MaterialEmission] = "materialEmission"; // unused
212  uniformNames[C4SSU_MaterialShininess] = "materialShininess"; // unused
213  uniformNames[C4SSU_Bones] = "bones"; // unused
214  uniformNames[C4SSU_CullMode] = "cullMode"; // unused
215  uniformNames[C4SSU_FrameCounter] = "frameCounter";
216  uniformNames[C4SSU_Count] = nullptr;
217 
218  const char* attributeNames[C4SSA_Count + 1];
219  attributeNames[C4SSA_Position] = "oc_Position";
220  attributeNames[C4SSA_Normal] = "oc_Normal"; // unused
221  attributeNames[C4SSA_TexCoord] = "oc_TexCoord"; // only used if C4SSC_Base is set
222  attributeNames[C4SSA_Color] = "oc_Color";
223  attributeNames[C4SSA_BoneIndices0] = "oc_BoneIndices0"; // unused
224  attributeNames[C4SSA_BoneIndices1] = "oc_BoneIndices1"; // unused
225  attributeNames[C4SSA_BoneWeights0] = "oc_BoneWeights0"; // unused
226  attributeNames[C4SSA_BoneWeights1] = "oc_BoneWeights1"; // unused
227  attributeNames[C4SSA_Count] = nullptr;
228 
229  // Clear previous content
230  shader.Clear();
231  shader.ClearSlices();
232 
233  // Start with #defines
234  shader.AddDefine("OPENCLONK");
235  shader.AddDefine("OC_SPRITE");
236  if (ssc & C4SSC_MOD2) shader.AddDefine("OC_CLRMOD_MOD2");
237  if (ssc & C4SSC_NORMAL) shader.AddDefine("OC_WITH_NORMALMAP");
238  if (ssc & C4SSC_LIGHT) shader.AddDefine("OC_DYNAMIC_LIGHT");
239  if (ssc & C4SSC_BASE) shader.AddDefine("OC_HAVE_BASE");
240  if (ssc & C4SSC_OVERLAY) shader.AddDefine("OC_HAVE_OVERLAY");
241 
242  if (additionalDefines)
243  for (const char* const* define = additionalDefines; *define != nullptr; ++define)
244  shader.AddDefine(*define);
245 
246  // Then load slices for fragment and vertex shader
247  shader.LoadVertexSlices(pGroups, "SpriteVertexShader.glsl");
248  shader.LoadFragmentSlices(pGroups, "CommonShader.glsl");
249  shader.LoadFragmentSlices(pGroups, "ObjectShader.glsl");
250 
251  // Categories for script shaders.
252  shader.SetScriptCategories({"Common", "Object"});
253 
254  if (additionalSlices)
255  for (const char* const* slice = additionalSlices; *slice != nullptr; ++slice)
256  shader.LoadFragmentSlices(pGroups, *slice);
257 
258  if (!shader.Init(name, uniformNames, attributeNames))
259  {
260  shader.ClearSlices();
261  return false;
262  }
263 
264  return true;
265 }
@ C4SSA_BoneIndices0
Definition: C4DrawGL.h:94
@ C4SSA_Normal
Definition: C4DrawGL.h:90
@ C4SSA_Count
Definition: C4DrawGL.h:100
@ C4SSA_BoneIndices1
Definition: C4DrawGL.h:95
@ C4SSA_BoneWeights1
Definition: C4DrawGL.h:98
@ C4SSA_BoneWeights0
Definition: C4DrawGL.h:97
@ C4SSU_MaterialEmission
Definition: C4DrawGL.h:75
@ C4SSU_LightTransform
Definition: C4DrawGL.h:65
@ C4SSU_FrameCounter
Definition: C4DrawGL.h:81
@ C4SSU_NormalMatrix
Definition: C4DrawGL.h:54
@ C4SSU_NormalTex
Definition: C4DrawGL.h:66
@ C4SSU_OverlayClr
Definition: C4DrawGL.h:62
@ C4SSU_AmbientTex
Definition: C4DrawGL.h:68
@ C4SSU_ModelViewMatrix
Definition: C4DrawGL.h:53
@ C4SSU_BaseTex
Definition: C4DrawGL.h:60
@ C4SSU_LightTex
Definition: C4DrawGL.h:64
@ C4SSU_MaterialAmbient
Definition: C4DrawGL.h:72
@ C4SSU_AmbientBrightness
Definition: C4DrawGL.h:70
@ C4SSU_Count
Definition: C4DrawGL.h:83
@ C4SSU_OverlayTex
Definition: C4DrawGL.h:61
@ C4SSU_ClrMod
Definition: C4DrawGL.h:56
@ C4SSU_MaterialDiffuse
Definition: C4DrawGL.h:73
@ C4SSU_AmbientTransform
Definition: C4DrawGL.h:69
@ C4SSU_ProjectionMatrix
Definition: C4DrawGL.h:52
@ C4SSU_Bones
Definition: C4DrawGL.h:78
@ C4SSU_MaterialSpecular
Definition: C4DrawGL.h:74
@ C4SSU_MaterialShininess
Definition: C4DrawGL.h:76
@ C4SSU_CullMode
Definition: C4DrawGL.h:79
@ C4SSU_Gamma
Definition: C4DrawGL.h:57
bool LoadVertexSlices(C4GroupSet *pGroupSet, const char *szFile)
Definition: C4Shader.cpp:97
bool LoadFragmentSlices(C4GroupSet *pGroupSet, const char *szFile)
Definition: C4Shader.cpp:92
void AddDefine(const char *name)
Definition: C4Shader.cpp:65
void SetScriptCategories(const std::vector< std::string > &categories)
Definition: C4Shader.cpp:102
void ClearSlices()
Definition: C4Shader.cpp:324
bool Init(const char *szWhat, const char **szUniforms, const char **szAttributes)
Definition: C4Shader.cpp:348

References C4Shader::AddDefine(), C4SSA_BoneIndices0, C4SSA_BoneIndices1, C4SSA_BoneWeights0, C4SSA_BoneWeights1, C4SSA_Color, C4SSA_Count, C4SSA_Normal, C4SSA_Position, C4SSA_TexCoord, C4SSU_AmbientBrightness, C4SSU_AmbientTex, C4SSU_AmbientTransform, C4SSU_BaseTex, C4SSU_Bones, C4SSU_ClrMod, C4SSU_Count, C4SSU_CullMode, C4SSU_FrameCounter, C4SSU_Gamma, C4SSU_LightTex, C4SSU_LightTransform, C4SSU_MaterialAmbient, C4SSU_MaterialDiffuse, C4SSU_MaterialEmission, C4SSU_MaterialShininess, C4SSU_MaterialSpecular, C4SSU_ModelViewMatrix, C4SSU_NormalMatrix, C4SSU_NormalTex, C4SSU_OverlayClr, C4SSU_OverlayTex, C4SSU_ProjectionMatrix, C4SSU_Resolution, C4Shader::Clear(), and C4Shader::ClearSlices().

Referenced by InitShaders().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrimaryUnlocked()

void C4Draw::PrimaryUnlocked ( )
inlineinherited

Definition at line 139 of file C4Draw.h.

139 { PrimaryLocked=false; }

References C4Draw::PrimaryLocked.

◆ RemoveZoom()

void C4Draw::RemoveZoom ( float &  X,
float &  Y 
)
inherited

Definition at line 784 of file C4Draw.cpp.

785 {
786  X = (X - ZoomX) / Zoom + ZoomX;
787  Y = (Y - ZoomY) / Zoom + ZoomY;
788 }

References X, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

◆ RenderMesh()

bool C4Draw::RenderMesh ( StdMeshInstance instance,
C4Surface sfcTarget,
float  tx,
float  ty,
float  twdt,
float  thgt,
DWORD  dwPlayerColor,
C4BltTransform pTransform 
)
inherited

Definition at line 397 of file C4Draw.cpp.

398 {
399  // TODO: Emulate rendering
400  if (!sfcTarget->IsRenderTarget()) return false;
401 
402  // TODO: Clip
403 
404  // prepare rendering to surface
405  if (!PrepareRendering(sfcTarget)) return false;
406  // Update bone matrices and vertex data (note this also updates attach transforms and child transforms)
407  instance.UpdateBoneTransforms();
408  // Order faces according to MeshTransformation (note pTransform does not affect Z coordinate, so does not need to be taken into account for correct ordering)
410  if(MeshTransform) mat = *MeshTransform * mat;
411  instance.ReorderFaces(&mat);
412  // Render mesh
413  PerformMesh(instance, tx, ty, twdt, thgt, dwPlayerColor, pTransform);
414  // success
415  return true;
416 }
virtual void PerformMesh(StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform)=0
void ReorderFaces(StdMeshMatrix *global_trans)
Definition: StdMesh.cpp:1552
bool UpdateBoneTransforms()
Definition: StdMesh.cpp:1471

References StdMeshMatrix::Identity(), C4Surface::IsRenderTarget(), C4Draw::MeshTransform, C4Draw::PerformMesh(), C4Draw::PrepareRendering(), StdMeshInstance::ReorderFaces(), and StdMeshInstance::UpdateBoneTransforms().

Referenced by C4DefGraphics::Draw(), C4GraphicsOverlay::Draw(), and C4Object::DrawFaceImpl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetBlitMode()

void C4Draw::ResetBlitMode ( )
inlineinherited

◆ ResetGamma()

void C4Draw::ResetGamma ( )
inherited

Definition at line 754 of file C4Draw.cpp.

755 {
756  for (auto & i : gamma) {
757  i[0] = 1.0f;
758  i[1] = 1.0f;
759  i[2] = 1.0f;
760  }
761  gammaOut[0] = 1.0f;
762  gammaOut[1] = 1.0f;
763  gammaOut[2] = 1.0f;
764 }
float gamma[C4MaxGammaRamps][3]
Definition: C4Draw.h:97

References C4Draw::gamma, and C4Draw::gammaOut.

Referenced by C4Draw::Clear(), C4Draw::Default(), and C4Game::SetDefaultGamma().

Here is the caller graph for this function:

◆ RestoreDeviceObjects()

bool CStdGL::RestoreDeviceObjects ( )
overridevirtual

Implements C4Draw.

Definition at line 762 of file C4DrawGL.cpp.

763 {
764  assert(pMainCtx);
765  // delete any previous objects
767 
768  // set states
769  Active = pMainCtx->Select();
771 
772  // lines texture
773  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
774  glGenTextures(1, &lines_tex);
775  glBindTexture(GL_TEXTURE_2D, lines_tex);
776  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
777  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
778  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
779  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
780  static const char * linedata = "\xff\xff\xff\x00\xff\xff\xff\xff";
781  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, linedata);
782 
783  MaxTexSize = 64;
784  GLint s = 0;
785  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s);
786  if (s>0) MaxTexSize = s;
787 
788  // Generic VBOs
789  glGenBuffers(N_GENERIC_VBOS, GenericVBOs);
790  for (unsigned int i = 0; i < N_GENERIC_VBOS; ++i)
791  {
793  glBindBuffer(GL_ARRAY_BUFFER, GenericVBOs[i]);
794  glBufferData(GL_ARRAY_BUFFER, GenericVBOSizes[i] * sizeof(C4BltVertex), nullptr, GL_STREAM_DRAW);
795  GenericVAOs[i] = GenVAOID();
797  }
798 
799  glBindBuffer(GL_ARRAY_BUFFER, 0);
800 
801  // reset blit states
802  dwBlitMode = 0;
803 
804  // done
805  return Active;
806 }
#define s
int MaxTexSize
Definition: C4Draw.h:99
unsigned int GenVAOID()
Definition: C4DrawGL.cpp:927
static const unsigned int GENERIC_VBO_SIZE
Definition: C4DrawGL.h:217

References C4Draw::Active, C4Draw::dwBlitMode, GENERIC_VBO_SIZE, GenericVAOs, GenericVBOs, GenericVBOSizes, GenVAOID(), InvalidateDeviceObjects(), lines_tex, C4Draw::MaxTexSize, N_GENERIC_VBOS, C4Draw::pApp, pMainCtx, C4Window::pSurface, C4AbstractApp::pWindow, C4Draw::RenderTarget, s, and CStdGLCtx::Select().

Referenced by OnResolutionChanged().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RestorePrimaryClipper()

bool C4Draw::RestorePrimaryClipper ( )
inherited

Definition at line 210 of file C4Draw.cpp.

211 {
212  // Restore primary clipper
214  return true;
215 }
float fStClipX1
Definition: C4Draw.h:103
float fStClipY1
Definition: C4Draw.h:103
float fStClipX2
Definition: C4Draw.h:103
float fStClipY2
Definition: C4Draw.h:103

References C4Draw::fStClipX1, C4Draw::fStClipX2, C4Draw::fStClipY1, C4Draw::fStClipY2, and C4Draw::SetPrimaryClipper().

Referenced by C4ScriptGuiWindow::DrawChildren(), C4GUI::WoodenLabel::DrawElement(), C4GUI::ComboBox::DrawElement(), C4MenuItem::DrawElement(), and C4FoWRegion::Render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetBlitMode()

void C4Draw::SetBlitMode ( DWORD  dwBlitMode)
inlineinherited

Definition at line 191 of file C4Draw.h.

191 { this->dwBlitMode=dwBlitMode & C4GFXBLIT_ALL; } // set blit mode extra flags (additive blits, mod2-modulation, etc.)
#define C4GFXBLIT_ALL
Definition: C4Surface.h:32

References C4GFXBLIT_ALL, and C4Draw::dwBlitMode.

Referenced by C4GraphicsOverlay::Draw(), C4MouseControl::Draw(), C4GUI::Tabular::Sheet::DrawCaption(), C4GUI::Button::DrawElement(), C4GUI::IconButton::DrawElement(), C4GUI::ArrowButton::DrawElement(), C4GUI::CheckBox::DrawElement(), C4GUI::ContextButton::DrawElement(), C4GUI::ComboBox::DrawElement(), C4EditCursor::DrawObject(), C4GraphicsOverlay::DrawPicture(), and C4Object::PrepareDrawing().

Here is the caller graph for this function:

◆ SetFoW()

void C4Draw::SetFoW ( const C4FoWRegion fow)
inlineinherited

Definition at line 193 of file C4Draw.h.

193 { pFoW = fow; }

References C4Draw::pFoW.

Referenced by C4Viewport::Draw(), and C4Object::Draw().

Here is the caller graph for this function:

◆ SetGamma()

void C4Draw::SetGamma ( float  r,
float  g,
float  b,
int32_t  iRampIndex 
)
inherited

Definition at line 738 of file C4Draw.cpp.

739 {
740  // Set
741  gamma[iRampIndex][0] = r;
742  gamma[iRampIndex][1] = g;
743  gamma[iRampIndex][2] = b;
744  // Recalculate resulting gamma. Note that we flip gamma direction here,
745  // because higher gammaOut means darker.
746  gammaOut[0] = gammaOut[1] = gammaOut[2] = 1.0f;
747  for (auto & i : gamma) {
748  gammaOut[0] /= i[0];
749  gammaOut[1] /= i[1];
750  gammaOut[2] /= i[2];
751  }
752 }

References b, C4Draw::gamma, and C4Draw::gammaOut.

Referenced by C4Game::SetDefaultGamma().

Here is the caller graph for this function:

◆ SetMeshTransform()

void C4Draw::SetMeshTransform ( const StdMeshMatrix Transform)
inlineinherited

Definition at line 200 of file C4Draw.h.

200 { MeshTransform = Transform; } // if non-nullptr make sure to keep matrix valid

References C4Draw::MeshTransform.

Referenced by C4DefGraphics::Draw(), C4GraphicsOverlay::Draw(), and C4Object::DrawFaceImpl().

Here is the caller graph for this function:

◆ SetPerspective()

void C4Draw::SetPerspective ( bool  fSet)
inlineinherited

Definition at line 201 of file C4Draw.h.

201 { fUsePerspective = fSet; }

References C4Draw::fUsePerspective.

Referenced by C4DefGraphics::Draw().

Here is the caller graph for this function:

◆ SetPrimaryClipper()

bool C4Draw::SetPrimaryClipper ( int  iX1,
int  iY1,
int  iX2,
int  iY2 
)
inherited

Definition at line 217 of file C4Draw.cpp.

218 {
219  // set clipper
220  fClipX1=iX1; fClipY1=iY1; fClipX2=iX2; fClipY2=iY2;
221  iClipX1=iX1; iClipY1=iY1; iClipX2=iX2; iClipY2=iY2;
222  UpdateClipper();
223  // Done
224  return true;
225 }
virtual bool UpdateClipper()=0

References C4Draw::fClipX1, C4Draw::fClipX2, C4Draw::fClipY1, C4Draw::fClipY2, C4Draw::iClipX1, C4Draw::iClipX2, C4Draw::iClipY1, C4Draw::iClipY2, and C4Draw::UpdateClipper().

Referenced by C4Draw::CreatePrimaryClipper(), C4GUI::Window::Draw(), C4Viewport::Draw(), C4ScriptGuiWindow::DrawChildren(), C4GUI::WoodenLabel::DrawElement(), C4GUI::Edit::DrawElement(), C4Draw::NoPrimaryClipper(), C4Draw::RestorePrimaryClipper(), and C4Draw::SubPrimaryClipper().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetupMultiBlt()

void CStdGL::SetupMultiBlt ( C4ShaderCall call,
const C4BltTransform pTransform,
GLuint  baseTex,
GLuint  overlayTex,
GLuint  normalTex,
DWORD  dwOverlayModClr,
StdProjectionMatrix out_modelview 
)

Definition at line 356 of file C4DrawGL.cpp.

357 {
358  // Initialize multi blit shader.
359  int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE;
360  glBlendFunc(GL_SRC_ALPHA, iAdditive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA);
361 
362  call.Start();
363 
364  // Upload uniforms
365  const DWORD dwModClr = BlitModulated ? BlitModulateClr : 0xffffffff;
366  const float fMod[4] = {
367  ((dwModClr >> 16) & 0xff) / 255.0f,
368  ((dwModClr >> 8) & 0xff) / 255.0f,
369  ((dwModClr ) & 0xff) / 255.0f,
370  ((dwModClr >> 24) & 0xff) / 255.0f
371  };
372 
373  call.SetUniform4fv(C4SSU_ClrMod, 1, fMod);
375 
376  if(baseTex != 0)
377  {
379  glBindTexture(GL_TEXTURE_2D, baseTex);
380  }
381 
382  if(overlayTex != 0)
383  {
385  glBindTexture(GL_TEXTURE_2D, overlayTex);
386 
387  const float fOverlayModClr[4] = {
388  ((dwOverlayModClr >> 16) & 0xff) / 255.0f,
389  ((dwOverlayModClr >> 8) & 0xff) / 255.0f,
390  ((dwOverlayModClr ) & 0xff) / 255.0f,
391  ((dwOverlayModClr >> 24) & 0xff) / 255.0f
392  };
393 
394  call.SetUniform4fv(C4SSU_OverlayClr, 1, fOverlayModClr);
395  }
396 
397  if(pFoW != nullptr && normalTex != 0)
398  {
400  glBindTexture(GL_TEXTURE_2D, normalTex);
401  }
402 
403  if(pFoW != nullptr)
404  {
405  const C4Rect OutRect = GetOutRect();
406  const C4Rect ClipRect = GetClipRect();
407  const FLOAT_RECT vpRect = pFoW->getViewportRegion();
408 
409  // Dynamic Light
411  glBindTexture(GL_TEXTURE_2D, pFoW->getSurfaceName());
412 
413  float lightTransform[6];
414  pFoW->GetFragTransform(ClipRect, OutRect, lightTransform);
415  call.SetUniformMatrix2x3fv(C4SSU_LightTransform, 1, lightTransform);
416 
417  // Ambient Light
419  glBindTexture(GL_TEXTURE_2D, pFoW->getFoW()->Ambient.Tex);
421 
422  float ambientTransform[6];
423  pFoW->getFoW()->Ambient.GetFragTransform(vpRect, ClipRect, OutRect, ambientTransform);
424  call.SetUniformMatrix2x3fv(C4SSU_AmbientTransform, 1, ambientTransform);
425  }
426 
427  call.SetUniform1f(C4SSU_CullMode, 0.0f);
428 
429  // The primary reason we use a 4x4 matrix for the modelview matrix is that
430  // that the C4BltTransform pTransform parameter can have projection components
431  // (see SetObjDrawTransform2). Still, for sprites the situation is a bit
432  // unsatisfactory because there's no distinction between modelview and projection
433  // components in the BltTransform. Object rotation is part of the BltTransform
434  // for sprites, which should be part of the modelview matrix, so that lighting
435  // is correct for rotated sprites. This is much more common than projection
436  // components in the BltTransform, and therefore we turn the BltTransform into
437  // the modelview matrix and not the projection matrix.
439  StdProjectionMatrix& modelview = out_modelview ? *out_modelview : default_modelview;
440 
441  // Apply zoom and transform
442  Translate(modelview, ZoomX, ZoomY, 0.0f);
443  // Scale Z as well so that we don't distort normals.
444  Scale(modelview, Zoom, Zoom, Zoom);
445  Translate(modelview, -ZoomX, -ZoomY, 0.0f);
446 
447  if(pTransform)
448  {
449  float sz = 1.0f;
450  if (pFoW != nullptr && normalTex != 0)
451  {
452  // Decompose scale factors and scale Z accordingly to X and Y, again to avoid distorting normals
453  // We could instead work around this by using the projection matrix, but then for object rotations (SetR)
454  // the normals would not be correct.
455  const float sx = sqrt(pTransform->mat[0]*pTransform->mat[0] + pTransform->mat[1]*pTransform->mat[1]);
456  const float sy = sqrt(pTransform->mat[3]*pTransform->mat[3] + pTransform->mat[4]*pTransform->mat[4]);
457  sz = sqrt(sx * sy);
458  }
459 
460  // Multiply modelview matrix with transform
461  StdProjectionMatrix transform;
462  transform(0, 0) = pTransform->mat[0];
463  transform(0, 1) = pTransform->mat[1];
464  transform(0, 2) = 0.0f;
465  transform(0, 3) = pTransform->mat[2];
466  transform(1, 0) = pTransform->mat[3];
467  transform(1, 1) = pTransform->mat[4];
468  transform(1, 2) = 0.0f;
469  transform(1, 3) = pTransform->mat[5];
470  transform(2, 0) = 0.0f;
471  transform(2, 1) = 0.0f;
472  transform(2, 2) = sz;
473  transform(2, 3) = 0.0f;
474  transform(3, 0) = pTransform->mat[6];
475  transform(3, 1) = pTransform->mat[7];
476  transform(3, 2) = 0.0f;
477  transform(3, 3) = pTransform->mat[8];
478  modelview *= transform;
479  }
480 
483 
484  if (pFoW != nullptr && normalTex != 0)
486 
487  scriptUniform.Apply(call);
488 }
#define C4GFXBLIT_ADDITIVE
Definition: C4Surface.h:26
C4ScriptUniform scriptUniform
Definition: C4Draw.h:100
void GetFragTransform(const struct FLOAT_RECT &vpRect, const C4Rect &clipRect, const C4Rect &outRect, float ambientTransform[6]) const
double GetBrightness() const
Definition: C4FoWAmbient.h:56
C4FoWAmbient Ambient
Definition: C4FoW.h:115
GLuint getSurfaceName() const
const C4FoW * getFoW() const
Definition: C4FoWRegion.h:52
const FLOAT_RECT & getViewportRegion() const
Definition: C4FoWRegion.h:54
void GetFragTransform(const C4Rect &clipRect, const C4Rect &outRect, float lightTransform[6]) const
void Apply(C4ShaderCall &call)
Definition: C4Shader.cpp:828
void SetUniform1f(int iUniform, float gX) const
Definition: C4Shader.h:241
void Start()
Definition: C4Shader.cpp:691
void SetUniformMatrix4x4(int iUniform, const StdMeshMatrix &matrix)
Definition: C4Shader.h:351
GLint AllocTexUnit(int iUniform)
Definition: C4Shader.cpp:668
void SetUniform4fv(int iUniform, int iLength, const float *pVals) const
Definition: C4Shader.h:301
void SetUniform3fv(int iUniform, int iLength, const float *pVals) const
Definition: C4Shader.h:297
void SetUniformMatrix2x3fv(int iUniform, int iLength, const float *pVals) const
Definition: C4Shader.h:307
void SetUniformMatrix3x3Transpose(int iUniform, const StdMeshMatrix &matrix)
Definition: C4Shader.h:336
static StdMeshMatrix Inverse(const StdMeshMatrix &mat)
static StdMeshMatrix Upper3x4(const StdProjectionMatrix &matrix)

References C4ShaderCall::AllocTexUnit(), C4FoW::Ambient, C4ScriptUniform::Apply(), C4Draw::BlitModulateClr, C4Draw::BlitModulated, C4GFXBLIT_ADDITIVE, C4SSU_AmbientBrightness, C4SSU_AmbientTex, C4SSU_AmbientTransform, C4SSU_BaseTex, C4SSU_ClrMod, C4SSU_CullMode, C4SSU_Gamma, C4SSU_LightTex, C4SSU_LightTransform, C4SSU_ModelViewMatrix, C4SSU_NormalMatrix, C4SSU_NormalTex, C4SSU_OverlayClr, C4SSU_OverlayTex, C4SSU_ProjectionMatrix, C4Draw::dwBlitMode, C4Draw::gammaOut, C4FoWAmbient::GetBrightness(), C4Draw::GetClipRect(), C4FoWRegion::getFoW(), C4FoWRegion::GetFragTransform(), C4FoWAmbient::GetFragTransform(), C4Draw::GetOutRect(), C4FoWRegion::getSurfaceName(), C4FoWRegion::getViewportRegion(), StdProjectionMatrix::Identity(), StdMeshMatrix::Inverse(), C4BltTransform::mat, C4Draw::pFoW, ProjectionMatrix, Scale(), C4Draw::scriptUniform, C4ShaderCall::SetUniform1f(), C4ShaderCall::SetUniform3fv(), C4ShaderCall::SetUniform4fv(), C4ShaderCall::SetUniformMatrix2x3fv(), C4ShaderCall::SetUniformMatrix3x3Transpose(), C4ShaderCall::SetUniformMatrix4x4(), C4ShaderCall::Start(), C4FoWAmbient::Tex, Translate(), StdProjectionMatrix::Upper3x4(), C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

Referenced by C4ParticleList::Draw(), PerformMultiLines(), PerformMultiPix(), and PerformMultiTris().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetZoom() [1/2]

void C4Draw::SetZoom ( const ZoomData zoom)
inlineinherited

Definition at line 196 of file C4Draw.h.

196 { SetZoom(zoom.X, zoom.Y, zoom.Zoom); }
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:773

References C4Draw::SetZoom(), ZoomData::X, ZoomData::Y, and ZoomData::Zoom.

Referenced by C4Draw::SetZoom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetZoom() [2/2]

void C4Draw::SetZoom ( float  X,
float  Y,
float  Zoom 
)
inherited

Definition at line 773 of file C4Draw.cpp.

774 {
775  this->ZoomX = X; this->ZoomY = Y; this->Zoom = Zoom;
776 }

References X, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

Referenced by C4Viewport::Draw(), C4MouseControl::Draw(), C4GUI::CMouse::Draw(), C4Game::DrawCrewOverheadText(), C4Viewport::DrawMenu(), ZoomDataStackItem::ZoomDataStackItem(), and ZoomDataStackItem::~ZoomDataStackItem().

Here is the caller graph for this function:

◆ StorePrimaryClipper()

bool C4Draw::StorePrimaryClipper ( )
inherited

Definition at line 203 of file C4Draw.cpp.

204 {
205  // Store current primary clipper
207  return true;
208 }

References C4Draw::fClipX1, C4Draw::fClipX2, C4Draw::fClipY1, C4Draw::fClipY2, C4Draw::fStClipX1, C4Draw::fStClipX2, C4Draw::fStClipY1, and C4Draw::fStClipY2.

Referenced by C4Draw::CreatePrimaryClipper(), C4ScriptGuiWindow::DrawChildren(), C4GUI::WoodenLabel::DrawElement(), C4GUI::ComboBox::DrawElement(), C4MenuItem::DrawElement(), and C4FoWRegion::Render().

Here is the caller graph for this function:

◆ StringOut() [1/2]

bool C4Draw::StringOut ( const char *  szText,
C4Surface sfcDest,
float  iTx,
float  iTy,
DWORD  dwFCol,
BYTE  byForm,
bool  fDoMarkup,
C4Markup Markup,
CStdFont pFont,
float  fZoom 
)
protectedinherited

Definition at line 578 of file C4Draw.cpp.

579 {
580  // clip
581  if (ClipAll) return true;
582  // safety
583  if (!PrepareRendering(sfcDest)) return false;
584  // convert align
585  int iFlags=0;
586  switch (byForm)
587  {
588  case ACenter: iFlags |= STDFONT_CENTERED; break;
589  case ARight: iFlags |= STDFONT_RIGHTALGN; break;
590  }
591  if (!fDoMarkup) iFlags|=STDFONT_NOMARKUP;
592  // draw text
593  pFont->DrawText(sfcDest, iTx , iTy , dwFCol, szText, iFlags, Markup, fZoom);
594  // done, success
595  return true;
596 }
#define STDFONT_NOMARKUP
Definition: C4FontLoader.h:33
#define STDFONT_CENTERED
Definition: C4FontLoader.h:28
#define STDFONT_RIGHTALGN
Definition: C4FontLoader.h:31
const int ARight
Definition: C4Surface.h:41
const int ACenter
Definition: C4Surface.h:41
void DrawText(C4Surface *sfcDest, float iX, float iY, DWORD dwColor, const char *szText, DWORD dwFlags, C4Markup &Markup, float fZoom)

References ACenter, ARight, C4Draw::ClipAll, CStdFont::DrawText(), C4Draw::PrepareRendering(), STDFONT_CENTERED, STDFONT_NOMARKUP, and STDFONT_RIGHTALGN.

Here is the call graph for this function:

◆ StringOut() [2/2]

bool C4Draw::StringOut ( const char *  szText,
CStdFont rFont,
float  fZoom,
C4Surface sfcDest,
float  iTx,
float  iTy,
DWORD  dwFCol = 0xffffffff,
BYTE  byForm = ALeft,
bool  fDoMarkup = true 
)
inherited

Definition at line 570 of file C4Draw.cpp.

571 {
572  // init markup
573  C4Markup Markup(true);
574  // output string
575  return StringOut(szText, sfcDest, iTx, iTy, dwFCol, byForm, fDoMarkup, Markup, &rFont, fZoom);
576 }
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:570

Referenced by C4MessageBoard::Draw(), C4LoaderScreen::Draw(), and C4Draw::TextOut().

Here is the caller graph for this function:

◆ SubPrimaryClipper()

bool C4Draw::SubPrimaryClipper ( int  iX1,
int  iY1,
int  iX2,
int  iY2 
)
inherited

Definition at line 196 of file C4Draw.cpp.

197 {
198  // Set sub primary clipper
199  SetPrimaryClipper(std::max(iX1,iClipX1),std::max(iY1,iClipY1),std::min(iX2,iClipX2),std::min(iY2,iClipY2));
200  return true;
201 }

References C4Draw::iClipX1, C4Draw::iClipX2, C4Draw::iClipY1, C4Draw::iClipY2, and C4Draw::SetPrimaryClipper().

Referenced by C4GUI::Window::Draw(), C4GUI::ComboBox::DrawElement(), and C4MenuItem::DrawElement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TextOut()

bool C4Draw::TextOut ( const char *  szText,
CStdFont rFont,
float  fZoom,
C4Surface sfcDest,
float  iTx,
float  iTy,
DWORD  dwFCol = 0xffffffff,
BYTE  byForm = ALeft,
bool  fDoMarkup = true 
)
inherited

Definition at line 561 of file C4Draw.cpp.

562 {
563  C4Markup Markup(true);
564  static char szLinebuf[2500+1];
565  for (int cnt=0; SCopySegmentEx(szText,cnt,szLinebuf,fDoMarkup ? '|' : '\n','\n',2500); cnt++,iTy+=int(fZoom*rFont.GetLineHeight()))
566  if (!StringOut(szLinebuf,sfcDest,iTx,iTy,dwFCol,byForm,fDoMarkup,Markup,&rFont,fZoom)) return false;
567  return true;
568 }
bool SCopySegmentEx(const char *szString, int iSegment, char *sTarget, char cSep1, char cSep2, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:298
int GetLineHeight() const
Definition: C4FontLoader.h:125

References CStdFont::GetLineHeight(), SCopySegmentEx(), and C4Draw::StringOut().

Referenced by C4UpperBoard::Draw(), C4LoaderScreen::Draw(), C4IDList::Draw(), C4Object::Draw(), C4GameMessage::Draw(), C4ScriptGuiWindow::Draw(), C4GUI::Tabular::Sheet::DrawCaption(), C4Game::DrawCrewOverheadText(), C4GUI::Label::DrawElement(), C4GUI::WoodenLabel::DrawElement(), C4GUI::MultilineLabel::DrawElement(), C4GUI::ProgressBar::DrawElement(), C4GUI::GroupBox::DrawElement(), C4GUI::Button::DrawElement(), C4GUI::IconButton::DrawElement(), C4GUI::FacetButton::DrawElement(), C4GUI::Edit::DrawElement(), C4GUI::CheckBox::DrawElement(), C4GUI::ContextMenu::Entry::DrawElement(), C4GUI::ComboBox::DrawElement(), C4MenuItem::DrawElement(), C4ScoreboardDlg::DrawElement(), C4StartupMainDlg::DrawElement(), C4Chart::DrawElement(), C4Viewport::DrawMenu(), C4Viewport::DrawPlayerStartup(), C4Network2::DrawStatus(), C4GUI::Screen::DrawToolTip(), C4Facet::DrawValue(), and C4Facet::DrawValue2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateClipper()

bool CStdGL::UpdateClipper ( )
overridevirtual

Implements C4Draw.

Definition at line 143 of file C4DrawGL.cpp.

144 {
145  // no render target? do nothing
146  if (!RenderTarget || !Active) return true;
147  // negative/zero?
148  C4Rect clipRect = GetClipRect();
149  if (clipRect.Wdt<=0 || clipRect.Hgt<=0)
150  {
151  ClipAll=true;
152  return true;
153  }
154  ClipAll=false;
155  // set it
156  glViewport(clipRect.x, RenderTarget->Hgt-clipRect.y-clipRect.Hgt, clipRect.Wdt, clipRect.Hgt);
157  ProjectionMatrix = StdProjectionMatrix::Orthographic(clipRect.x, clipRect.x + clipRect.Wdt, clipRect.y + clipRect.Hgt, clipRect.y);
158  return true;
159 }
static StdProjectionMatrix Orthographic(float left, float right, float bottom, float top)

References C4Draw::Active, C4Draw::ClipAll, C4Draw::GetClipRect(), C4Surface::Hgt, C4Rect::Hgt, StdProjectionMatrix::Orthographic(), ProjectionMatrix, C4Draw::RenderTarget, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by PrepareRendering().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4FoWRegion

friend class C4FoWRegion
friend

Definition at line 299 of file C4DrawGL.h.

◆ C4FullScreen

friend class C4FullScreen
friend

Definition at line 296 of file C4DrawGL.h.

◆ C4Pattern

friend class C4Pattern
friend

Definition at line 293 of file C4DrawGL.h.

◆ C4ShaderCall

friend class C4ShaderCall
friend

Definition at line 298 of file C4DrawGL.h.

◆ C4StartupOptionsDlg

friend class C4StartupOptionsDlg
friend

Definition at line 295 of file C4DrawGL.h.

◆ C4Surface

friend class C4Surface
friend

Definition at line 291 of file C4DrawGL.h.

◆ C4TexRef

friend class C4TexRef
friend

Definition at line 292 of file C4DrawGL.h.

◆ C4Window

friend class C4Window
friend

Definition at line 297 of file C4DrawGL.h.

◆ CStdGLCtx

friend class CStdGLCtx
friend

Definition at line 294 of file C4DrawGL.h.

Referenced by CreateContext().

Member Data Documentation

◆ Active

◆ BlitModulateClr

DWORD C4Draw::BlitModulateClr
protectedinherited

◆ BlitModulated

◆ ClipAll

bool C4Draw::ClipAll
protectedinherited

Definition at line 105 of file C4Draw.h.

Referenced by C4Draw::BlitUnscaled(), C4Draw::Default(), C4Draw::StringOut(), and UpdateClipper().

◆ COLOR_DEPTH

constexpr int C4Draw::COLOR_DEPTH = 32
staticconstexprinherited

Definition at line 89 of file C4Draw.h.

Referenced by C4Application::ApplyResolutionConstraints().

◆ COLOR_DEPTH_BYTES

constexpr int C4Draw::COLOR_DEPTH_BYTES = COLOR_DEPTH / 8
staticconstexprinherited

Definition at line 90 of file C4Draw.h.

Referenced by C4TexRef::C4TexRef(), C4TexRef::Lock(), and C4TexRef::LockForUpdate().

◆ CurrentVBO

unsigned int CStdGL::CurrentVBO {0}
protected

Definition at line 220 of file C4DrawGL.h.

Referenced by InvalidateDeviceObjects(), and PerformMultiBlt().

◆ dwBlitMode

◆ fClipX1

float C4Draw::fClipX1
protectedinherited

◆ fClipX2

float C4Draw::fClipX2
protectedinherited

◆ fClipY1

float C4Draw::fClipY1
protectedinherited

◆ fClipY2

float C4Draw::fClipY2
protectedinherited

◆ fStClipX1

float C4Draw::fStClipX1
protectedinherited

Definition at line 103 of file C4Draw.h.

Referenced by C4Draw::RestorePrimaryClipper(), and C4Draw::StorePrimaryClipper().

◆ fStClipX2

float C4Draw::fStClipX2
protectedinherited

Definition at line 103 of file C4Draw.h.

Referenced by C4Draw::RestorePrimaryClipper(), and C4Draw::StorePrimaryClipper().

◆ fStClipY1

float C4Draw::fStClipY1
protectedinherited

Definition at line 103 of file C4Draw.h.

Referenced by C4Draw::RestorePrimaryClipper(), and C4Draw::StorePrimaryClipper().

◆ fStClipY2

float C4Draw::fStClipY2
protectedinherited

Definition at line 103 of file C4Draw.h.

Referenced by C4Draw::RestorePrimaryClipper(), and C4Draw::StorePrimaryClipper().

◆ fUsePerspective

bool C4Draw::fUsePerspective
protectedinherited

Definition at line 114 of file C4Draw.h.

Referenced by C4Draw::Default(), PerformMesh(), and C4Draw::SetPerspective().

◆ gamma

float C4Draw::gamma[C4MaxGammaRamps][3]
inherited

Definition at line 97 of file C4Draw.h.

Referenced by C4Weather::CompileFunc(), C4Draw::ResetGamma(), and C4Draw::SetGamma().

◆ gammaOut

float C4Draw::gammaOut[3]
inherited

◆ GENERIC_VBO_SIZE

const unsigned int CStdGL::GENERIC_VBO_SIZE = 3 * 64
staticprotected

Definition at line 217 of file C4DrawGL.h.

Referenced by RestoreDeviceObjects().

◆ GenericVAOs

unsigned int CStdGL::GenericVAOs[N_GENERIC_VBOS *2]
protected

Definition at line 224 of file C4DrawGL.h.

Referenced by InvalidateDeviceObjects(), PerformMultiBlt(), and RestoreDeviceObjects().

◆ GenericVBOs

GLuint CStdGL::GenericVBOs[N_GENERIC_VBOS]
protected

Definition at line 218 of file C4DrawGL.h.

Referenced by CStdGL(), InvalidateDeviceObjects(), PerformMultiBlt(), and RestoreDeviceObjects().

◆ GenericVBOSizes

unsigned int CStdGL::GenericVBOSizes[N_GENERIC_VBOS]
protected

Definition at line 219 of file C4DrawGL.h.

Referenced by PerformMultiBlt(), and RestoreDeviceObjects().

◆ has_khr_debug

bool CStdGL::has_khr_debug
protected

Definition at line 230 of file C4DrawGL.h.

Referenced by CreateContext(), and ObjectLabel().

◆ iClipX1

int32_t C4Draw::iClipX1
protectedinherited

◆ iClipX2

int32_t C4Draw::iClipX2
protectedinherited

◆ iClipY1

int32_t C4Draw::iClipY1
protectedinherited

◆ iClipY2

int32_t C4Draw::iClipY2
protectedinherited

◆ iPixelFormat

int CStdGL::iPixelFormat
protected

Definition at line 176 of file C4DrawGL.h.

Referenced by Default().

◆ lines_tex

GLuint CStdGL::lines_tex
protected

◆ MaxTexSize

int C4Draw::MaxTexSize {0}
inherited

◆ MeshTransform

const StdMeshMatrix* C4Draw::MeshTransform
protectedinherited

◆ N_GENERIC_VBOS

const unsigned int CStdGL::N_GENERIC_VBOS = 16
staticprotected

Definition at line 216 of file C4DrawGL.h.

Referenced by InvalidateDeviceObjects(), PerformMultiBlt(), and RestoreDeviceObjects().

◆ NextVAOID

std::set<unsigned int>::iterator CStdGL::NextVAOID
protected

Definition at line 228 of file C4DrawGL.h.

Referenced by FreeVAOID(), and GenVAOID().

◆ pApp

C4AbstractApp* C4Draw::pApp
inherited

◆ pCurrCtx

◆ pFoW

const C4FoWRegion* C4Draw::pFoW
protectedinherited

Definition at line 111 of file C4Draw.h.

Referenced by C4Draw::Default(), C4Draw::GetFoW(), PerformMesh(), C4Draw::SetFoW(), and SetupMultiBlt().

◆ pMainCtx

CStdGLCtx* CStdGL::pMainCtx {nullptr}
protected

◆ PrimaryLocked

bool C4Draw::PrimaryLocked
protectedinherited

Definition at line 106 of file C4Draw.h.

Referenced by C4Draw::LockingPrimary(), and C4Draw::PrimaryUnlocked().

◆ ProjectionMatrix

StdProjectionMatrix CStdGL::ProjectionMatrix
protected

Definition at line 185 of file C4DrawGL.h.

Referenced by GetProjectionMatrix(), PerformMesh(), SetupMultiBlt(), and UpdateClipper().

◆ RenderTarget

C4Surface* C4Draw::RenderTarget
protectedinherited

◆ scriptUniform

C4ScriptUniform C4Draw::scriptUniform
inherited

◆ sfcFmt

GLenum CStdGL::sfcFmt
protected

Definition at line 178 of file C4DrawGL.h.

Referenced by C4Surface::Create(), and Default().

◆ SpriteShader

C4Shader CStdGL::SpriteShader
protected

Definition at line 191 of file C4DrawGL.h.

Referenced by Clear(), GetSpriteShader(), and InitShaders().

◆ SpriteShaderBase

C4Shader CStdGL::SpriteShaderBase
protected

Definition at line 193 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderBaseMod2

C4Shader CStdGL::SpriteShaderBaseMod2
protected

Definition at line 194 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderBaseOverlay

C4Shader CStdGL::SpriteShaderBaseOverlay
protected

Definition at line 195 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderBaseOverlayMod2

C4Shader CStdGL::SpriteShaderBaseOverlayMod2
protected

Definition at line 196 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLight

C4Shader CStdGL::SpriteShaderLight
protected

Definition at line 198 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBase

C4Shader CStdGL::SpriteShaderLightBase
protected

Definition at line 200 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseMod2

C4Shader CStdGL::SpriteShaderLightBaseMod2
protected

Definition at line 201 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseNormal

C4Shader CStdGL::SpriteShaderLightBaseNormal
protected

Definition at line 204 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseNormalMod2

C4Shader CStdGL::SpriteShaderLightBaseNormalMod2
protected

Definition at line 205 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseNormalOverlay

C4Shader CStdGL::SpriteShaderLightBaseNormalOverlay
protected

Definition at line 206 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseNormalOverlayMod2

C4Shader CStdGL::SpriteShaderLightBaseNormalOverlayMod2
protected

Definition at line 207 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseOverlay

C4Shader CStdGL::SpriteShaderLightBaseOverlay
protected

Definition at line 202 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightBaseOverlayMod2

C4Shader CStdGL::SpriteShaderLightBaseOverlayMod2
protected

Definition at line 203 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderLightMod2

C4Shader CStdGL::SpriteShaderLightMod2
protected

Definition at line 199 of file C4DrawGL.h.

Referenced by Clear(), and GetSpriteShader().

◆ SpriteShaderMod2

C4Shader CStdGL::SpriteShaderMod2
protected

Definition at line 192 of file C4DrawGL.h.

Referenced by Clear(), GetSpriteShader(), and InitShaders().

◆ VAOIDs

std::set<unsigned int> CStdGL::VAOIDs
protected

Definition at line 227 of file C4DrawGL.h.

Referenced by FreeVAOID(), GenVAOID(), and GetVAO().

◆ 

struct { ... } CStdGL::Workarounds

Referenced by Default(), and PrepareMaterial().

◆ Zoom

◆ ZoomX

float C4Draw::ZoomX
protectedinherited

◆ ZoomY

float C4Draw::ZoomY
protectedinherited

The documentation for this class was generated from the following files: