OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 StdProjectionMatrix & GetProjectionMatrix () 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
 
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 StdMeshMatrix * MeshTransform
 
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 168 of file C4DrawGL.h.

Member Enumeration Documentation

anonymous enum
inherited
Enumerator
DEFAULT_MESSAGE_COLOR 

Definition at line 167 of file C4Draw.h.

enum C4Draw::DrawOperation
inherited
Enumerator
OP_POINTS 
OP_TRIANGLES 

Definition at line 87 of file C4Draw.h.

Constructor & Destructor Documentation

CStdGL::CStdGL ( )

Definition at line 98 of file C4DrawGL.cpp.

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

98  :
99  NextVAOID(VAOIDs.end())
100 {
101  GenericVBOs[0] = 0;
102  Default();
103  // global ptr
104  pGL = this;
105  lines_tex = 0;
106 }
std::set< unsigned int >::iterator NextVAOID
Definition: C4DrawGL.h:227
GLuint GenericVBOs[N_GENERIC_VBOS]
Definition: C4DrawGL.h:217
void Default() override
Definition: C4DrawGL.cpp:915
GLuint lines_tex
Definition: C4DrawGL.h:181
std::set< unsigned int > VAOIDs
Definition: C4DrawGL.h:226
CStdGL * pGL
Definition: C4DrawGL.cpp:905

Here is the call graph for this function:

CStdGL::~CStdGL ( )
override

Definition at line 108 of file C4DrawGL.cpp.

References Clear(), and pGL.

109 {
110  Clear();
111  pGL=nullptr;
112 }
void Clear() override
Definition: C4DrawGL.cpp:114
CStdGL * pGL
Definition: C4DrawGL.cpp:905

Here is the call graph for this function:

Member Function Documentation

void C4Draw::ActivateBlitModulation ( DWORD  dwWithClr)
inlineinherited

Definition at line 188 of file C4Draw.h.

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

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

Here is the caller graph for this function:

DWORD C4Draw::ApplyGammaTo ( DWORD  dwClr)
inherited

Definition at line 772 of file C4Draw.cpp.

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

773 {
774  return C4RGB(int(pow(float(GetRedValue(dwClr)) / 255.0f, gammaOut[0]) * 255.0),
775  int(pow(float(GetGreenValue(dwClr)) / 255.0f, gammaOut[1]) * 255.0),
776  int(pow(float(GetBlueValue(dwClr)) / 255.0f, gammaOut[2]) * 255.0));
777 }
#define GetGreenValue(rgb)
Definition: StdColors.h:28
float gammaOut[3]
Definition: C4Draw.h:98
#define GetRedValue(rgb)
Definition: StdColors.h:29
#define GetBlueValue(rgb)
Definition: StdColors.h:27
#define C4RGB(r, g, b)
Definition: StdColors.h:26
bool C4Draw::ApplyPrimaryClipper ( C4Surface sfcSurface)
inherited

Definition at line 227 of file C4Draw.cpp.

228 {
229  return true;
230 }
void C4Draw::ApplyZoom ( float &  X,
float &  Y 
)
inherited

Definition at line 784 of file C4Draw.cpp.

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

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

785 {
786  X = (X - ZoomX) * Zoom + ZoomX;
787  Y = (Y - ZoomY) * Zoom + ZoomY;
788 }
float ZoomY
Definition: C4Draw.h:112
float ZoomX
Definition: C4Draw.h:112
float Zoom
Definition: C4Draw.h:116
#define X(sdl, oc)

Here is the caller graph for this function:

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.

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().

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 }
int Scale
Definition: C4Surface.h:66
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

Here is the call graph for this function:

Here is the caller graph for this function:

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 424 of file C4Draw.cpp.

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

Referenced by C4Draw::BlitUnscaled().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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().

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 fty
Definition: C4Draw.h:64
void ApplyZoom(float &X, float &Y)
Definition: C4Draw.cpp:784
bool Lock()
Definition: C4Surface.cpp:453
bool Unlock()
Definition: C4Surface.cpp:464
uint8_t BYTE
BYTE GetPix(int iX, int iY) const
Definition: CSurface8.h:49
DWORD GetClr(BYTE byCol)
Definition: StdColors.h:186
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
virtual void PerformMultiPix(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call)=0
CStdPalette * pPal
Definition: CSurface8.h:31
float Zoom
Definition: C4Draw.h:116
float ftx
Definition: C4Draw.h:64
bool IsRenderTarget()
Definition: C4Surface.cpp:144
bool fPrimary
Definition: C4Surface.h:89
uint32_t DWORD

Here is the call graph for this function:

Here is the caller graph for this function:

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.

References C4Draw::Blit().

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

Here is the call graph for this function:

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 469 of file C4Draw.cpp.

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

Referenced by C4Draw::Blit8().

472 {
473  // rendertarget?
474  if (sfcTarget->IsRenderTarget())
475  {
476  return Blit(sfcSource, float(fx), float(fy), float(fwdt), float(fhgt), sfcTarget, float(tx), float(ty), float(twdt), float(thgt), true);
477  }
478  // Object is first stretched to dest rect
479  int xcnt,ycnt,tcx,tcy,cpcx,cpcy;
480  if (!fwdt || !fhgt || !twdt || !thgt) return false;
481  // Lock the surfaces
482  if (!sfcSource->Lock())
483  return false;
484  if (!sfcTarget->Lock())
485  { sfcSource->Unlock(); return false; }
486  // Rectangle centers
487  tcx=twdt/2; tcy=thgt/2;
488  for (ycnt=0; ycnt<thgt; ycnt++)
489  if (Inside(cpcy=ty+tcy-thgt/2+ycnt,0,sfcTarget->Hgt-1))
490  for (xcnt=0; xcnt<twdt; xcnt++)
491  if (Inside(cpcx=tx+tcx-twdt/2+xcnt,0,sfcTarget->Wdt-1))
492  sfcTarget->BltPix(cpcx, cpcy, sfcSource, xcnt*fwdt/twdt+fx, ycnt*fhgt/thgt+fy, fTransparency);
493  // Unlock the surfaces
494  sfcSource->Unlock();
495  sfcTarget->Unlock();
496  return true;
497 }
int Wdt
Definition: C4Surface.h:65
bool Lock()
Definition: C4Surface.cpp:453
bool Unlock()
Definition: C4Surface.cpp:464
int Hgt
Definition: C4Surface.h:65
bool BltPix(int iX, int iY, C4Surface *sfcSource, int iSrcX, int iSrcY, bool fTransparency)
Definition: C4Surface.cpp:591
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
bool IsRenderTarget()
Definition: C4Surface.cpp:144
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:43

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 517 of file C4Draw.cpp.

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

Referenced by C4Surface::Copy().

518 {
519  if (fBlitBase)
520  {
521  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
522  return true;
523  }
524  else
525  {
526  if (!sfcSurface) return false;
527  C4Surface *pSfcBase = sfcSurface->pMainSfc;
528  sfcSurface->pMainSfc = nullptr;
529  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
530  sfcSurface->pMainSfc = pSfcBase;
531  return true;
532  }
533 }
int Wdt
Definition: C4Surface.h:65
int Hgt
Definition: C4Surface.h:65
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
C4Surface * pMainSfc
Definition: C4Surface.h:79

Here is the call graph for this function:

Here is the caller graph for this function:

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 535 of file C4Draw.cpp.

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().

