Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Made several variables/parameters unsigned in the DX9, DX11 and OGL p…
…lugins. They make more sense like this (given their names).

This also gets rid of some more typecasts in some cases.
  • Loading branch information
lioncash committed Jan 16, 2013
1 parent 7e5d877 commit 8743166
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/Src/FramebufferManagerBase.h
Expand Up @@ -17,7 +17,7 @@ struct XFBSourceBase

// TODO: only DX9 uses the width/height params
virtual void Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const = 0;
const MathUtil::Rectangle<float> &drawrc, u32 width, u32 height) const = 0;

virtual void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight) = 0;

Expand Down
22 changes: 11 additions & 11 deletions Source/Core/VideoCommon/Src/RenderBase.cpp
Expand Up @@ -60,12 +60,12 @@ std::string Renderer::s_sScreenshotName;
volatile bool Renderer::s_bScreenshot;

// The framebuffer size
int Renderer::s_target_width;
int Renderer::s_target_height;
unsigned int Renderer::s_target_width;
unsigned int Renderer::s_target_height;

// TODO: Add functionality to reinit all the render targets when the window is resized.
int Renderer::s_backbuffer_width;
int Renderer::s_backbuffer_height;
unsigned int Renderer::s_backbuffer_width;
unsigned int Renderer::s_backbuffer_height;

TargetRectangle Renderer::target_rc;

Expand Down Expand Up @@ -163,7 +163,7 @@ int Renderer::EFBToScaledY(int y)
};
}

void Renderer::CalculateTargetScale(int x, int y, int &scaledX, int &scaledY)
void Renderer::CalculateTargetScale(unsigned int x, unsigned int y, unsigned int &scaledX, unsigned int &scaledY)
{
if (g_ActiveConfig.iEFBScale == 0 || g_ActiveConfig.iEFBScale == 1)
{
Expand All @@ -172,15 +172,15 @@ void Renderer::CalculateTargetScale(int x, int y, int &scaledX, int &scaledY)
}
else
{
scaledX = x * (int)efb_scale_numeratorX / (int)efb_scale_denominatorX;
scaledY = y * (int)efb_scale_numeratorY / (int)efb_scale_denominatorY;
scaledX = x * (efb_scale_numeratorX / efb_scale_denominatorX);
scaledY = y * (efb_scale_numeratorY / efb_scale_denominatorY);
}
}

// return true if target size changed
bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, int multiplier)
bool Renderer::CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, unsigned int multiplier)
{
int newEFBWidth, newEFBHeight;
u32 newEFBWidth, newEFBHeight;

// TODO: Ugly. Clean up
switch (s_LastEFBScale)
Expand Down Expand Up @@ -374,7 +374,7 @@ void Renderer::DrawDebugText()
// TODO: remove
extern bool g_aspect_wide;

void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height)
void Renderer::UpdateDrawRectangle(u32 backbuffer_width, u32 backbuffer_height)
{
float FloatGLWidth = (float)backbuffer_width;
float FloatGLHeight = (float)backbuffer_height;
Expand Down Expand Up @@ -492,7 +492,7 @@ void Renderer::UpdateDrawRectangle(int backbuffer_width, int backbuffer_height)
target_rc.bottom = YOffset + iHeight;
}

