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 ()
 
unsigned int GenVAOID ()
 
void FreeVAOID (unsigned int vaoid)
 
bool GetVAO (unsigned int vaoid, GLuint &vao)
 
void Clear () override
 
void Default () override
 
virtual bool OnResolutionChanged (unsigned int iXRes, unsigned int iYRes) override
 
bool UpdateClipper () override
 
const StdProjectionMatrix & GetProjectionMatrix () const
 
virtual bool PrepareMaterial (StdMeshMatManager &mat_manager, StdMeshMaterialLoader &loader, StdMeshMaterial &mat) override
 
virtual bool PrepareRendering (C4Surface *sfcToSurface) override
 
virtual bool PrepareSpriteShader (C4Shader &shader, const char *name, int ssc, C4GroupSet *pGroups, const char *const *additionalDefines, const char *const *additionalSlices) override
 
bool EnsureMainContextSelected () override
 
virtual CStdGLCtxCreateContext (C4Window *pWindow, C4AbstractApp *pApp) override
 
void SetupMultiBlt (C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
 
virtual void PerformMesh (StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform) override
 
void FillBG (DWORD dwClr=0) override
 
virtual void PerformMultiPix (C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, C4ShaderCall *shader_call) override
 
virtual void PerformMultiLines (C4Surface *sfcTarget, const C4BltVertex *vertices, unsigned int n_vertices, float width, C4ShaderCall *shader_call) override
 
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) 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
 
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)
 
virtual 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
 
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
 
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 107 of file C4DrawGL.cpp.

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

107  :
108  pMainCtx(0), CurrentVBO(0), NextVAOID(VAOIDs.end())
109 {
110  GenericVBOs[0] = 0;
111  Default();
112  // global ptr
113  pGL = this;
114  lines_tex = 0;
115 }
unsigned int CurrentVBO
Definition: C4DrawGL.h:219
std::set< unsigned int >::iterator NextVAOID
Definition: C4DrawGL.h:227
CStdGLCtx * pMainCtx
Definition: C4DrawGL.h:178
GLuint GenericVBOs[N_GENERIC_VBOS]
Definition: C4DrawGL.h:217
void Default() override
Definition: C4DrawGL.cpp:924
GLuint lines_tex
Definition: C4DrawGL.h:181
std::set< unsigned int > VAOIDs
Definition: C4DrawGL.h:226
CStdGL * pGL
Definition: C4DrawGL.cpp:914

Here is the call graph for this function:

CStdGL::~CStdGL ( )

Definition at line 117 of file C4DrawGL.cpp.

References Clear(), and pGL.

118 {
119  Clear();
120  pGL=nullptr;
121 }
void Clear() override
Definition: C4DrawGL.cpp:123
CStdGL * pGL
Definition: C4DrawGL.cpp:914

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

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

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

Definition at line 230 of file C4Draw.cpp.

231 {
232  return true;
233 }
void C4Draw::ApplyZoom ( float &  X,
float &  Y 
)
inherited

Definition at line 787 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().

788 {
789  X = (X - ZoomX) * Zoom + ZoomX;
790  Y = (Y - ZoomY) * Zoom + ZoomY;
791 }
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 304 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().