536 {
537  // Only direct rendering from single, tileable, texture
538  if (!sfcTarget->IsRenderTarget()) return false;
539  if ((sfcSurface->texture->iFlags & C4SF_Tileable) == 0) return false;
540 
541  // source surface dimensions
542  const float sourceWdt = sfcSurface->Wdt;
543  const float sourceHgt = sfcSurface->Hgt;
544 
545  // vertex positions
546  C4BltVertex vertices[6];
547  vertices[0].ftx = iToX; vertices[0].fty = iToY; vertices[0].ftz = 0.0f;
548  vertices[0].tx = (0.0f + iOffsetX) / sourceWdt; vertices[0].ty = (0.0f + iOffsetY) / sourceHgt;
549  DwTo4UB(0xffffffff, vertices[0].color);
550  vertices[1].ftx = iToX + iToWdt; vertices[1].fty = iToY; vertices[1].ftz = 0.0f;
551  vertices[1].tx = (iToWdt + iOffsetX) / sourceWdt; vertices[1].ty = (0.0f + iOffsetY) / sourceHgt;
552  DwTo4UB(0xffffffff, vertices[1].color);
553  vertices[2].ftx = iToX + iToWdt; vertices[2].fty = iToY + iToHgt; vertices[2].ftz = 0.0f;
554  vertices[2].tx = (iToWdt + iOffsetX) / sourceWdt; vertices[2].ty = (iToHgt + iOffsetY) / sourceHgt;
555  DwTo4UB(0xffffffff, vertices[2].color);
556  vertices[3].ftx = iToX; vertices[3].fty = iToY + iToHgt; vertices[3].ftz = 0.0f;
557  vertices[3].tx = (0.0f + iOffsetX) / sourceWdt; vertices[3].ty = (iToHgt + iOffsetY) / sourceHgt;
558  DwTo4UB(0xffffffff, vertices[3].color);
559  // duplicate vertices
560  vertices[4] = vertices[0]; vertices[5] = vertices[2];
561 
562  // Draw
563  PerformMultiTris(sfcTarget, vertices, 6, nullptr, sfcSurface->texture.get(), nullptr, nullptr, 0, shader_call);
564  return true;
565 }
float fty
Definition: C4Draw.h:64
float ftz
Definition: C4Draw.h:64
int Wdt
Definition: C4Surface.h:65
float tx
Definition: C4Draw.h:62
float ty
Definition: C4Draw.h:62
int Hgt
Definition: C4Surface.h:65
virtual void PerformMultiTris(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, const C4BltTransform *pTransform, C4TexRef *pTex, C4TexRef *pOverlay, C4TexRef *pNormal, DWORD dwOverlayClrMod, C4ShaderCall *shader_call)=0
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
const int C4SF_Tileable
Definition: C4Surface.h:49
std::unique_ptr< C4TexRef > texture
Definition: C4Surface.h:78
float ftx
Definition: C4Draw.h:64
bool IsRenderTarget()
Definition: C4Surface.cpp:144

Here is the call graph for this function:

Here is the caller graph for this function:

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.

References C4Draw::ApplyZoom(), C4Draw::Blit8(), C4Draw::ClipAll, C4Surface::ClrByOwnerClr, DwTo4UB(), C4Surface::fPrimary, C4BltVertex::ftx, C4BltVertex::fty, C4TexRef::iSizeX, C4TexRef::iSizeY, C4Surface::IsRenderTarget(), C4Surface::iTexSize, 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().

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  // calc stretch
337  float scaleX = twdt/fwdt;
338  float scaleY = thgt/fhgt;
339  // bound
340  if (ClipAll) return true;
341  // inside screen?
342  if (twdt<=0 || thgt<=0) return false;
343  // prepare rendering to surface
344  if (!PrepareRendering(sfcTarget)) return false;
345  // texture present?
346  if (!sfcSource->texture)
347  {
348  // primary surface?
349  if (sfcSource->fPrimary)
350  {
351  // blit emulated
352  return Blit8(sfcSource, int(fx), int(fy), int(fwdt), int(fhgt), sfcTarget, int(tx), int(ty), int(twdt), int(thgt), fSrcColKey);
353  }
354  return false;
355  }
356  // blit with basesfc?
357  bool fBaseSfc=false;
358  if (sfcSource->pMainSfc) if (sfcSource->pMainSfc->texture) fBaseSfc = true;
359  // get involved texture offsets
360  int iTexSizeX=sfcSource->iTexSize;
361  int iTexSizeY=sfcSource->iTexSize;
362 
363  C4TexRef *pTex = sfcSource->texture.get();
364  // set up blit data
365  C4BltVertex vertices[6];
366  vertices[0].ftx = tx; vertices[0].fty = ty;
367  vertices[1].ftx = tx + twdt; vertices[1].fty = ty;
368  vertices[2].ftx = tx + twdt; vertices[2].fty = ty + thgt;
369  vertices[3].ftx = tx; vertices[3].fty = ty + thgt;
370  vertices[0].tx = fx / pTex->iSizeX; vertices[0].ty = fy / pTex->iSizeY;
371  vertices[1].tx = (fx + fwdt) / pTex->iSizeX; vertices[1].ty = fy / pTex->iSizeY;
372  vertices[2].tx = (fx + fwdt) / pTex->iSizeX; vertices[2].ty = (fy + fhgt) / pTex->iSizeY;
373  vertices[3].tx = fx / pTex->iSizeX; vertices[3].ty = (fy + fhgt) / pTex->iSizeY;
374  DwTo4UB(0xffffffff, vertices[0].color);
375  DwTo4UB(0xffffffff, vertices[1].color);
376  DwTo4UB(0xffffffff, vertices[2].color);
377  DwTo4UB(0xffffffff, vertices[3].color);
378 
379  // duplicate vertices
380  vertices[4] = vertices[0]; vertices[5] = vertices[2];
381 
382  C4TexRef * pBaseTex = pTex;
383  // is there a base-surface to be blitted first?
384  if (fBaseSfc)
385  {
386  // then get this surface as same offset as from other surface
387  // assuming this is only valid as long as there's no texture management,
388  // organizing partially used textures together!
389  pBaseTex = sfcSource->pMainSfc->texture.get();
390  }
391 
392  C4TexRef* pNormalTex = nullptr;
393  if (sfcSource->pNormalSfc)
394  pNormalTex = sfcSource->pNormalSfc->texture.get();
395 
396  // ClrByOwner is always fully opaque
397  const DWORD dwOverlayClrMod = 0xff000000 | sfcSource->ClrByOwnerClr;
398  PerformMultiTris(sfcTarget, vertices, 6, pTransform, pBaseTex, fBaseSfc ? pTex : nullptr, pNormalTex, dwOverlayClrMod, nullptr);
399  // success
400  return true;
401 }
float fty
Definition: C4Draw.h:64
void ApplyZoom(float &X, float &Y)
Definition: C4Draw.cpp:784
float ZoomY
Definition: C4Draw.h:112
float tx
Definition: C4Draw.h:62
int iSizeY
Definition: C4Surface.h:158
DWORD ClrByOwnerClr
Definition: C4Surface.h:81
float ty
Definition: C4Draw.h:62
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
int iSizeX
Definition: C4Surface.h:157
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
C4Surface * pNormalSfc
Definition: C4Surface.h:80
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
void Set(float fA, float fB, float fC, float fD, float fE, float fF, float fG, float fH, float fI)
int iTexSize
Definition: C4Surface.h:68
float ZoomX
Definition: C4Draw.h:112
float Zoom
Definition: C4Draw.h:116
std::unique_ptr< C4TexRef > texture
Definition: C4Surface.h:78
float ftx
Definition: C4Draw.h:64
bool ClipAll
Definition: C4Draw.h:105
bool IsRenderTarget()
Definition: C4Surface.cpp:144
bool fPrimary
Definition: C4Surface.h:89
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:424
uint32_t DWORD
C4Surface * pMainSfc
Definition: C4Surface.h:79

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 896 of file C4DrawGL.cpp.

References GLErrorString(), and LogF().

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

Here is the call graph for this function:

void CStdGL::Clear ( )
overridevirtual

Reimplemented from C4Draw.

Definition at line 114 of file C4DrawGL.cpp.

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().

115 {
117  // cannot unlock TexMgr here or we can't preserve textures across GL reinitialization as required when changing multisampling
120  RenderTarget = nullptr;
121  // Clear all shaders
138  // clear context
139  if (pCurrCtx) pCurrCtx->Deselect();
140  pMainCtx=nullptr;
141  C4Draw::Clear();
142 }
C4Shader SpriteShaderLightBaseNormalOverlay
Definition: C4DrawGL.h:205
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
virtual void Deselect()
C4Shader SpriteShaderBase
Definition: C4DrawGL.h:192
C4Shader SpriteShaderLightBaseNormalMod2
Definition: C4DrawGL.h:204
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:178
C4Shader SpriteShaderBaseOverlay
Definition: C4DrawGL.h:194
C4Shader SpriteShaderLightBaseOverlay
Definition: C4DrawGL.h:201
C4Shader SpriteShaderLightBaseMod2
Definition: C4DrawGL.h:200
C4Shader SpriteShaderBaseMod2
Definition: C4DrawGL.h:193
C4Shader SpriteShaderBaseOverlayMod2
Definition: C4DrawGL.h:195
void Clear()
Definition: C4Shader.cpp:333
C4Shader SpriteShaderLightBaseNormalOverlayMod2
Definition: C4DrawGL.h:206
C4Shader SpriteShader
Definition: C4DrawGL.h:190
C4Shader SpriteShaderMod2
Definition: C4DrawGL.h:191
C4Shader SpriteShaderLightBaseOverlayMod2
Definition: C4DrawGL.h:202
C4Shader SpriteShaderLightBaseNormal
Definition: C4DrawGL.h:203
C4Surface * RenderTarget
Definition: C4Draw.h:107
virtual void Clear()
Definition: C4Draw.cpp:184
bool NoPrimaryClipper()
Definition: C4Draw.cpp:237
bool InvalidateDeviceObjects() override
Definition: C4DrawGL.cpp:806
C4Shader SpriteShaderLight
Definition: C4DrawGL.h:197
C4Shader SpriteShaderLightBase
Definition: C4DrawGL.h:199
C4Shader SpriteShaderLightMod2
Definition: C4DrawGL.h:198

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from C4Draw.

Definition at line 282 of file C4DrawGL.cpp.

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

Referenced by C4Surface::C4Surface().

283 {
284  // safety
285  if (!pWindow) return nullptr;
286 
287  // create it
288  CStdGLCtx *pCtx;
289 #ifdef WITH_QT_EDITOR
290  auto app = dynamic_cast<C4Application*>(pApp);
291  if (app->isEditor)
292  pCtx = new CStdGLCtxQt();
293  else
294 #endif
295  pCtx = new CStdGLCtx();
296  bool first_ctx = !pMainCtx;
297  if (first_ctx)
298  {
299  pMainCtx = pCtx;
300  LogF(" gl: Create first %scontext...", Config.Graphics.DebugOpenGL ? "debug " : "");
301  }
302  bool success = pCtx->Init(pWindow, pApp);
303  if (Config.Graphics.DebugOpenGL && glDebugMessageCallbackARB)
304  {
305  if (first_ctx) Log(" gl: Setting OpenGLDebugProc callback");
306  glDebugMessageCallbackARB(&OpenGLDebugProc, nullptr);
307  glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
308 #ifdef GL_KHR_debug
309  if (GLEW_KHR_debug)
310  glEnable(GL_DEBUG_OUTPUT);
311 #endif
312  }
313  // First context: Log some information about hardware/drivers
314  // Must log after context creation to get valid results
315  if (first_ctx)
316  {
317  const auto *gl_vendor = reinterpret_cast<const char *>(glGetString(GL_VENDOR));
318  const auto *gl_renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
319  const auto *gl_version = reinterpret_cast<const char *>(glGetString(GL_VERSION));
320  LogF("GL %s on %s (%s)", gl_version ? gl_version : "", gl_renderer ? gl_renderer : "", gl_vendor ? gl_vendor : "");
321 
323  {
324  // Dump extension list
325  if (glGetStringi)
326  {
327  GLint gl_extension_count = 0;
328  glGetIntegerv(GL_NUM_EXTENSIONS, &gl_extension_count);
329  if (gl_extension_count == 0)
330  {
331  LogSilentF("No available extensions.");
332  }
333  else
334  {
335  LogSilentF("%d available extensions:", gl_extension_count);
336  for (GLint i = 0; i < gl_extension_count; ++i)
337  {
338  const char *gl_extension = (const char*)glGetStringi(GL_EXTENSIONS, i);
339  LogSilentF(" %4d: %s", i, gl_extension);
340  }
341  }
342  }
343  else
344  {
345  const char *gl_extensions = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
346  LogSilentF("GLExt: %s", gl_extensions ? gl_extensions : "");
347  }
348  }
349  }
350  if (!success)
351  {
352  delete pCtx; Error(" gl: Error creating secondary context!"); return nullptr;
353  }
354  // creation selected the new context - switch back to previous context
355  RenderTarget = nullptr;
356  pCurrCtx = nullptr;
357  // done
358  return pCtx;
359 }
int32_t DebugOpenGL
Definition: C4Config.h:117
C4Config Config
Definition: C4Config.cpp:833
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:178
C4ConfigGraphics Graphics
Definition: C4Config.h:253
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:260
friend class CStdGLCtx
Definition: C4DrawGL.h:291
virtual bool Init(C4Window *pWindow, C4AbstractApp *pApp)
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
bool Error(const char *szMsg) override
Definition: C4DrawGL.cpp:853
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250
C4AbstractApp * pApp
Definition: C4Draw.h:95

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 507 of file C4Draw.cpp.

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

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

508 {
509  // simply setup primary viewport
510  // assume no zoom has been set yet
511  assert(Zoom==1.0f);
512  SetPrimaryClipper(0, 0, iXRes - 1, iYRes - 1);
514  return true;
515 }
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217
float Zoom
Definition: C4Draw.h:116
bool StorePrimaryClipper()
Definition: C4Draw.cpp:203

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Draw::DeactivateBlitModulation ( )
inlineinherited

Definition at line 189 of file C4Draw.h.

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

189 { BlitModulated=false; } // stop color modulation of blits
bool BlitModulated
Definition: C4Draw.h:108

Here is the caller graph for this function:

void CStdGL::Default ( )
overridevirtual

Reimplemented from C4Draw.

Definition at line 915 of file C4DrawGL.cpp.

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

Referenced by CStdGL().

916 {
917  C4Draw::Default();
918  pCurrCtx = nullptr;
919  iPixelFormat=0;
920  sfcFmt=0;
921  Workarounds.LowMaxVertexUniformCount = false;
922  Workarounds.ForceSoftwareTransform = false;
923 }
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
GLenum sfcFmt
Definition: C4DrawGL.h:177
int iPixelFormat
Definition: C4DrawGL.h:175
struct CStdGL::@10 Workarounds
virtual void Default()
Definition: C4Draw.cpp:169

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Draw::DetachPrimaryClipper ( C4Surface sfcSurface)
inherited

Definition at line 232 of file C4Draw.cpp.

233 {
234  return true;
235 }
bool CStdGL::DeviceReady ( )
inlineoverridevirtual

Implements C4Draw.

Definition at line 271 of file C4DrawGL.h.

References pMainCtx.

271 { return !!pMainCtx; }
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:178
void C4Draw::DrawBoxDw ( C4Surface sfcDest,
int  iX1,
int  iY1,
int  iX2,
int  iY2,
DWORD  dwClr 
)
inherited

Definition at line 846 of file C4Draw.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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 830 of file C4Draw.cpp.

References C4Draw::DrawQuadDw().

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 624 of file C4Draw.cpp.

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

Referenced by C4EditCursor::Draw().

625 {
626  // Draw as line segments
627  int32_t num_lines = 12 + int32_t(r / 10);
628  std::unique_ptr<C4BltVertex[]> vertices(new C4BltVertex[num_lines * 2]);
629  for (int32_t i = 0; i < num_lines; ++i)
630  {
631  float ang = float(i) * 2 * M_PI / num_lines;
632  int32_t iv = i * 2 + 1;
633  vertices[iv].ftx = cx + sin(ang) * r;
634  vertices[iv].fty = cy + cos(ang) * r;
635  DwTo4UB(dwClr, vertices[iv].color);
636  vertices[(iv + 1) % (num_lines * 2)] = vertices[iv];
637  }
638  PerformMultiLines(sfcTarget, vertices.get(), num_lines * 2, width, nullptr);
639 }
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
virtual void PerformMultiLines(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call)=0

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 641 of file C4Draw.cpp.

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

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

642 {
643  C4BltVertex vertices[8];
644  vertices[0].ftx = x1; vertices[0].fty = y1;
645  vertices[1].ftx = x2; vertices[1].fty = y1;
646  vertices[2] = vertices[1];
647  vertices[3].ftx = x2; vertices[3].fty = y2;
648  vertices[4] = vertices[3];
649  vertices[5].ftx = x1; vertices[5].fty = y2;
650  vertices[6] = vertices[5];
651  vertices[7] = vertices[0];
652 
653  for(auto & vertex : vertices)
654  DwTo4UB(dwClr, vertex.color);
655 
656  PerformMultiLines(sfcDest, vertices, 8, width, nullptr);
657 }
float fty
Definition: C4Draw.h:64
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
virtual void PerformMultiLines(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call)=0
float ftx
Definition: C4Draw.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 614 of file C4Draw.cpp.

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

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

615 {
616  C4BltVertex vertices[2];
617  vertices[0].ftx = x1; vertices[0].fty = y1;
618  vertices[1].ftx = x2; vertices[1].fty = y2;
619  DwTo4UB(dwClr, vertices[0].color);
620  DwTo4UB(dwClr, vertices[1].color);
621  PerformMultiLines(sfcTarget, vertices, 2, width, nullptr);
622 }
float fty
Definition: C4Draw.h:64
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
virtual void PerformMultiLines(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call)=0
float ftx
Definition: C4Draw.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 675 of file C4Draw.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 604 of file C4Draw.cpp.

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

Referenced by C4Draw::DrawPatternedCircle().

605 {
606  // Draw
607  C4BltVertex vtx;
608  vtx.ftx = tx;
609  vtx.fty = ty;
610  DwTo4UB(dwClr, vtx.color);
611  PerformMultiPix(sfcDest, &vtx, 1, nullptr);
612 }
float fty
Definition: C4Draw.h:64
unsigned char color[4]
Definition: C4Draw.h:63
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
virtual void PerformMultiPix(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call)=0
float ftx
Definition: C4Draw.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 659 of file C4Draw.cpp.

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

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