void Renderer::SetWindowSize(int width, int height)
void Renderer::SetWindowSize(u32 width, u32 height)
{
if (width < 1)
width = 1;
Expand Down
24 changes: 12 additions & 12 deletions Source/Core/VideoCommon/Src/RenderBase.h
Expand Up @@ -67,22 +67,22 @@ class Renderer
virtual void RestoreState() = 0;

// Ideal internal resolution - determined by display resolution (automatic scaling) and/or a multiple of the native EFB resolution
static int GetTargetWidth() { return s_target_width; }
static int GetTargetHeight() { return s_target_height; }
static u32 GetTargetWidth() { return s_target_width; }
static u32 GetTargetHeight() { return s_target_height; }

// Display resolution
static int GetBackbufferWidth() { return s_backbuffer_width; }
static int GetBackbufferHeight() { return s_backbuffer_height; }
static u32 GetBackbufferWidth() { return s_backbuffer_width; }
static u32 GetBackbufferHeight() { return s_backbuffer_height; }

static void SetWindowSize(int width, int height);
static void SetWindowSize(u32 width, u32 height);

// EFB coordinate conversion functions

// Use this to convert a whole native EFB rect to backbuffer coordinates
virtual TargetRectangle ConvertEFBRectangle(const EFBRectangle& rc) = 0;

static const TargetRectangle& GetTargetRectangle() { return target_rc; }
static void UpdateDrawRectangle(int backbuffer_width, int backbuffer_height);
static void UpdateDrawRectangle(u32 backbuffer_width, u32 backbuffer_height);


// Use this to upscale native EFB coordinates to IDEAL internal resolution
Expand Down Expand Up @@ -132,8 +132,8 @@ class Renderer

protected:

static void CalculateTargetScale(int x, int y, int &scaledX, int &scaledY);
static bool CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, int multiplier = 1);
static void CalculateTargetScale(unsigned int x, unsigned int y, unsigned int &scaledX, unsigned int &scaledY);
static bool CalculateTargetSize(unsigned int framebuffer_width, unsigned int framebuffer_height, unsigned int multiplier = 1);

static void CheckFifoRecording();
static void RecordVideoMemory();
Expand All @@ -151,12 +151,12 @@ class Renderer
bool bLastFrameDumped;

// The framebuffer size
static int s_target_width;
static int s_target_height;
static u32 s_target_width;
static u32 s_target_height;

// TODO: Add functionality to reinit all the render targets when the window is resized.
static int s_backbuffer_width;
static int s_backbuffer_height;
static u32 s_backbuffer_width;
static u32 s_backbuffer_height;

static TargetRectangle target_rc;

Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Plugin_VideoDX11/Src/FramebufferManager.cpp
Expand Up @@ -193,7 +193,7 @@ void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height
}

void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const
const MathUtil::Rectangle<float> &drawrc, u32 width, u32 height) const
{
D3D::drawShadedTexSubQuad(tex->GetSRV(), &sourcerc,
texWidth, texHeight, &drawrc, PixelShaderCache::GetColorCopyProgram(false),
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Plugin_VideoDX11/Src/FramebufferManager.h
Expand Up @@ -64,7 +64,7 @@ struct XFBSource : public XFBSourceBase
~XFBSource() { tex->Release(); }

void Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const;
const MathUtil::Rectangle<float> &drawrc, u32 width, u32 height) const;
void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight);
void CopyEFB(float Gamma);

Expand Down
27 changes: 10 additions & 17 deletions Source/Plugins/Plugin_VideoDX11/Src/Render.cpp
Expand Up @@ -691,18 +691,14 @@ void Renderer::UpdateViewport(Matrix44& vpCorrection)
}

// In D3D, the viewport rectangle must fit within the render target.
int X = intendedX;
if (X < 0)
X = 0;
u32 X = intendedX;
u32 Y = intendedY;
u32 Wd = intendedWd;
u32 Ht = intendedHt;

int Y = intendedY;
if (Y < 0)
Y = 0;

int Wd = intendedWd;
if (X + Wd > GetTargetWidth())
Wd = GetTargetWidth() - X;
int Ht = intendedHt;

if (Y + Ht > GetTargetHeight())
Ht = GetTargetHeight() - Y;

Expand Down Expand Up @@ -928,20 +924,17 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight,cons
// Prepare to copy the XFBs to our backbuffer
UpdateDrawRectangle(s_backbuffer_width, s_backbuffer_height);

int X = GetTargetRectangle().left;
int Y = GetTargetRectangle().top;
int Width = GetTargetRectangle().right - GetTargetRectangle().left;
int Height = GetTargetRectangle().bottom - GetTargetRectangle().top;
u32 X = GetTargetRectangle().left;
u32 Y = GetTargetRectangle().top;
u32 Width = GetTargetRectangle().right - GetTargetRectangle().left;
u32 Height = GetTargetRectangle().bottom - GetTargetRectangle().top;

