Files
itgmania212121/stepmania/src/RageDisplay.h
T

242 lines
6.7 KiB
C++
Raw Normal View History

#ifndef RAGEDISPLAY_H
#define RAGEDISPLAY_H
2002-05-20 08:59:37 +00:00
/*
-----------------------------------------------------------------------------
Class: RageDisplay
2003-05-22 05:28:37 +00:00
Desc: Wrapper around a graphics device.
2002-05-20 08:59:37 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
2003-05-04 07:22:20 +00:00
#include "SDL_types.h"
#include "RageTypes.h"
2002-09-15 03:13:21 +00:00
2002-11-12 09:29:46 +00:00
const int REFRESH_DEFAULT = 0;
2003-05-22 05:28:37 +00:00
struct SDL_Surface;
2003-05-22 05:28:37 +00:00
// VertexArray holds vertex data in a format that is most efficient for
// the graphics API.
/*struct VertexArray
{
VertexArray();
~VertexArray();
unsigned size();
void resize( unsigned new_size );
RageVector2& TexCoord( int index );
RageColor& Color( int index );
RageVector3& Normal( int index );
RageVector3& Position( int index );
// convenience. Remove this later!
void Set( int index, const RageVertex& v );
struct Impl;
Impl* pImpl;
};
*/
enum PixelFormat {
FMT_RGBA8,
FMT_RGBA4,
FMT_RGB5A1,
FMT_RGB5,
FMT_RGB8,
FMT_PAL,
NUM_PIX_FORMATS
};
CString PixelFormatToString( PixelFormat pixfmt );
2003-05-22 05:28:37 +00:00
struct PixelFormatDesc {
int bpp;
unsigned int masks[4];
};
2002-05-20 08:59:37 +00:00
class RageDisplay
{
friend class RageTexture;
2002-05-20 08:59:37 +00:00
public:
2003-06-05 19:29:27 +00:00
struct VideoModeParams
{
// Initialize with a constructor so to guarantee all paramters
// are filled (in case new params are added).
VideoModeParams(
bool _windowed,
int _width,
int _height,
int _bpp,
int _rate,
bool _vsync,
bool _bAntiAliasing,
CString _sWindowTitle,
CString _sIconFile )
{
windowed = _windowed;
width = _width;
height = _height;
bpp = _bpp;
rate = _rate;
vsync = _vsync;
bAntiAliasing = _bAntiAliasing;
sWindowTitle = _sWindowTitle;
sIconFile = _sIconFile;
}
VideoModeParams() {}
bool windowed;
int width;
int height;
int bpp;
int rate;
bool vsync;
bool bAntiAliasing;
CString sWindowTitle;
CString sIconFile;
};
virtual const PixelFormatDesc *GetPixelFormatDesc(PixelFormat pf) const = 0;
2003-06-05 19:29:27 +00:00
virtual void Update(float fDeltaTime) { }
2002-05-20 08:59:37 +00:00
virtual bool IsSoftwareRenderer() = 0;
2003-06-05 19:29:27 +00:00
// Don't override this. Override TryVideoMode() instead.
// This will set the video mode to be as close as possible to params.
// Return true if device was re-created and we need to reload textures.
bool SetVideoMode( VideoModeParams params );
2002-05-20 08:59:37 +00:00
2002-12-28 21:37:18 +00:00
/* Call this when the resolution has been changed externally: */
virtual void ResolutionChanged() { }
2002-12-28 21:37:18 +00:00
virtual void BeginFrame() = 0;
virtual void EndFrame() = 0;
2003-06-05 19:29:27 +00:00
virtual VideoModeParams GetVideoModeParams() const = 0;
bool IsWindowed() const { return this->GetVideoModeParams().windowed; }
2002-05-20 08:59:37 +00:00
virtual void SetBlendMode( BlendMode mode ) = 0;
virtual bool SupportsTextureFormat( PixelFormat pixfmt ) = 0;
2003-05-22 05:28:37 +00:00
/* return 0 if failed or internal texture resource handle
* (unsigned in OpenGL, texture pointer in D3D) */
virtual unsigned CreateTexture(
2003-05-22 05:28:37 +00:00
PixelFormat pixfmt, // format of img and of texture in video mem
SDL_Surface*& img // must be in pixfmt
) = 0;
virtual void UpdateTexture(
2003-05-22 05:28:37 +00:00
unsigned uTexHandle,
PixelFormat pixfmt, // this must be the same as what was passed to CreateTexture
SDL_Surface*& img,
int xoffset, int yoffset, int width, int height
) = 0;
virtual void DeleteTexture( unsigned uTexHandle ) = 0;
virtual void SetTexture( RageTexture* pTexture ) = 0;
virtual void SetTextureModeModulate() = 0;
virtual void SetTextureModeGlow( GlowMode m=GLOW_WHITEN ) = 0;
virtual void SetTextureWrapping( bool b ) = 0;
virtual int GetMaxTextureSize() const = 0;
virtual void SetTextureFiltering( bool b ) = 0;
2003-04-27 05:14:27 +00:00
virtual bool IsZBufferEnabled() const = 0;
virtual void SetZBuffer( bool b ) = 0;
virtual void ClearZBuffer() = 0;
virtual void SetBackfaceCull( bool b ) = 0;
virtual void SetAlphaTest( bool b ) = 0;
2003-05-22 05:28:37 +00:00
virtual void SetMaterial(
2003-04-27 05:14:27 +00:00
float emissive[4],
float ambient[4],
float diffuse[4],
float specular[4],
float shininess
) = 0;
2003-04-27 05:14:27 +00:00
virtual void SetLighting( bool b ) = 0;
virtual void SetLightOff( int index ) = 0;
virtual void SetLightDirectional(
2003-04-27 05:14:27 +00:00
int index,
RageColor ambient,
RageColor diffuse,
RageColor specular,
RageVector3 dir ) = 0;
2003-05-22 05:28:37 +00:00
void DrawQuad( const RageVertex v[] ) { DrawQuads(v,4); } /* alias. upper-left, upper-right, lower-left, lower-right */
virtual void DrawQuads( const RageVertex v[], int iNumVerts ) = 0;
virtual void DrawFan( const RageVertex v[], int iNumVerts ) = 0;
virtual void DrawStrip( const RageVertex v[], int iNumVerts ) = 0;
virtual void DrawTriangles( const RageVertex v[], int iNumVerts ) = 0;
virtual void DrawIndexedTriangles( const RageVertex v[], int iNumVerts, const Uint16* pIndices, int iNumIndices ) = 0;
virtual void DrawLineStrip( const RageVertex v[], int iNumVerts, float LineWidth );
void DrawCircle( const RageVertex &v, float radius );
virtual void SaveScreenshot( CString sPath ) = 0;
2003-06-22 01:20:58 +00:00
virtual CString GetTextureDiagnostics( unsigned id ) const { return ""; }
2003-05-22 05:28:37 +00:00
protected:
2003-06-05 19:29:27 +00:00
// Return true if mode change was successful.
// bNewDeviceOut is set true if a new device was created and textures
// need to be reloaded.
virtual bool TryVideoMode( VideoModeParams params, bool &bNewDeviceOut ) = 0;
virtual void SetViewport(int shift_left, int shift_down) = 0;
void DrawPolyLine(const RageVertex &p1, const RageVertex &p2, float LineWidth );
2003-05-22 05:28:37 +00:00
// Stuff in RageDisplay.cpp
void SetDefaultRenderStates();
public:
2002-11-11 20:43:30 +00:00
/* Statistics */
int GetFPS() const;
int GetVPF() const;
2003-01-11 05:12:17 +00:00
int GetCumFPS() const; /* average FPS since last reset */
2002-12-21 07:54:24 +00:00
void ResetStats();
2003-05-22 05:28:37 +00:00
void ProcessStatsOnFlip();
void StatsAddVerts( int iNumVertsRendered );
2002-11-11 20:43:30 +00:00
2003-05-22 05:28:37 +00:00
void PushMatrix();
void PopMatrix();
void Translate( float x, float y, float z );
void TranslateWorld( float x, float y, float z );
void Scale( float x, float y, float z );
void RotateX( float deg );
void RotateY( float deg );
void RotateZ( float deg );
void MultMatrix( const RageMatrix &f ) { this->PostMultMatrix(f); } /* alias */
void PostMultMatrix( const RageMatrix &f );
void PreMultMatrix( const RageMatrix &f );
void LoadIdentity();
void LoadMenuPerspective(float fovDegrees);
void EnterPerspective(float fov, bool preserve_loc = true, float znear = 1, float zfar = 1000);
void ExitPerspective();
void LookAt(const RageVector3 &Eye, const RageVector3 &At, const RageVector3 &Up);
virtual RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf ) = 0;
RageMatrix GetFrustrumMatrix(
float left,
float right,
float bottom,
float top,
float znear,
float zfar );
RageMatrix GetPerspectiveMatrix(float fovy, float aspect, float zNear, float zFar);
protected:
2003-05-22 05:28:37 +00:00
const RageMatrix* GetProjection();
const RageMatrix* GetModelViewTop();
2003-01-25 03:57:14 +00:00
2002-05-20 08:59:37 +00:00
};
extern RageDisplay* DISPLAY; // global and accessable from anywhere in our program
#endif