660 {
661  C4BltVertex vertices[6];
662  vertices[0].ftx = ipVtx[0]; vertices[0].fty = ipVtx[1];
663  vertices[1].ftx = ipVtx[2]; vertices[1].fty = ipVtx[3];
664  vertices[2].ftx = ipVtx[4]; vertices[2].fty = ipVtx[5];
665  vertices[3].ftx = ipVtx[6]; vertices[3].fty = ipVtx[7];
666  DwTo4UB(dwClr1, vertices[0].color);
667  DwTo4UB(dwClr2, vertices[1].color);
668  DwTo4UB(dwClr3, vertices[2].color);
669  DwTo4UB(dwClr4, vertices[3].color);
670  vertices[4] = vertices[0];
671  vertices[5] = vertices[2];
672  PerformMultiTris(sfcTarget, vertices, 6, nullptr, nullptr, nullptr, nullptr, 0, shader_call);
673 }
float fty
Definition: C4Draw.h:64
virtual void PerformMultiTris(C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, const C4BltTransform *pTransform, C4TexRef *pTex, C4TexRef *pOverlay, C4TexRef *pNormal, DWORD dwOverlayClrMod, C4ShaderCall *shader_call)=0
void DwTo4UB(DWORD dwClr, unsigned char(&r)[4])
Definition: C4Draw.h:29
float ftx
Definition: C4Draw.h:64

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdGL::EnsureMainContextSelected ( )
overridevirtual

Implements C4Draw.

Definition at line 755 of file C4DrawGL.cpp.

References pMainCtx, and CStdGLCtx::Select().

756 {
757  return pMainCtx->Select();
758 }
virtual bool Select(bool verbose=false)
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:178

Here is the call graph for this function:

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

Reimplemented from C4Draw.

Definition at line 853 of file C4DrawGL.cpp.

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

Referenced by CreateContext().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements C4Draw.

Definition at line 144 of file C4DrawGL.cpp.

References GetBlueValue, GetGreenValue, GetRedValue, and pCurrCtx.

145 {
146  if (!pCurrCtx) return;
147  glClearColor((float)GetRedValue(dwClr)/255.0f, (float)GetGreenValue(dwClr)/255.0f, (float)GetBlueValue(dwClr)/255.0f, 0.0f);
148  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
149 }
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
#define GetGreenValue(rgb)
Definition: StdColors.h:28
#define GetRedValue(rgb)
Definition: StdColors.h:29
#define GetBlueValue(rgb)
Definition: StdColors.h:27
void CStdGL::FreeVAOID ( unsigned int  vaoid)

Definition at line 967 of file C4DrawGL.cpp.

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().

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

Here is the caller graph for this function:

unsigned int CStdGL::GenVAOID ( )

Definition at line 925 of file C4DrawGL.cpp.

References NextVAOID, and VAOIDs.

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

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

Here is the caller graph for this function:

bool C4Draw::GetBlitModulation ( DWORD rdwColor)
inlineinherited

Definition at line 190 of file C4Draw.h.

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

Referenced by CStdFont::DrawText().

190 { rdwColor=BlitModulateClr; return BlitModulated; }
DWORD BlitModulateClr
Definition: C4Draw.h:109
bool BlitModulated
Definition: C4Draw.h:108

Here is the caller graph for this function:

C4Rect C4Draw::GetClipRect ( ) const
inherited

Definition at line 730 of file C4Draw.cpp.

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

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

731 {
732  int iWdt=std::min(iClipX2, RenderTarget->Wdt-1)-iClipX1+1;
733  int iHgt=std::min(iClipY2, RenderTarget->Hgt-1)-iClipY1+1;
734  int iX=iClipX1; if (iX<0) { iWdt+=iX; iX=0; }
735  int iY=iClipY1; if (iY<0) { iHgt+=iY; iY=0; }
736  return C4Rect(iX, iY, iWdt, iHgt);
737 }
int Wdt
Definition: C4Surface.h:65
Definition: C4Rect.h:27
int Hgt
Definition: C4Surface.h:65
int32_t iClipY2
Definition: C4Draw.h:104
C4Surface * RenderTarget
Definition: C4Draw.h:107
int32_t iClipY1
Definition: C4Draw.h:104
int32_t iClipX1
Definition: C4Draw.h:104
int32_t iClipX2
Definition: C4Draw.h:104

Here is the caller graph for this function:

const C4FoWRegion* C4Draw::GetFoW ( ) const
inlineinherited

Definition at line 194 of file C4Draw.h.

References C4Draw::pFoW.

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

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

Here is the caller graph for this function:

C4Rect C4Draw::GetOutRect ( ) const
inherited

Definition at line 739 of file C4Draw.cpp.

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

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

740 {
741  return C4Rect(0, 0, RenderTarget->Wdt, RenderTarget->Hgt);
742 }
int Wdt
Definition: C4Surface.h:65
Definition: C4Rect.h:27
int Hgt
Definition: C4Surface.h:65
C4Surface * RenderTarget
Definition: C4Draw.h:107

Here is the caller graph for this function:

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

Definition at line 722 of file C4Draw.cpp.

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

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

723 {
724  // Store drawing clip values
725  rX1=fClipX1; rY1=fClipY1; rX2=fClipX2; rY2=fClipY2;
726  // Done
727  return true;
728 }
float fClipY2
Definition: C4Draw.h:102
float fClipY1
Definition: C4Draw.h:102
float fClipX2
Definition: C4Draw.h:102
float fClipX1
Definition: C4Draw.h:102

Here is the caller graph for this function:

const StdProjectionMatrix& CStdGL::GetProjectionMatrix ( ) const
inline

Definition at line 251 of file C4DrawGL.h.

References ProjectionMatrix.

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

251 { return ProjectionMatrix; }
StdProjectionMatrix ProjectionMatrix
Definition: C4DrawGL.h:184

Here is the caller graph for this function:

C4Shader * CStdGL::GetSpriteShader ( int  ssc)

Definition at line 674 of file C4DrawGL.cpp.

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

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

675 {
676  C4Shader* shaders[16] = {
677  &SpriteShader,
683 
694  };
695 
696  int index = 0;
697  if(ssc & C4SSC_LIGHT) index += 6;
698 
699  if(ssc & C4SSC_BASE)
700  {
701  index += 2;
702  if(ssc & C4SSC_OVERLAY)
703  index += 2;
704  if( (ssc & C4SSC_NORMAL) && (ssc & C4SSC_LIGHT))
705  index += 4;
706  }
707 
708  if(ssc & C4SSC_MOD2)
709  index += 1;
710 
711  assert(index < 16);
712  return shaders[index];
713 }
C4Shader SpriteShaderLightBaseNormalOverlay
Definition: C4DrawGL.h:205
C4Shader SpriteShaderBase
Definition: C4DrawGL.h:192
C4Shader SpriteShaderLightBaseNormalMod2
Definition: C4DrawGL.h:204
C4Shader SpriteShaderBaseOverlay
Definition: C4DrawGL.h:194
C4Shader SpriteShaderLightBaseOverlay
Definition: C4DrawGL.h:201
C4Shader SpriteShaderLightBaseMod2
Definition: C4DrawGL.h:200
C4Shader SpriteShaderBaseMod2
Definition: C4DrawGL.h:193
C4Shader SpriteShaderBaseOverlayMod2
Definition: C4DrawGL.h:195
C4Shader SpriteShaderLightBaseNormalOverlayMod2
Definition: C4DrawGL.h:206
C4Shader SpriteShader
Definition: C4DrawGL.h:190
C4Shader SpriteShaderMod2
Definition: C4DrawGL.h:191
C4Shader SpriteShaderLightBaseOverlayMod2
Definition: C4DrawGL.h:202
C4Shader SpriteShaderLightBaseNormal
Definition: C4DrawGL.h:203
C4Shader SpriteShaderLight
Definition: C4DrawGL.h:197
C4Shader SpriteShaderLightBase
Definition: C4DrawGL.h:199
C4Shader SpriteShaderLightMod2
Definition: C4DrawGL.h:198

Here is the caller graph for this function:

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

Definition at line 663 of file C4DrawGL.cpp.

References C4GFXBLIT_MOD2, C4Draw::dwBlitMode, GetSpriteShader(), and C4Draw::pFoW.

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

Here is the call graph for this function:

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

Definition at line 191 of file C4Draw.cpp.

References C4Surface::GetSurfaceSize().

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

Here is the call graph for this function:

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

Definition at line 1013 of file C4DrawGL.cpp.

References CStdGLCtx::hVAOs, pCurrCtx, and VAOIDs.

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

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

Here is the caller graph for this function:

void C4Draw::GetZoom ( ZoomData r)
inlineinherited

Definition at line 197 of file C4Draw.h.

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().

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

Here is the caller graph for this function:

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

Definition at line 880 of file C4DrawGL.cpp.

Referenced by CheckGLError().

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

Here is the caller graph for this function:

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

Definition at line 701 of file C4Draw.cpp.

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

Referenced by C4FacetSurface::Grayscale().

702 {
703  // safety
704  if (!sfcSfc) return;
705  // change colors
706  int xcnt,ycnt,wdt=sfcSfc->Wdt,hgt=sfcSfc->Hgt;
707  // Lock surface
708  if (!sfcSfc->Lock()) return;
709  for (ycnt=0; ycnt<hgt; ycnt++)
710  {
711  for (xcnt=0; xcnt<wdt; xcnt++)
712  {
713  DWORD dwColor = sfcSfc->GetPixDw(xcnt,ycnt,false);
714  uint32_t r = GetRedValue(dwColor), g = GetGreenValue(dwColor), b = GetBlueValue(dwColor), a = dwColor >> 24;
715  int32_t gray = Clamp<int32_t>((r + g + b) / 3 + iOffset, 0, 255);
716  sfcSfc->SetPixDw(xcnt, ycnt, RGBA(gray, gray, gray, a));
717  }
718  }
719  sfcSfc->Unlock();
720 }
int Wdt
Definition: C4Surface.h:65
#define GetGreenValue(rgb)
Definition: StdColors.h:28
#define b
bool Lock()
Definition: C4Surface.cpp:453
bool Unlock()
Definition: C4Surface.cpp:464
#define a
#define GetRedValue(rgb)
Definition: StdColors.h:29
int Hgt
Definition: C4Surface.h:65
#define GetBlueValue(rgb)
Definition: StdColors.h:27
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:576
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:491
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:22
uint32_t DWORD

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 815 of file C4Draw.cpp.

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

Referenced by DDrawInit().

816 {
817  this->pApp = pApp;
818 
819  pApp->pWindow->pSurface = new C4Surface(pApp, pApp->pWindow);
820 
821  if (!RestoreDeviceObjects())
822  return false;
823 
824  if (!CreatePrimaryClipper(iXRes, iYRes))
825  return Error(" Clipper failure.");
826 
827  return true;
828 }
virtual bool RestoreDeviceObjects()=0
C4Surface * pSurface
Definition: C4Window.h:274
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
Definition: C4Draw.cpp:507
virtual bool Error(const char *szMsg)
Definition: C4Draw.cpp:500
friend class C4Surface
Definition: C4Draw.h:213
C4Window * pWindow
Definition: C4App.h:80
C4AbstractApp * pApp
Definition: C4Draw.h:95

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdGL::InitShaders ( C4GroupSet pGroups)

Definition at line 715 of file C4DrawGL.cpp.

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

Referenced by C4GraphicsResource::Init().

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdGL::InvalidateDeviceObjects ( )
overridevirtual

Implements C4Draw.

Definition at line 806 of file C4DrawGL.cpp.

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

Referenced by Clear(), and RestoreDeviceObjects().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Draw::LockingPrimary ( )
inlineinherited

Definition at line 138 of file C4Draw.h.

138 { PrimaryLocked=true; }
bool PrimaryLocked
Definition: C4Draw.h:106
bool C4Draw::NoPrimaryClipper ( )
inherited

Definition at line 237 of file C4Draw.cpp.

References C4Draw::SetPrimaryClipper().

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

238 {
239  // apply maximum clipper
240  SetPrimaryClipper(0,0,439832,439832);
241  // Done
242  return true;
243 }
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 274 of file C4DrawGL.cpp.

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

275 {
276 #ifdef GL_KHR_debug
277  if (glObjectLabel)
278  glObjectLabel(identifier, name, length, label);
279 #endif
280 }

Here is the caller graph for this function:

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

Implements C4Draw.

Definition at line 907 of file C4DrawGL.cpp.

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

908 {
909  // Re-create primary clipper to adapt to new size.
910  CreatePrimaryClipper(iXRes, iYRes);
912  return true;
913 }
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
Definition: C4Draw.cpp:507
bool RestoreDeviceObjects() override
Definition: C4DrawGL.cpp:760

Here is the call graph for this function:

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

Implements C4Draw.

Definition at line 1024 of file C4DrawMeshGL.cpp.

References b, C4Draw::BlitModulateClr, C4Draw::BlitModulated, C4Draw::fUsePerspective, StdMesh::GetBoundingBox(), StdMesh::GetBoundingRadius(), C4Draw::GetClipRect(), StdMeshInstance::GetMesh(), C4Draw::GetOutRect(), C4Rect::Hgt, C4Draw::MeshTransform, ProjectionMatrix, StdMeshVector::Translate(), ControllerKeys::Up(), C4Rect::Wdt, StdMeshVector::x, C4Rect::x, StdMeshBox::x1, StdMeshBox::x2, StdMeshVector::y, C4Rect::y, StdMeshBox::y1, StdMeshBox::y2, StdMeshVector::z, StdMeshBox::z1, and StdMeshBox::z2.

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

Here is the call graph for this function:

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

Definition at line 598 of file C4DrawGL.cpp.

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

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

599 {
600  // Only direct rendering
601  assert(sfcTarget->IsRenderTarget());
602  if(!PrepareRendering(sfcTarget)) return;
603 
604  // Select a buffer
605  const unsigned int vbo_index = CurrentVBO;
607 
608  // Upload data into the buffer, resize buffer if necessary
609  glBindBuffer(GL_ARRAY_BUFFER, GenericVBOs[vbo_index]);
610  if (GenericVBOSizes[vbo_index] < n_vertices)
611  {
612  GenericVBOSizes[vbo_index] = n_vertices;
613  glBufferData(GL_ARRAY_BUFFER, n_vertices * sizeof(C4BltVertex), vertices, GL_STREAM_DRAW);
614  }
615  else
616  {
617  glBufferSubData(GL_ARRAY_BUFFER, 0, n_vertices * sizeof(C4BltVertex), vertices);
618  }
619 
620  // Choose the VAO that corresponds to the chosen VBO. Also, use one
621  // that supplies texture coordinates if we have texturing enabled.
622  GLuint vao;
623  const unsigned int vao_index = vbo_index + (has_tex ? N_GENERIC_VBOS : 0);
624  const unsigned int vao_id = GenericVAOs[vao_index];
625  const bool has_vao = GetVAO(vao_id, vao);
626  glBindVertexArray(vao);
627  if (!has_vao)
628  {
629  // Initialize VAO for this context
630  const GLuint position = shader_call->GetAttribute(C4SSA_Position);
631  const GLuint color = shader_call->GetAttribute(C4SSA_Color);
632  const GLuint texcoord = has_tex ? shader_call->GetAttribute(C4SSA_TexCoord) : 0;
633 
634  glEnableVertexAttribArray(position);
635  glEnableVertexAttribArray(color);
636  if (has_tex)
637  glEnableVertexAttribArray(texcoord);
638 
639 
640  glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, sizeof(C4BltVertex), reinterpret_cast<const uint8_t*>(offsetof(C4BltVertex, ftx)));
641  glVertexAttribPointer(color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(C4BltVertex), reinterpret_cast<const uint8_t*>(offsetof(C4BltVertex, color)));
642  if (has_tex)
643  glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(C4BltVertex), reinterpret_cast<const uint8_t*>(offsetof(C4BltVertex, tx)));
644  }
645 
646  switch (op)
647  {
648  case OP_POINTS:
649  glDrawArrays(GL_POINTS, 0, n_vertices);
650  break;
651  case OP_TRIANGLES:
652  glDrawArrays(GL_TRIANGLES, 0, n_vertices);
653  break;
654  default:
655  assert(false);
656  break;
657  }
658 
659  glBindVertexArray(0);
660  glBindBuffer(GL_ARRAY_BUFFER, 0);
661 }
static const unsigned int N_GENERIC_VBOS
Definition: C4DrawGL.h:215
unsigned int CurrentVBO
Definition: C4DrawGL.h:219
GLint GetAttribute(int iAttribute) const
Definition: C4Shader.h:194
GLuint GenericVBOs[N_GENERIC_VBOS]
Definition: C4DrawGL.h:217
bool GetVAO(unsigned int vaoid, GLuint &vao)
Definition: C4DrawGL.cpp:1013
unsigned int GenericVBOSizes[N_GENERIC_VBOS]
Definition: C4DrawGL.h:218
unsigned int GenericVAOs[N_GENERIC_VBOS *2]
Definition: C4DrawGL.h:223
bool PrepareRendering(C4Surface *sfcToSurface) override
Definition: C4DrawGL.cpp:169
bool IsRenderTarget()
Definition: C4Surface.cpp:144

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implements C4Draw.

Definition at line 522 of file C4DrawGL.cpp.

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

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

Here is the call graph for this function:

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

Implements C4Draw.

Definition at line 495 of file C4DrawGL.cpp.

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

496 {
497  // Draw on pixel center:
498  StdProjectionMatrix transform = StdProjectionMatrix::Translate(0.5f, 0.5f, 0.0f);
499 
500  // This is a workaround. Instead of submitting the whole vertex array to the GL, we do it
501  // in batches of 256 vertices. The intel graphics driver on Linux crashes with
502  // significantly larger arrays, such as 400. It's not clear to me why, maybe POINT drawing
503  // is just not very well tested.
504  const unsigned int BATCH_SIZE = 256;
505 
506  // Feed the vertices to the GL
507  if (!shader_call)
508  {
509  C4ShaderCall call(GetSpriteShader(false, false, false));
510  SetupMultiBlt(call, nullptr, 0, 0, 0, 0, &transform);
511  for(unsigned int i = 0; i < n_vertices; i += BATCH_SIZE)
512  PerformMultiBlt(sfcTarget, OP_POINTS, &vertices[i], std::min(n_vertices - i, BATCH_SIZE), false, &call);
513  }
514  else
515  {
516  SetupMultiBlt(*shader_call, nullptr, 0, 0, 0, 0, &transform);
517  for(unsigned int i = 0; i < n_vertices; i += BATCH_SIZE)
518  PerformMultiBlt(sfcTarget, OP_POINTS, &vertices[i], std::min(n_vertices - i, BATCH_SIZE), false, shader_call);
519  }
520 }
void SetupMultiBlt(C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
Definition: C4DrawGL.cpp:361
void PerformMultiBlt(C4Surface *sfcTarget, DrawOperation op, const C4BltVertex *vertices, unsigned int n_vertices, bool has_tex, C4ShaderCall *shader_call)
Definition: C4DrawGL.cpp:598
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:674

Here is the call graph for this function:

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 582 of file C4DrawGL.cpp.

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

583 {
584  // Feed the vertices to the GL
585  if (!shader_call)
586  {
587  C4ShaderCall call(GetSpriteShader(pTex != nullptr, pOverlay != nullptr, pNormal != nullptr));
588  SetupMultiBlt(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, &call);
590  }
591  else
592  {
593  SetupMultiBlt(*shader_call, pTransform, pTex ? pTex->texName : 0, pOverlay ? pOverlay->texName : 0, pNormal ? pNormal->texName : 0, dwOverlayModClr, nullptr);
594  PerformMultiBlt(sfcTarget, OP_TRIANGLES, vertices, n_vertices, pTex != nullptr, shader_call);
595  }
596 }
void SetupMultiBlt(C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
Definition: C4DrawGL.cpp:361
unsigned int texName
Definition: C4Surface.h:155
void PerformMultiBlt(C4Surface *sfcTarget, DrawOperation op, const C4BltVertex *vertices, unsigned int n_vertices, bool has_tex, C4ShaderCall *shader_call)
Definition: C4DrawGL.cpp:598
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:674

Here is the call graph for this function:

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

Implements C4Draw.

Definition at line 272 of file C4DrawMeshGL.cpp.

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.

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 }
const char * getData() const
Definition: StdBuf.h:442
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
StdMeshMaterialShaderParameters Parameters
ShaderInstance FragmentShader
ShaderInstance GeometryShader
const StdMeshMaterialShader * Shader
ShaderInstance VertexShader
unsigned int texName
Definition: C4Surface.h:155
std::shared_ptr< ProgramInstance > Program
std::vector< StdMeshMaterialPass > Passes
struct CStdGL::@10 Workarounds
std::vector< StdMeshMaterialTextureUnit > TextureUnits
bool Log(const char *szMessage)
Definition: C4Log.cpp:192
StdCopyStrBuf Name
const StdMeshMaterialProgram * AddProgram(const char *name, StdMeshMaterialLoader &loader, const StdMeshMaterialPass::ShaderInstance &fragment_shader, const StdMeshMaterialPass::ShaderInstance &vertex_shader, const StdMeshMaterialPass::ShaderInstance &geometry_shader)
size_t getLength() const
Definition: StdBuf.h:445
std::vector< StdMeshMaterialTechnique > Techniques
const StdMeshMaterialShader * AddShader(const char *filename, const char *name, const char *language, StdMeshMaterialShaderType type, const char *text, uint32_t load_flags)
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270

Here is the call graph for this function:

bool CStdGL::PrepareRendering ( C4Surface sfcToSurface)
overridevirtual

Implements C4Draw.

Definition at line 169 of file C4DrawGL.cpp.

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().

170 {
171  // call from gfx thread only!
172  if (!pApp || !pApp->AssertMainThread()) return false;
173  // not ready?
174  if (!Active)
175  return false;
176  // target?
177  if (!sfcToSurface) return false;
178  // target locked?
179  if (sfcToSurface->Locked) return false;
180  // target is already set as render target?
181  if (sfcToSurface != RenderTarget)
182  {
183  // target is a render-target?
184  if (!sfcToSurface->IsRenderTarget()) return false;
185  // context
186  if (sfcToSurface->pCtx && sfcToSurface->pCtx != pCurrCtx)
187  if (!sfcToSurface->pCtx->Select()) return false;
188  // set target
189  RenderTarget=sfcToSurface;
190  // new target has different size; needs other clipping rect
191  UpdateClipper();
192  }
193  // done
194  return true;
195 }
bool AssertMainThread()
Definition: C4App.h:123
virtual bool Select(bool verbose=false)
bool Active
Definition: C4Draw.h:96
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
CStdGLCtx * pCtx
Definition: C4Surface.h:76
bool UpdateClipper() override
Definition: C4DrawGL.cpp:151
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool IsRenderTarget()
Definition: C4Surface.cpp:144
int Locked
Definition: C4Surface.h:87
C4AbstractApp * pApp
Definition: C4Draw.h:95

Here is the call graph for this function:

Here is the caller graph for this function:

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 198 of file C4DrawGL.cpp.

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, C4Shader::Clear(), C4Shader::ClearSlices(), C4Shader::Init(), C4Shader::LoadFragmentSlices(), C4Shader::LoadVertexSlices(), and C4Shader::SetScriptCategories().

Referenced by InitShaders().

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Draw::PrimaryUnlocked ( )
inlineinherited

Definition at line 139 of file C4Draw.h.

139 { PrimaryLocked=false; }
bool PrimaryLocked
Definition: C4Draw.h:106
void C4Draw::RemoveZoom ( float &  X,
float &  Y 
)
inherited

Definition at line 790 of file C4Draw.cpp.

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

791 {
792  X = (X - ZoomX) / Zoom + ZoomX;
793  Y = (Y - ZoomY) / Zoom + ZoomY;
794 }
float ZoomY
Definition: C4Draw.h:112
float ZoomX
Definition: C4Draw.h:112
float Zoom
Definition: C4Draw.h:116
#define X(sdl, oc)
bool C4Draw::RenderMesh ( StdMeshInstance instance,
C4Surface sfcTarget,
float  tx,
float  ty,
float  twdt,
float  thgt,
DWORD  dwPlayerColor,
C4BltTransform pTransform 
)
inherited

Definition at line 403 of file C4Draw.cpp.

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Draw::ResetBlitMode ( )
inlineinherited
void C4Draw::ResetGamma ( )
inherited

Definition at line 760 of file C4Draw.cpp.

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

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

761 {
762  for (auto & i : gamma) {
763  i[0] = 1.0f;
764  i[1] = 1.0f;
765  i[2] = 1.0f;
766  }
767  gammaOut[0] = 1.0f;
768  gammaOut[1] = 1.0f;
769  gammaOut[2] = 1.0f;
770 }
float gammaOut[3]
Definition: C4Draw.h:98
float gamma[C4MaxGammaRamps][3]
Definition: C4Draw.h:97

Here is the caller graph for this function:

bool CStdGL::RestoreDeviceObjects ( )
overridevirtual

Implements C4Draw.

Definition at line 760 of file C4DrawGL.cpp.

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().

761 {
762  assert(pMainCtx);
763  // delete any previous objects
765 
766  // set states
767  Active = pMainCtx->Select();
769 
770  // lines texture
771  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
772  glGenTextures(1, &lines_tex);
773  glBindTexture(GL_TEXTURE_2D, lines_tex);
774  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
775  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
776  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
777  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
778  static const char * linedata = "\xff\xff\xff\x00\xff\xff\xff\xff";
779  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, linedata);
780 
781  MaxTexSize = 64;
782  GLint s = 0;
783  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s);
784  if (s>0) MaxTexSize = s;
785 
786  // Generic VBOs
787  glGenBuffers(N_GENERIC_VBOS, GenericVBOs);
788  for (unsigned int i = 0; i < N_GENERIC_VBOS; ++i)
789  {
791  glBindBuffer(GL_ARRAY_BUFFER, GenericVBOs[i]);
792  glBufferData(GL_ARRAY_BUFFER, GenericVBOSizes[i] * sizeof(C4BltVertex), nullptr, GL_STREAM_DRAW);
793  GenericVAOs[i] = GenVAOID();
795  }
796 
797  glBindBuffer(GL_ARRAY_BUFFER, 0);
798 
799  // reset blit states
800  dwBlitMode = 0;
801 
802  // done
803  return Active;
804 }
int MaxTexSize
Definition: C4Draw.h:99
virtual bool Select(bool verbose=false)
static const unsigned int N_GENERIC_VBOS
Definition: C4DrawGL.h:215
bool Active
Definition: C4Draw.h:96
C4Surface * pSurface
Definition: C4Window.h:274
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:178
GLuint GenericVBOs[N_GENERIC_VBOS]
Definition: C4DrawGL.h:217
GLuint lines_tex
Definition: C4DrawGL.h:181
unsigned int GenericVBOSizes[N_GENERIC_VBOS]
Definition: C4DrawGL.h:218
unsigned int GenericVAOs[N_GENERIC_VBOS *2]
Definition: C4DrawGL.h:223
unsigned int GenVAOID()
Definition: C4DrawGL.cpp:925
static const unsigned int GENERIC_VBO_SIZE
Definition: C4DrawGL.h:216
C4Surface * RenderTarget
Definition: C4Draw.h:107
DWORD dwBlitMode
Definition: C4Draw.h:110
bool InvalidateDeviceObjects() override
Definition: C4DrawGL.cpp:806
#define s
C4Window * pWindow
Definition: C4App.h:80
C4AbstractApp * pApp
Definition: C4Draw.h:95

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Draw::RestorePrimaryClipper ( )
inherited