307 {
308  return BlitUnscaled(sfcSource, fx * sfcSource->Scale, fy * sfcSource->Scale, fwdt * sfcSource->Scale, fhgt * sfcSource->Scale,
309  sfcTarget, tx, ty, twdt, thgt, fSrcColKey, pTransform);
310 }
int Scale
Definition: C4Surface.h:68
bool BlitUnscaled(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:312

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

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

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

References C4Draw::Blit().

250 {
251  Blit(sfcSource, fx, fy, wdt, hgt, sfcTarget, tx, ty, wdt, hgt, false);
252 }
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:304

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

475 {
476  // rendertarget?
477  if (sfcTarget->IsRenderTarget())
478  {
479  return Blit(sfcSource, float(fx), float(fy), float(fwdt), float(fhgt), sfcTarget, float(tx), float(ty), float(twdt), float(thgt), true);
480  }
481  // Object is first stretched to dest rect
482  int xcnt,ycnt,tcx,tcy,cpcx,cpcy;
483  if (!fwdt || !fhgt || !twdt || !thgt) return false;
484  // Lock the surfaces
485  if (!sfcSource->Lock())
486  return false;
487  if (!sfcTarget->Lock())
488  { sfcSource->Unlock(); return false; }
489  // Rectangle centers
490  tcx=twdt/2; tcy=thgt/2;
491  for (ycnt=0; ycnt<thgt; ycnt++)
492  if (Inside(cpcy=ty+tcy-thgt/2+ycnt,0,sfcTarget->Hgt-1))
493  for (xcnt=0; xcnt<twdt; xcnt++)
494  if (Inside(cpcx=tx+tcx-twdt/2+xcnt,0,sfcTarget->Wdt-1))
495  sfcTarget->BltPix(cpcx, cpcy, sfcSource, xcnt*fwdt/twdt+fx, ycnt*fhgt/thgt+fy, fTransparency);
496  // Unlock the surfaces
497  sfcSource->Unlock();
498  sfcTarget->Unlock();
499  return true;
500 }
int Wdt
Definition: C4Surface.h:67
bool Lock()
Definition: C4Surface.cpp:463
bool Unlock()
Definition: C4Surface.cpp:474
int Hgt
Definition: C4Surface.h:67
bool BltPix(int iX, int iY, C4Surface *sfcSource, int iSrcX, int iSrcY, bool fTransparency)
Definition: C4Surface.cpp:601
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:304
bool IsRenderTarget()
Definition: C4Surface.cpp:154
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:45

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

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

Referenced by C4Surface::Copy().

521 {
522  if (fBlitBase)
523  {
524  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
525  return true;
526  }
527  else
528  {
529  if (!sfcSurface) return false;
530  C4Surface *pSfcBase = sfcSurface->pMainSfc;
531  sfcSurface->pMainSfc = nullptr;
532  Blit(sfcSurface, 0.0f, 0.0f, (float)sfcSurface->Wdt, (float)sfcSurface->Hgt, sfcTarget, float(tx), float(ty), float(sfcSurface->Wdt), float(sfcSurface->Hgt), false);
533  sfcSurface->pMainSfc = pSfcBase;
534  return true;
535  }
536 }
int Wdt
Definition: C4Surface.h:67
int Hgt
Definition: C4Surface.h:67
bool Blit(C4Surface *sfcSource, float fx, float fy, float fwdt, float fhgt, C4Surface *sfcTarget, float tx, float ty, float twdt, float thgt, bool fSrcColKey=false, const C4BltTransform *pTransform=nullptr)
Definition: C4Draw.cpp:304
C4Surface * pMainSfc
Definition: C4Surface.h:81

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

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

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

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

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

References GLErrorString(), and LogF().

906 {
907  GLenum err = glGetError();
908  if (!err) return true;
909 
910  LogF("GL error with %s: %d - %s", szAtOp, err, GLErrorString(err));
911  return false;
912 }
const char * GLErrorString(GLenum code)
Definition: C4DrawGL.cpp:889
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

Here is the call graph for this function:

void CStdGL::Clear ( )
overridevirtual

Reimplemented from C4Draw.

Definition at line 123 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().

124 {
126  // cannot unlock TexMgr here or we can't preserve textures across GL reinitialization as required when changing multisampling
129  RenderTarget = nullptr;
130  // Clear all shaders
147  // clear context
148  if (pCurrCtx) pCurrCtx->Deselect();
149  pMainCtx=0;
150  C4Draw::Clear();
151 }
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:337
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:187
bool NoPrimaryClipper()
Definition: C4Draw.cpp:240
bool InvalidateDeviceObjects() override
Definition: C4DrawGL.cpp:815
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 291 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().

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

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

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

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

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

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

Referenced by CStdGL().

925 {
926  C4Draw::Default();
927  pCurrCtx = nullptr;
928  iPixelFormat=0;
929  sfcFmt=0;
930  Workarounds.LowMaxVertexUniformCount = false;
931  Workarounds.ForceSoftwareTransform = false;
932 }
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:172

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

236 {
237  return true;
238 }
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 849 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().

850 {
851  if (!sfcDest->IsRenderTarget())
852  {
853  // Box on non-render target: Emulate by setting pixels
854  if (!sfcDest->Lock()) return;
855  for (int y = iY1; y <= iY2; ++y)
856  for (int x = iX1; x <= iX2; ++x)
857  sfcDest->SetPixDw(x,y, dwClr);
858  sfcDest->Unlock();
859  }
860  else
861  {
862  DrawBoxFade(sfcDest, float(iX1), float(iY1), float(iX2 - iX1 + 1), float(iY2 - iY1 + 1), dwClr, dwClr, dwClr, dwClr, nullptr);
863  }
864 }
bool Lock()
Definition: C4Surface.cpp:463
bool Unlock()
Definition: C4Surface.cpp:474
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:586
void DrawBoxFade(C4Surface *sfcDest, float iX, float iY, float iWdt, float iHgt, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, C4ShaderCall *shader_call)
Definition: C4Draw.cpp:833
bool IsRenderTarget()
Definition: C4Surface.cpp:154

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

References C4Draw::DrawQuadDw().

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

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

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

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

Referenced by C4EditCursor::Draw().

628 {
629  // Draw as line segments
630  int32_t num_lines = 12 + int32_t(r / 10);
631  std::unique_ptr<C4BltVertex[]> vertices(new C4BltVertex[num_lines * 2]);
632  for (int32_t i = 0; i < num_lines; ++i)
633  {
634  float ang = float(i) * 2 * M_PI / num_lines;
635  int32_t iv = i * 2 + 1;
636  vertices[iv].ftx = cx + sin(ang) * r;
637  vertices[iv].fty = cy + cos(ang) * r;
638  DwTo4UB(dwClr, vertices[iv].color);
639  vertices[(iv + 1) % (num_lines * 2)] = vertices[iv];
640  }
641  PerformMultiLines(sfcTarget, vertices.get(), num_lines * 2, width, nullptr);
642 }
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 644 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().

645 {
646  C4BltVertex vertices[8];
647  vertices[0].ftx = x1; vertices[0].fty = y1;
648  vertices[1].ftx = x2; vertices[1].fty = y1;
649  vertices[2] = vertices[1];
650  vertices[3].ftx = x2; vertices[3].fty = y2;
651  vertices[4] = vertices[3];
652  vertices[5].ftx = x1; vertices[5].fty = y2;
653  vertices[6] = vertices[5];
654  vertices[7] = vertices[0];
655 
656  for(int i = 0; i < 8; ++i)
657  DwTo4UB(dwClr, vertices[i].color);
658 
659  PerformMultiLines(sfcDest, vertices, 8, width, nullptr);
660 }
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 617 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().

618 {
619  C4BltVertex vertices[2];
620  vertices[0].ftx = x1; vertices[0].fty = y1;
621  vertices[1].ftx = x2; vertices[1].fty = y2;
622  DwTo4UB(dwClr, vertices[0].color);
623  DwTo4UB(dwClr, vertices[1].color);
624  PerformMultiLines(sfcTarget, vertices, 2, width, nullptr);
625 }
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 678 of file C4Draw.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 607 of file C4Draw.cpp.

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

Referenced by C4Draw::DrawPatternedCircle().

608 {
609  // Draw
610  C4BltVertex vtx;
611  vtx.ftx = tx;
612  vtx.fty = ty;
613  DwTo4UB(dwClr, vtx.color);
614  PerformMultiPix(sfcDest, &vtx, 1, nullptr);
615 }
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 662 of file C4Draw.cpp.

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

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

663 {
664  C4BltVertex vertices[6];
665  vertices[0].ftx = ipVtx[0]; vertices[0].fty = ipVtx[1];
666  vertices[1].ftx = ipVtx[2]; vertices[1].fty = ipVtx[3];
667  vertices[2].ftx = ipVtx[4]; vertices[2].fty = ipVtx[5];
668  vertices[3].ftx = ipVtx[6]; vertices[3].fty = ipVtx[7];
669  DwTo4UB(dwClr1, vertices[0].color);
670  DwTo4UB(dwClr2, vertices[1].color);
671  DwTo4UB(dwClr3, vertices[2].color);
672  DwTo4UB(dwClr4, vertices[3].color);
673  vertices[4] = vertices[0];
674  vertices[5] = vertices[2];
675  PerformMultiTris(sfcTarget, vertices, 6, nullptr, nullptr, nullptr, nullptr, 0, shader_call);
676 }
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 764 of file C4DrawGL.cpp.

References pMainCtx, and CStdGLCtx::Select().

765 {
766  return pMainCtx->Select();
767 }
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 862 of file C4DrawGL.cpp.

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

Referenced by CreateContext().

863 {
864 #ifdef USE_WIN32_WINDOWS
865  DWORD err = GetLastError();
866 #endif
867  bool r = C4Draw::Error(szMsg);
868 #ifdef USE_WIN32_WINDOWS
869  wchar_t * lpMsgBuf;
870  FormatMessage(
871  FORMAT_MESSAGE_ALLOCATE_BUFFER |
872  FORMAT_MESSAGE_FROM_SYSTEM |
873  FORMAT_MESSAGE_IGNORE_INSERTS,
874  nullptr,
875  err,
876  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
877  (LPTSTR) &lpMsgBuf,
878  0, nullptr );
879  LogF(" gl: GetLastError() = %d - %s", err, StdStrBuf(lpMsgBuf).getData());
880  LocalFree(lpMsgBuf);
881 #endif
882  LogF(" gl: %s", glGetString(GL_VENDOR));
883  LogF(" gl: %s", glGetString(GL_RENDERER));
884  LogF(" gl: %s", glGetString(GL_VERSION));
885  LogF(" gl: %s", glGetString(GL_EXTENSIONS));
886  return r;
887 }
virtual bool Error(const char *szMsg)
Definition: C4Draw.cpp:503
uint32_t DWORD
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:253

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

References GetBlueValue, GetGreenValue, GetRedValue, and pCurrCtx.

154 {
155  if (!pCurrCtx) return;
156  glClearColor((float)GetRedValue(dwClr)/255.0f, (float)GetGreenValue(dwClr)/255.0f, (float)GetBlueValue(dwClr)/255.0f, 0.0f);
157  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
158 }
CStdGLCtx * pCurrCtx
Definition: C4DrawGL.h:179
#define GetGreenValue(rgb)
Definition: StdColors.h:30
#define GetRedValue(rgb)
Definition: StdColors.h:31
#define GetBlueValue(rgb)
Definition: StdColors.h:29
void CStdGL::FreeVAOID ( unsigned int  vaoid)

Definition at line 976 of file C4DrawGL.cpp.

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

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

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

References NextVAOID, and VAOIDs.

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

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

734 {
735  int iWdt=std::min(iClipX2, RenderTarget->Wdt-1)-iClipX1+1;
736  int iHgt=std::min(iClipY2, RenderTarget->Hgt-1)-iClipY1+1;
737  int iX=iClipX1; if (iX<0) { iWdt+=iX; iX=0; }
738  int iY=iClipY1; if (iY<0) { iHgt+=iY; iY=0; }
739  return C4Rect(iX, iY, iWdt, iHgt);
740 }
int Wdt
Definition: C4Surface.h:67
Definition: C4Rect.h:29
int Hgt
Definition: C4Surface.h:67
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 742 of file C4Draw.cpp.

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

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

743 {
744  return C4Rect(0, 0, RenderTarget->Wdt, RenderTarget->Hgt);
745 }
int Wdt
Definition: C4Surface.h:67
Definition: C4Rect.h:29
int Hgt
Definition: C4Surface.h:67
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 725 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().

726 {
727  // Store drawing clip values
728  rX1=fClipX1; rY1=fClipY1; rX2=fClipX2; rY2=fClipY2;
729  // Done
730  return true;
731 }
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 683 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().

684 {
685  C4Shader* shaders[16] = {
686  &SpriteShader,
692 
703  };
704 
705  int index = 0;
706  if(ssc & C4SSC_LIGHT) index += 6;
707 
708  if(ssc & C4SSC_BASE)
709  {
710  index += 2;
711  if(ssc & C4SSC_OVERLAY)
712  index += 2;
713  if( (ssc & C4SSC_NORMAL) && (ssc & C4SSC_LIGHT))
714  index += 4;
715  }
716 
717  if(ssc & C4SSC_MOD2)
718  index += 1;
719 
720  assert(index < 16);
721  return shaders[index];
722 }
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 672 of file C4DrawGL.cpp.

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

673 {
674  int ssc = 0;
675  if(dwBlitMode & C4GFXBLIT_MOD2) ssc |= C4SSC_MOD2;
676  if(haveBase) ssc |= C4SSC_BASE;
677  if(haveBase && haveOverlay) ssc |= C4SSC_OVERLAY;
678  if(pFoW != nullptr) ssc |= C4SSC_LIGHT;
679  if(pFoW != nullptr && haveBase && haveNormal) ssc |= C4SSC_NORMAL;
680  return GetSpriteShader(ssc);
681 }
#define C4GFXBLIT_MOD2
Definition: C4Surface.h:29
const C4FoWRegion * pFoW
Definition: C4Draw.h:111
DWORD dwBlitMode
Definition: C4Draw.h:110
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:683

Here is the call graph for this function:

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

Definition at line 194 of file C4Draw.cpp.

References C4Surface::GetSurfaceSize().

195 {
196  return sfcSurface->GetSurfaceSize(iWdt, iHgt);
197 }
bool GetSurfaceSize(int &irX, int &irY)
Definition: C4Surface.cpp:454

Here is the call graph for this function:

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

Definition at line 1023 of file C4DrawGL.cpp.

References CStdGLCtx::hVAOs, pCurrCtx, and VAOIDs.

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

1024 {
1025  assert(pCurrCtx != nullptr);
1026 
1027  if (vaoid >= pCurrCtx->hVAOs.size())
1028  {
1029  // Resize the VAO array so that all generated VAO IDs fit
1030  // in it, and not only the one requested in this call.
1031  // We hope to get away with fewer reallocations this way.
1032  assert(VAOIDs.find(vaoid) != VAOIDs.end());
1033  std::set<unsigned int>::iterator iter = VAOIDs.end();
1034  --iter;
1035 
1036  pCurrCtx->hVAOs.resize(*iter + 1);
1037  }
1038 
1039  if (pCurrCtx->hVAOs[vaoid] == 0)
1040  {
1041  glGenVertexArrays(1, &pCurrCtx->hVAOs[vaoid]);
1042  vao = pCurrCtx->hVAOs[vaoid];
1043  return false;
1044  }
1045 
1046  vao = pCurrCtx->hVAOs[vaoid];
1047  return true;
1048 }
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 889 of file C4DrawGL.cpp.

Referenced by CheckGLError().

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

Here is the caller graph for this function:

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

Definition at line 704 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().

705 {
706  // safety
707  if (!sfcSfc) return;
708  // change colors
709  int xcnt,ycnt,wdt=sfcSfc->Wdt,hgt=sfcSfc->Hgt;
710  // Lock surface
711  if (!sfcSfc->Lock()) return;
712  for (ycnt=0; ycnt<hgt; ycnt++)
713  {
714  for (xcnt=0; xcnt<wdt; xcnt++)
715  {
716  DWORD dwColor = sfcSfc->GetPixDw(xcnt,ycnt,false);
717  uint32_t r = GetRedValue(dwColor), g = GetGreenValue(dwColor), b = GetBlueValue(dwColor), a = dwColor >> 24;
718  int32_t gray = Clamp<int32_t>((r + g + b) / 3 + iOffset, 0, 255);
719  sfcSfc->SetPixDw(xcnt, ycnt, RGBA(gray, gray, gray, a));
720  }
721  }
722  sfcSfc->Unlock();
723 }
int Wdt
Definition: C4Surface.h:67
#define GetGreenValue(rgb)
Definition: StdColors.h:30
#define b
bool Lock()
Definition: C4Surface.cpp:463
bool Unlock()
Definition: C4Surface.cpp:474
#define a
#define GetRedValue(rgb)
Definition: StdColors.h:31
int Hgt
Definition: C4Surface.h:67
#define GetBlueValue(rgb)
Definition: StdColors.h:29
bool SetPixDw(int iX, int iY, DWORD dwCol)
Definition: C4Surface.cpp:586
DWORD GetPixDw(int iX, int iY, bool fApplyModulation)
Definition: C4Surface.cpp:501
uint32_t RGBA(uint32_t r, uint32_t g, uint32_t b, uint32_t a)
Definition: StdColors.h:24
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 818 of file C4Draw.cpp.

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

Referenced by DDrawInit().

819 {
820  this->pApp = pApp;
821 
822  pApp->pWindow->pSurface = new C4Surface(pApp, pApp->pWindow);
823 
824  if (!RestoreDeviceObjects())
825  return false;
826 
827  if (!CreatePrimaryClipper(iXRes, iYRes))
828  return Error(" Clipper failure.");
829 
830  return true;
831 }
virtual bool RestoreDeviceObjects()=0
C4Surface * pSurface
Definition: C4Window.h:279
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
Definition: C4Draw.cpp:510
virtual bool Error(const char *szMsg)
Definition: C4Draw.cpp:503
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 724 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().

725 {
726  // Create sprite blitting shaders
727  if(!PrepareSpriteShader(SpriteShader, "sprite", 0, pGroups, nullptr, nullptr))
728  return false;
729  if(!PrepareSpriteShader(SpriteShaderMod2, "spriteMod2", C4SSC_MOD2, pGroups, nullptr, nullptr))
730  return false;
731  if(!PrepareSpriteShader(SpriteShaderBase, "spriteBase", C4SSC_BASE, pGroups, nullptr, nullptr))
732  return false;
733  if(!PrepareSpriteShader(SpriteShaderBaseMod2, "spriteBaseMod2", C4SSC_MOD2 | C4SSC_BASE, pGroups, nullptr, nullptr))
734  return false;
735  if(!PrepareSpriteShader(SpriteShaderBaseOverlay, "spriteBaseOverlay", C4SSC_BASE | C4SSC_OVERLAY, pGroups, nullptr, nullptr))
736  return false;
737  if(!PrepareSpriteShader(SpriteShaderBaseOverlayMod2, "spriteBaseOverlayMod2", C4SSC_MOD2 | C4SSC_BASE | C4SSC_OVERLAY, pGroups, nullptr, nullptr))
738  return false;
739 
740  if(!PrepareSpriteShader(SpriteShaderLight, "spriteLight", C4SSC_LIGHT, pGroups, nullptr, nullptr))
741  return false;
742  if(!PrepareSpriteShader(SpriteShaderLightMod2, "spriteLightMod2", C4SSC_LIGHT | C4SSC_MOD2, pGroups, nullptr, nullptr))
743  return false;
744  if(!PrepareSpriteShader(SpriteShaderLightBase, "spriteLightBase", C4SSC_LIGHT | C4SSC_BASE, pGroups, nullptr, nullptr))
745  return false;
746  if(!PrepareSpriteShader(SpriteShaderLightBaseMod2, "spriteLightBaseMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_MOD2, pGroups, nullptr, nullptr))
747  return false;
748  if(!PrepareSpriteShader(SpriteShaderLightBaseOverlay, "spriteLightBaseOverlay", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY, pGroups, nullptr, nullptr))
749  return false;
750  if(!PrepareSpriteShader(SpriteShaderLightBaseOverlayMod2, "spriteLightBaseOverlayMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY | C4SSC_MOD2, pGroups, nullptr, nullptr))
751  return false;
752  if(!PrepareSpriteShader(SpriteShaderLightBaseNormal, "spriteLightBaseNormal", C4SSC_LIGHT | C4SSC_BASE | C4SSC_NORMAL, pGroups, nullptr, nullptr))
753  return false;
754  if(!PrepareSpriteShader(SpriteShaderLightBaseNormalMod2, "spriteLightBaseNormalMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_NORMAL | C4SSC_MOD2, pGroups, nullptr, nullptr))
755  return false;
756  if(!PrepareSpriteShader(SpriteShaderLightBaseNormalOverlay, "spriteLightBaseNormalOverlay", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY | C4SSC_NORMAL, pGroups, nullptr, nullptr))
757  return false;
758  if(!PrepareSpriteShader(SpriteShaderLightBaseNormalOverlayMod2, "spriteLightBaseNormalOverlayMod2", C4SSC_LIGHT | C4SSC_BASE | C4SSC_OVERLAY | C4SSC_NORMAL | C4SSC_MOD2, pGroups, nullptr, nullptr))
759  return false;
760 
761  return true;
762 }
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
virtual bool PrepareSpriteShader(C4Shader &shader, const char *name, int ssc, C4GroupSet *pGroups, const char *const *additionalDefines, const char *const *additionalSlices) override
Definition: C4DrawGL.cpp:207
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 815 of file C4DrawGL.cpp.

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

Referenced by Clear(), and RestoreDeviceObjects().

816 {
817  bool fSuccess=true;
818  // deactivate
819  Active=false;
820  // invalidate font objects
821  // invalidate primary surfaces
822  if (lines_tex)
823  {
824  glDeleteTextures(1, &lines_tex);
825  lines_tex = 0;
826  }
827 
828  // invalidate generic VBOs
829  if (GenericVBOs[0] != 0)
830  {
831  glDeleteBuffers(N_GENERIC_VBOS, GenericVBOs);
832  GenericVBOs[0] = 0;
833  CurrentVBO = 0;
834  for (unsigned int i = 0; i < N_GENERIC_VBOS * 2; ++i)
836  }
837 
838  // invalidate shaders
839 
840  // TODO: We don't do this here because we cannot re-validate them in
841  // RestoreDeviceObjects. This should be refactored.
842 
843  /*SpriteShader.Clear();
844  SpriteShaderMod2.Clear();
845  SpriteShaderBase.Clear();
846  SpriteShaderBaseMod2.Clear();
847  SpriteShaderBaseOverlay.Clear();
848  SpriteShaderBaseOverlayMod2.Clear();
849  SpriteShaderLight.Clear();
850  SpriteShaderLightMod2.Clear();
851  SpriteShaderLightBase.Clear();
852  SpriteShaderLightBaseMod2.Clear();
853  SpriteShaderLightBaseOverlay.Clear();
854  SpriteShaderLightBaseOverlayMod2.Clear();
855  SpriteShaderLightBaseNormal.Clear();
856  SpriteShaderLightBaseNormalMod2.Clear();
857  SpriteShaderLightBaseNormalOverlay.Clear();
858  SpriteShaderLightBaseNormalOverlayMod2.Clear();*/
859  return fSuccess;
860 }
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:976
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 240 of file C4Draw.cpp.

References C4Draw::SetPrimaryClipper().

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

241 {
242  // apply maximum clipper
243  SetPrimaryClipper(0,0,439832,439832);
244  // Done
245  return true;
246 }
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:220

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

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

284 {
285 #ifdef GL_KHR_debug
286  if (glObjectLabel)
287  glObjectLabel(identifier, name, length, label);
288 #endif
289 }

Here is the caller graph for this function:

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

Implements C4Draw.

Definition at line 916 of file C4DrawGL.cpp.

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

917 {
918  // Re-create primary clipper to adapt to new size.
919  CreatePrimaryClipper(iXRes, iYRes);
921  return true;
922 }
bool CreatePrimaryClipper(unsigned int iXRes, unsigned int iYRes)
Definition: C4Draw.cpp:510
bool RestoreDeviceObjects() override
Definition: C4DrawGL.cpp:769

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 1027 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.

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

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

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

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

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

532 {
533  // In a first step, we transform the lines array to a triangle array, so that we can draw
534  // the lines with some thickness.
535  // In principle, this step could be easily (and probably much more efficiently) performed
536  // by a geometry shader as well, however that would require OpenGL 3.2.
537  C4BltVertex* tri_vertices = new C4BltVertex[n_vertices * 3];
538  for(unsigned int i = 0; i < n_vertices; i += 2)
539  {
540  const float x1 = vertices[i].ftx;
541  const float y1 = vertices[i].fty;
542  const float x2 = vertices[i+1].ftx;
543  const float y2 = vertices[i+1].fty;
544 
545  float offx = y1 - y2;
546  float offy = x2 - x1;
547  float l = sqrtf(offx * offx + offy * offy);
548  // avoid division by zero
549  l += 0.000000005f;
550  offx *= width/l;
551  offy *= width/l;
552 
553  tri_vertices[3*i + 0].ftx = x1 + offx; tri_vertices[3*i + 0].fty = y1 + offy;
554  tri_vertices[3*i + 1].ftx = x1 - offx; tri_vertices[3*i + 1].fty = y1 - offy;
555  tri_vertices[3*i + 2].ftx = x2 - offx; tri_vertices[3*i + 2].fty = y2 - offy;
556  tri_vertices[3*i + 3].ftx = x2 + offx; tri_vertices[3*i + 3].fty = y2 + offy;
557 
558  for(int j = 0; j < 4; ++j)
559  {
560  tri_vertices[3*i + 0].color[j] = vertices[i].color[j];
561  tri_vertices[3*i + 1].color[j] = vertices[i].color[j];
562  tri_vertices[3*i + 2].color[j] = vertices[i + 1].color[j];
563  tri_vertices[3*i + 3].color[j] = vertices[i + 1].color[j];
564  }
565 
566  tri_vertices[3*i + 0].tx = 0.f; tri_vertices[3*i + 0].ty = 0.f;
567  tri_vertices[3*i + 1].tx = 0.f; tri_vertices[3*i + 1].ty = 2.f;
568  tri_vertices[3*i + 2].tx = 1.f; tri_vertices[3*i + 2].ty = 2.f;
569  tri_vertices[3*i + 3].tx = 1.f; tri_vertices[3*i + 3].ty = 0.f;
570 
571  tri_vertices[3*i + 4] = tri_vertices[3*i + 2]; // duplicate vertex
572  tri_vertices[3*i + 5] = tri_vertices[3*i + 0]; // duplicate vertex
573  }
574 
575  // Then, feed the vertices to the GL
576  if (!shader_call)
577  {
578  C4ShaderCall call(GetSpriteShader(true, false, false));
579  SetupMultiBlt(call, nullptr, lines_tex, 0, 0, 0, nullptr);
580  PerformMultiBlt(sfcTarget, OP_TRIANGLES, tri_vertices, n_vertices * 3, true, &call);
581  }
582  else
583  {
584  SetupMultiBlt(*shader_call, nullptr, lines_tex, 0, 0, 0, nullptr);
585  PerformMultiBlt(sfcTarget, OP_TRIANGLES, tri_vertices, n_vertices * 3, true, shader_call);
586  }
587 
588  delete[] tri_vertices;
589 }
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:370
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:607
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:683

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

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

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

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

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

592 {
593  // Feed the vertices to the GL
594  if (!shader_call)
595  {
596  C4ShaderCall call(GetSpriteShader(pTex != nullptr, pOverlay != nullptr, pNormal != nullptr));
597  SetupMultiBlt(call, pTransform, pTex ? pTex->texName : 0, pOverlay ? pOverlay->texName : 0, pNormal ? pNormal->texName : 0, dwOverlayModClr, nullptr);
598  PerformMultiBlt(sfcTarget, OP_TRIANGLES, vertices, n_vertices, pTex != nullptr, &call);
599  }
600  else
601  {
602  SetupMultiBlt(*shader_call, pTransform, pTex ? pTex->texName : 0, pOverlay ? pOverlay->texName : 0, pNormal ? pNormal->texName : 0, dwOverlayModClr, nullptr);
603  PerformMultiBlt(sfcTarget, OP_TRIANGLES, vertices, n_vertices, pTex != nullptr, shader_call);
604  }
605 }
void SetupMultiBlt(C4ShaderCall &call, const C4BltTransform *pTransform, GLuint baseTex, GLuint overlayTex, GLuint normalTex, DWORD dwOverlayModClr, StdProjectionMatrix *out_modelview)
Definition: C4DrawGL.cpp:370
unsigned int texName
Definition: C4Surface.h:157
void PerformMultiBlt(C4Surface *sfcTarget, DrawOperation op, const C4BltVertex *vertices, unsigned int n_vertices, bool has_tex, C4ShaderCall *shader_call)
Definition: C4DrawGL.cpp:607
C4Shader * GetSpriteShader(int ssc)
Definition: C4DrawGL.cpp:683

Here is the call graph for this function:

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

Implements C4Draw.

Definition at line 273 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.

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

Here is the call graph for this function:

bool CStdGL::PrepareRendering ( C4Surface sfcToSurface)
overridevirtual

Implements C4Draw.

Definition at line 178 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().

179 {
180  // call from gfx thread only!
181  if (!pApp || !pApp->AssertMainThread()) return false;
182  // not ready?
183  if (!Active)
184  return false;
185  // target?
186  if (!sfcToSurface) return false;
187  // target locked?
188  if (sfcToSurface->Locked) return false;
189  // target is already set as render target?
190  if (sfcToSurface != RenderTarget)
191  {
192  // target is a render-target?
193  if (!sfcToSurface->IsRenderTarget()) return false;
194  // context
195  if (sfcToSurface->pCtx && sfcToSurface->pCtx != pCurrCtx)
196  if (!sfcToSurface->pCtx->Select()) return false;
197  // set target
198  RenderTarget=sfcToSurface;
199  // new target has different size; needs other clipping rect
200  UpdateClipper();
201  }
202  // done
203  return true;
204 }
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:78
bool UpdateClipper() override
Definition: C4DrawGL.cpp:160
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool IsRenderTarget()
Definition: C4Surface.cpp:154
int Locked
Definition: C4Surface.h:89
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 207 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().

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

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

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

794 {
795  X = (X - ZoomX) / Zoom + ZoomX;
796  Y = (Y - ZoomY) / Zoom + ZoomY;
797 }
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 406 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().

407 {
408  // TODO: Emulate rendering
409  if (!sfcTarget->IsRenderTarget()) return false;
410 
411  // TODO: Clip
412 
413  // prepare rendering to surface
414  if (!PrepareRendering(sfcTarget)) return false;
415  // Update bone matrices and vertex data (note this also updates attach transforms and child transforms)
416  instance.UpdateBoneTransforms();
417  // Order faces according to MeshTransformation (note pTransform does not affect Z coordinate, so does not need to be taken into account for correct ordering)
418  StdMeshMatrix mat = StdMeshMatrix::Identity();
419  if(MeshTransform) mat = *MeshTransform * mat;
420  instance.ReorderFaces(&mat);
421  // Render mesh
422  PerformMesh(instance, tx, ty, twdt, thgt, dwPlayerColor, pTransform);
423  // success
424  return true;
425 }
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:1566
bool UpdateBoneTransforms()
Definition: StdMesh.cpp:1484
bool IsRenderTarget()
Definition: C4Surface.cpp:154

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

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

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

764 {
765  for (int i = 0; i < C4MaxGammaRamps; i++) {
766  gamma[i][0] = 1.0f;
767  gamma[i][1] = 1.0f;
768  gamma[i][2] = 1.0f;
769  }
770  gammaOut[0] = 1.0f;
771  gammaOut[1] = 1.0f;
772  gammaOut[2] = 1.0f;
773 }
float gammaOut[3]
Definition: C4Draw.h:98
const int C4MaxGammaRamps
Definition: C4Constants.h:35
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 769 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().

770 {
771  assert(pMainCtx);
772  // delete any previous objects
774 
775  // set states
776  Active = pMainCtx->Select();
778 
779  // lines texture
780  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
781  glGenTextures(1, &lines_tex);
782  glBindTexture(GL_TEXTURE_2D, lines_tex);
783  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
784  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
785  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
786  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
787  static const char * linedata = "\xff\xff\xff\x00\xff\xff\xff\xff";
788  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, linedata);
789 
790  MaxTexSize = 64;
791  GLint s = 0;
792  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &s);
793  if (s>0) MaxTexSize = s;
794 
795  // Generic VBOs
796  glGenBuffers(N_GENERIC_VBOS, GenericVBOs);
797  for (unsigned int i = 0; i < N_GENERIC_VBOS; ++i)
798  {
800  glBindBuffer(GL_ARRAY_BUFFER, GenericVBOs[i]);
801  glBufferData(GL_ARRAY_BUFFER, GenericVBOSizes[i] * sizeof(C4BltVertex), nullptr, GL_STREAM_DRAW);
802  GenericVAOs[i] = GenVAOID();
804  }
805 
806  glBindBuffer(GL_ARRAY_BUFFER, 0);
807 
808  // reset blit states
809  dwBlitMode = 0;
810 
811  // done
812  return Active;
813 }
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:279
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:934
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:815
#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 213 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().

214 {
215  // Restore primary clipper
217  return true;
218 }
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:220
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:34
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 747 of file C4Draw.cpp.

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

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

748 {
749  // Set
750  gamma[iRampIndex][0] = r;
751  gamma[iRampIndex][1] = g;
752  gamma[iRampIndex][2] = b;
753  // Recalculate resulting gamma. Note that we flip gamma direction here,
754  // because higher gammaOut means darker.
755  gammaOut[0] = gammaOut[1] = gammaOut[2] = 1.0f;
756  for (int i = 0; i < C4MaxGammaRamps; i++) {
757  gammaOut[0] /= gamma[i][0];
758  gammaOut[1] /= gamma[i][1];
759  gammaOut[2] /= gamma[i][2];
760  }
761 }
#define b
float gammaOut[3]
Definition: C4Draw.h:98
const int C4MaxGammaRamps
Definition: C4Constants.h:35
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 220 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().

221 {
222  // set clipper
223  fClipX1=iX1; fClipY1=iY1; fClipX2=iX2; fClipY2=iY2;
224  iClipX1=iX1; iClipY1=iY1; iClipX2=iX2; iClipY2=iY2;
225  UpdateClipper();
226  // Done
227  return true;
228 }
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 370 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().

371 {
372  // Initialize multi blit shader.
373  int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE;
374  glBlendFunc(GL_SRC_ALPHA, iAdditive ? GL_ONE : GL_ONE_MINUS_SRC_ALPHA);
375 
376  call.Start();
377 
378  // Upload uniforms
379  const DWORD dwModClr = BlitModulated ? BlitModulateClr : 0xffffffff;
380  const float fMod[4] = {
381  ((dwModClr >> 16) & 0xff) / 255.0f,
382  ((dwModClr >> 8) & 0xff) / 255.0f,
383  ((dwModClr ) & 0xff) / 255.0f,
384  ((dwModClr >> 24) & 0xff) / 255.0f
385  };
386 
387  call.SetUniform4fv(C4SSU_ClrMod, 1, fMod);
389 
390  if(baseTex != 0)
391  {
393  glBindTexture(GL_TEXTURE_2D, baseTex);
394  }
395 
396  if(overlayTex != 0)
397  {
399  glBindTexture(GL_TEXTURE_2D, overlayTex);
400 
401  const float fOverlayModClr[4] = {
402  ((dwOverlayModClr >> 16) & 0xff) / 255.0f,
403  ((dwOverlayModClr >> 8) & 0xff) / 255.0f,
404  ((dwOverlayModClr ) & 0xff) / 255.0f,
405  ((dwOverlayModClr >> 24) & 0xff) / 255.0f
406  };
407 
408  call.SetUniform4fv(C4SSU_OverlayClr, 1, fOverlayModClr);
409  }
410 
411  if(pFoW != nullptr && normalTex != 0)
412  {
414  glBindTexture(GL_TEXTURE_2D, normalTex);
415  }
416 
417  if(pFoW != nullptr)
418  {
419  const C4Rect OutRect = GetOutRect();
420  const C4Rect ClipRect = GetClipRect();
421  const FLOAT_RECT vpRect = pFoW->getViewportRegion();
422 
423  // Dynamic Light
425  glBindTexture(GL_TEXTURE_2D, pFoW->getSurfaceName());
426 
427  float lightTransform[6];
428  pFoW->GetFragTransform(ClipRect, OutRect, lightTransform);
429  call.SetUniformMatrix2x3fv(C4SSU_LightTransform, 1, lightTransform);
430 
431  // Ambient Light
433  glBindTexture(GL_TEXTURE_2D, pFoW->getFoW()->Ambient.Tex);
435 
436  float ambientTransform[6];
437  pFoW->getFoW()->Ambient.GetFragTransform(vpRect, ClipRect, OutRect, ambientTransform);
438  call.SetUniformMatrix2x3fv(C4SSU_AmbientTransform, 1, ambientTransform);
439  }
440 
441  call.SetUniform1f(C4SSU_CullMode, 0.0f);
442 
443  // The primary reason we use a 4x4 matrix for the modelview matrix is that
444  // that the C4BltTransform pTransform parameter can have projection components
445  // (see SetObjDrawTransform2). Still, for sprites the situation is a bit
446  // unsatisfactory because there's no distinction between modelview and projection
447  // components in the BltTransform. Object rotation is part of the BltTransform
448  // for sprites, which should be part of the modelview matrix, so that lighting
449  // is correct for rotated sprites. This is much more common than projection
450  // components in the BltTransform, and therefore we turn the BltTransform into
451  // the modelview matrix and not the projection matrix.
452  StdProjectionMatrix default_modelview = StdProjectionMatrix::Identity();
453  StdProjectionMatrix& modelview = out_modelview ? *out_modelview : default_modelview;
454 
455  // Apply zoom and transform
456  Translate(modelview, ZoomX, ZoomY, 0.0f);
457  // Scale Z as well so that we don't distort normals.
458  Scale(modelview, Zoom, Zoom, Zoom);
459  Translate(modelview, -ZoomX, -ZoomY, 0.0f);
460 
461  if(pTransform)
462  {
463  float sz = 1.0f;
464  if (pFoW != nullptr && normalTex != 0)
465  {
466  // Decompose scale factors and scale Z accordingly to X and Y, again to avoid distorting normals
467  // We could instead work around this by using the projection matrix, but then for object rotations (SetR)
468  // the normals would not be correct.
469  const float sx = sqrt(pTransform->mat[0]*pTransform->mat[0] + pTransform->mat[1]*pTransform->mat[1]);
470  const float sy = sqrt(pTransform->mat[3]*pTransform->mat[3] + pTransform->mat[4]*pTransform->mat[4]);
471  sz = sqrt(sx * sy);
472  }
473 
474  // Multiply modelview matrix with transform
475  StdProjectionMatrix transform;
476  transform(0, 0) = pTransform->mat[0];
477  transform(0, 1) = pTransform->mat[1];
478  transform(0, 2) = 0.0f;
479  transform(0, 3) = pTransform->mat[2];
480  transform(1, 0) = pTransform->mat[3];
481  transform(1, 1) = pTransform->mat[4];
482  transform(1, 2) = 0.0f;
483  transform(1, 3) = pTransform->mat[5];
484  transform(2, 0) = 0.0f;
485  transform(2, 1) = 0.0f;
486  transform(2, 2) = sz;
487  transform(2, 3) = 0.0f;
488  transform(3, 0) = pTransform->mat[6];
489  transform(3, 1) = pTransform->mat[7];
490  transform(3, 2) = 0.0f;
491  transform(3, 3) = pTransform->mat[8];
492  modelview *= transform;
493  }
494 
497 
498  if (pFoW != nullptr && normalTex != 0)
499  call.SetUniformMatrix3x3Transpose(C4SSU_NormalMatrix, StdMeshMatrix::Inverse(StdProjectionMatrix::Upper3x4(modelview)));
500 
501  scriptUniform.Apply(call);
502 }
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:28
void Apply(C4ShaderCall &call)
Definition: C4Shader.cpp:830
Definition: C4Rect.h:29
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:273
GLuint getSurfaceName() const
void SetUniformMatrix2x3fv(int iUniform, int iLength, const float *pVals) const
Definition: C4Shader.h:244
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:234
void SetUniform1f(int iUniform, float gX) const
Definition: C4Shader.h:214
void GetFragTransform(const C4Rect &clipRect, const C4Rect &outRect, float lightTransform[6]) const
GLint AllocTexUnit(int iUniform)
Definition: C4Shader.cpp:670
C4Rect GetOutRect() const
Definition: C4Draw.cpp:742
DWORD dwBlitMode
Definition: C4Draw.h:110
void SetUniformMatrix4x4(int iUniform, const StdMeshMatrix &matrix)
Definition: C4Shader.h:288
C4Rect GetClipRect() const
Definition: C4Draw.cpp:733
void Start()
Definition: C4Shader.cpp:693
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:238

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

783 {
784  this->ZoomX = X; this->ZoomY = Y; this->Zoom = Zoom;
785 }
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:782
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 206 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().

207 {
208  // Store current primary clipper
210  return true;
211 }
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 579 of file C4Draw.cpp.

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

580 {
581  // init markup
582  C4Markup Markup(true);
583  // output string
584  return StringOut(szText, sfcDest, iTx, iTy, dwFCol, byForm, fDoMarkup, Markup, &rFont, fZoom);
585 }
bool StringOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:579

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

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

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

Here is the call graph for this function:

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

Definition at line 199 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().

200 {
201  // Set sub primary clipper
202  SetPrimaryClipper(std::max(iX1,iClipX1),std::max(iY1,iClipY1),std::min(iX2,iClipX2),std::min(iY2,iClipY2));
203  return true;
204 }
bool SetPrimaryClipper(int iX1, int iY1, int iX2, int iY2)
Definition: C4Draw.cpp:220
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 570 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().

571 {
572  C4Markup Markup(true);
573  static char szLinebuf[2500+1];
574  for (int cnt=0; SCopySegmentEx(szText,cnt,szLinebuf,fDoMarkup ? '|' : '\n','\n',2500); cnt++,iTy+=int(fZoom*rFont.GetLineHeight()))
575  if (!StringOut(szLinebuf,sfcDest,iTx,iTy,dwFCol,byForm,fDoMarkup,Markup,&rFont,fZoom)) return false;
576  return true;
577 }
int GetLineHeight() const
Definition: C4FontLoader.h:132
bool StringOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:579
bool SCopySegmentEx(const char *szString, int iSegment, char *sTarget, char cSep1, char cSep2, int iMaxL, bool fSkipWhitespace)
Definition: Standard.cpp:269

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

161 {
162  // no render target? do nothing
163  if (!RenderTarget || !Active) return true;
164  // negative/zero?
165  C4Rect clipRect = GetClipRect();
166  if (clipRect.Wdt<=0 || clipRect.Hgt<=0)
167  {
168  ClipAll=true;
169  return true;
170  }
171  ClipAll=false;
172  // set it
173  glViewport(clipRect.x, RenderTarget->Hgt-clipRect.y-clipRect.Hgt, clipRect.Wdt, clipRect.Hgt);
174  ProjectionMatrix = StdProjectionMatrix::Orthographic(clipRect.x, clipRect.x + clipRect.Wdt, clipRect.y + clipRect.Hgt, clipRect.y);
175  return true;
176 }
bool Active
Definition: C4Draw.h:96
Definition: C4Rect.h:29
int Hgt
Definition: C4Surface.h:67
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
int32_t x
Definition: C4Rect.h:32
C4Surface * RenderTarget
Definition: C4Draw.h:107
bool ClipAll
Definition: C4Draw.h:105
int32_t Hgt
Definition: C4Rect.h:32
C4Rect GetClipRect() const
Definition: C4Draw.cpp:733
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
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
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
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: