2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_GRAPHICS_H
|
|
|
|
#define ENGINE_GRAPHICS_H
|
|
|
|
|
2012-08-09 00:13:16 +00:00
|
|
|
#include <base/vmath.h>
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
|
2011-12-31 09:04:46 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CImageInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
FORMAT_AUTO=-1,
|
|
|
|
FORMAT_RGB=0,
|
|
|
|
FORMAT_RGBA=1,
|
|
|
|
FORMAT_ALPHA=2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Variable: width
|
|
|
|
Contains the width of the image */
|
|
|
|
int m_Width;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
/* Variable: height
|
|
|
|
Contains the height of the image */
|
|
|
|
int m_Height;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
/* Variable: format
|
|
|
|
Contains the format of the image. See <Image Formats> for more information. */
|
|
|
|
int m_Format;
|
|
|
|
|
|
|
|
/* Variable: data
|
|
|
|
Pointer to the image data. */
|
|
|
|
void *m_pData;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Structure: CVideoMode
|
|
|
|
*/
|
|
|
|
class CVideoMode
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int m_Width, m_Height;
|
|
|
|
int m_Red, m_Green, m_Blue;
|
2012-08-18 15:51:47 +00:00
|
|
|
|
|
|
|
bool operator<(const CVideoMode &Other) { return Other.m_Width < m_Width; }
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IGraphics : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("graphics", 0)
|
|
|
|
protected:
|
|
|
|
int m_ScreenWidth;
|
|
|
|
int m_ScreenHeight;
|
2012-08-11 21:51:17 +00:00
|
|
|
int m_DesktopScreenWidth;
|
|
|
|
int m_DesktopScreenHeight;
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
|
|
|
/* Constants: Texture Loading Flags
|
|
|
|
TEXLOAD_NORESAMPLE - Prevents the texture from any resampling
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
2011-12-31 10:18:55 +00:00
|
|
|
TEXLOAD_NORESAMPLE = 1,
|
|
|
|
TEXLOAD_NOMIPMAPS = 2,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2012-08-12 10:41:50 +00:00
|
|
|
|
|
|
|
class CTextureHandle
|
|
|
|
{
|
|
|
|
friend class IGraphics;
|
|
|
|
int m_Id;
|
|
|
|
public:
|
|
|
|
CTextureHandle()
|
|
|
|
: m_Id(-1)
|
|
|
|
{}
|
|
|
|
|
2012-08-12 12:02:50 +00:00
|
|
|
bool IsValid() const { return Id() >= 0; }
|
|
|
|
int Id() const { return m_Id; }
|
2012-08-12 10:41:50 +00:00
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int ScreenWidth() const { return m_ScreenWidth; }
|
|
|
|
int ScreenHeight() const { return m_ScreenHeight; }
|
|
|
|
float ScreenAspect() const { return (float)ScreenWidth()/(float)ScreenHeight(); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Clear(float r, float g, float b) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void ClipEnable(int x, int y, int w, int h) = 0;
|
|
|
|
virtual void ClipDisable() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void MapScreen(float TopLeftX, float TopLeftY, float BottomRightX, float BottomRightY) = 0;
|
|
|
|
virtual void GetScreen(float *pTopLeftX, float *pTopLeftY, float *pBottomRightX, float *pBottomRightY) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// TODO: These should perhaps not be virtuals
|
|
|
|
virtual void BlendNone() = 0;
|
|
|
|
virtual void BlendNormal() = 0;
|
|
|
|
virtual void BlendAdditive() = 0;
|
2012-01-08 00:47:53 +00:00
|
|
|
virtual void WrapNormal() = 0;
|
|
|
|
virtual void WrapClamp() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int MemoryUsage() const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-07-25 16:28:02 +00:00
|
|
|
virtual int LoadPNG(CImageInfo *pImg, const char *pFilename, int StorageType) = 0;
|
2012-08-12 10:41:50 +00:00
|
|
|
|
|
|
|
virtual int UnloadTexture(CTextureHandle Index) = 0;
|
|
|
|
virtual CTextureHandle LoadTextureRaw(int Width, int Height, int Format, const void *pData, int StoreFormat, int Flags) = 0;
|
|
|
|
virtual int LoadTextureRawSub(CTextureHandle TextureID, int x, int y, int Width, int Height, int Format, const void *pData) = 0;
|
|
|
|
virtual CTextureHandle LoadTexture(const char *pFilename, int StorageType, int StoreFormat, int Flags) = 0;
|
|
|
|
virtual void TextureSet(CTextureHandle Texture) = 0;
|
|
|
|
void TextureClear() { TextureSet(CTextureHandle()); }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
struct CLineItem
|
|
|
|
{
|
|
|
|
float m_X0, m_Y0, m_X1, m_Y1;
|
|
|
|
CLineItem() {}
|
|
|
|
CLineItem(float x0, float y0, float x1, float y1) : m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1) {}
|
|
|
|
};
|
|
|
|
virtual void LinesBegin() = 0;
|
|
|
|
virtual void LinesEnd() = 0;
|
|
|
|
virtual void LinesDraw(const CLineItem *pArray, int Num) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void QuadsBegin() = 0;
|
|
|
|
virtual void QuadsEnd() = 0;
|
|
|
|
virtual void QuadsSetRotation(float Angle) = 0;
|
|
|
|
virtual void QuadsSetSubset(float TopLeftY, float TopLeftV, float BottomRightU, float BottomRightV) = 0;
|
|
|
|
virtual void QuadsSetSubsetFree(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
struct CQuadItem
|
|
|
|
{
|
|
|
|
float m_X, m_Y, m_Width, m_Height;
|
|
|
|
CQuadItem() {}
|
|
|
|
CQuadItem(float x, float y, float w, float h) : m_X(x), m_Y(y), m_Width(w), m_Height(h) {}
|
|
|
|
};
|
|
|
|
virtual void QuadsDraw(CQuadItem *pArray, int Num) = 0;
|
|
|
|
virtual void QuadsDrawTL(const CQuadItem *pArray, int Num) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
struct CFreeformItem
|
|
|
|
{
|
|
|
|
float m_X0, m_Y0, m_X1, m_Y1, m_X2, m_Y2, m_X3, m_Y3;
|
|
|
|
CFreeformItem() {}
|
|
|
|
CFreeformItem(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3)
|
|
|
|
: m_X0(x0), m_Y0(y0), m_X1(x1), m_Y1(y1), m_X2(x2), m_Y2(y2), m_X3(x3), m_Y3(y3) {}
|
|
|
|
};
|
|
|
|
virtual void QuadsDrawFreeform(const CFreeformItem *pArray, int Num) = 0;
|
2012-10-14 12:04:48 +00:00
|
|
|
virtual void QuadsText(float x, float y, float Size, const char *pText) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
struct CColorVertex
|
|
|
|
{
|
|
|
|
int m_Index;
|
|
|
|
float m_R, m_G, m_B, m_A;
|
|
|
|
CColorVertex() {}
|
|
|
|
CColorVertex(int i, float r, float g, float b, float a) : m_Index(i), m_R(r), m_G(g), m_B(b), m_A(a) {}
|
|
|
|
};
|
|
|
|
virtual void SetColorVertex(const CColorVertex *pArray, int Num) = 0;
|
|
|
|
virtual void SetColor(float r, float g, float b, float a) = 0;
|
2012-08-09 00:13:16 +00:00
|
|
|
virtual void SetColor4(vec4 TopLeft, vec4 TopRight, vec4 BottomLeft, vec4 BottomRight) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-12-12 15:48:13 +00:00
|
|
|
virtual void TakeScreenshot(const char *pFilename) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int GetVideoModes(CVideoMode *pModes, int MaxModes) = 0;
|
|
|
|
|
2012-08-11 21:51:17 +00:00
|
|
|
virtual int GetDesktopScreenWidth() = 0;
|
|
|
|
virtual int GetDesktopScreenHeight() = 0;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Swap() = 0;
|
2011-12-31 09:04:46 +00:00
|
|
|
|
|
|
|
// syncronization
|
2012-02-05 12:22:39 +00:00
|
|
|
virtual void InsertSignal(class semaphore *pSemaphore) = 0;
|
2011-12-31 09:04:46 +00:00
|
|
|
virtual bool IsIdle() = 0;
|
|
|
|
virtual void WaitForIdle() = 0;
|
2012-08-12 10:41:50 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
inline CTextureHandle CreateTextureHandle(int Index)
|
|
|
|
{
|
|
|
|
CTextureHandle Tex;
|
|
|
|
Tex.m_Id = Index;
|
|
|
|
return Tex;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IEngineGraphics : public IGraphics
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("enginegraphics", 0)
|
|
|
|
public:
|
2012-01-03 20:39:10 +00:00
|
|
|
virtual int Init() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Shutdown() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Minimize() = 0;
|
|
|
|
virtual void Maximize() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int WindowActive() = 0;
|
|
|
|
virtual int WindowOpen() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern IEngineGraphics *CreateEngineGraphics();
|
2011-12-31 09:29:25 +00:00
|
|
|
extern IEngineGraphics *CreateEngineGraphicsThreaded();
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
#endif
|