2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-08 05:25:12 +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/
|
|
|
|
|
|
|
|
#include "Common.h"
|
2010-05-23 02:29:23 +00:00
|
|
|
#include "StringUtil.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#include "D3DBase.h"
|
|
|
|
#include "D3DUtil.h"
|
|
|
|
#include "Render.h"
|
|
|
|
|
|
|
|
namespace D3D
|
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
CD3DFont font;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#define MAX_NUM_VERTICES 50*6
|
2009-09-15 21:25:34 +00:00
|
|
|
struct FONT2DVERTEX {
|
|
|
|
float x,y,z;
|
|
|
|
float rhw;
|
|
|
|
u32 color;
|
|
|
|
float tu, tv;
|
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
#define D3DFVF_FONT2DVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
|
|
|
|
#define D3DFVF_FONT3DVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_NORMAL|D3DFVF_TEX1)
|
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
inline FONT2DVERTEX InitFont2DVertex(float x, float y, u32 color, float tu, float tv)
|
|
|
|
{
|
|
|
|
FONT2DVERTEX v; v.x=x; v.y=y; v.z=0; v.rhw=1.0f; v.color = color; v.tu = tu; v.tv = tv;
|
|
|
|
return v;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
CD3DFont::CD3DFont()
|
|
|
|
{
|
2010-06-05 01:38:22 +00:00
|
|
|
m_pTexture = NULL;
|
|
|
|
m_pVB = NULL;
|
2009-09-15 21:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum {m_dwTexWidth = 512, m_dwTexHeight = 512};
|
|
|
|
|
|
|
|
int CD3DFont::Init()
|
|
|
|
{
|
|
|
|
// Create vertex buffer for the letters
|
|
|
|
HRESULT hr;
|
|
|
|
if (FAILED(hr = dev->CreateVertexBuffer(MAX_NUM_VERTICES*sizeof(FONT2DVERTEX),
|
|
|
|
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &m_pVB, NULL)))
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
return hr;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-09-15 21:25:34 +00:00
|
|
|
m_fTextScale = 1.0f; // Draw fonts into texture without scaling
|
|
|
|
|
|
|
|
// Prepare to create a bitmap
|
|
|
|
int *pBitmapBits;
|
|
|
|
BITMAPINFO bmi;
|
|
|
|
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
|
|
|
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
|
|
|
|
bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
|
|
|
|
bmi.bmiHeader.biPlanes = 1;
|
|
|
|
bmi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
bmi.bmiHeader.biBitCount = 32;
|
|
|
|
|
|
|
|
// Create a DC and a bitmap for the font
|
2010-06-05 01:38:22 +00:00
|
|
|
HDC hDC = CreateCompatibleDC(NULL);
|
2009-09-15 21:25:34 +00:00
|
|
|
HBITMAP hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (VOID**)&pBitmapBits, NULL, 0);
|
|
|
|
SetMapMode(hDC, MM_TEXT);
|
|
|
|
|
|
|
|
// Create a font. By specifying ANTIALIASED_QUALITY, we might get an
|
|
|
|
// antialiased font, but this is not guaranteed.
|
|
|
|
// We definitely don't want to get it cleartype'd, anyway.
|
|
|
|
int m_dwFontHeight = 24;
|
|
|
|
int nHeight = -MulDiv(m_dwFontHeight, int(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72);
|
|
|
|
int dwBold = FW_NORMAL; ///FW_BOLD
|
|
|
|
HFONT hFont = CreateFont(nHeight, 0, 0, 0, dwBold, 0,
|
|
|
|
FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
|
|
|
|
CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
|
|
|
|
VARIABLE_PITCH, _T("Tahoma"));
|
|
|
|
if (NULL == hFont)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
HGDIOBJ hOldbmBitmap = SelectObject(hDC, hbmBitmap);
|
|
|
|
HGDIOBJ hOldFont = SelectObject(hDC, hFont);
|
|
|
|
|
|
|
|
// Set text properties
|
|
|
|
SetTextColor(hDC, 0xFFFFFF);
|
|
|
|
SetBkColor (hDC, 0);
|
|
|
|
SetTextAlign(hDC, TA_TOP);
|
|
|
|
|
|
|
|
// Loop through all printable character and output them to the bitmap..
|
|
|
|
// Meanwhile, keep track of the corresponding tex coords for each character.
|
|
|
|
int x = 0, y = 0;
|
|
|
|
char str[2] = "\0";
|
|
|
|
for (int c = 0; c < 127 - 32; c++)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
str[0] = c + 32;
|
|
|
|
SIZE size;
|
|
|
|
GetTextExtentPoint32A(hDC, str, 1, &size);
|
|
|
|
if ((int)(x+size.cx+1) > m_dwTexWidth)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
x = 0;
|
|
|
|
y += size.cy + 1;
|
2009-09-13 17:46:33 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
ExtTextOutA(hDC, x+1, y+0, ETO_OPAQUE | ETO_CLIPPED, NULL, str, 1, NULL);
|
|
|
|
m_fTexCoords[c][0] = ((float)(x+0))/m_dwTexWidth;
|
|
|
|
m_fTexCoords[c][1] = ((float)(y+0))/m_dwTexHeight;
|
|
|
|
m_fTexCoords[c][2] = ((float)(x+0+size.cx))/m_dwTexWidth;
|
|
|
|
m_fTexCoords[c][3] = ((float)(y+0+size.cy))/m_dwTexHeight;
|
|
|
|
|
|
|
|
x += size.cx + 3; //3 to work around annoying ij conflict (part of the j ends up with the i)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new texture for the font
|
|
|
|
hr = dev->CreateTexture(m_dwTexWidth, m_dwTexHeight, 1, D3DUSAGE_DYNAMIC,
|
2010-06-05 01:38:22 +00:00
|
|
|
D3DFMT_A4R4G4B4, D3DPOOL_DEFAULT, &m_pTexture, NULL);
|
2009-09-15 21:25:34 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
PanicAlert("Failed to create font texture");
|
|
|
|
return hr;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
// Lock the surface and write the alpha values for the set pixels
|
|
|
|
D3DLOCKED_RECT d3dlr;
|
|
|
|
m_pTexture->LockRect(0, &d3dlr, 0, D3DLOCK_DISCARD);
|
|
|
|
int bAlpha; // 4-bit measure of pixel intensity
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
for (y = 0; y < m_dwTexHeight; y++)
|
|
|
|
{
|
|
|
|
u16 *pDst16 = (u16*)((u8 *)d3dlr.pBits + y * d3dlr.Pitch);
|
|
|
|
for (x = 0; x < m_dwTexWidth; x++)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
bAlpha = ((pBitmapBits[m_dwTexWidth * y + x] & 0xff) >> 4);
|
|
|
|
pDst16[x] = (bAlpha << 12) | 0x0fff;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2009-09-15 21:25:34 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
// Done updating texture, so clean up used objects
|
|
|
|
m_pTexture->UnlockRect(0);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
SelectObject(hDC, hOldbmBitmap);
|
|
|
|
DeleteObject(hbmBitmap);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
SelectObject(hDC, hOldFont);
|
|
|
|
DeleteObject(hFont);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CD3DFont::Shutdown()
|
|
|
|
{
|
|
|
|
m_pVB->Release();
|
|
|
|
m_pVB = NULL;
|
|
|
|
m_pTexture->Release();
|
|
|
|
m_pTexture = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
const int RS[6][2] =
|
|
|
|
{
|
|
|
|
{D3DRS_ALPHABLENDENABLE, TRUE},
|
2010-06-05 01:38:22 +00:00
|
|
|
{D3DRS_SRCBLEND, D3DBLEND_SRCALPHA},
|
|
|
|
{D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA},
|
|
|
|
{D3DRS_CULLMODE, D3DCULL_NONE},
|
|
|
|
{D3DRS_ZENABLE, FALSE},
|
|
|
|
{D3DRS_FOGENABLE, FALSE},
|
2009-09-15 21:25:34 +00:00
|
|
|
};
|
|
|
|
const int TS[6][2] =
|
|
|
|
{
|
|
|
|
{D3DTSS_COLOROP, D3DTOP_MODULATE},
|
|
|
|
{D3DTSS_COLORARG1, D3DTA_TEXTURE},
|
|
|
|
{D3DTSS_COLORARG2, D3DTA_DIFFUSE },
|
|
|
|
{D3DTSS_ALPHAOP, D3DTOP_MODULATE },
|
|
|
|
{D3DTSS_ALPHAARG1, D3DTA_TEXTURE },
|
|
|
|
{D3DTSS_ALPHAARG2, D3DTA_DIFFUSE },
|
|
|
|
};
|
|
|
|
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
static LPDIRECT3DPIXELSHADER9 ps_old = NULL;
|
|
|
|
static LPDIRECT3DVERTEXSHADER9 vs_old = NULL;
|
2009-09-15 21:25:34 +00:00
|
|
|
|
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 RestoreShaders()
|
2009-09-15 21:25:34 +00:00
|
|
|
{
|
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
|
|
|
D3D::SetTexture(0, 0);
|
|
|
|
D3D::RefreshVertexDeclaration();
|
|
|
|
D3D::RefreshPixelShader();
|
2010-06-05 01:38:22 +00:00
|
|
|
D3D::RefreshVertexShader();
|
2009-09-15 21:25:34 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
void RestoreRenderStates()
|
|
|
|
{
|
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
|
|
|
RestoreShaders();
|
2009-09-15 21:25:34 +00:00
|
|
|
for (int i = 0; i < 6; i++)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
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
|
|
|
D3D::RefreshRenderState((_D3DRENDERSTATETYPE)RS[i][0]);
|
|
|
|
D3D::RefreshTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]));
|
2009-09-15 21:25:34 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
void CD3DFont::SetRenderStates()
|
|
|
|
{
|
|
|
|
D3D::SetTexture(0, m_pTexture);
|
|
|
|
|
|
|
|
dev->SetPixelShader(0);
|
|
|
|
dev->SetVertexShader(0);
|
|
|
|
|
|
|
|
dev->SetFVF(D3DFVF_FONT2DVERTEX);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
for (int i = 0; i < 6; i++)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
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
|
|
|
D3D::ChangeRenderState((_D3DRENDERSTATETYPE)RS[i][0], RS[i][1]);
|
|
|
|
D3D::ChangeTextureStageState(0, (_D3DTEXTURESTAGESTATETYPE)int(TS[i][0]), TS[i][1]);
|
2009-09-13 17:46:33 +00:00
|
|
|
}
|
2009-09-15 21:25:34 +00:00
|
|
|
}
|
2009-09-13 17:46:33 +00:00
|
|
|
|
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const char* strText, bool center)
|
|
|
|
{
|
|
|
|
if (!m_pVB)
|
|
|
|
return 0;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
SetRenderStates();
|
|
|
|
dev->SetStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float vpWidth = 1;
|
|
|
|
float vpHeight = 1;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
float sx = x*vpWidth-0.5f;
|
2009-09-15 21:25:34 +00:00
|
|
|
float sy = y*vpHeight-0.5f;
|
|
|
|
|
|
|
|
float fStartX = sx;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float invLineHeight = 1.0f / ((m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight);
|
|
|
|
// Fill vertex buffer
|
|
|
|
FONT2DVERTEX* pVertices;
|
|
|
|
int dwNumTriangles = 0L;
|
|
|
|
m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
const char *oldstrText=strText;
|
|
|
|
//First, let's measure the text
|
|
|
|
float tw=0;
|
|
|
|
float mx=0;
|
|
|
|
float maxx=0;
|
|
|
|
|
|
|
|
while (*strText)
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
char c = *strText++;
|
2009-09-13 17:46:33 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
if (c == ('\n'))
|
|
|
|
mx = 0;
|
|
|
|
if (c < (' '))
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float tx1 = m_fTexCoords[c-32][0];
|
|
|
|
float tx2 = m_fTexCoords[c-32][2];
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float w = (tx2-tx1)*m_dwTexWidth;
|
|
|
|
w *= (fXScale*vpHeight)*invLineHeight;
|
|
|
|
mx += w + spacing*fXScale*vpWidth;
|
|
|
|
if (mx > maxx) maxx = mx;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float offset = -maxx/2;
|
|
|
|
strText = oldstrText;
|
|
|
|
//Then let's draw it
|
|
|
|
if (center)
|
|
|
|
{
|
|
|
|
sx+=offset;
|
|
|
|
fStartX+=offset;
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float wScale = (fXScale*vpHeight)*invLineHeight;
|
|
|
|
float hScale = (fYScale*vpHeight)*invLineHeight;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
while (*strText)
|
|
|
|
{
|
|
|
|
char c = *strText++;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
if (c == ('\n'))
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
sx = fStartX;
|
|
|
|
sy += fYScale*vpHeight;
|
|
|
|
}
|
|
|
|
if (c < (' '))
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
c-=32;
|
|
|
|
float tx1 = m_fTexCoords[c][0];
|
|
|
|
float ty1 = m_fTexCoords[c][1];
|
|
|
|
float tx2 = m_fTexCoords[c][2];
|
|
|
|
float ty2 = m_fTexCoords[c][3];
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
float w = (tx2-tx1)*m_dwTexWidth;
|
|
|
|
float h = (ty2-ty1)*m_dwTexHeight;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
w *= wScale;
|
|
|
|
h *= hScale;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
FONT2DVERTEX v[6];
|
|
|
|
v[0] = InitFont2DVertex(sx, sy+h, dwColor, tx1, ty2);
|
|
|
|
v[1] = InitFont2DVertex(sx, sy, dwColor, tx1, ty1);
|
|
|
|
v[2] = InitFont2DVertex(sx+w, sy+h, dwColor, tx2, ty2);
|
|
|
|
v[3] = InitFont2DVertex(sx+w, sy, dwColor, tx2, ty1);
|
|
|
|
v[4] = v[2];
|
|
|
|
v[5] = v[1];
|
|
|
|
|
2010-06-05 01:38:22 +00:00
|
|
|
memcpy(pVertices, v, 6*sizeof(FONT2DVERTEX));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
pVertices+=6;
|
|
|
|
dwNumTriangles += 2;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
if (dwNumTriangles * 3 > (MAX_NUM_VERTICES - 6))
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2009-09-15 21:25:34 +00:00
|
|
|
// Unlock, render, and relock the vertex buffer
|
|
|
|
m_pVB->Unlock();
|
|
|
|
dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
|
|
|
|
m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
|
|
|
|
dwNumTriangles = 0;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
sx += w + spacing*fXScale*vpWidth;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 21:25:34 +00:00
|
|
|
// Unlock and render the vertex buffer
|
|
|
|
m_pVB->Unlock();
|
|
|
|
if (dwNumTriangles > 0)
|
|
|
|
dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles);
|
|
|
|
RestoreRenderStates();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void quad2d(float x1, float y1, float x2, float y2, u32 color, float u1, float v1, float u2, float v2)
|
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
|
|
|
{
|
2010-02-03 03:52:50 +00:00
|
|
|
struct Q2DVertex { float x,y,z,rhw;u32 color;float u,v,w,h; } coords[4] = {
|
2009-09-15 21:25:34 +00:00
|
|
|
{x1-0.5f, y1-0.5f, 0, 1, color, u1, v1},
|
|
|
|
{x2-0.5f, y1-0.5f, 0, 1, color, u2, v1},
|
|
|
|
{x2-0.5f, y2-0.5f, 0, 1, color, u2, v2},
|
|
|
|
{x1-0.5f, y2-0.5f, 0, 1, color, u1, v2},
|
|
|
|
};
|
|
|
|
dev->SetPixelShader(0);
|
|
|
|
dev->SetVertexShader(0);
|
2010-02-03 03:52:50 +00:00
|
|
|
dev->SetVertexDeclaration(NULL);
|
2009-09-15 21:25:34 +00:00
|
|
|
dev->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
|
|
|
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex));
|
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
|
|
|
RestoreShaders();
|
2009-09-15 21:25:34 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
void drawShadedTexQuad(IDirect3DTexture9 *texture,
|
|
|
|
const RECT *rSource,
|
|
|
|
int SourceWidth,
|
|
|
|
int SourceHeight,
|
2010-05-24 14:20:19 +00:00
|
|
|
int DestWidth,
|
|
|
|
int DestHeight,
|
2009-11-08 20:35:11 +00:00
|
|
|
IDirect3DPixelShader9 *PShader,
|
|
|
|
IDirect3DVertexShader9 *Vshader)
|
|
|
|
{
|
2010-02-03 03:52:50 +00:00
|
|
|
float sw = 1.0f /(float) SourceWidth;
|
|
|
|
float sh = 1.0f /(float) SourceHeight;
|
2010-05-24 14:20:19 +00:00
|
|
|
float dw = 1.0f /(float) DestWidth;
|
|
|
|
float dh = 1.0f /(float) DestHeight;
|
|
|
|
float u1=((float)rSource->left) * sw;
|
|
|
|
float u2=((float)rSource->right) * sw;
|
|
|
|
float v1=((float)rSource->top) * sh;
|
|
|
|
float v2=((float)rSource->bottom) * sh;
|
2010-02-03 03:52:50 +00:00
|
|
|
|
2010-02-04 22:25:09 +00:00
|
|
|
struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = {
|
2010-05-24 14:20:19 +00:00
|
|
|
{-1.0f - dw,-1.0f + dh, 0.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2},
|
|
|
|
{-1.0f - dw, 1.0f + dh, 0.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2},
|
|
|
|
{ 1.0f - dw,-1.0f + dh, 0.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2},
|
|
|
|
{ 1.0f - dw, 1.0f + dh, 0.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}
|
2009-11-08 20:35:11 +00:00
|
|
|
};
|
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
|
|
|
dev->SetVertexShader(Vshader);
|
2010-06-05 01:38:22 +00:00
|
|
|
dev->SetPixelShader(PShader);
|
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
|
|
|
D3D::SetTexture(0, texture);
|
2010-02-04 22:25:09 +00:00
|
|
|
dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2));
|
2010-06-05 01:38:22 +00:00
|
|
|
dev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, coords, sizeof(Q2DVertex));
|
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
|
|
|
RestoreShaders();
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 18:57:50 +00:00
|
|
|
void drawShadedTexSubQuad(IDirect3DTexture9 *texture,
|
|
|
|
const MathUtil::Rectangle<float> *rSource,
|
|
|
|
int SourceWidth,
|
|
|
|
int SourceHeight,
|
|
|
|
const MathUtil::Rectangle<float> *rDest,
|
2010-05-24 14:20:19 +00:00
|
|
|
int DestWidth,
|
|
|
|
int DestHeight,
|
2010-03-14 18:57:50 +00:00
|
|
|
IDirect3DPixelShader9 *PShader,
|
|
|
|
IDirect3DVertexShader9 *Vshader)
|
|
|
|
{
|
|
|
|
float sw = 1.0f /(float) SourceWidth;
|
|
|
|
float sh = 1.0f /(float) SourceHeight;
|
2010-05-24 14:20:19 +00:00
|
|
|
float dw = 1.0f /(float) DestWidth;
|
|
|
|
float dh = 1.0f /(float) DestHeight;
|
|
|
|
float u1= rSource->left * sw;
|
|
|
|
float u2= rSource->right * sw;
|
|
|
|
float v1= rSource->top * sh;
|
|
|
|
float v2= rSource->bottom * sh;
|
2010-03-14 18:57:50 +00:00
|
|
|
|
|
|
|
struct Q2DVertex { float x,y,z,rhw,u,v,w,h,L,T,R,B; } coords[4] = {
|
2010-05-24 14:20:19 +00:00
|
|
|
{ rDest->left - dw , rDest->top + dh, 1.0f,1.0f, u1, v2, sw, sh,u1,v1,u2,v2},
|
|
|
|
{ rDest->left - dw , rDest->bottom + dh, 1.0f,1.0f, u1, v1, sw, sh,u1,v1,u2,v2},
|
|
|
|
{ rDest->right - dw , rDest->top + dh, 1.0f,1.0f, u2, v2, sw, sh,u1,v1,u2,v2},
|
|
|
|
{ rDest->right - dw , rDest->bottom + dh, 1.0f,1.0f, u2, v1, sw, sh,u1,v1,u2,v2}
|
2010-03-14 18:57:50 +00:00
|
|
|
};
|
|
|
|
dev->SetVertexShader(Vshader);
|
2010-06-05 01:38:22 +00:00
|
|
|
dev->SetPixelShader(PShader);
|
2010-03-14 18:57:50 +00:00
|
|
|
D3D::SetTexture(0, texture);
|
|
|
|
dev->SetFVF(D3DFVF_XYZW | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE4(2));
|
2010-06-05 01:38:22 +00:00
|
|
|
dev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, coords, sizeof(Q2DVertex));
|
2010-03-14 18:57:50 +00:00
|
|
|
RestoreShaders();
|
|
|
|
}
|
|
|
|
|
2010-02-03 03:52:50 +00:00
|
|
|
void drawClearQuad(u32 Color,float z,IDirect3DPixelShader9 *PShader,IDirect3DVertexShader9 *Vshader)
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
{
|
2010-02-03 03:52:50 +00:00
|
|
|
struct Q2DVertex { float x,y,z,rhw;u32 color;} coords[4] = {
|
|
|
|
{-1.0f, 1.0f, z, 1.0f, Color},
|
|
|
|
{ 1.0f, 1.0f, z, 1.0f, Color},
|
|
|
|
{ 1.0f, -1.0f, z, 1.0f, Color},
|
|
|
|
{-1.0f, -1.0f, z, 1.0f, Color}
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
};
|
2009-11-22 02:37:00 +00:00
|
|
|
dev->SetVertexShader(Vshader);
|
2010-06-05 01:38:22 +00:00
|
|
|
dev->SetPixelShader(PShader);
|
2010-02-03 03:52:50 +00:00
|
|
|
dev->SetFVF(D3DFVF_XYZW | D3DFVF_DIFFUSE);
|
2010-06-05 01:38:22 +00:00
|
|
|
dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, coords, sizeof(Q2DVertex));
|
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
|
|
|
RestoreShaders();
|
Well this commit has 2 parts:
first part if fixing, fixed, i thing, the flickering that everyone has reported, at least in my case i only have flickering in the one texture in one game and now is fixed. The other fix is not for an reported issue, is more a correctness fix, running dolphin with pix to review debug errors, result in a ton of warnings and error, now with this commit, at least for ati, there no more error or warnings, this means, correct management and state change, no accurate emulation, for this still a lot of work to do.
for this part of the commit please give me feedback and let me know of remaining issues
Te second part is the partial implementation of efb to ram copy in d3d, this won't brake anything because is commented but i commit this to ask for help from ector and donko in some errors remaining in the implementation related to differences between opengl an d3d.
if you want to test this you have to uncomment line 150 to 155 of bpstruct.cpp
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4594 8ced0084-cf51-0410-be5f-012b33b47a6e
2009-11-20 18:46:30 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 20:35:11 +00:00
|
|
|
|
2008-12-26 17:02:46 +00:00
|
|
|
} // namespace
|