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-05-28 00:29:51 +00:00
|
|
|
|
#ifdef _XBOX
|
2012-01-05 11:37:27 +00:00
|
|
|
|
#include <xtl.h>
|
2012-10-01 01:35:38 +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-10-01 01:35:38 +00:00
|
|
|
|
#include "xdk_d3d.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
|
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#ifdef _XBOX1
|
|
|
|
|
#include "./../gfx/fonts/xdk1_xfonts.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-05-28 00:29:51 +00:00
|
|
|
|
#include "./../gfx/gfx_context.h"
|
2012-01-05 12:30:13 +00:00
|
|
|
|
#include "../general.h"
|
2012-02-16 15:14:31 +00:00
|
|
|
|
#include "../message.h"
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-15 05:25:42 +00:00
|
|
|
|
#ifdef _XBOX360
|
|
|
|
|
#include "../gfx/fonts/xdk360_fonts.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-16 00:15:47 +00:00
|
|
|
|
#include "../xdk/xdk_resources.h"
|
2012-03-17 23:23:11 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
wchar_t strw_buffer[128];
|
|
|
|
|
unsigned font_x, font_y;
|
|
|
|
|
FLOAT angle;
|
|
|
|
|
#elif defined(_XBOX360)
|
2012-07-15 05:25:42 +00:00
|
|
|
|
extern video_console_t video_console;
|
|
|
|
|
extern xdk360_video_font_t m_Font;
|
|
|
|
|
|
|
|
|
|
const DWORD g_MapLinearToSrgbGpuFormat[] =
|
|
|
|
|
{
|
|
|
|
|
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-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-07-15 05:25:42 +00:00
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void check_window(xdk_d3d_video_t *d3d)
|
2012-05-28 00:29:51 +00:00
|
|
|
|
{
|
|
|
|
|
bool quit, resize;
|
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
d3d->driver->check_window(&quit,
|
2012-05-28 00:29:51 +00:00
|
|
|
|
&resize, NULL, NULL,
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->frame_count);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
|
|
|
|
|
if (quit)
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->quitting = true;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
else if (resize)
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->should_resize = true;
|
2012-05-28 00:29:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-01 00:45:29 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
|
|
|
|
static bool hlsl_shader_init(void)
|
|
|
|
|
{
|
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
|
|
|
|
const char *shader_path = g_settings.video.cg_shader_path;
|
|
|
|
|
|
|
|
|
|
return hlsl_init(g_settings.video.cg_shader_path, d3d->d3d_render_device);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_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-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
2012-02-02 18:01:52 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if (!d3d)
|
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
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#ifdef HAVE_D3D9
|
2012-09-30 22:09:04 +00:00
|
|
|
|
d3d9_deinit_font();
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-09-30 22:09:04 +00:00
|
|
|
|
|
|
|
|
|
d3d->driver->destroy();
|
2012-04-15 16:13:24 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
free(d3d);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#ifdef _XBOX360
|
2012-07-15 05:25:42 +00:00
|
|
|
|
void xdk_video_font_draw_text(xdk360_video_font_t *font,
|
|
|
|
|
float fOriginX, float fOriginY, const wchar_t * strText, float fMaxPixelWidth )
|
|
|
|
|
{
|
|
|
|
|
if( strText == NULL || strText[0] == L'\0')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver.video_data;
|
|
|
|
|
D3DDevice *pd3dDevice = vid->d3d_render_device;
|
|
|
|
|
|
|
|
|
|
// Set the color as a vertex shader constant
|
|
|
|
|
float vColor[4];
|
|
|
|
|
vColor[0] = ( ( 0xffffffff & 0x00ff0000 ) >> 16L ) / 255.0F;
|
|
|
|
|
vColor[1] = ( ( 0xffffffff & 0x0000ff00 ) >> 8L ) / 255.0F;
|
|
|
|
|
vColor[2] = ( ( 0xffffffff & 0x000000ff ) >> 0L ) / 255.0F;
|
|
|
|
|
vColor[3] = ( ( 0xffffffff & 0xff000000 ) >> 24L ) / 255.0F;
|
|
|
|
|
|
|
|
|
|
d3d9_render_msg_pre(font);
|
|
|
|
|
|
|
|
|
|
// Perform the actual storing of the color constant here to prevent
|
|
|
|
|
// a load-hit-store by inserting work between the store and the use of
|
|
|
|
|
// the vColor array.
|
|
|
|
|
pd3dDevice->SetVertexShaderConstantF( 1, vColor, 1 );
|
|
|
|
|
|
|
|
|
|
// Set the starting screen position
|
|
|
|
|
if((fOriginX < 0.0f))
|
|
|
|
|
fOriginX += font->m_rcWindow.x2;
|
|
|
|
|
if( fOriginY < 0.0f )
|
|
|
|
|
fOriginY += font->m_rcWindow.y2;
|
|
|
|
|
|
|
|
|
|
font->m_fCursorX = floorf( fOriginX );
|
|
|
|
|
font->m_fCursorY = floorf( fOriginY );
|
|
|
|
|
|
|
|
|
|
// Adjust for padding
|
|
|
|
|
fOriginY -= font->m_fFontTopPadding;
|
|
|
|
|
|
|
|
|
|
// Add window offsets
|
|
|
|
|
float Winx = 0.0f;
|
|
|
|
|
float Winy = 0.0f;
|
|
|
|
|
fOriginX += Winx;
|
|
|
|
|
fOriginY += Winy;
|
|
|
|
|
font->m_fCursorX += Winx;
|
|
|
|
|
font->m_fCursorY += Winy;
|
|
|
|
|
|
|
|
|
|
// Begin drawing the vertices
|
|
|
|
|
|
|
|
|
|
// Declared as volatile to force writing in ascending
|
|
|
|
|
// address order. It prevents out of sequence writing in write combined
|
|
|
|
|
// memory.
|
|
|
|
|
|
|
|
|
|
volatile float * pVertex;
|
|
|
|
|
|
|
|
|
|
unsigned long dwNumChars = wcslen(strText);
|
|
|
|
|
HRESULT hr = pd3dDevice->BeginVertices( D3DPT_QUADLIST, 4 * dwNumChars, sizeof( XMFLOAT4 ) ,
|
|
|
|
|
( VOID** )&pVertex );
|
|
|
|
|
|
|
|
|
|
// The ring buffer may run out of space when tiling, doing z-prepasses,
|
|
|
|
|
// or using BeginCommandBuffer. If so, make the buffer larger.
|
|
|
|
|
if( hr < 0 )
|
|
|
|
|
RARCH_ERR( "Ring buffer out of memory.\n" );
|
|
|
|
|
|
|
|
|
|
// Draw four vertices for each glyph
|
|
|
|
|
while( *strText )
|
|
|
|
|
{
|
|
|
|
|
wchar_t letter;
|
|
|
|
|
|
|
|
|
|
// Get the current letter in the string
|
|
|
|
|
letter = *strText++;
|
|
|
|
|
|
|
|
|
|
// Handle the newline character
|
|
|
|
|
if( letter == L'\n' )
|
|
|
|
|
{
|
|
|
|
|
font->m_fCursorX = fOriginX;
|
|
|
|
|
font->m_fCursorY += font->m_fFontYAdvance * font->m_fYScaleFactor;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Translate unprintable characters
|
|
|
|
|
const GLYPH_ATTR * pGlyph = &font->m_Glyphs[ ( letter <= font->m_cMaxGlyph )
|
|
|
|
|
? font->m_TranslatorTable[letter] : 0 ];
|
|
|
|
|
|
|
|
|
|
float fOffset = font->m_fXScaleFactor * (float)pGlyph->wOffset;
|
|
|
|
|
float fAdvance = font->m_fXScaleFactor * (float)pGlyph->wAdvance;
|
|
|
|
|
float fWidth = font->m_fXScaleFactor * (float)pGlyph->wWidth;
|
|
|
|
|
float fHeight = font->m_fYScaleFactor * font->m_fFontHeight;
|
|
|
|
|
|
|
|
|
|
// Setup the screen coordinates
|
|
|
|
|
font->m_fCursorX += fOffset;
|
|
|
|
|
float X4 = font->m_fCursorX;
|
|
|
|
|
float X1 = X4;
|
|
|
|
|
float X3 = X4 + fWidth;
|
|
|
|
|
float X2 = X1 + fWidth;
|
|
|
|
|
float Y1 = font->m_fCursorY;
|
|
|
|
|
float Y3 = Y1 + fHeight;
|
|
|
|
|
float Y2 = Y1;
|
|
|
|
|
float Y4 = Y3;
|
|
|
|
|
|
|
|
|
|
font->m_fCursorX += fAdvance;
|
|
|
|
|
|
|
|
|
|
// Add the vertices to draw this glyph
|
|
|
|
|
|
|
|
|
|
unsigned long tu1 = pGlyph->tu1; // Convert shorts to 32 bit longs for in register merging
|
|
|
|
|
unsigned long tv1 = pGlyph->tv1;
|
|
|
|
|
unsigned long tu2 = pGlyph->tu2;
|
|
|
|
|
unsigned long tv2 = pGlyph->tv2;
|
|
|
|
|
|
|
|
|
|
// NOTE: The vertexs are 2 floats for the screen coordinates,
|
|
|
|
|
// followed by two USHORTS for the u/vs of the character,
|
|
|
|
|
// terminated with the ARGB 32 bit color.
|
|
|
|
|
// This makes for 16 bytes per vertex data (Easier to read)
|
|
|
|
|
// Second NOTE: The uvs are merged and written using a DWORD due
|
|
|
|
|
// to the write combining hardware being only able to handle 32,
|
|
|
|
|
// 64 and 128 writes. Never store to write combined memory with
|
|
|
|
|
// 8 or 16 bit instructions. You've been warned.
|
|
|
|
|
|
|
|
|
|
pVertex[0] = X1;
|
|
|
|
|
pVertex[1] = Y1;
|
|
|
|
|
((volatile unsigned long *)pVertex)[2] = (tu1<<16)|tv1; // Merged using big endian rules
|
|
|
|
|
pVertex[3] = 0;
|
|
|
|
|
pVertex[4] = X2;
|
|
|
|
|
pVertex[5] = Y2;
|
|
|
|
|
((volatile unsigned long *)pVertex)[6] = (tu2<<16)|tv1; // Merged using big endian rules
|
|
|
|
|
pVertex[7] = 0;
|
|
|
|
|
pVertex[8] = X3;
|
|
|
|
|
pVertex[9] = Y3;
|
|
|
|
|
((volatile unsigned long *)pVertex)[10] = (tu2<<16)|tv2; // Merged using big endian rules
|
|
|
|
|
pVertex[11] = 0;
|
|
|
|
|
pVertex[12] = X4;
|
|
|
|
|
pVertex[13] = Y4;
|
|
|
|
|
((volatile unsigned long *)pVertex)[14] = (tu1<<16)|tv2; // Merged using big endian rules
|
|
|
|
|
pVertex[15] = 0;
|
|
|
|
|
pVertex+=16;
|
|
|
|
|
|
|
|
|
|
dwNumChars--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Since we allocated vertex data space based on the string length, we now need to
|
|
|
|
|
// add some dummy verts for any skipped characters (like newlines, etc.)
|
|
|
|
|
while( dwNumChars )
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < 16; i++)
|
|
|
|
|
pVertex[i] = 0;
|
|
|
|
|
|
|
|
|
|
pVertex += 16;
|
|
|
|
|
dwNumChars--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stop drawing vertices
|
|
|
|
|
D3DDevice_EndVertices(pd3dDevice);
|
|
|
|
|
|
|
|
|
|
// Undo window offsets
|
|
|
|
|
font->m_fCursorX -= Winx;
|
|
|
|
|
font->m_fCursorY -= Winy;
|
|
|
|
|
|
|
|
|
|
d3d9_render_msg_post(font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void xdk360_console_draw(void)
|
|
|
|
|
{
|
|
|
|
|
xdk_d3d_video_t *vid = (xdk_d3d_video_t*)driver.video_data;
|
|
|
|
|
D3DDevice *m_pd3dDevice = vid->d3d_render_device;
|
|
|
|
|
|
|
|
|
|
// The top line
|
|
|
|
|
unsigned int nTextLine = ( video_console.m_nCurLine -
|
|
|
|
|
video_console.m_cScreenHeight + video_console.m_cScreenHeightVirtual -
|
|
|
|
|
video_console.m_nScrollOffset + 1 )
|
|
|
|
|
% video_console.m_cScreenHeightVirtual;
|
|
|
|
|
|
|
|
|
|
d3d9_render_msg_pre(&m_Font);
|
|
|
|
|
|
|
|
|
|
for( unsigned int nScreenLine = 0; nScreenLine < video_console.m_cScreenHeight; nScreenLine++ )
|
|
|
|
|
{
|
|
|
|
|
xdk_video_font_draw_text(&m_Font, (float)( video_console.m_cxSafeAreaOffset ),
|
|
|
|
|
(float)( video_console.m_cySafeAreaOffset + video_console.m_fLineHeight * nScreenLine ),
|
|
|
|
|
video_console.m_Lines[nTextLine], 0.0f );
|
|
|
|
|
|
|
|
|
|
nTextLine = ( nTextLine + 1 ) % video_console.m_cScreenHeightVirtual;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
d3d9_render_msg_post(&m_Font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void xdk_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
|
|
|
|
|
pTexture->Format.DataFormat = g_MapLinearToSrgbGpuFormat[ (desc.Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT ];
|
|
|
|
|
}
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-07-15 05:25:42 +00:00
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_set_viewport(bool force_full)
|
2012-03-08 23:09:39 +00:00
|
|
|
|
{
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
2012-10-01 01:35:38 +00:00
|
|
|
|
int width, height; // Set the viewport based on the current resolution
|
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;
|
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
|
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
// Get the "video mode"
|
|
|
|
|
d3d->video_mode = XGetVideoFlags();
|
|
|
|
|
|
|
|
|
|
width = d3d->d3dpp.BackBufferWidth;
|
|
|
|
|
height = d3d->d3dpp.BackBufferHeight;
|
|
|
|
|
#elif defined(_XBOX360)
|
|
|
|
|
width = d3d->video_mode.fIsHiDef ? 1280 : 640;
|
|
|
|
|
height = d3d->video_mode.fIsHiDef ? 720 : 480;
|
|
|
|
|
#endif
|
2012-04-10 19:23:42 +00:00
|
|
|
|
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-10-15 04:24:39 +00:00
|
|
|
|
if(g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
|
2012-05-22 00:19:40 +00:00
|
|
|
|
{
|
2012-05-29 13:25:39 +00:00
|
|
|
|
delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
|
2012-10-15 04:24:39 +00:00
|
|
|
|
m_viewport_x_temp = g_extern.console.screen.viewports.custom_vp.x;
|
|
|
|
|
m_viewport_y_temp = g_extern.console.screen.viewports.custom_vp.y;
|
|
|
|
|
m_viewport_width_temp = g_extern.console.screen.viewports.custom_vp.width;
|
|
|
|
|
m_viewport_height_temp = g_extern.console.screen.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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 13:40:14 +00:00
|
|
|
|
D3DVIEWPORT vp = {0};
|
2012-04-10 19:23:42 +00:00
|
|
|
|
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-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetViewport(&vp);
|
2012-03-08 23:09:39 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#ifdef _XBOX1
|
|
|
|
|
font_x = vp.X;
|
|
|
|
|
font_y = vp.Y;
|
|
|
|
|
#endif
|
|
|
|
|
|
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-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_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-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
2012-04-10 19:23:42 +00:00
|
|
|
|
FLOAT angle;
|
|
|
|
|
|
|
|
|
|
switch(orientation)
|
|
|
|
|
{
|
|
|
|
|
case ORIENTATION_NORMAL:
|
|
|
|
|
angle = M_PI * 0 / 180;
|
2012-05-29 13:25:39 +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-07-07 17:56:46 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
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-07-07 17:56:46 +00:00
|
|
|
|
#endif
|
2012-05-22 18:15:27 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->should_resize = TRUE;
|
2012-03-08 23:09:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#ifdef HAVE_FBO
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_init_fbo(xdk_d3d_video_t *d3d)
|
2012-05-07 03:34:41 +00:00
|
|
|
|
{
|
2012-07-07 17:31:04 +00:00
|
|
|
|
if(!g_settings.video.render_to_texture)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if (d3d->lpTexture_ot)
|
2012-05-23 21:46:45 +00:00
|
|
|
|
{
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpTexture_ot->Release();
|
|
|
|
|
d3d->lpTexture_ot = NULL;
|
2012-05-23 21:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if (d3d->lpSurface)
|
2012-05-23 21:46:45 +00:00
|
|
|
|
{
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpSurface->Release();
|
|
|
|
|
d3d->lpSurface = NULL;
|
2012-05-23 21:46:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-15 05:22:20 +00:00
|
|
|
|
d3d->d3d_render_device->CreateTexture(512 * g_settings.video.fbo.scale_x, 512 * g_settings.video.fbo.scale_y,
|
2012-10-15 04:24:39 +00:00
|
|
|
|
1, 0, g_extern.console.screen.gamma_correction ? ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 ) : D3DFMT_A8R8G8B8,
|
2012-07-07 13:40:14 +00:00
|
|
|
|
0, &d3d->lpTexture_ot
|
|
|
|
|
, NULL
|
|
|
|
|
);
|
2012-05-23 21:46:45 +00:00
|
|
|
|
|
2012-10-15 05:22:20 +00:00
|
|
|
|
d3d->d3d_render_device->CreateRenderTarget(512 * g_settings.video.fbo.scale_x, 512 * g_settings.video.fbo.scale_y,
|
2012-10-15 04:24:39 +00:00
|
|
|
|
g_extern.console.screen.gamma_correction ? ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 ) : D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE,
|
2012-07-07 12:41:58 +00:00
|
|
|
|
0, 0, &d3d->lpSurface, NULL);
|
2012-05-23 21:46:45 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpTexture_ot_as16srgb = *d3d->lpTexture_ot;
|
2012-07-15 05:25:42 +00:00
|
|
|
|
xdk_convert_texture_to_as16_srgb(d3d->lpTexture);
|
|
|
|
|
xdk_convert_texture_to_as16_srgb(&d3d->lpTexture_ot_as16srgb);
|
2012-07-07 17:31:04 +00:00
|
|
|
|
d3d->fbo_enabled = 1;
|
2012-05-23 21:46:45 +00:00
|
|
|
|
}
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#endif
|
2012-05-23 21:46:45 +00:00
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void *xdk_d3d_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-09-30 22:09:04 +00:00
|
|
|
|
//we'll just use driver.video_data throughout here because it needs to
|
|
|
|
|
//exist when we delegate initing to the context file
|
|
|
|
|
driver.video_data = (xdk_d3d_video_t*)calloc(1, sizeof(xdk_d3d_video_t));
|
|
|
|
|
if (!driver.video_data)
|
2012-01-07 13:54:55 +00:00
|
|
|
|
return NULL;
|
2012-02-13 14:16:01 +00:00
|
|
|
|
|
2012-09-30 22:09:04 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
2012-05-28 21:19:40 +00:00
|
|
|
|
|
2012-09-30 22:09:04 +00:00
|
|
|
|
d3d->vsync = video->vsync;
|
2012-05-29 13:25:39 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
d3d->driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D8_API);
|
|
|
|
|
#elif defined(_XBOX360)
|
2012-09-30 22:09:04 +00:00
|
|
|
|
d3d->driver = gfx_ctx_init_first(GFX_CTX_DIRECT3D9_API);
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-09-30 22:09:04 +00:00
|
|
|
|
if (!d3d->driver)
|
2012-05-22 14:04:39 +00:00
|
|
|
|
{
|
2012-09-30 22:09:04 +00:00
|
|
|
|
free(d3d);
|
|
|
|
|
return NULL;
|
2012-05-22 14:04:39 +00:00
|
|
|
|
}
|
2012-01-22 00:43:54 +00:00
|
|
|
|
|
2012-09-30 22:09:04 +00:00
|
|
|
|
RARCH_LOG("Found D3D context: %s\n", d3d->driver->ident);
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-09-30 23:17:30 +00:00
|
|
|
|
d3d->driver->get_video_size(&d3d->full_x, &d3d->full_y);
|
|
|
|
|
RARCH_LOG("Detecting screen resolution: %ux%u.\n", d3d->full_x, d3d->full_y);
|
|
|
|
|
|
|
|
|
|
gfx_ctx_xdk_set_swap_interval(d3d->vsync ? 1 : 0);
|
|
|
|
|
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
2012-10-01 00:45:29 +00:00
|
|
|
|
if (!hlsl_shader_init())
|
|
|
|
|
{
|
|
|
|
|
RARCH_ERR("Shader init failed.\n");
|
|
|
|
|
d3d->driver->destroy();
|
|
|
|
|
free(d3d);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-01 00:46:58 +00:00
|
|
|
|
RARCH_LOG("D3D: Loaded %u program(s).\n", d3d_hlsl_num());
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#endif
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#ifdef HAVE_FBO
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_init_fbo(d3d);
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#endif
|
2012-04-18 03:01:17 +00:00
|
|
|
|
|
2012-10-15 04:24:39 +00:00
|
|
|
|
xdk_d3d_set_rotation(d3d, g_extern.console.screen.orientation);
|
2012-05-22 00:19:40 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
/* load debug fonts */
|
|
|
|
|
XFONT_OpenDefaultFont(&d3d->debug_font);
|
|
|
|
|
d3d->debug_font->SetBkMode(XFONT_TRANSPARENT);
|
|
|
|
|
d3d->debug_font->SetBkColor(D3DCOLOR_ARGB(100,0,0,0));
|
|
|
|
|
d3d->debug_font->SetTextHeight(14);
|
|
|
|
|
d3d->debug_font->SetTextAntialiasLevel(d3d->debug_font->GetTextAntialiasLevel());
|
|
|
|
|
|
|
|
|
|
font_x = 0;
|
|
|
|
|
font_y = 0;
|
|
|
|
|
#elif defined(_XBOX360)
|
2012-09-30 22:09:04 +00:00
|
|
|
|
HRESULT hr = d3d9_init_font("game:\\media\\Arial_12.xpr");
|
2012-03-10 14:31:54 +00:00
|
|
|
|
|
2012-09-30 22:09:04 +00:00
|
|
|
|
if(hr < 0)
|
|
|
|
|
{
|
2012-10-01 00:45:29 +00:00
|
|
|
|
RARCH_ERR("Couldn't initialize HLSL shader fonts.\n");
|
2012-09-30 22:09:04 +00:00
|
|
|
|
}
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-09-30 22:09:04 +00:00
|
|
|
|
//really returns driver.video_data to driver.video_data - see comment above
|
2012-07-07 12:41:58 +00:00
|
|
|
|
return d3d;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static bool xdk_d3d_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-06-23 17:58:30 +00:00
|
|
|
|
if (!frame)
|
|
|
|
|
return true;
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
2012-07-07 19:47:23 +00:00
|
|
|
|
#ifdef HAVE_FBO
|
2012-05-06 16:53:43 +00:00
|
|
|
|
D3DSurface* pRenderTarget0;
|
2012-07-07 19:47:23 +00:00
|
|
|
|
#endif
|
2012-10-15 04:24:39 +00:00
|
|
|
|
bool menu_enabled = g_extern.console.rmenu.state.rmenu.enable;
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#ifdef _XBOX1
|
2012-10-15 04:24:39 +00:00
|
|
|
|
bool fps_enable = g_extern.console.rmenu.state.msg_fps.enable;
|
|
|
|
|
unsigned flicker_filter = g_extern.console.screen.state.flicker_filter.value;
|
2012-10-15 05:00:58 +00:00
|
|
|
|
bool soft_filter_enable = g_extern.console.screen.state.soft_filter.enable;
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if (d3d->last_width != width || d3d->last_height != height)
|
2012-01-07 14:21:23 +00:00
|
|
|
|
{
|
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
2012-03-08 15:14:09 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpTexture->UnlockRect(0);
|
2012-01-07 14:21:23 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
float tex_w = width; // / 512.0f;
|
|
|
|
|
float tex_h = height; // / 512.0f;
|
|
|
|
|
|
|
|
|
|
DrawVerticeFormats verts[] = {
|
|
|
|
|
{ -1.0f, -1.0f, 1.0f, 0.0f, tex_h },
|
|
|
|
|
{ 1.0f, -1.0f, 1.0f, tex_w, tex_h },
|
|
|
|
|
{ -1.0f, 1.0f, 1.0f, 0.0f, 0.0f },
|
|
|
|
|
{ 1.0f, 1.0f, 1.0f, tex_w, 0.0f },
|
|
|
|
|
};
|
|
|
|
|
#elif defined(_XBOX360)
|
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-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
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-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
BYTE *verts_ptr;
|
|
|
|
|
#elif defined(_XBOX360)
|
2012-04-17 03:12:03 +00:00
|
|
|
|
void *verts_ptr;
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->vertex_buf->Lock(0, 0, &verts_ptr, 0);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
memcpy(verts_ptr, verts, sizeof(verts));
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->vertex_buf->Unlock();
|
2012-03-08 12:44:20 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->last_width = width;
|
|
|
|
|
d3d->last_height = height;
|
2012-01-07 14:21:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 19:47:23 +00:00
|
|
|
|
#ifdef HAVE_FBO
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if (d3d->fbo_enabled)
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->GetRenderTarget(0, &pRenderTarget0);
|
|
|
|
|
d3d->d3d_render_device->SetRenderTarget(0, d3d->lpSurface);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
2012-07-07 19:47:23 +00:00
|
|
|
|
#endif
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if (d3d->should_resize)
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_set_viewport(false);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
d3d->frame_count++;
|
|
|
|
|
#ifdef _XBOX360
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
|
2012-05-06 20:02:54 +00:00
|
|
|
|
0xff000000, 1.0f, 0);
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetTexture(0, d3d->lpTexture);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
2012-05-06 19:57:01 +00:00
|
|
|
|
hlsl_use(1);
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#ifdef HAVE_FBO
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if(d3d->fbo_enabled)
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
2012-10-15 05:22:20 +00:00
|
|
|
|
hlsl_set_params(width, height, 512, 512, g_settings.video.fbo.scale_x * width,
|
|
|
|
|
g_settings.video.fbo.scale_y * height, d3d->frame_count);
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
D3DVIEWPORT vp = {0};
|
2012-10-15 05:22:20 +00:00
|
|
|
|
vp.Width = g_settings.video.fbo.scale_x * width;
|
|
|
|
|
vp.Height = g_settings.video.fbo.scale_y * height;
|
2012-05-06 16:53:43 +00:00
|
|
|
|
vp.X = 0;
|
|
|
|
|
vp.Y = 0;
|
|
|
|
|
vp.MinZ = 0.0f;
|
|
|
|
|
vp.MaxZ = 1.0f;
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetViewport(&vp);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#endif
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
2012-07-07 12:41:58 +00:00
|
|
|
|
hlsl_set_params(width, height, 512, 512, d3d->d3dpp.BackBufferWidth,
|
|
|
|
|
d3d->d3dpp.BackBufferHeight, d3d->frame_count);
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#endif
|
2012-07-07 17:31:04 +00:00
|
|
|
|
}
|
2012-04-19 13:59:07 +00:00
|
|
|
|
|
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
2012-11-10 15:04:22 +00:00
|
|
|
|
size_t size_screen = g_settings.video.color_format ? sizeof(uint32_t) : sizeof(uint16_t);
|
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;
|
2012-11-10 15:03:08 +00:00
|
|
|
|
memcpy(out, in, width * size_screen);
|
2012-04-19 13:59:07 +00:00
|
|
|
|
}
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->lpTexture->UnlockRect(0);
|
2012-04-19 13:59:07 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
2012-04-17 03:23:54 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
d3d->d3d_render_device->SetVertexShader(D3DFVF_XYZ | D3DFVF_TEX1);
|
|
|
|
|
|
|
|
|
|
D3DXMATRIX p_out, p_rotate;
|
|
|
|
|
D3DXMatrixIdentity(&p_out);
|
|
|
|
|
D3DXMatrixRotationZ(&p_rotate, angle);
|
|
|
|
|
|
|
|
|
|
d3d->d3d_render_device->SetTransform(D3DTS_WORLD, &p_rotate);
|
|
|
|
|
d3d->d3d_render_device->SetTransform(D3DTS_VIEW, &p_out);
|
|
|
|
|
d3d->d3d_render_device->SetTransform(D3DTS_PROJECTION, &p_out);
|
|
|
|
|
|
|
|
|
|
d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, sizeof(DrawVerticeFormats));
|
|
|
|
|
d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
|
|
|
|
|
|
|
|
|
|
d3d->d3d_render_device->BeginScene();
|
|
|
|
|
d3d->d3d_render_device->SetFlickerFilter(flicker_filter);
|
|
|
|
|
d3d->d3d_render_device->SetSoftDisplayFilter(soft_filter_enable);
|
|
|
|
|
d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
|
|
|
|
d3d->d3d_render_device->EndScene();
|
|
|
|
|
#elif defined(_XBOX360)
|
|
|
|
|
|
2012-07-07 20:02:01 +00:00
|
|
|
|
d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl);
|
2012-07-07 13:40:14 +00:00
|
|
|
|
d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf,
|
|
|
|
|
0,
|
|
|
|
|
sizeof(DrawVerticeFormats));
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#ifdef HAVE_FBO
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if(d3d->fbo_enabled)
|
2012-05-06 16:53:43 +00:00
|
|
|
|
{
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, d3d->lpTexture_ot,
|
2012-05-29 13:25:39 +00:00
|
|
|
|
NULL, 0, 0, NULL, 0, 0, NULL);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetRenderTarget(0, pRenderTarget0);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
pRenderTarget0->Release();
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetTexture(0, &d3d->lpTexture_ot_as16srgb);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#ifdef HAVE_HLSL
|
2012-05-06 19:57:01 +00:00
|
|
|
|
hlsl_use(2);
|
2012-10-15 05:22:20 +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, d3d->d3dpp.BackBufferWidth,
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3dpp.BackBufferHeight, d3d->frame_count);
|
2012-07-07 13:40:14 +00:00
|
|
|
|
#endif
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_set_viewport(false);
|
2012-05-28 00:29:51 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
|
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
|
|
|
|
|
d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
|
|
|
|
|
d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl);
|
2012-07-07 13:40:14 +00:00
|
|
|
|
d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf,
|
|
|
|
|
0,
|
|
|
|
|
sizeof(DrawVerticeFormats));
|
2012-07-07 12:41:58 +00:00
|
|
|
|
d3d->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
2012-05-06 16:53:43 +00:00
|
|
|
|
}
|
2012-07-07 17:31:04 +00:00
|
|
|
|
#endif
|
2012-05-06 16:53:43 +00:00
|
|
|
|
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
|
if(fps_enable)
|
|
|
|
|
{
|
|
|
|
|
MEMORYSTATUS stat;
|
|
|
|
|
GlobalMemoryStatus(&stat);
|
|
|
|
|
|
|
|
|
|
//Output memory usage
|
|
|
|
|
|
2012-11-14 20:51:56 +00:00
|
|
|
|
static char fps_txt[128];
|
|
|
|
|
char buf[128];
|
2012-10-01 01:35:38 +00:00
|
|
|
|
bool ret = false;
|
|
|
|
|
snprintf(buf, sizeof(buf), "%.2f MB free / %.2f MB total", stat.dwAvailPhys/(1024.0f*1024.0f), stat.dwTotalPhys/(1024.0f*1024.0f));
|
|
|
|
|
xfonts_render_msg_place(d3d, font_x + 30, font_y + 50, 0 /* scale */, buf);
|
|
|
|
|
|
2012-11-14 20:51:56 +00:00
|
|
|
|
gfx_window_title(fps_txt, sizeof(fps_txt));
|
|
|
|
|
xfonts_render_msg_place(d3d, font_x + 30, font_y + 70, 0 /* scale */, fps_txt);
|
2012-10-01 01:35:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
|
xfonts_render_msg_place(d3d, 60, 365, 0, msg); //TODO: dehardcode x/y here for HD (720p) mode
|
|
|
|
|
#elif defined(_XBOX360)
|
2012-05-22 13:21:45 +00:00
|
|
|
|
if (msg && !menu_enabled)
|
2012-02-12 14:23:35 +00:00
|
|
|
|
{
|
2012-08-22 01:56:57 +00:00
|
|
|
|
xdk360_console_format(msg);
|
2012-04-10 19:23:42 +00:00
|
|
|
|
xdk360_console_draw();
|
2012-02-12 14:23:35 +00:00
|
|
|
|
}
|
2012-10-01 01:35:38 +00:00
|
|
|
|
#endif
|
2012-02-12 14:23:35 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if(!d3d->block_swap)
|
2012-09-30 16:29:32 +00:00
|
|
|
|
gfx_ctx_xdk_swap_buffers();
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_set_nonblock_state(void *data, bool state)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
|
2012-07-07 12:41:58 +00:00
|
|
|
|
if(d3d->vsync)
|
2012-05-28 13:47:27 +00:00
|
|
|
|
{
|
|
|
|
|
RARCH_LOG("D3D Vsync => %s\n", state ? "off" : "on");
|
2012-09-30 16:29:32 +00:00
|
|
|
|
gfx_ctx_xdk_set_swap_interval(state ? 0 : 1);
|
2012-05-28 13:47:27 +00:00
|
|
|
|
}
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static bool xdk_d3d_alive(void *data)
|
2012-01-05 11:37:27 +00:00
|
|
|
|
{
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
|
2012-07-07 12:41:58 +00:00
|
|
|
|
check_window(d3d);
|
|
|
|
|
return !d3d->quitting;
|
2012-01-05 11:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static bool xdk_d3d_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-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_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-07-07 17:15:06 +00:00
|
|
|
|
driver.video_data = xdk_d3d_init(&video_info, NULL, NULL);
|
2012-01-21 22:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_restart(void)
|
2012-05-27 22:37:54 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
static void xdk_d3d_stop(void)
|
2012-01-21 22:59:27 +00:00
|
|
|
|
{
|
2012-05-27 22:56:58 +00:00
|
|
|
|
void *data = driver.video_data;
|
2012-09-30 22:09:04 +00:00
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_free(data);
|
2012-09-30 22:09:04 +00:00
|
|
|
|
|
|
|
|
|
driver.video_data = NULL;
|
2012-01-21 22:59:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-20 10:41:10 +00:00
|
|
|
|
static void xdk_d3d_apply_state_changes(void)
|
|
|
|
|
{
|
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
|
|
|
|
d3d->should_resize = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-30 15:51:48 +00:00
|
|
|
|
static void xdk_d3d_set_aspect_ratio(void *data, unsigned aspectratio_index)
|
|
|
|
|
{
|
|
|
|
|
(void)data;
|
|
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
|
|
|
|
|
2012-10-15 04:24:39 +00:00
|
|
|
|
if(g_settings.video.aspect_ratio_idx == ASPECT_RATIO_AUTO)
|
2012-09-30 15:51:48 +00:00
|
|
|
|
rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height);
|
2012-10-15 04:24:39 +00:00
|
|
|
|
else if(g_settings.video.aspect_ratio_idx == ASPECT_RATIO_CORE)
|
2012-09-30 15:51:48 +00:00
|
|
|
|
rarch_set_core_viewport();
|
|
|
|
|
|
2012-10-15 04:24:39 +00:00
|
|
|
|
g_settings.video.aspect_ratio = aspectratio_lut[g_settings.video.aspect_ratio_idx].value;
|
2012-09-30 15:51:48 +00:00
|
|
|
|
g_settings.video.force_aspect = false;
|
|
|
|
|
d3d->should_resize = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-07 17:15:06 +00:00
|
|
|
|
const video_driver_t video_xdk_d3d = {
|
|
|
|
|
xdk_d3d_init,
|
|
|
|
|
xdk_d3d_frame,
|
|
|
|
|
xdk_d3d_set_nonblock_state,
|
|
|
|
|
xdk_d3d_alive,
|
|
|
|
|
xdk_d3d_focus,
|
2012-01-05 12:30:13 +00:00
|
|
|
|
NULL,
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_free,
|
2012-07-07 14:53:33 +00:00
|
|
|
|
"xdk_d3d",
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_start,
|
|
|
|
|
xdk_d3d_stop,
|
|
|
|
|
xdk_d3d_restart,
|
2012-08-20 10:41:10 +00:00
|
|
|
|
xdk_d3d_apply_state_changes,
|
2012-09-30 15:51:48 +00:00
|
|
|
|
xdk_d3d_set_aspect_ratio,
|
2012-07-07 17:15:06 +00:00
|
|
|
|
xdk_d3d_set_rotation,
|
2012-04-09 14:04:24 +00:00
|
|
|
|
};
|