Definition at line 210 of file C4Draw.cpp.

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

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

211 {
212  // Restore primary clipper
214  return true;
215 }
float fStClipY1
Definition: C4Draw.h:103
float fStClipX2
Definition: C4Draw.h:103
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217
float fStClipY2
Definition: C4Draw.h:103
float fStClipX1
Definition: C4Draw.h:103

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Draw::SetBlitMode ( DWORD  dwBlitMode)
inlineinherited

Definition at line 191 of file C4Draw.h.

References C4GFXBLIT_ALL.

Referenced by C4MouseControl::Draw(), C4GraphicsOverlay::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().

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

Here is the caller graph for this function:

void C4Draw::SetFoW ( const C4FoWRegion fow)
inlineinherited

Definition at line 193 of file C4Draw.h.

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

193 { pFoW = fow; }
const C4FoWRegion * pFoW
Definition: C4Draw.h:111

Here is the caller graph for this function:

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

Definition at line 744 of file C4Draw.cpp.

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

Referenced by C4Game::SetDefaultGamma(), and C4Weather::SetSeasonGamma().

745 {
746  // Set
747  gamma[iRampIndex][0] = r;
748  gamma[iRampIndex][1] = g;
749  gamma[iRampIndex][2] = b;
750  // Recalculate resulting gamma. Note that we flip gamma direction here,
751  // because higher gammaOut means darker.
752  gammaOut[0] = gammaOut[1] = gammaOut[2] = 1.0f;
753  for (auto & i : gamma) {
754  gammaOut[0] /= i[0];
755  gammaOut[1] /= i[1];
756  gammaOut[2] /= i[2];
757  }
758 }
#define b
float gammaOut[3]
Definition: C4Draw.h:98
float gamma[C4MaxGammaRamps][3]
Definition: C4Draw.h:97

Here is the caller graph for this function:

void C4Draw::SetMeshTransform ( const StdMeshMatrix *  Transform)
inlineinherited

Definition at line 200 of file C4Draw.h.

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

200 { MeshTransform = Transform; } // if non-nullptr make sure to keep matrix valid
const StdMeshMatrix * MeshTransform
Definition: C4Draw.h:113

Here is the caller graph for this function:

void C4Draw::SetPerspective ( bool  fSet)
inlineinherited

Definition at line 201 of file C4Draw.h.

Referenced by C4DefGraphics::Draw().

201 { fUsePerspective = fSet; }
bool fUsePerspective
Definition: C4Draw.h:114

Here is the caller graph for this function:

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

Definition at line 217 of file C4Draw.cpp.

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

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

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 }
float fClipY2
Definition: C4Draw.h:102
float fClipY1
Definition: C4Draw.h:102
int32_t iClipY2
Definition: C4Draw.h:104
float fClipX2
Definition: C4Draw.h:102
int32_t iClipY1
Definition: C4Draw.h:104
virtual bool UpdateClipper()=0
int32_t iClipX1
Definition: C4Draw.h:104
float fClipX1
Definition: C4Draw.h:102
int32_t iClipX2
Definition: C4Draw.h:104

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 361 of file C4DrawGL.cpp.

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(), C4BltTransform::mat, C4Draw::pFoW, ProjectionMatrix, C4Draw::scriptUniform, C4ShaderCall::SetUniform1f(), C4ShaderCall::SetUniform3fv(), C4ShaderCall::SetUniform4fv(), C4ShaderCall::SetUniformMatrix2x3fv(), C4ShaderCall::SetUniformMatrix3x3Transpose(), C4ShaderCall::SetUniformMatrix4x4(), C4ShaderCall::Start(), C4FoWAmbient::Tex, C4Draw::Zoom, C4Draw::ZoomX, and C4Draw::ZoomY.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 779 of file C4Draw.cpp.

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().

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

Here is the caller graph for this function:

void C4Draw::SetZoom ( const ZoomData zoom)
inlineinherited

Definition at line 196 of file C4Draw.h.

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

Referenced by C4Draw::SetZoom().

196 { SetZoom(zoom.X, zoom.Y, zoom.Zoom); }
float Y
Definition: C4Draw.h:71
float X
Definition: C4Draw.h:71
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:779
float Zoom
Definition: C4Draw.h:70

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Draw::StorePrimaryClipper ( )
inherited

Definition at line 203 of file C4Draw.cpp.

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

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

204 {
205  // Store current primary clipper
207  return true;
208 }
float fClipY2
Definition: C4Draw.h:102
float fClipY1
Definition: C4Draw.h:102
float fStClipY1
Definition: C4Draw.h:103
float fStClipX2
Definition: C4Draw.h:103
float fStClipY2
Definition: C4Draw.h:103
float fClipX2
Definition: C4Draw.h:102
float fStClipX1
Definition: C4Draw.h:103
float fClipX1
Definition: C4Draw.h:102

Here is the caller graph for this function:

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 576 of file C4Draw.cpp.

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

577 {
578  // init markup
579  C4Markup Markup(true);
580  // output string
581  return StringOut(szText, sfcDest, iTx, iTy, dwFCol, byForm, fDoMarkup, Markup, &rFont, fZoom);
582 }
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:576

Here is the caller graph for this function:

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 584 of file C4Draw.cpp.

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

585 {
586  // clip
587  if (ClipAll) return true;
588  // safety
589  if (!PrepareRendering(sfcDest)) return false;
590  // convert align
591  int iFlags=0;
592  switch (byForm)
593  {
594  case ACenter: iFlags |= STDFONT_CENTERED; break;
595  case ARight: iFlags |= STDFONT_RIGHTALGN; break;
596  }
597  if (!fDoMarkup) iFlags|=STDFONT_NOMARKUP;
598  // draw text
599  pFont->DrawText(sfcDest, iTx , iTy , dwFCol, szText, iFlags, Markup, fZoom);
600  // done, success
601  return true;
602 }
#define STDFONT_NOMARKUP
Definition: C4FontLoader.h:33
#define STDFONT_CENTERED
Definition: C4FontLoader.h:28
const int ARight
Definition: C4Surface.h:41
virtual bool PrepareRendering(C4Surface *sfcToSurface)=0
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)
bool ClipAll
Definition: C4Draw.h:105
#define STDFONT_RIGHTALGN
Definition: C4FontLoader.h:31

Here is the call graph for this function:

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

Definition at line 196 of file C4Draw.cpp.

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

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

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 }
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:217
int32_t iClipY2
Definition: C4Draw.h:104
int32_t iClipY1
Definition: C4Draw.h:104
int32_t iClipX1
Definition: C4Draw.h:104
int32_t iClipX2
Definition: C4Draw.h:104