// TODO: Redundant checks...
if (X < 0) X = 0;
if (Y < 0) Y = 0;
if (X > s_backbuffer_width) X = s_backbuffer_width;
if (Y > s_backbuffer_height) Y = s_backbuffer_height;
if (Width < 0) Width = 0;
if (Height < 0) Height = 0;
if (Width > (s_backbuffer_width - X)) Width = s_backbuffer_width - X;
if (Height > (s_backbuffer_height - Y)) Height = s_backbuffer_height - Y;

D3D11_VIEWPORT vp = CD3D11_VIEWPORT((float)X, (float)Y, (float)Width, (float)Height);
D3D::context->RSSetViewports(1, &vp);
D3D::context->OMSetRenderTargets(1, &D3D::GetBackBuffer()->GetRTV(), NULL);
Expand Down
29 changes: 17 additions & 12 deletions Source/Plugins/Plugin_VideoDX9/Src/D3DBase.cpp
Expand Up @@ -49,9 +49,9 @@ LPDIRECT3DSURFACE9 back_buffer_z;
D3DCAPS9 caps;
HWND hWnd;

static int multisample;
static int resolution;
static int xres, yres;
static unsigned int multisample;
static unsigned int resolution;
static unsigned int xres, yres;
static bool auto_depth_stencil = false;

#define VENDOR_NVIDIA 4318
Expand Down Expand Up @@ -480,24 +480,25 @@ const D3DCAPS9 &GetCaps()
}

// returns true if size was changed
bool FixTextureSize(int& width, int& height)
bool FixTextureSize(u32& width, u32& height)
{
int oldw = width, oldh = height;
u32 oldw = width;
u32 oldh = height;

// conditional nonpow2 support should work fine for us
if ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) && !(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
{
// all texture dimensions need to be powers of two
width = (int)MakePow2((u32)width);
height = (int)MakePow2((u32)height);
width = MakePow2(width);
height = MakePow2(height);
}
if (caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY)
{
width = height = max(width, height);
}

width = min(width, (int)caps.MaxTextureWidth);
height = min(height, (int)caps.MaxTextureHeight);
width = min(width, (u32)caps.MaxTextureWidth);
height = min(height, (u32)caps.MaxTextureHeight);

return (width != oldw) || (height != oldh);
}
Expand All @@ -515,18 +516,22 @@ bool CheckDepthStencilSupport(D3DFORMAT target_format, D3DFORMAT depth_format)

