Files
itgmania212121/stepmania/src/RageDisplay.h
T

282 lines
8.2 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 RageSpriteVertex& v );
2003-05-22 05:28:37 +00:00
struct Impl;
Impl* pImpl;
};
*/
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
2003-10-03 21:38:38 +00:00
struct PixelFormatDesc {
int bpp;
unsigned int masks[4];
};
enum PixelFormat {
FMT_RGBA8,
FMT_RGBA4,
FMT_RGB5A1,
FMT_RGB5,
FMT_RGB8,
FMT_PAL,
/* The above formats differ between OpenGL and D3D. These are provided as
* alternatives for OpenGL that match some format in D3D. Don't use them
* directly; they'll be matched automatically by FindPixelFormat. */
FMT_BGR8,
FMT_A1BGR5,
NUM_PIX_FORMATS
};
static CString PixelFormatToString( PixelFormat pixfmt );
virtual const PixelFormatDesc *GetPixelFormatDesc(PixelFormat pf) const = 0;
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 interlaced_,
bool bAntiAliasing_,
CString sWindowTitle_,
CString sIconFile_
#ifdef _XBOX
, bool PAL_
#endif
)
2003-06-05 19:29:27 +00:00
{
windowed = windowed_;
width = width_;
height = height_;
bpp = bpp_;
rate = rate_;
vsync = vsync_;
interlaced = interlaced_;
bAntiAliasing = bAntiAliasing_;
sWindowTitle = sWindowTitle_;
sIconFile = sIconFile_;
#ifdef _XBOX
PAL = PAL_;
#endif
2003-06-05 19:29:27 +00:00
}
VideoModeParams() {}
bool windowed;
int width;
int height;
int bpp;
int rate;
bool vsync;
bool bAntiAliasing;
bool interlaced;
#ifdef _XBOX
bool PAL;
#endif
2003-06-05 19:29:27 +00:00
CString sWindowTitle;
CString sIconFile;
};
2003-09-22 23:37:33 +00:00
/* This is needed or the overridden classes' dtors will not be called. */
virtual ~RageDisplay() { }
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-10-09 03:06:10 +00:00
/* This really indicates whether 4-bit palettes will actually use less memory
* than 8-bit ones. Note that 4-bit palettes are uploaded as 8-bit paletted
* surfaces with color index values in the range 0..15; not as 4-bit "packed
* indexes". */
virtual bool Supports4BitPalettes() { return false; }
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,
SDL_Surface* img,
2003-05-22 05:28:37 +00:00
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;
void DrawQuad( const RageSpriteVertex v[] ) { DrawQuads(v,4); } /* alias. upper-left, upper-right, lower-left, lower-right */
virtual void DrawQuads( const RageSpriteVertex v[], int iNumVerts ) = 0;
virtual void DrawFan( const RageSpriteVertex v[], int iNumVerts ) = 0;
virtual void DrawStrip( const RageSpriteVertex v[], int iNumVerts ) = 0;
virtual void DrawTriangles( const RageSpriteVertex v[], int iNumVerts ) = 0;
virtual void DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16* pIndices, int iNumIndices ) = 0;
virtual void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
void DrawCircle( const RageSpriteVertex &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:
// Return "" if mode change was successful, an error message otherwise.
2003-06-05 19:29:27 +00:00
// bNewDeviceOut is set true if a new device was created and textures
// need to be reloaded.
virtual CString TryVideoMode( VideoModeParams params, bool &bNewDeviceOut ) = 0;
2003-06-05 19:29:27 +00:00
virtual void SetViewport(int shift_left, int shift_down) = 0;
void DrawPolyLine(const RageSpriteVertex &p1, const RageSpriteVertex &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
/* World matrix stack functions. */
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();
/* Projection and View matrix stack functions. */
void CameraPushMatrix();
void CameraPopMatrix();
void LoadMenuPerspective( float fovDegrees, float fVanishPointX, float fVanishPointY );
void LoadLookAt( float fov, const RageVector3 &Eye, const RageVector3 &At, const RageVector3 &Up );
/* Centering matrix */
void CenteringTranslate( float x, float y, float z );
void CenteringScale( float x, float y, float z );
void ResetCentering();
SDL_Surface *CreateSurfaceFromPixfmt( PixelFormat pixfmt, void *pixels, int width, int height, int pitch );
PixelFormat FindPixelFormat( int bpp, int Rmask, int Gmask, int Bmask, int Amask );
protected:
RageMatrix GetPerspectiveMatrix(float fovy, float aspect, float zNear, float zFar);
// Different for D3D and OpenGL. Not sure why they're not compatible. -Chris
virtual RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf ) = 0;
2003-09-21 18:07:29 +00:00
virtual RageMatrix GetFrustumMatrix( float l, float r, float b, float t, float zn, float zf );
2003-01-25 03:57:14 +00:00
//
// Matrix that adjusts position and scale of image on the screen
//
RageMatrix m_Centering;
// Called by the RageDisplay derivitives
const RageMatrix* GetCentering() { return &m_Centering; }
const RageMatrix* GetProjectionTop();
const RageMatrix* GetViewTop();
const RageMatrix* GetWorldTop();
2002-05-20 08:59:37 +00:00
};
extern RageDisplay* DISPLAY; // global and accessable from anywhere in our program
#endif