Here is the call graph for this function:

Here is the caller graph for this function:

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 567 of file C4Draw.cpp.

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

Referenced by C4UpperBoard::Draw(), C4LoaderScreen::Draw(), C4GameMessage::Draw(), C4IDList::Draw(), C4Object::Draw(), C4ScriptGuiWindow::Draw(), C4GUI::Tabular::Sheet::DrawCaption(), C4Game::DrawCrewOverheadText(), C4StartupMainDlg::DrawElement(), C4ScoreboardDlg::DrawElement(), C4MenuItem::DrawElement(), C4Chart::DrawElement(), 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(), C4Viewport::DrawMenu(), C4Viewport::DrawPlayerStartup(), C4Network2::DrawStatus(), C4GUI::Screen::DrawToolTip(), C4Facet::DrawValue(), and C4Facet::DrawValue2().

568 {
569  C4Markup Markup(true);
570  static char szLinebuf[2500+1];
571  for (int cnt=0; SCopySegmentEx(szText,cnt,szLinebuf,fDoMarkup ? '|' : '\n','\n',2500); cnt++,iTy+=int(fZoom*rFont.GetLineHeight()))
572  if (!StringOut(szLinebuf,sfcDest,iTx,iTy,dwFCol,byForm,fDoMarkup,Markup,&rFont,fZoom)) return false;
573  return true;
574 }
int GetLineHeight() const
Definition: C4FontLoader.h:125
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:576
bool SCopySegmentEx(const char *szString, int iSegment, char *sTarget, char cSep1, char cSep2, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:292

Here is the call graph for this function:

Here is the caller graph for this function:

bool CStdGL::UpdateClipper ( )
overridevirtual

Implements C4Draw.

Definition at line 151 of file C4DrawGL.cpp.

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

Referenced by PrepareRendering().

152 {
153  // no render target? do nothing
154  if (!RenderTarget || !Active) return true;
155  // negative/zero?
156  C4Rect clipRect = GetClipRect();
157  if (clipRect.Wdt<=0 || clipRect.Hgt<=0)
158  {
159  ClipAll=true;
160  return true;
161  }
162  ClipAll=false;
163  // set it
164  glViewport(clipRect.x, RenderTarget->Hgt-clipRect.y-clipRect.Hgt, clipRect.Wdt, clipRect.Hgt);
165  ProjectionMatrix = StdProjectionMatrix::Orthographic(clipRect.x, clipRect.x + clipRect.Wdt, clipRect.y + clipRect.Hgt, clipRect.y);
166  return true;
167 }
bool Active
Definition: C4Draw.h:96
Definition: C4Rect.h:27
int Hgt
Definition: C4Surface.h:65
int32_t Wdt
Definition: C4Rect.h:30
int32_t y
Definition: C4Rect.h:30
int32_t x
Definition: C4Rect.h:30
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool ClipAll
Definition: C4Draw.h:105
int32_t Hgt
Definition: C4Rect.h:30
C4Rect GetClipRect() const
Definition: C4Draw.cpp:730
StdProjectionMatrix ProjectionMatrix
Definition: C4DrawGL.h:184

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4FoWRegion
friend

Definition at line 296 of file C4DrawGL.h.

friend class C4FullScreen
friend

Definition at line 293 of file C4DrawGL.h.

friend class C4Pattern
friend

Definition at line 290 of file C4DrawGL.h.

friend class C4ShaderCall
friend

Definition at line 295 of file C4DrawGL.h.

friend class C4StartupOptionsDlg
friend

Definition at line 292 of file C4DrawGL.h.

friend class C4Surface
friend

Definition at line 288 of file C4DrawGL.h.

friend class C4TexRef
friend

Definition at line 289 of file C4DrawGL.h.

friend class C4Window
friend

Definition at line 294 of file C4DrawGL.h.

friend class CStdGLCtx
friend

Definition at line 291 of file C4DrawGL.h.

Referenced by CreateContext().

Member Data Documentation

DWORD C4Draw::BlitModulateClr
protectedinherited
bool C4Draw::BlitModulated
protectedinherited
bool C4Draw::ClipAll
protectedinherited

Definition at line 105 of file C4Draw.h.

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

constexpr int C4Draw::COLOR_DEPTH = 32
staticinherited
constexpr int C4Draw::COLOR_DEPTH_BYTES = COLOR_DEPTH / 8
staticinherited

Definition at line 90 of file C4Draw.h.

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

unsigned int CStdGL::CurrentVBO {0}
protected

Definition at line 219 of file C4DrawGL.h.

Referenced by InvalidateDeviceObjects(), and PerformMultiBlt().

DWORD C4Draw::dwBlitMode
protectedinherited
float C4Draw::fClipX1
protectedinherited
float C4Draw::fClipX2
protectedinherited
float C4Draw::fClipY1
protectedinherited
float C4Draw::fClipY2
protectedinherited
float C4Draw::fStClipX1
protectedinherited

Definition at line 103 of file C4Draw.h.

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

float C4Draw::fStClipX2
protectedinherited

Definition at line 103 of file C4Draw.h.

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

float C4Draw::fStClipY1
protectedinherited

Definition at line 103 of file C4Draw.h.

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

float C4Draw::fStClipY2
protectedinherited

Definition at line 103 of file C4Draw.h.

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

bool C4Draw::fUsePerspective
protectedinherited

Definition at line 114 of file C4Draw.h.

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

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

Definition at line 97 of file C4Draw.h.

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

float C4Draw::gammaOut[3]
inherited
const unsigned int CStdGL::GENERIC_VBO_SIZE = 3 * 64
staticprotected

Definition at line 216 of file C4DrawGL.h.

Referenced by RestoreDeviceObjects().

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

Definition at line 223 of file C4DrawGL.h.

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

GLuint CStdGL::GenericVBOs[N_GENERIC_VBOS]
protected

Definition at line 217 of file C4DrawGL.h.

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

unsigned int CStdGL::GenericVBOSizes[N_GENERIC_VBOS]
protected

Definition at line 218 of file C4DrawGL.h.

Referenced by PerformMultiBlt(), and RestoreDeviceObjects().

int32_t C4Draw::iClipX1
protectedinherited
int32_t C4Draw::iClipX2
protectedinherited
int32_t C4Draw::iClipY1
protectedinherited
int32_t C4Draw::iClipY2
protectedinherited
int CStdGL::iPixelFormat
protected

Definition at line 175 of file C4DrawGL.h.

Referenced by Default().

GLuint CStdGL::lines_tex
protected
int C4Draw::MaxTexSize {0}
inherited
const StdMeshMatrix* C4Draw::MeshTransform
protectedinherited

Definition at line 113 of file C4Draw.h.

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

const unsigned int CStdGL::N_GENERIC_VBOS = 16
staticprotected

Definition at line 215 of file C4DrawGL.h.

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

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

Definition at line 227 of file C4DrawGL.h.

Referenced by FreeVAOID(), and GenVAOID().

C4AbstractApp* C4Draw::pApp
inherited
const C4FoWRegion* C4Draw::pFoW
protectedinherited

Definition at line 111 of file C4Draw.h.

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

CStdGLCtx* CStdGL::pMainCtx {nullptr}
protected
bool C4Draw::PrimaryLocked
protectedinherited

Definition at line 106 of file C4Draw.h.

StdProjectionMatrix CStdGL::ProjectionMatrix
protected

Definition at line 184 of file C4DrawGL.h.

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

C4Surface* C4Draw::RenderTarget
protectedinherited
C4ScriptUniform C4Draw::scriptUniform
inherited
GLenum CStdGL::sfcFmt
protected

Definition at line 177 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShader
protected

Definition at line 190 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderBase
protected

Definition at line 192 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderBaseMod2
protected

Definition at line 193 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderBaseOverlay
protected

Definition at line 194 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderBaseOverlayMod2
protected

Definition at line 195 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLight
protected

Definition at line 197 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBase
protected

Definition at line 199 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseMod2
protected

Definition at line 200 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseNormal
protected

Definition at line 203 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseNormalMod2
protected

Definition at line 204 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseNormalOverlay
protected

Definition at line 205 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseNormalOverlayMod2
protected

Definition at line 206 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseOverlay
protected

Definition at line 201 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightBaseOverlayMod2
protected

Definition at line 202 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderLightMod2
protected

Definition at line 198 of file C4DrawGL.h.

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

C4Shader CStdGL::SpriteShaderMod2
protected

Definition at line 191 of file C4DrawGL.h.

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

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

Definition at line 226 of file C4DrawGL.h.

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

struct { ... } CStdGL::Workarounds

Referenced by Default(), and PrepareMaterial().

float C4Draw::ZoomX
protectedinherited
float C4Draw::ZoomY
protectedinherited

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