D3DFORMAT GetSupportedDepthTextureFormat()
{
for (int i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
for (size_t i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
{
if (D3D::CheckTextureSupport(D3DUSAGE_DEPTHSTENCIL, DepthFormats[i]))
return DepthFormats[i];
}

return D3DFMT_UNKNOWN;
}

D3DFORMAT GetSupportedDepthSurfaceFormat(D3DFORMAT target_format)
{
for (int i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
for (size_t i = 0; i < sizeof(DepthFormats)/sizeof(D3DFORMAT); ++i)
{
if (D3D::CheckDepthStencilSupport(target_format, DepthFormats[i]))
return DepthFormats[i];
}

return D3DFMT_UNKNOWN;
}
Expand Down Expand Up @@ -567,7 +572,7 @@ void ShowD3DError(HRESULT err)
PanicAlert("Driver Internal Error");
break;
case D3DERR_OUTOFVIDEOMEMORY:
PanicAlert("Out of vid mem");
PanicAlert("Out of video memory");
break;
default:
// MessageBox(0,_T("Other error or success"),_T("ERROR"),0);
Expand Down
6 changes: 3 additions & 3 deletions Source/Plugins/Plugin_VideoDX9/Src/D3DBase.h
Expand Up @@ -75,7 +75,7 @@ const char *VertexShaderVersionString();
void ShowD3DError(HRESULT err);

// returns true if size was changed
bool FixTextureSize(int& width, int& height);
bool FixTextureSize(u32& width, u32& height);

// returns true if format is supported
bool CheckTextureSupport(DWORD usage, D3DFORMAT tex_format);
Expand Down Expand Up @@ -115,8 +115,8 @@ void EnableAlphaToCoverage();
struct Resolution
{
char name[32];
int xres;
int yres;
unsigned int xres;
unsigned int yres;
std::set<D3DFORMAT> bitdepths;
std::set<int> refreshes;
};
Expand Down
16 changes: 8 additions & 8 deletions Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.cpp
Expand Up @@ -365,10 +365,10 @@ int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, flo
*/
void drawShadedTexQuad(IDirect3DTexture9 *texture,
const RECT *rSource,
int SourceWidth,
int SourceHeight,
int DestWidth,
int DestHeight,
u32 SourceWidth,
u32 SourceHeight,
u32 DestWidth,
u32 DestHeight,
IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader,
float Gamma)
Expand Down Expand Up @@ -399,11 +399,11 @@ void drawShadedTexQuad(IDirect3DTexture9 *texture,

void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
const MathUtil::Rectangle<float> *rSource,
int SourceWidth,
int SourceHeight,
u32 SourceWidth,
u32 SourceHeight,
const MathUtil::Rectangle<float> *rDest,
int DestWidth,
int DestHeight,
u32 DestWidth,
u32 DestHeight,
IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader,
float Gamma)
Expand Down
16 changes: 8 additions & 8 deletions Source/Plugins/Plugin_VideoDX9/Src/D3DUtil.h
Expand Up @@ -65,20 +65,20 @@ namespace D3D
void quad2d(float x1, float y1, float x2, float y2, u32 color, float u1=0, float v1=0, float u2=1, float v2=1);
void drawShadedTexQuad(IDirect3DTexture9 *texture,
const RECT *rSource,
int SourceWidth,
int SourceHeight,
int DestWidth,
int DestHeight,
u32 SourceWidth,
u32 SourceHeight,
u32 DestWidth,
u32 DestHeight,
IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader,
float Gamma = 1.0f);
void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
const MathUtil::Rectangle<float> *rSource,
int SourceWidth,
int SourceHeight,
u32 SourceWidth,
u32 SourceHeight,
const MathUtil::Rectangle<float> *rDest,
int DestWidth,
int DestHeight,
u32 DestWidth,
u32 DestHeight,
IDirect3DPixelShader9 *PShader,
IDirect3DVertexShader9 *Vshader,
float Gamma = 1.0f);
Expand Down
6 changes: 3 additions & 3 deletions Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.cpp
Expand Up @@ -44,8 +44,8 @@ FramebufferManager::Efb FramebufferManager::s_efb;
FramebufferManager::FramebufferManager()
{
bool depth_textures_supported = true;
int target_width = Renderer::GetTargetWidth();
int target_height = Renderer::GetTargetHeight();
u32 target_width = Renderer::GetTargetWidth();
u32 target_height = Renderer::GetTargetHeight();
s_efb.color_surface_Format = D3DFMT_A8R8G8B8;

// EFB color texture - primary render target
Expand Down Expand Up @@ -161,7 +161,7 @@ void FramebufferManager::GetTargetSize(unsigned int *width, unsigned int *height
}

void XFBSource::Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const
const MathUtil::Rectangle<float> &drawrc, u32 width, u32 height) const
{
D3D::drawShadedTexSubQuad(texture, &sourcerc, texWidth, texHeight, &drawrc, width , height,
PixelShaderCache::GetColorCopyProgram(0), VertexShaderCache::GetSimpleVertexShader(0));
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugins/Plugin_VideoDX9/Src/FramebufferManager.h
Expand Up @@ -58,7 +58,7 @@ struct XFBSource : public XFBSourceBase
~XFBSource() { texture->Release(); }

void Draw(const MathUtil::Rectangle<float> &sourcerc,
const MathUtil::Rectangle<float> &drawrc, int width, int height) const;
const MathUtil::Rectangle<float> &drawrc, u32 width, u32 height) const;
void DecodeToTexture(u32 xfbAddr, u32 fbWidth, u32 fbHeight);
void CopyEFB(float Gamma);

Expand Down

0 comments on commit 8743166

Please sign in to comment.