2012-04-21 21:13:50 +00:00
|
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-01-22 00:43:54 +00:00
|
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
|
|
|
|
* Copyright (C) 2011-2012 - Daniel De Matteis
|
2012-01-05 11:37:27 +00:00
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2012-01-05 11:37:27 +00:00
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2012-01-05 11:37:27 +00:00
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-04-17 03:23:54 +00:00
|
|
|
|
// Xbox 360-specific headers
|
2012-05-28 00:29:51 +00:00
|
|
|
|
#ifdef _XBOX
|
2012-01-05 11:37:27 +00:00
|
|
|
|
#include <xtl.h>
|
2012-03-17 23:23:11 +00:00
|
|
|
|
#include <xgraphics.h>
|
2012-05-28 00:29:51 +00:00
|
|
|
|
#endif
|
2012-04-17 03:23:54 +00:00
|
|
|
|
|
2012-01-05 12:30:13 +00:00
|
|
|
|
#include "../driver.h"
|
2012-01-21 22:59:27 +00:00
|
|
|
|
#include "xdk360_video.h"
|
2012-03-17 23:23:11 +00:00
|
|
|
|
#include "xdk360_video_resources.h"
|
2012-05-28 00:29:51 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_HLSL
|
2012-04-14 19:45:43 +00:00
|
|
|
|
#include "../gfx/shader_hlsl.h"
|
2012-05-28 00:29:51 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "./../gfx/gfx_context.h"
|
2012-04-09 14:04:24 +00:00
|
|
|
|
#include "../console/console_ext.h"
|
2012-01-05 12:30:13 +00:00
|
|
|
|
#include "../general.h"
|
2012-02-16 15:14:31 +00:00
|
|
|
|
#include "../message.h"
|
2012-03-08 12:44:20 +00:00
|
|
|
|
#include "shared.h"
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-02-12 14:23:35 +00:00
|
|
|
|
static bool g_first_msg;
|
2012-02-12 00:34:48 +00:00
|
|
|
|
|
2012-04-17 03:23:54 +00:00
|
|
|
|
/* Xbox 360 specific code */
|
|
|
|
|
|
2012-04-19 13:59:47 +00:00
|
|
|
|
const DWORD g_MapLinearToSrgbGpuFormat[] =
|
2012-04-18 03:01:17 +00:00
|
|
|
|
{
|
|
|
|
|
GPUTEXTUREFORMAT_1_REVERSE,
|
|
|
|
|
GPUTEXTUREFORMAT_1,
|
|
|
|
|
GPUTEXTUREFORMAT_8,
|
|
|
|
|
GPUTEXTUREFORMAT_1_5_5_5,
|
|
|
|
|
GPUTEXTUREFORMAT_5_6_5,
|
|
|
|
|
GPUTEXTUREFORMAT_6_5_5,
|
|
|
|
|
GPUTEXTUREFORMAT_8_8_8_8_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_2_10_10_10_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_8_A,
|
|
|
|
|
GPUTEXTUREFORMAT_8_B,
|
|
|
|
|
GPUTEXTUREFORMAT_8_8,
|
|
|
|
|
GPUTEXTUREFORMAT_Cr_Y1_Cb_Y0_REP,
|
|
|
|
|
GPUTEXTUREFORMAT_Y1_Cr_Y0_Cb_REP,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_EDRAM,
|
|
|
|
|
GPUTEXTUREFORMAT_8_8_8_8_A,
|
|
|
|
|
GPUTEXTUREFORMAT_4_4_4_4,
|
|
|
|
|
GPUTEXTUREFORMAT_10_11_11_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_11_11_10_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_16_16_EDRAM,
|
|
|
|
|
GPUTEXTUREFORMAT_24_8,
|
|
|
|
|
GPUTEXTUREFORMAT_24_8_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_16,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_16_EXPAND,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_EXPAND,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_16_16_EXPAND,
|
|
|
|
|
GPUTEXTUREFORMAT_16_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_16_16_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_32,
|
|
|
|
|
GPUTEXTUREFORMAT_32_32,
|
|
|
|
|
GPUTEXTUREFORMAT_32_32_32_32,
|
|
|
|
|
GPUTEXTUREFORMAT_32_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_32_32_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_32_32_32_32_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_32_AS_8,
|
|
|
|
|
GPUTEXTUREFORMAT_32_AS_8_8,
|
|
|
|
|
GPUTEXTUREFORMAT_16_MPEG,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_MPEG,
|
|
|
|
|
GPUTEXTUREFORMAT_8_INTERLACED,
|
|
|
|
|
GPUTEXTUREFORMAT_32_AS_8_INTERLACED,
|
|
|
|
|
GPUTEXTUREFORMAT_32_AS_8_8_INTERLACED,
|
|
|
|
|
GPUTEXTUREFORMAT_16_INTERLACED,
|
|
|
|
|
GPUTEXTUREFORMAT_16_MPEG_INTERLACED,
|
|
|
|
|
GPUTEXTUREFORMAT_16_16_MPEG_INTERLACED,
|
|
|
|
|
GPUTEXTUREFORMAT_DXN,
|
|
|
|
|
GPUTEXTUREFORMAT_8_8_8_8_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_2_10_10_10_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_10_11_11_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_11_11_10_AS_16_16_16_16,
|
|
|
|
|
GPUTEXTUREFORMAT_32_32_32_FLOAT,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT3A,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT5A,
|
|
|
|
|
GPUTEXTUREFORMAT_CTX1,
|
|
|
|
|
GPUTEXTUREFORMAT_DXT3A_AS_1_1_1_1,
|
|
|
|
|
GPUTEXTUREFORMAT_8_8_8_8_GAMMA_EDRAM,
|
|
|
|
|
GPUTEXTUREFORMAT_2_10_10_10_FLOAT_EDRAM,
|
|
|
|
|
};
|
|
|
|
|
|
2012-03-17 23:23:11 +00:00
|
|
|
|
struct XPR_HEADER
|
|
|
|
|
{
|
2012-05-27 22:45:30 +00:00
|
|
|
|
unsigned long dwMagic;
|
2012-04-13 01:23:23 +00:00
|
|
|
|
unsigned long dwHeaderSize;
|
|
|
|
|
unsigned long dwDataSize;
|
2012-03-17 23:23:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define XPR2_MAGIC_VALUE (0x58505232)
|
|
|
|
|
|
|
|
|
|
PackedResource::PackedResource()
|
|
|
|
|
{
|
2012-04-13 01:23:23 +00:00
|
|
|
|
m_pSysMemData = NULL;
|
|
|
|
|
m_dwSysMemDataSize = 0L;
|
|
|
|
|
m_pVidMemData = NULL;
|
|
|
|
|
m_dwVidMemDataSize = 0L;
|
|
|
|
|
m_pResourceTags = NULL;
|
|
|
|
|
m_dwNumResourceTags = 0L;
|
|
|
|
|
m_bInitialized = FALSE;
|
2012-03-17 23:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PackedResource::~PackedResource()
|
|
|
|
|
{
|
2012-04-13 01:23:23 +00:00
|
|
|
|
Destroy();
|
2012-03-17 23:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void * PackedResource::GetData( const char * strName ) const
|
|
|
|
|
{
|
2012-04-13 01:23:23 +00:00
|
|
|
|
if( m_pResourceTags == NULL || strName == NULL )
|
|
|
|
|
return NULL;
|
2012-03-17 23:23:11 +00:00
|
|
|
|
|
2012-04-13 01:23:23 +00:00
|
|
|
|
for( unsigned long i = 0; i < m_dwNumResourceTags; i++ )
|
|
|
|
|
{
|
|
|
|
|
if( !_stricmp( strName, m_pResourceTags[i].strName ) )
|
|
|
|
|
return &m_pSysMemData[m_pResourceTags[i].dwOffset];
|
|
|
|
|
}
|
2012-03-17 23:23:11 +00:00
|
|
|
|
|
2012-04-13 01:23:23 +00:00
|
|
|
|
return NULL;
|
2012-03-17 23:23:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HRESULT PackedResource::Create( const char * strFilename )
|
|
|
|
|
{
|
|
|
|
|
unsigned long dwNumBytesRead;
|
|
|
|
|
HANDLE hFile = CreateFile( strFilename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL );
|
|
|
|
|
if( hFile == INVALID_HANDLE_VALUE )
|
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_ERR( "File <%s> not found.\n", strFilename );
|
2012-03-17 23:23:11 +00:00
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read in and verify the XPR magic header
|
|
|
|
|
XPR_HEADER xprh;
|
|
|
|
|
if( !ReadFile( hFile, &xprh, sizeof( XPR_HEADER ), &dwNumBytesRead, NULL ) )
|
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_ERR( "Error reading XPR header in file <%s>.\n", strFilename );
|
2012-03-17 23:23:11 +00:00
|
|
|
|
CloseHandle( hFile );
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-27 22:45:30 +00:00
|
|
|
|
if( xprh.dwMagic != XPR2_MAGIC_VALUE )
|
|
|
|
|
{
|
|
|
|
|
RARCH_ERR( "Invalid Xbox Packed Resource (.xpr) file: Magic = 0x%08lx.\n", xprh.dwMagic );
|
|
|
|
|
CloseHandle( hFile );
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-17 23:23:11 +00:00
|
|
|
|
// Compute memory requirements
|
|
|
|
|
m_dwSysMemDataSize = xprh.dwHeaderSize;
|
|
|
|
|
m_dwVidMemDataSize = xprh.dwDataSize;
|
|
|
|
|
|
|
|
|
|
// Allocate memory
|
2012-03-29 15:27:42 +00:00
|
|
|
|
m_pSysMemData = (BYTE*)malloc(m_dwSysMemDataSize);
|
2012-03-17 23:23:11 +00:00
|
|
|
|
if( m_pSysMemData == NULL )
|
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_ERR( "Could not allocate system memory.\n" );
|
2012-03-17 23:23:11 +00:00
|
|
|
|
m_dwSysMemDataSize = 0;
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
m_pVidMemData = ( BYTE* )XMemAlloc( m_dwVidMemDataSize, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax,
|
|
|
|
|
XALLOC_PHYSICAL_ALIGNMENT_4K, XALLOC_MEMPROTECT_WRITECOMBINE, 0, XALLOC_MEMTYPE_PHYSICAL ) );
|
|
|
|
|
|
|
|
|
|
if( m_pVidMemData == NULL )
|
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_ERR( "Could not allocate physical memory.\n" );
|
2012-03-17 23:23:11 +00:00
|
|
|
|
m_dwSysMemDataSize = 0;
|
|
|
|
|
m_dwVidMemDataSize = 0;
|
2012-03-29 15:27:42 +00:00
|
|
|
|
free(m_pSysMemData);
|
2012-03-17 23:23:11 +00:00
|
|
|
|
m_pSysMemData = NULL;
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Read in the data from the file
|
|
|
|
|
if( !ReadFile( hFile, m_pSysMemData, m_dwSysMemDataSize, &dwNumBytesRead, NULL ) ||
|
|
|
|
|
!ReadFile( hFile, m_pVidMemData, m_dwVidMemDataSize, &dwNumBytesRead, NULL ) )
|
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_ERR( "Unable to read Xbox Packed Resource (.xpr) file.\n" );
|
2012-03-17 23:23:11 +00:00
|
|
|
|
CloseHandle( hFile );
|
|
|
|
|
return E_FAIL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Done with the file
|
|
|
|
|
CloseHandle( hFile );
|
|
|
|
|
|
|
|
|
|
// Extract resource table from the header data
|
|
|
|
|
m_dwNumResourceTags = *( unsigned long * )( m_pSysMemData + 0 );
|
|
|
|
|
m_pResourceTags = ( RESOURCE* )( m_pSysMemData + 4 );
|
|
|
|
|
|
|
|
|
|
// Patch up the resources
|
|
|
|
|
for( unsigned long i = 0; i < m_dwNumResourceTags; i++ )
|
|
|
|
|
{
|
|
|
|
|
m_pResourceTags[i].strName = ( char * )( m_pSysMemData + ( unsigned long )m_pResourceTags[i].strName );
|
|
|
|
|
|
|
|
|
|
// Fixup the texture memory
|
|
|
|
|
if( ( m_pResourceTags[i].dwType & 0xffff0000 ) == ( RESOURCETYPE_TEXTURE & 0xffff0000 ) )
|
|
|
|
|
{
|
|
|
|
|
D3DTexture* pTexture = ( D3DTexture* )&m_pSysMemData[m_pResourceTags[i].dwOffset];
|
|
|
|
|
// Adjust Base address according to where memory was allocated
|
|
|
|
|
XGOffsetBaseTextureAddress( pTexture, m_pVidMemData, m_pVidMemData );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_bInitialized = TRUE;
|
|
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PackedResource::Destroy()
|
|
|
|
|
{
|
|
|
|
|
delete[] m_pSysMemData;
|
|
|
|
|
m_pSysMemData = NULL;
|
|
|
|
|
m_dwSysMemDataSize = 0L;
|
|
|
|
|
|
|
|
|
|
if( m_pVidMemData != NULL )
|
|
|
|
|
XMemFree( m_pVidMemData, MAKE_XALLOC_ATTRIBUTES( 0, 0, 0, 0, eXALLOCAllocatorId_GameMax,
|
|
|
|
|
0, 0, 0, XALLOC_MEMTYPE_PHYSICAL ) );
|
|
|
|
|
|
|
|
|
|
m_pVidMemData = NULL;
|
|
|
|
|
m_dwVidMemDataSize = 0L;
|
|
|
|
|
|
|
|
|
|
m_pResourceTags = NULL;
|
|
|
|
|
m_dwNumResourceTags = 0L;
|
|
|
|
|
|
|
|
|
|
m_bInitialized = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-17 03:23:54 +00:00
|
|
|
|
/* end of Xbox 360 specific code */
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static void check_window(xdk360_video_t *d3d9)
|
|
|
|
|
{
|
|
|
|
|
bool quit, resize;
|
|
|
|
|
|
|
|
|
|
gfx_ctx_check_window(&quit,
|
|
|
|
|
&resize, NULL, NULL,
|
|
|
|
|
d3d9->frame_count);
|
|
|
|
|
|
|
|
|
|
if (quit)
|
|
|
|
|
d3d9->quitting = true;
|
|
|
|
|
else if (resize)
|
|
|
|
|
d3d9->should_resize = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void xdk360_free(void * data)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-05-27 22:56:58 +00:00
|
|
|
|
#ifdef RARCH_CONSOLE
|
|
|
|
|
if (driver.video_data)
|
2012-01-21 22:59:27 +00:00
|
|
|
|
return;
|
2012-05-27 22:56:58 +00:00
|
|
|
|
#endif
|
2012-01-21 22:59:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)data;
|
2012-02-02 18:01:52 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if (!d3d9)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
2012-04-17 03:12:03 +00:00
|
|
|
|
hlsl_deinit();
|
2012-05-28 00:29:51 +00:00
|
|
|
|
#endif
|
|
|
|
|
d3d9->d3d_render_device->Release();
|
|
|
|
|
d3d9->d3d_device->Release();
|
2012-04-15 16:13:24 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
free(d3d9);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static void xdk360_set_viewport(bool force_full)
|
2012-03-08 23:09:39 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data;
|
2012-05-27 22:56:58 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
|
2012-04-17 03:12:03 +00:00
|
|
|
|
0xff000000, 1.0f, 0);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
int width = d3d9->video_mode.fIsHiDef ? 1280 : 640;
|
|
|
|
|
int height = d3d9->video_mode.fIsHiDef ? 720 : 480;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp;
|
|
|
|
|
float m_zNear, m_zFar;
|
|
|
|
|
|
|
|
|
|
m_viewport_x_temp = 0;
|
|
|
|
|
m_viewport_y_temp = 0;
|
|
|
|
|
m_viewport_width_temp = width;
|
|
|
|
|
m_viewport_height_temp = height;
|
|
|
|
|
|
|
|
|
|
m_zNear = 0.0f;
|
|
|
|
|
m_zFar = 1.0f;
|
|
|
|
|
|
|
|
|
|
if (!force_full)
|
|
|
|
|
{
|
|
|
|
|
float desired_aspect = g_settings.video.aspect_ratio;
|
|
|
|
|
float device_aspect = (float)width / height;
|
|
|
|
|
float delta;
|
|
|
|
|
|
|
|
|
|
// If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff),
|
2012-05-22 00:19:40 +00:00
|
|
|
|
if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM)
|
|
|
|
|
{
|
|
|
|
|
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
2012-05-22 00:36:31 +00:00
|
|
|
|
m_viewport_x_temp = g_console.viewports.custom_vp.x;
|
|
|
|
|
m_viewport_y_temp = g_console.viewports.custom_vp.y;
|
|
|
|
|
m_viewport_width_temp = g_console.viewports.custom_vp.width;
|
|
|
|
|
m_viewport_height_temp = g_console.viewports.custom_vp.height;
|
2012-05-22 00:19:40 +00:00
|
|
|
|
}
|
|
|
|
|
else if (device_aspect > desired_aspect)
|
2012-04-10 19:23:42 +00:00
|
|
|
|
{
|
|
|
|
|
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
2012-04-14 19:45:43 +00:00
|
|
|
|
m_viewport_x_temp = (int)(width * (0.5 - delta));
|
|
|
|
|
m_viewport_width_temp = (int)(2.0 * width * delta);
|
|
|
|
|
width = (unsigned)(2.0 * width * delta);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
|
2012-04-14 19:45:43 +00:00
|
|
|
|
m_viewport_y_temp = (int)(height * (0.5 - delta));
|
|
|
|
|
m_viewport_height_temp = (int)(2.0 * height * delta);
|
|
|
|
|
height = (unsigned)(2.0 * height * delta);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
D3DVIEWPORT9 vp = {0};
|
|
|
|
|
vp.Width = m_viewport_width_temp;
|
|
|
|
|
vp.Height = m_viewport_height_temp;
|
|
|
|
|
vp.X = m_viewport_x_temp;
|
|
|
|
|
vp.Y = m_viewport_y_temp;
|
|
|
|
|
vp.MinZ = m_zNear;
|
|
|
|
|
vp.MaxZ = m_zFar;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetViewport(&vp);
|
2012-03-08 23:09:39 +00:00
|
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
|
//if(gl->overscan_enable && !force_full)
|
|
|
|
|
//{
|
|
|
|
|
// m_left = -gl->overscan_amount/2;
|
|
|
|
|
// m_right = 1 + gl->overscan_amount/2;
|
|
|
|
|
// m_bottom = -gl->overscan_amount/2;
|
|
|
|
|
//}
|
2012-03-08 23:09:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static void xdk360_set_rotation(void * data, unsigned orientation)
|
2012-03-10 15:41:10 +00:00
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
|
(void)data;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)data;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
FLOAT angle;
|
|
|
|
|
|
|
|
|
|
switch(orientation)
|
|
|
|
|
{
|
|
|
|
|
case ORIENTATION_NORMAL:
|
|
|
|
|
angle = M_PI * 0 / 180;
|
2012-04-14 19:45:43 +00:00
|
|
|
|
break;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
case ORIENTATION_VERTICAL:
|
2012-04-14 19:45:43 +00:00
|
|
|
|
angle = M_PI * 270 / 180;
|
|
|
|
|
break;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
case ORIENTATION_FLIPPED:
|
2012-04-14 19:45:43 +00:00
|
|
|
|
angle = M_PI * 180 / 180;
|
|
|
|
|
break;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
case ORIENTATION_FLIPPED_ROTATED:
|
2012-04-14 19:45:43 +00:00
|
|
|
|
angle = M_PI * 90 / 180;
|
|
|
|
|
break;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-17 03:23:54 +00:00
|
|
|
|
/* TODO: Move to D3DXMATRIX here */
|
2012-04-14 18:33:56 +00:00
|
|
|
|
hlsl_set_proj_matrix(XMMatrixRotationZ(angle));
|
2012-05-22 18:15:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->should_resize = TRUE;
|
2012-03-08 23:09:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 03:01:17 +00:00
|
|
|
|
static void xdk360_convert_texture_to_as16_srgb( D3DTexture *pTexture )
|
|
|
|
|
{
|
|
|
|
|
pTexture->Format.SignX = GPUSIGN_GAMMA;
|
|
|
|
|
pTexture->Format.SignY = GPUSIGN_GAMMA;
|
|
|
|
|
pTexture->Format.SignZ = GPUSIGN_GAMMA;
|
|
|
|
|
|
|
|
|
|
XGTEXTURE_DESC desc;
|
|
|
|
|
XGGetTextureDesc( pTexture, 0, &desc );
|
|
|
|
|
|
|
|
|
|
//convert to AS_16_16_16_16 format
|
2012-04-19 13:59:47 +00:00
|
|
|
|
pTexture->Format.DataFormat = g_MapLinearToSrgbGpuFormat[ (desc.Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT ];
|
2012-04-18 03:01:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
void xdk360_init_fbo(xdk360_video_t *d3d9)
|
2012-05-07 03:34:41 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if (d3d9->lpTexture_ot)
|
2012-05-23 21:46:45 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture_ot->Release();
|
|
|
|
|
d3d9->lpTexture_ot = NULL;
|
2012-05-23 21:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if (d3d9->lpSurface)
|
2012-05-23 21:46:45 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpSurface->Release();
|
|
|
|
|
d3d9->lpSurface = NULL;
|
2012-05-23 21:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->CreateTexture(512 * g_settings.video.fbo_scale_x, 512 * g_settings.video.fbo_scale_y,
|
2012-05-23 21:46:45 +00:00
|
|
|
|
1, 0, g_console.gamma_correction_enable ? ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 ) : D3DFMT_A8R8G8B8,
|
2012-05-28 00:29:51 +00:00
|
|
|
|
0, &d3d9->lpTexture_ot, NULL);
|
2012-05-23 21:46:45 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->CreateRenderTarget(512 * g_settings.video.fbo_scale_x, 512 * g_settings.video.fbo_scale_y,
|
2012-05-23 21:46:45 +00:00
|
|
|
|
g_console.gamma_correction_enable ? ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 ) : D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE,
|
2012-05-28 00:29:51 +00:00
|
|
|
|
0, 0, &d3d9->lpSurface, NULL);
|
2012-05-23 21:46:45 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture_ot_as16srgb = *d3d9->lpTexture_ot;
|
|
|
|
|
xdk360_convert_texture_to_as16_srgb(d3d9->lpTexture);
|
|
|
|
|
xdk360_convert_texture_to_as16_srgb(&d3d9->lpTexture_ot_as16srgb);
|
2012-05-23 21:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static void *xdk360_init(const video_info_t *video, const input_driver_t **input, void **input_data)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-05-27 22:56:58 +00:00
|
|
|
|
if (driver.video_data)
|
|
|
|
|
return driver.video_data;
|
2012-01-21 22:59:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)calloc(1, sizeof(xdk360_video_t));
|
|
|
|
|
if (!d3d9)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_device = Direct3DCreate9(D3D_SDK_VERSION);
|
|
|
|
|
if (!d3d9->d3d_device)
|
2012-01-07 13:54:55 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
free(d3d9);
|
2012-01-07 13:54:55 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 16:31:20 +00:00
|
|
|
|
// Get video settings
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
memset(&d3d9->video_mode, 0, sizeof(d3d9->video_mode));
|
2012-01-22 00:43:54 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
XGetVideoMode(&d3d9->video_mode);
|
2012-02-10 16:31:20 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
memset(&d3d9->d3dpp, 0, sizeof(d3d9->d3dpp));
|
2012-02-13 14:16:01 +00:00
|
|
|
|
|
|
|
|
|
// no letterboxing in 4:3 mode (if widescreen is
|
|
|
|
|
// unsupported
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if(!d3d9->video_mode.fIsWideScreen)
|
|
|
|
|
d3d9->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX;
|
2012-02-10 16:31:20 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3dpp.BackBufferWidth = d3d9->video_mode.fIsHiDef ? 1280 : 640;
|
|
|
|
|
d3d9->d3dpp.BackBufferHeight = d3d9->video_mode.fIsHiDef ? 720 : 480;
|
2012-05-22 14:04:39 +00:00
|
|
|
|
if(g_console.gamma_correction_enable)
|
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3dpp.BackBufferFormat = g_console.color_format ? (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8) : (D3DFORMAT)MAKESRGBFMT(D3DFMT_LIN_A1R5G5B5);
|
|
|
|
|
d3d9->d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8);
|
2012-05-22 14:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3dpp.BackBufferFormat = g_console.color_format ? D3DFMT_A8R8G8B8 : D3DFMT_LIN_A1R5G5B5;
|
|
|
|
|
d3d9->d3dpp.FrontBufferFormat = D3DFMT_LE_X8R8G8B8;
|
2012-05-22 14:04:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
|
|
|
|
|
d3d9->d3dpp.MultiSampleQuality = 0;
|
|
|
|
|
d3d9->d3dpp.BackBufferCount = 2;
|
|
|
|
|
d3d9->d3dpp.EnableAutoDepthStencil = FALSE;
|
|
|
|
|
d3d9->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
|
|
d3d9->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
2012-01-22 00:43:54 +00:00
|
|
|
|
|
2012-03-08 15:14:09 +00:00
|
|
|
|
// D3DCREATE_HARDWARE_VERTEXPROCESSING is ignored on 360
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING,
|
|
|
|
|
&d3d9->d3dpp, &d3d9->d3d_render_device);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
hlsl_init(g_settings.video.cg_shader_path, d3d9->d3d_render_device);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5,
|
|
|
|
|
0, &d3d9->lpTexture, NULL);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_init_fbo(d3d9);
|
2012-04-18 03:01:17 +00:00
|
|
|
|
|
2012-01-07 14:21:23 +00:00
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
2012-03-08 15:14:09 +00:00
|
|
|
|
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture->UnlockRect(0);
|
2012-01-07 14:21:23 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->last_width = 512;
|
|
|
|
|
d3d9->last_height = 512;
|
2012-01-07 14:21:23 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats),
|
|
|
|
|
0, 0, 0, &d3d9->vertex_buf, NULL);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-01-07 13:54:55 +00:00
|
|
|
|
static const DrawVerticeFormats init_verts[] = {
|
2012-01-07 14:21:23 +00:00
|
|
|
|
{ -1.0f, -1.0f, 0.0f, 1.0f },
|
|
|
|
|
{ 1.0f, -1.0f, 1.0f, 1.0f },
|
|
|
|
|
{ -1.0f, 1.0f, 0.0f, 0.0f },
|
|
|
|
|
{ 1.0f, 1.0f, 1.0f, 0.0f },
|
2012-01-07 13:54:55 +00:00
|
|
|
|
};
|
2012-03-08 15:14:09 +00:00
|
|
|
|
|
2012-04-17 03:12:03 +00:00
|
|
|
|
void *verts_ptr;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->vertex_buf->Lock(0, 0, &verts_ptr, 0);
|
2012-01-07 13:54:55 +00:00
|
|
|
|
memcpy(verts_ptr, init_verts, sizeof(init_verts));
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->vertex_buf->Unlock();
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-01-07 13:54:55 +00:00
|
|
|
|
static const D3DVERTEXELEMENT9 VertexElements[] =
|
|
|
|
|
{
|
|
|
|
|
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
|
|
|
|
|
{ 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
|
2012-01-05 11:37:27 +00:00
|
|
|
|
D3DDECL_END()
|
2012-01-07 13:54:55 +00:00
|
|
|
|
};
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->CreateVertexDeclaration(VertexElements, &d3d9->v_decl);
|
2012-03-08 15:14:09 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
|
2012-04-17 03:12:03 +00:00
|
|
|
|
0xff000000, 1.0f, 0);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
|
|
|
|
|
d3d9->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE);
|
2012-01-07 14:11:57 +00:00
|
|
|
|
|
|
|
|
|
D3DVIEWPORT9 vp = {0};
|
2012-05-28 00:29:51 +00:00
|
|
|
|
vp.Width = d3d9->video_mode.fIsHiDef ? 1280 : 640;
|
|
|
|
|
vp.Height = d3d9->video_mode.fIsHiDef ? 720 : 480;
|
2012-01-07 14:11:57 +00:00
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
|
vp.MaxZ = 1.0f;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetViewport(&vp);
|
2012-01-07 14:11:57 +00:00
|
|
|
|
|
2012-05-22 00:36:31 +00:00
|
|
|
|
if(g_console.viewports.custom_vp.width == 0)
|
|
|
|
|
g_console.viewports.custom_vp.width = vp.Width;
|
2012-05-22 00:19:40 +00:00
|
|
|
|
|
2012-05-22 00:36:31 +00:00
|
|
|
|
if(g_console.viewports.custom_vp.height == 0)
|
|
|
|
|
g_console.viewports.custom_vp.height = vp.Height;
|
2012-05-22 00:19:40 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_set_rotation(d3d9, g_console.screen_orientation);
|
2012-03-10 14:31:54 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->fbo_enabled = 1;
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
return d3d9;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static bool xdk360_frame(void *data, const void *frame,
|
2012-01-07 13:54:55 +00:00
|
|
|
|
unsigned width, unsigned height, unsigned pitch, const char *msg)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)data;
|
2012-05-06 16:53:43 +00:00
|
|
|
|
D3DSurface* pRenderTarget0;
|
2012-05-22 13:21:45 +00:00
|
|
|
|
bool menu_enabled = g_console.menu_enable;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if (d3d9->last_width != width || d3d9->last_height != height)
|
2012-01-07 14:21:23 +00:00
|
|
|
|
{
|
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
2012-03-08 15:14:09 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture->UnlockRect(0);
|
2012-01-07 14:21:23 +00:00
|
|
|
|
|
2012-04-19 13:59:47 +00:00
|
|
|
|
float tex_w = width / 512.0f;
|
|
|
|
|
float tex_h = height / 512.0f;
|
2012-05-06 20:02:54 +00:00
|
|
|
|
|
2012-05-06 20:11:06 +00:00
|
|
|
|
DrawVerticeFormats verts[] = {
|
2012-04-14 02:38:40 +00:00
|
|
|
|
{ -1.0f, -1.0f, 0.0f, tex_h },
|
2012-05-06 20:02:54 +00:00
|
|
|
|
{ 1.0f, -1.0f, tex_w, tex_h },
|
|
|
|
|
{ -1.0f, 1.0f, 0.0f, 0.0f },
|
|
|
|
|
{ 1.0f, 1.0f, tex_w, 0.0f },
|
2012-04-10 19:23:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-05-06 20:02:54 +00:00
|
|
|
|
// Align texels and vertices (D3D9 quirk).
|
|
|
|
|
for (unsigned i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
verts[i].x -= 0.5f / 512.0f;
|
|
|
|
|
verts[i].y += 0.5f / 512.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-17 03:12:03 +00:00
|
|
|
|
void *verts_ptr;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->vertex_buf->Lock(0, 0, &verts_ptr, 0);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
memcpy(verts_ptr, verts, sizeof(verts));
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->vertex_buf->Unlock();
|
2012-03-08 12:44:20 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->last_width = width;
|
|
|
|
|
d3d9->last_height = height;
|
2012-01-07 14:21:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if (d3d9->fbo_enabled)
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->GetRenderTarget(0, &pRenderTarget0);
|
|
|
|
|
d3d9->d3d_render_device->SetRenderTarget(0, d3d9->lpSurface);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if (d3d9->should_resize)
|
|
|
|
|
xdk360_set_viewport(false);
|
|
|
|
|
|
|
|
|
|
d3d9->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
|
2012-05-06 20:02:54 +00:00
|
|
|
|
0xff000000, 1.0f, 0);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->frame_count++;
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetTexture(0, d3d9->lpTexture);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-05-06 19:57:01 +00:00
|
|
|
|
hlsl_use(1);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if(d3d9->fbo_enabled)
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
|
|
|
|
hlsl_set_params(width, height, 512, 512, g_settings.video.fbo_scale_x * width,
|
2012-05-28 00:29:51 +00:00
|
|
|
|
g_settings.video.fbo_scale_y * height, d3d9->frame_count);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
D3DVIEWPORT9 vp = {0};
|
|
|
|
|
vp.Width = g_settings.video.fbo_scale_x * width;
|
|
|
|
|
vp.Height = g_settings.video.fbo_scale_y * height;
|
|
|
|
|
vp.X = 0;
|
|
|
|
|
vp.Y = 0;
|
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
|
vp.MaxZ = 1.0f;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetViewport(&vp);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
hlsl_set_params(width, height, 512, 512, d3d9->d3dpp.BackBufferWidth,
|
|
|
|
|
d3d9->d3dpp.BackBufferHeight, d3d9->frame_count);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
2012-04-19 13:59:07 +00:00
|
|
|
|
|
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
2012-04-19 13:59:07 +00:00
|
|
|
|
for (unsigned y = 0; y < height; y++)
|
|
|
|
|
{
|
|
|
|
|
const uint8_t *in = (const uint8_t*)frame + y * pitch;
|
|
|
|
|
uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch;
|
|
|
|
|
memcpy(out, in, width * sizeof(uint16_t));
|
|
|
|
|
}
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->lpTexture->UnlockRect(0);
|
2012-04-19 13:59:07 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
2012-04-17 03:23:54 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetVertexDeclaration(d3d9->v_decl);
|
|
|
|
|
d3d9->d3d_render_device->SetStreamSource(0, d3d9->vertex_buf, 0, sizeof(DrawVerticeFormats));
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if(d3d9->fbo_enabled)
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, d3d9->lpTexture_ot,
|
2012-05-06 20:02:54 +00:00
|
|
|
|
NULL, 0, 0, NULL, 0, 0, NULL);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetRenderTarget(0, pRenderTarget0);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
pRenderTarget0->Release();
|
2012-05-28 00:29:51 +00:00
|
|
|
|
d3d9->d3d_render_device->SetTexture(0, &d3d9->lpTexture_ot_as16srgb);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-05-06 19:57:01 +00:00
|
|
|
|
hlsl_use(2);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
hlsl_set_params(g_settings.video.fbo_scale_x * width, g_settings.video.fbo_scale_y * height, g_settings.video.fbo_scale_x * 512, g_settings.video.fbo_scale_y * 512, d3d9->d3dpp.BackBufferWidth,
|
|
|
|
|
d3d9->d3dpp.BackBufferHeight, d3d9->frame_count);
|
|
|
|
|
xdk360_set_viewport(false);
|
|
|
|
|
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
|
|
|
|
d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
|
|
|
|
d3d9->d3d_render_device->SetVertexDeclaration(d3d9->v_decl);
|
|
|
|
|
d3d9->d3d_render_device->SetStreamSource(0, d3d9->vertex_buf, 0, sizeof(DrawVerticeFormats));
|
|
|
|
|
d3d9->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-17 03:23:54 +00:00
|
|
|
|
/* XBox 360 specific font code */
|
2012-05-22 13:21:45 +00:00
|
|
|
|
if (msg && !menu_enabled)
|
2012-02-12 14:23:35 +00:00
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
|
if(IS_TIMER_EXPIRED() || g_first_msg)
|
|
|
|
|
{
|
|
|
|
|
xdk360_console_format(msg);
|
2012-04-17 03:12:03 +00:00
|
|
|
|
g_first_msg = 0;
|
|
|
|
|
SET_TIMER_EXPIRATION(30);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
}
|
2012-05-06 20:02:54 +00:00
|
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
|
xdk360_console_draw();
|
2012-02-12 14:23:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if(!d3d9->block_swap)
|
|
|
|
|
d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-13 21:45:28 +00:00
|
|
|
|
static void xdk360_set_swap_block_swap (void * data, bool toggle)
|
2012-02-13 01:35:01 +00:00
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
|
(void)data;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data;
|
|
|
|
|
d3d9->block_swap = toggle;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
|
|
|
|
|
if(toggle)
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_LOG("Swap is set to blocked.\n");
|
2012-04-10 19:23:42 +00:00
|
|
|
|
else
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_LOG("Swap is set to non-blocked.\n");
|
2012-02-13 01:35:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-13 21:53:07 +00:00
|
|
|
|
static void xdk360_swap (void * data)
|
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
|
(void)data;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data;
|
|
|
|
|
d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL);
|
2012-02-13 21:53:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static void xdk360_set_nonblock_state(void *data, bool state)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)data;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
if(d3d9->vsync)
|
|
|
|
|
{
|
|
|
|
|
RARCH_LOG("D3D Vsync => %s\n", state ? "off" : "on");
|
|
|
|
|
gfx_ctx_set_swap_interval(state ? 0 : 1, TRUE);
|
|
|
|
|
}
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static bool xdk360_alive(void *data)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_video_t *d3d9 = (xdk360_video_t*)data;
|
|
|
|
|
check_window(d3d9);
|
|
|
|
|
return !d3d9->quitting;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
static bool xdk360_focus(void *data)
|
2012-02-12 17:42:51 +00:00
|
|
|
|
{
|
2012-05-28 00:29:51 +00:00
|
|
|
|
(void)data;
|
|
|
|
|
return gfx_ctx_window_has_focus();
|
2012-02-12 17:42:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-22 00:06:34 +00:00
|
|
|
|
// 360 needs a working graphics stack before RetroArch even starts.
|
2012-01-21 22:59:27 +00:00
|
|
|
|
// To deal with this main.c,
|
|
|
|
|
// the top level module owns the instance, and is created beforehand.
|
2012-04-21 21:13:50 +00:00
|
|
|
|
// When RetroArch gets around to init it, it is already allocated.
|
|
|
|
|
// When RetroArch wants to free it, it is ignored.
|
2012-05-27 22:37:54 +00:00
|
|
|
|
static void xdk360_start(void)
|
2012-01-21 22:59:27 +00:00
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
|
video_info_t video_info = {0};
|
|
|
|
|
|
|
|
|
|
video_info.vsync = g_settings.video.vsync;
|
|
|
|
|
video_info.force_aspect = false;
|
2012-05-27 22:56:58 +00:00
|
|
|
|
video_info.fullscreen = true;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
video_info.smooth = g_settings.video.smooth;
|
|
|
|
|
video_info.input_scale = 2;
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
driver.video_data = xdk360_init(&video_info, NULL, NULL);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
|
|
|
|
|
g_first_msg = true;
|
|
|
|
|
|
2012-04-17 03:23:54 +00:00
|
|
|
|
/* XBox 360 specific font code */
|
2012-04-10 19:23:42 +00:00
|
|
|
|
HRESULT hr = xdk360_console_init("game:\\media\\Arial_12.xpr",
|
2012-04-14 02:38:40 +00:00
|
|
|
|
0xff000000, 0xffffffff );
|
2012-04-10 19:23:42 +00:00
|
|
|
|
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
|
RARCH_ERR("Couldn't create debug console.\n");
|
2012-04-10 19:23:42 +00:00
|
|
|
|
}
|
2012-01-21 22:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-27 22:37:54 +00:00
|
|
|
|
static void xdk360_restart(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void xdk360_stop(void)
|
2012-01-21 22:59:27 +00:00
|
|
|
|
{
|
2012-05-27 22:56:58 +00:00
|
|
|
|
void *data = driver.video_data;
|
|
|
|
|
driver.video_data = NULL;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
xdk360_console_deinit();
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_free(data);
|
2012-01-21 22:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-05 11:37:27 +00:00
|
|
|
|
const video_driver_t video_xdk360 = {
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_init,
|
|
|
|
|
xdk360_frame,
|
|
|
|
|
xdk360_set_nonblock_state,
|
|
|
|
|
xdk360_alive,
|
|
|
|
|
xdk360_focus,
|
2012-01-05 12:30:13 +00:00
|
|
|
|
NULL,
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_free,
|
2012-02-13 21:45:28 +00:00
|
|
|
|
"xdk360",
|
2012-05-27 22:37:54 +00:00
|
|
|
|
xdk360_start,
|
|
|
|
|
xdk360_stop,
|
|
|
|
|
xdk360_restart,
|
2012-05-28 00:29:51 +00:00
|
|
|
|
xdk360_set_rotation,
|
2012-04-09 14:04:24 +00:00
|
|
|
|
};
|