2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
|
|
|
|
2010-05-23 02:59:36 +00:00
|
|
|
#include <d3dx9.h>
|
2008-12-08 04:46:09 +00:00
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
namespace DX9
|
|
|
|
{
|
|
|
|
|
2008-12-08 04:46:09 +00:00
|
|
|
namespace D3D
|
|
|
|
{
|
2009-09-13 08:21:35 +00:00
|
|
|
|
2009-09-16 20:12:14 +00:00
|
|
|
// From http://developer.amd.com/gpu_assets/Advanced%20DX9%20Capabilities%20for%20ATI%20Radeon%20Cards.pdf
|
|
|
|
// Magic FourCC's to unlock undocumented D3D9 features:
|
|
|
|
|
|
|
|
// Z texture formats
|
|
|
|
#define FOURCC_INTZ ((D3DFORMAT)(MAKEFOURCC('I','N','T','Z')))
|
|
|
|
#define FOURCC_RAWZ ((D3DFORMAT)(MAKEFOURCC('R','A','W','Z')))
|
2009-11-22 02:37:00 +00:00
|
|
|
#define FOURCC_DF24 ((D3DFORMAT)(MAKEFOURCC('D','F','2','4')))
|
|
|
|
#define FOURCC_DF16 ((D3DFORMAT)(MAKEFOURCC('D','F','1','6')))
|
2009-09-16 20:12:14 +00:00
|
|
|
|
|
|
|
// Depth buffer resolve:
|
|
|
|
#define FOURCC_RESZ ((D3DFORMAT)(MAKEFOURCC('R','E','S','Z')))
|
|
|
|
#define RESZ_CODE 0x7fa05000
|
|
|
|
|
|
|
|
// Null render target to do Z-only shadow maps: (probably not useful for Dolphin)
|
|
|
|
#define FOURCC_NULL ((D3DFORMAT)(MAKEFOURCC('N','U','L','L')))
|
|
|
|
|
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
|
|
|
bool IsATIDevice();
|
2011-10-08 22:23:00 +00:00
|
|
|
bool IsIntelDevice();
|
2009-09-13 08:21:35 +00:00
|
|
|
HRESULT Init();
|
2010-04-12 01:33:10 +00:00
|
|
|
HRESULT Create(int adapter, HWND wnd, int resolution, int aa_mode, bool auto_depth);
|
2009-09-13 08:21:35 +00:00
|
|
|
void Close();
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// Direct access to the device.
|
2010-05-23 02:59:36 +00:00
|
|
|
extern LPDIRECT3DDEVICE9 dev;
|
2009-09-18 02:03:56 +00:00
|
|
|
extern bool bFrameInProgress;
|
2009-09-13 08:21:35 +00:00
|
|
|
|
|
|
|
void Reset();
|
2009-09-13 17:46:33 +00:00
|
|
|
bool BeginFrame();
|
2009-09-13 08:21:35 +00:00
|
|
|
void EndFrame();
|
2009-09-20 03:29:43 +00:00
|
|
|
void Present();
|
2009-09-16 20:12:14 +00:00
|
|
|
bool CanUseINTZ();
|
2009-09-13 17:46:33 +00:00
|
|
|
|
|
|
|
int GetBackBufferWidth();
|
|
|
|
int GetBackBufferHeight();
|
2009-09-13 08:21:35 +00:00
|
|
|
LPDIRECT3DSURFACE9 GetBackBufferSurface();
|
2009-09-13 17:46:33 +00:00
|
|
|
LPDIRECT3DSURFACE9 GetBackBufferDepthSurface();
|
2009-11-08 20:35:11 +00:00
|
|
|
LPDIRECT3DVERTEXBUFFER9 GetquadVB();
|
|
|
|
LPDIRECT3DVERTEXDECLARATION9 GetBasicvertexDecl();
|
2009-09-13 08:21:35 +00:00
|
|
|
const D3DCAPS9 &GetCaps();
|
|
|
|
const char *PixelShaderVersionString();
|
|
|
|
const char *VertexShaderVersionString();
|
|
|
|
void ShowD3DError(HRESULT err);
|
|
|
|
|
2011-01-02 23:13:29 +00:00
|
|
|
// returns true if size was changed
|
|
|
|
bool FixTextureSize(int& width, int& height);
|
|
|
|
|
2011-01-03 14:35:07 +00:00
|
|
|
// returns true if format is supported
|
|
|
|
bool CheckTextureSupport(DWORD usage, D3DFORMAT tex_format);
|
|
|
|
bool CheckDepthStencilSupport(D3DFORMAT target_format, D3DFORMAT depth_format);
|
|
|
|
|
2011-01-04 12:56:52 +00:00
|
|
|
D3DFORMAT GetSupportedDepthTextureFormat();
|
|
|
|
D3DFORMAT GetSupportedDepthSurfaceFormat(D3DFORMAT target_format);
|
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
// The following are "filtered" versions of the corresponding D3Ddev-> functions.
|
|
|
|
void SetTexture(DWORD Stage, IDirect3DBaseTexture9 *pTexture);
|
|
|
|
void SetRenderState(D3DRENDERSTATETYPE State, DWORD Value);
|
2009-12-15 01:40:54 +00:00
|
|
|
void RefreshRenderState(D3DRENDERSTATETYPE State);
|
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
|
|
|
void ChangeRenderState(D3DRENDERSTATETYPE State, DWORD Value);
|
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
void SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
|
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
|
|
|
void RefreshTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type);
|
|
|
|
void ChangeTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
|
|
|
|
|
2009-09-13 08:21:35 +00:00
|
|
|
void SetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
|
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
|
|
|
void RefreshSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type);
|
|
|
|
void ChangeSamplerState(DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value);
|
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
void RefreshVertexDeclaration();
|
2009-09-19 10:46:25 +00:00
|
|
|
void SetVertexDeclaration(LPDIRECT3DVERTEXDECLARATION9 decl);
|
ok big changes here:
in videocommon little fix for the alpha test values, return to the original values as they are more accurate.
in D3D:
huge change in state management, now all the state management is centralized and redundant state changes are eliminated.
Fixed the overlapped viewport error in non ati cards:
the error was caused by this: when a viewport is defined larger than the current rendertarget, an error is thrown and the last valid viewport is used, this is the reference behavior, in ati cards if a larger viewport is defined, no eror is returned, the rendering is valid and is rendered using the projection defined by the viewport but limited to the rendertarget are, exactly like opengl or the GC hardware.
to solve this in reference drivers defined a large rendertarget (2x the size of the original) and proceed to render in a centered quad insithe the larger rendertarget, in this way larger viewports always falls inside a valid rendertarget size, the drawback of this is the waste of resources. it can be dynamized, depending or games or changed at runtime when a oversized viewport is detected, but i live that to future commits.
please test this and let me know the results.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4841 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-01-15 15:52:08 +00:00
|
|
|
|
|
|
|
void RefreshVertexShader();
|
|
|
|
void SetVertexShader(LPDIRECT3DVERTEXSHADER9 shader);
|
|
|
|
|
|
|
|
void RefreshPixelShader();
|
|
|
|
void SetPixelShader(LPDIRECT3DPIXELSHADER9 shader);
|
|
|
|
|
2009-09-16 20:12:14 +00:00
|
|
|
void ApplyCachedState();
|
2009-09-13 08:21:35 +00:00
|
|
|
|
|
|
|
// Utility functions for vendor specific hacks. So far, just the one.
|
|
|
|
void EnableAlphaToCoverage();
|
|
|
|
|
|
|
|
struct Resolution
|
|
|
|
{
|
|
|
|
char name[32];
|
|
|
|
int xres;
|
|
|
|
int yres;
|
|
|
|
std::set<D3DFORMAT> bitdepths;
|
|
|
|
std::set<int> refreshes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AALevel
|
|
|
|
{
|
2010-01-17 17:44:09 +00:00
|
|
|
AALevel(const char *n, D3DMULTISAMPLE_TYPE m, int q) {
|
2010-06-09 21:19:23 +00:00
|
|
|
strncpy(name, n, 32);
|
|
|
|
name[31] = '\0';
|
2010-01-17 17:44:09 +00:00
|
|
|
ms_setting = m;
|
|
|
|
qual_setting = q;
|
|
|
|
}
|
2010-05-23 02:59:36 +00:00
|
|
|
char name[32];
|
2009-09-13 08:21:35 +00:00
|
|
|
D3DMULTISAMPLE_TYPE ms_setting;
|
|
|
|
int qual_setting;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Adapter
|
|
|
|
{
|
|
|
|
D3DADAPTER_IDENTIFIER9 ident;
|
|
|
|
std::vector<Resolution> resolutions;
|
|
|
|
std::vector<AALevel> aa_levels;
|
|
|
|
bool supports_alpha_to_coverage;
|
2009-09-16 20:12:14 +00:00
|
|
|
|
|
|
|
// Magic render targets, see the top of this file.
|
|
|
|
bool supports_intz;
|
|
|
|
bool supports_rawz;
|
|
|
|
bool supports_resz;
|
|
|
|
bool supports_null;
|
2009-09-13 08:21:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Adapter &GetAdapter(int i);
|
|
|
|
const Adapter &GetCurAdapter();
|
|
|
|
int GetNumAdapters();
|
|
|
|
|
|
|
|
} // namespace
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
} // namespace DX9
|
|
|
|
|
2010-07-17 11:42:28 +00:00
|
|
|
|
|
|
|
// Used to not require the SDK and runtime versions to match:
|
|
|
|
// Linking with d3dx9.lib makes the most recent d3dx9_xx.dll of the
|
|
|
|
// compiler's SDK an actually unnecessary requirement.
|
|
|
|
// Add any d3dx9 functions which you want to use here and load them in LoadD3DX9()
|
|
|
|
typedef HRESULT (WINAPI* D3DXSAVESURFACETOFILEATYPE)(LPCSTR, D3DXIMAGE_FILEFORMAT, LPDIRECT3DSURFACE9, CONST PALETTEENTRY*, CONST RECT*);
|
|
|
|
typedef HRESULT (WINAPI* D3DXSAVETEXTURETOFILEATYPE)(LPCSTR, D3DXIMAGE_FILEFORMAT, LPDIRECT3DBASETEXTURE9, CONST PALETTEENTRY*);
|
|
|
|
typedef HRESULT (WINAPI* D3DXCOMPILESHADERTYPE)(LPCSTR, UINT, CONST D3DXMACRO*, LPD3DXINCLUDE, LPCSTR, LPCSTR, DWORD, LPD3DXBUFFER*, LPD3DXBUFFER*, LPD3DXCONSTANTTABLE*);
|
|
|
|
|
|
|
|
extern D3DXSAVESURFACETOFILEATYPE PD3DXSaveSurfaceToFileA;
|
|
|
|
extern D3DXSAVETEXTURETOFILEATYPE PD3DXSaveTextureToFileA;
|
|
|
|
extern D3DXCOMPILESHADERTYPE PD3DXCompileShader;
|