00001
00002
00003
00004
00005
#ifndef RAGEDISPLAY_H
00006
#define RAGEDISPLAY_H
00007
00008
#include "RageTypes.h"
00009
#include "ModelTypes.h"
00010
00011 const int REFRESH_DEFAULT = 0;
00012
struct RageSurface;
00013 const int MAX_TEXTURE_UNITS = 2;
00014
00015
00016
00017 class RageCompiledGeometry
00018 {
00019
public:
00020 virtual ~RageCompiledGeometry()
00021 {
00022
m_bNeedsNormals =
false;
00023 }
00024
00025 void Set(
const vector<msMesh> &vMeshes,
bool bNeedsNormals )
00026 {
00027
m_bNeedsNormals = bNeedsNormals;
00028
00029 size_t totalVerts = 0;
00030 size_t totalTriangles = 0;
00031
00032
m_vMeshInfo.resize( vMeshes.size() );
00033
for(
unsigned i=0; i<vMeshes.size(); i++ )
00034 {
00035
const msMesh& mesh = vMeshes[i];
00036
const vector<RageModelVertex> &Vertices = mesh.
Vertices;
00037
const vector<msTriangle> &Triangles = mesh.
Triangles;
00038
00039
MeshInfo& meshInfo =
m_vMeshInfo[i];
00040
00041 meshInfo.
iVertexStart = totalVerts;
00042 meshInfo.
iVertexCount = Vertices.size();
00043 meshInfo.
iTriangleStart = totalTriangles;
00044 meshInfo.
iTriangleCount = Triangles.size();
00045
00046 totalVerts += Vertices.size();
00047 totalTriangles += Triangles.size();
00048 }
00049
00050 this->
Allocate( vMeshes );
00051
00052
Change( vMeshes );
00053 }
00054
00055
virtual void Allocate(
const vector<msMesh> &vMeshes ) = 0;
00056
virtual void Change(
const vector<msMesh> &vMeshes ) = 0;
00057
virtual void Draw(
int iMeshIndex )
const = 0;
00058
00059
protected:
00060 size_t
GetTotalVertices() {
if(
m_vMeshInfo.empty() )
return 0;
return m_vMeshInfo.back().iVertexStart +
m_vMeshInfo.back().iVertexCount; }
00061 size_t
GetTotalTriangles() {
if(
m_vMeshInfo.empty() )
return 0;
return m_vMeshInfo.back().iTriangleStart +
m_vMeshInfo.back().iTriangleCount; }
00062
00063 struct MeshInfo
00064 {
00065 int iVertexStart;
00066 int iVertexCount;
00067 int iTriangleStart;
00068 int iTriangleCount;
00069 };
00070 vector<MeshInfo>
m_vMeshInfo;
00071 bool m_bNeedsNormals;
00072 };
00073
00074 class RageDisplay
00075 {
00076
friend class RageTexture;
00077
00078
public:
00079
00080 struct PixelFormatDesc {
00081 int bpp;
00082 unsigned int masks[4];
00083 };
00084
00085 enum PixelFormat {
00086
FMT_RGBA8,
00087
FMT_RGBA4,
00088
FMT_RGB5A1,
00089
FMT_RGB5,
00090
FMT_RGB8,
00091
FMT_PAL,
00092
00093
00094
00095
FMT_BGR8,
00096
FMT_A1BGR5,
00097
NUM_PIX_FORMATS
00098 };
00099
00100
static CString PixelFormatToString( PixelFormat pixfmt );
00101
virtual const PixelFormatDesc *GetPixelFormatDesc(PixelFormat pf)
const = 0;
00102
00103 struct VideoModeParams
00104 {
00105
00106
00107 VideoModeParams(
00108
bool windowed_,
00109
int width_,
00110
int height_,
00111
int bpp_,
00112
int rate_,
00113
bool vsync_,
00114
bool interlaced_,
00115
bool bSmoothLines_,
00116
bool bTrilinearFiltering_,
00117
bool bAnisotropicFiltering_,
00118 CString sWindowTitle_,
00119 CString sIconFile_,
00120
bool PAL_,
00121
float fDisplayAspectRatio_
00122 )
00123 {
00124
windowed = windowed_;
00125
width = width_;
00126
height = height_;
00127
bpp = bpp_;
00128
rate = rate_;
00129
vsync = vsync_;
00130
interlaced = interlaced_;
00131
bSmoothLines = bSmoothLines_;
00132
bTrilinearFiltering = bTrilinearFiltering_;
00133
bAnisotropicFiltering = bAnisotropicFiltering_;
00134
sWindowTitle = sWindowTitle_;
00135
sIconFile = sIconFile_;
00136
PAL = PAL_;
00137
fDisplayAspectRatio = fDisplayAspectRatio_;
00138 }
00139 VideoModeParams() {}
00140
00141 bool windowed;
00142 int width;
00143 int height;
00144 int bpp;
00145 int rate;
00146 bool vsync;
00147 bool bSmoothLines;
00148 bool bTrilinearFiltering;
00149 bool bAnisotropicFiltering;
00150 bool interlaced;
00151 bool PAL;
00152 float fDisplayAspectRatio;
00153 CString sWindowTitle;
00154 CString sIconFile;
00155 };
00156
00157
00158 virtual ~RageDisplay() { }
00159
00160 virtual void Update(
float fDeltaTime) { }
00161
00162
00163
00164
00165
CString SetVideoMode( VideoModeParams p,
bool &bNeedReloadTextures );
00166
00167
00168 virtual void ResolutionChanged() { }
00169
00170
virtual bool BeginFrame() = 0;
00171
virtual void EndFrame() = 0;
00172
virtual VideoModeParams
GetVideoModeParams() const = 0;
00173 bool IsWindowed()
const {
return this->
GetVideoModeParams().
windowed; }
00174
00175
virtual void SetBlendMode( BlendMode mode ) = 0;
00176
00177
virtual bool SupportsTextureFormat( PixelFormat pixfmt,
bool realtime=
false ) = 0;
00178
00179
00180
00181
virtual unsigned CreateTexture(
00182 PixelFormat pixfmt,
00183
RageSurface* img,
00184
bool bGenerateMipMaps
00185 ) = 0;
00186
virtual void UpdateTexture(
00187
unsigned uTexHandle,
00188
RageSurface* img,
00189
int xoffset,
int yoffset,
int width,
int height
00190 ) = 0;
00191
virtual void DeleteTexture(
unsigned uTexHandle ) = 0;
00192
virtual void ClearAllTextures() = 0;
00193
virtual int GetNumTextureUnits() = 0;
00194
virtual void SetTexture(
int iTextureUnitIndex,
RageTexture* pTexture ) = 0;
00195
virtual void SetTextureModeModulate() = 0;
00196
virtual void SetTextureModeGlow() = 0;
00197
virtual void SetTextureModeAdd() = 0;
00198
virtual void SetTextureWrapping(
bool b ) = 0;
00199
virtual int GetMaxTextureSize() const = 0;
00200 virtual
void SetTextureFiltering(
bool b ) = 0;
00201
00202 virtual
bool IsZTestEnabled() const = 0;
00203 virtual
bool IsZWriteEnabled() const = 0;
00204 virtual
void SetZWrite(
bool b ) = 0;
00205 virtual
void SetZTestMode( ZTestMode mode ) = 0;
00206 virtual
void ClearZBuffer() = 0;
00207
00208 virtual
void SetCullMode( CullMode mode ) = 0;
00209
00210 virtual
void SetAlphaTest(
bool b ) = 0;
00211
00212 virtual
void SetMaterial(
00213 const
RageColor &emissive,
00214 const
RageColor &ambient,
00215 const
RageColor &diffuse,
00216 const
RageColor &specular,
00217
float shininess
00218 ) = 0;
00219
00220 virtual
void SetLighting(
bool b ) = 0;
00221 virtual
void SetLightOff(
int index ) = 0;
00222 virtual
void SetLightDirectional(
00223
int index,
00224 const
RageColor &ambient,
00225 const
RageColor &diffuse,
00226 const
RageColor &specular,
00227 const
RageVector3 &dir ) = 0;
00228
00229 virtual
void SetSphereEnvironmentMapping(
bool b ) = 0;
00230
00231 virtual
RageCompiledGeometry* CreateCompiledGeometry() = 0;
00232 virtual
void DeleteCompiledGeometry(
RageCompiledGeometry* p ) = 0;
00233
00234
void DrawQuads( const
RageSpriteVertex v[],
int iNumVerts );
00235
void DrawQuadStrip( const
RageSpriteVertex v[],
int iNumVerts );
00236
void DrawFan( const
RageSpriteVertex v[],
int iNumVerts );
00237
void DrawStrip( const
RageSpriteVertex v[],
int iNumVerts );
00238
void DrawTriangles( const
RageSpriteVertex v[],
int iNumVerts );
00239
void DrawCompiledGeometry( const
RageCompiledGeometry *p,
int iMeshIndex, const vector<
msMesh> &vMeshes );
00240
void DrawLineStrip( const
RageSpriteVertex v[],
int iNumVerts,
float LineWidth );
00241
void DrawCircle( const
RageSpriteVertex &v,
float radius );
00242
00243 void DrawQuad( const
RageSpriteVertex v[] ) {
DrawQuads(v,4); }
00244
00245
00246 virtual void SetPolygonMode( PolygonMode pm ) {}
00247 virtual void SetLineWidth(
float fWidth ) {}
00248
00249 enum GraphicsFileFormat
00250 {
00251
SAVE_LOSSLESS,
00252
SAVE_LOSSY_LOW_QUAL,
00253
SAVE_LOSSY_HIGH_QUAL
00254 };
00255
bool SaveScreenshot( CString sPath, GraphicsFileFormat format );
00256
00257 virtual CString GetTextureDiagnostics(
unsigned id )
const {
return ""; }
00258
virtual RageSurface*
CreateScreenshot() = 0;
00259
00260
protected:
00261
virtual void DrawQuadsInternal(
const RageSpriteVertex v[],
int iNumVerts ) = 0;
00262
virtual void DrawQuadStripInternal(
const RageSpriteVertex v[],
int iNumVerts ) = 0;
00263
virtual void DrawFanInternal(
const RageSpriteVertex v[],
int iNumVerts ) = 0;
00264
virtual void DrawStripInternal(
const RageSpriteVertex v[],
int iNumVerts ) = 0;
00265
virtual void DrawTrianglesInternal(
const RageSpriteVertex v[],
int iNumVerts ) = 0;
00266
virtual void DrawCompiledGeometryInternal(
const RageCompiledGeometry *p,
int iMeshIndex ) = 0;
00267
virtual void DrawLineStripInternal(
const RageSpriteVertex v[],
int iNumVerts,
float LineWidth );
00268
virtual void DrawCircleInternal(
const RageSpriteVertex &v,
float radius );
00269
00270
00271
00272
00273
virtual CString TryVideoMode( VideoModeParams params,
bool &bNewDeviceOut ) = 0;
00274
00275
virtual void SetViewport(
int shift_left,
int shift_down) = 0;
00276
00277
void DrawPolyLine(
const RageSpriteVertex &p1,
const RageSpriteVertex &p2,
float LineWidth );
00278
00279
00280
00281
void SetDefaultRenderStates();
00282
00283
public:
00284
00285
int GetFPS() const;
00286
int GetVPF() const;
00287
int GetCumFPS() const;
00288 virtual
void ResetStats();
00289 virtual
void ProcessStatsOnFlip();
00290 virtual CString GetStats() const;
00291
void StatsAddVerts(
int iNumVertsRendered );
00292
00293
00294
void PushMatrix();
00295
void PopMatrix();
00296
void Translate(
float x,
float y,
float z );
00297
void TranslateWorld(
float x,
float y,
float z );
00298
void Scale(
float x,
float y,
float z );
00299
void RotateX(
float deg );
00300
void RotateY(
float deg );
00301
void RotateZ(
float deg );
00302 void MultMatrix( const
RageMatrix &f ) { this->
PostMultMatrix(
f); }
00303
void PostMultMatrix(
const RageMatrix &f );
00304
void PreMultMatrix(
const RageMatrix &f );
00305
void LoadIdentity();
00306
00307
00308
void TexturePushMatrix();
00309
void TexturePopMatrix();
00310
void TextureTranslate(
float x,
float y,
float z );
00311
00312
00313
void CameraPushMatrix();
00314
void CameraPopMatrix();
00315
void LoadMenuPerspective(
float fovDegrees,
float fVanishPointX,
float fVanishPointY );
00316
void LoadLookAt(
float fov,
const RageVector3 &Eye,
const RageVector3 &At,
const RageVector3 &Up );
00317
00318
00319
void ChangeCentering(
int trans_x,
int trans_y,
int add_width,
int add_height );
00320
00321
RageSurface *CreateSurfaceFromPixfmt( PixelFormat pixfmt,
void *pixels,
int width,
int height,
int pitch );
00322 PixelFormat FindPixelFormat(
int bpp,
int Rmask,
int Gmask,
int Bmask,
int Amask,
bool realtime=
false );
00323
00324
protected:
00325
RageMatrix GetPerspectiveMatrix(
float fovy,
float aspect,
float zNear,
float zFar);
00326
00327
00328
virtual RageMatrix GetOrthoMatrix(
float l,
float r,
float b,
float t,
float zn,
float zf );
00329
virtual RageMatrix GetFrustumMatrix(
float l,
float r,
float b,
float t,
float zn,
float zf );
00330
00331
00332
00333
00334 RageMatrix m_Centering;
00335
00336
00337 const RageMatrix*
GetCentering() {
return &
m_Centering; }
00338
const RageMatrix*
GetProjectionTop();
00339
const RageMatrix*
GetViewTop();
00340
const RageMatrix*
GetWorldTop();
00341
const RageMatrix*
GetTextureTop();
00342 };
00343
00344
00345 extern RageDisplay*
DISPLAY;
00346
00347
#endif
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371