mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 18:41:14 +00:00
3DS: Account for sprite scaling when resizing UI (#503)
This commit is contained in:
parent
1c0588727e
commit
af9f7cd791
@ -642,8 +642,14 @@ int GetColorIndexWithLocality(int p_col, int p_row)
|
|||||||
|
|
||||||
void MxTransitionManager::FakeMosaicTransition()
|
void MxTransitionManager::FakeMosaicTransition()
|
||||||
{
|
{
|
||||||
|
static LPDIRECTDRAWSURFACE g_fakeTranstionSurface = nullptr;
|
||||||
|
|
||||||
if (m_animationTimer == 16) {
|
if (m_animationTimer == 16) {
|
||||||
m_animationTimer = 0;
|
m_animationTimer = 0;
|
||||||
|
if (g_fakeTranstionSurface) {
|
||||||
|
g_fakeTranstionSurface->Release();
|
||||||
|
g_fakeTranstionSurface = nullptr;
|
||||||
|
}
|
||||||
EndTransition(TRUE);
|
EndTransition(TRUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -662,12 +668,33 @@ void MxTransitionManager::FakeMosaicTransition()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!g_fakeTranstionSurface) {
|
||||||
|
DDSURFACEDESC mainDesc = {};
|
||||||
|
mainDesc.dwSize = sizeof(mainDesc);
|
||||||
|
if (m_ddSurface->GetSurfaceDesc(&mainDesc) != DD_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DDSURFACEDESC tempDesc = {};
|
||||||
|
tempDesc.dwSize = sizeof(tempDesc);
|
||||||
|
tempDesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS;
|
||||||
|
tempDesc.dwWidth = 64;
|
||||||
|
tempDesc.dwHeight = 48;
|
||||||
|
tempDesc.ddpfPixelFormat = mainDesc.ddpfPixelFormat;
|
||||||
|
tempDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
|
||||||
|
|
||||||
|
HRESULT hr = MVideoManager()->GetDirectDraw()->CreateSurface(&tempDesc, &g_fakeTranstionSurface, nullptr);
|
||||||
|
if (hr != DD_OK || !g_fakeTranstionSurface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DDSURFACEDESC ddsd = {};
|
DDSURFACEDESC ddsd = {};
|
||||||
ddsd.dwSize = sizeof(ddsd);
|
ddsd.dwSize = sizeof(ddsd);
|
||||||
HRESULT res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_WRITEONLY, NULL);
|
HRESULT res = g_fakeTranstionSurface->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_WRITEONLY, NULL);
|
||||||
if (res == DDERR_SURFACELOST) {
|
if (res == DDERR_SURFACELOST) {
|
||||||
m_ddSurface->Restore();
|
g_fakeTranstionSurface->Restore();
|
||||||
res = m_ddSurface->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_WRITEONLY, NULL);
|
res = g_fakeTranstionSurface->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_WRITEONLY, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == DD_OK) {
|
if (res == DD_OK) {
|
||||||
@ -694,50 +721,33 @@ void MxTransitionManager::FakeMosaicTransition()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (MxS32 row = 0; row < 48; row++) {
|
for (MxS32 row = 0; row < 48; row++) {
|
||||||
MxS32 xShift = 10 * ((m_randomShift[row] + col) % 64);
|
int paletteIndex = GetColorIndexWithLocality(col, row);
|
||||||
MxS32 yStart = 10 * row;
|
|
||||||
|
|
||||||
int paletteIndex = GetColorIndexWithLocality(xShift / 10, row);
|
|
||||||
|
|
||||||
const MxU8* color = g_palette[paletteIndex];
|
const MxU8* color = g_palette[paletteIndex];
|
||||||
|
|
||||||
for (MxS32 y = 0; y < 10; y++) {
|
MxS32 xShift = (m_randomShift[row] + col) % 64;
|
||||||
MxU8* dest = (MxU8*) ddsd.lpSurface + (yStart + y) * ddsd.lPitch + xShift * bytesPerPixel;
|
MxU8* dest = (MxU8*) ddsd.lpSurface + row * ddsd.lPitch + xShift * bytesPerPixel;
|
||||||
switch (bytesPerPixel) {
|
|
||||||
case 1:
|
switch (bytesPerPixel) {
|
||||||
memset(dest, paletteIndex, 10);
|
case 1:
|
||||||
break;
|
*dest = paletteIndex;
|
||||||
case 2: {
|
break;
|
||||||
MxU32 pixel = RGB555_CREATE(color[2], color[1], color[0]);
|
case 2:
|
||||||
MxU16* p = (MxU16*) dest;
|
*((MxU16*) dest) = RGB555_CREATE(color[2], color[1], color[0]);
|
||||||
for (MxS32 i = 0; i < 10; i++) {
|
break;
|
||||||
p[i] = pixel;
|
default:
|
||||||
}
|
*((MxU32*) dest) = RGB8888_CREATE(color[2], color[1], color[0], 255);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default: {
|
|
||||||
MxU32 pixel = RGB8888_CREATE(color[2], color[1], color[0], 255);
|
|
||||||
MxU32* p = (MxU32*) dest;
|
|
||||||
for (MxS32 i = 0; i < 10; i++) {
|
|
||||||
p[i] = pixel;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupCopyRect(&ddsd);
|
SetupCopyRect(&ddsd);
|
||||||
m_ddSurface->Unlock(ddsd.lpSurface);
|
g_fakeTranstionSurface->Unlock(ddsd.lpSurface);
|
||||||
|
|
||||||
if (VideoManager()->GetVideoParam().Flags().GetFlipSurfaces()) {
|
RECT srcRect = {0, 0, 64, 48};
|
||||||
VideoManager()
|
m_ddSurface->Blt(&g_fullScreenRect, g_fakeTranstionSurface, &srcRect, DDBLT_WAIT, NULL);
|
||||||
->GetDisplaySurface()
|
|
||||||
->GetDirectDrawSurface1()
|
|
||||||
->BltFast(0, 0, m_ddSurface, &g_fullScreenRect, DDBLTFAST_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_animationTimer++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_animationTimer++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,31 +115,34 @@ static int NearestPowerOfTwoClamp(int val)
|
|||||||
return 512;
|
return 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_Surface* ConvertAndResizeSurface(SDL_Surface* original, bool isUI, float scale)
|
static SDL_Surface* ConvertAndResizeSurface(SDL_Surface* original, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
SDL_Surface* converted = SDL_ConvertSurface(original, SDL_PIXELFORMAT_RGBA8888);
|
|
||||||
if (!converted) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (!isUI) {
|
if (!isUI) {
|
||||||
return converted;
|
return SDL_ConvertSurface(original, SDL_PIXELFORMAT_RGBA8888);
|
||||||
}
|
}
|
||||||
|
|
||||||
int scaledW = static_cast<int>(converted->w * scale);
|
scaleX = std::min(scaleX, 1.0f);
|
||||||
int scaledH = static_cast<int>(converted->h * scale);
|
scaleY = std::min(scaleY, 1.0f);
|
||||||
|
|
||||||
|
int scaledW = static_cast<int>(original->w * scaleX);
|
||||||
|
int scaledH = static_cast<int>(original->h * scaleY);
|
||||||
|
|
||||||
int paddedW = NearestPowerOfTwoClamp(scaledW);
|
int paddedW = NearestPowerOfTwoClamp(scaledW);
|
||||||
int paddedH = NearestPowerOfTwoClamp(scaledH);
|
int paddedH = NearestPowerOfTwoClamp(scaledH);
|
||||||
|
|
||||||
SDL_Surface* padded = SDL_CreateSurface(paddedW, paddedH, SDL_PIXELFORMAT_RGBA8888);
|
SDL_Surface* padded = SDL_CreateSurface(paddedW, paddedH, SDL_PIXELFORMAT_RGBA8888);
|
||||||
if (!padded) {
|
if (!padded) {
|
||||||
SDL_DestroySurface(converted);
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect dstRect = {0, 0, scaledW, scaledH};
|
if (scaleX == 1.0f && scaleY == 1.0f) {
|
||||||
SDL_BlitSurfaceScaled(converted, nullptr, padded, &dstRect, SDL_SCALEMODE_LINEAR);
|
SDL_BlitSurface(original, nullptr, padded, nullptr);
|
||||||
SDL_DestroySurface(converted);
|
}
|
||||||
|
else {
|
||||||
|
SDL_ScaleMode scaleMode = (scaleX >= 1.0f && scaleY >= 1.0f) ? SDL_SCALEMODE_NEAREST : SDL_SCALEMODE_LINEAR;
|
||||||
|
SDL_Rect dstRect = {0, 0, scaledW, scaledH};
|
||||||
|
SDL_BlitSurfaceScaled(original, nullptr, padded, &dstRect, scaleMode);
|
||||||
|
}
|
||||||
|
|
||||||
return padded;
|
return padded;
|
||||||
}
|
}
|
||||||
@ -181,9 +184,9 @@ static void EncodeTextureLayout(const u8* src, u8* dst, int width, int height)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ConvertAndUploadTexture(C3D_Tex* tex, SDL_Surface* originalSurface, bool isUI, float scale)
|
static bool ConvertAndUploadTexture(C3D_Tex* tex, SDL_Surface* originalSurface, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
SDL_Surface* resized = ConvertAndResizeSurface(originalSurface, isUI, scale);
|
SDL_Surface* resized = ConvertAndResizeSurface(originalSurface, isUI, scaleX, scaleY);
|
||||||
if (!resized) {
|
if (!resized) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -198,18 +201,24 @@ static bool ConvertAndUploadTexture(C3D_Tex* tex, SDL_Surface* originalSurface,
|
|||||||
params.maxLevel = isUI ? 0 : 4;
|
params.maxLevel = isUI ? 0 : 4;
|
||||||
params.type = GPU_TEX_2D;
|
params.type = GPU_TEX_2D;
|
||||||
if (!C3D_TexInitWithParams(tex, nullptr, params)) {
|
if (!C3D_TexInitWithParams(tex, nullptr, params)) {
|
||||||
SDL_DestroySurface(resized);
|
if (resized != originalSurface) {
|
||||||
|
SDL_DestroySurface(resized);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* tiledData = (uint8_t*) malloc(width * height * 4);
|
uint8_t* tiledData = (uint8_t*) malloc(width * height * 4);
|
||||||
if (!tiledData) {
|
if (!tiledData) {
|
||||||
SDL_DestroySurface(resized);
|
if (resized != originalSurface) {
|
||||||
|
SDL_DestroySurface(resized);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EncodeTextureLayout((const u8*) resized->pixels, tiledData, width, height);
|
EncodeTextureLayout((const u8*) resized->pixels, tiledData, width, height);
|
||||||
SDL_DestroySurface(resized);
|
if (resized != originalSurface) {
|
||||||
|
SDL_DestroySurface(resized);
|
||||||
|
}
|
||||||
|
|
||||||
C3D_TexUpload(tex, tiledData);
|
C3D_TexUpload(tex, tiledData);
|
||||||
free(tiledData);
|
free(tiledData);
|
||||||
@ -228,7 +237,7 @@ static bool ConvertAndUploadTexture(C3D_Tex* tex, SDL_Surface* originalSurface,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 Citro3DRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
Uint32 Citro3DRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
@ -242,7 +251,13 @@ Uint32 Citro3DRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
|||||||
if (tex.texture == texture) {
|
if (tex.texture == texture) {
|
||||||
if (tex.version != texture->m_version) {
|
if (tex.version != texture->m_version) {
|
||||||
C3D_TexDelete(&tex.c3dTex);
|
C3D_TexDelete(&tex.c3dTex);
|
||||||
if (!ConvertAndUploadTexture(&tex.c3dTex, originalSurface, isUi, m_viewportTransform.scale)) {
|
if (!ConvertAndUploadTexture(
|
||||||
|
&tex.c3dTex,
|
||||||
|
originalSurface,
|
||||||
|
isUI,
|
||||||
|
scaleX * m_viewportTransform.scale,
|
||||||
|
scaleY * m_viewportTransform.scale
|
||||||
|
)) {
|
||||||
return NO_TEXTURE_ID;
|
return NO_TEXTURE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +275,13 @@ Uint32 Citro3DRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
|||||||
entry.width = NearestPowerOfTwoClamp(originalW * m_viewportTransform.scale);
|
entry.width = NearestPowerOfTwoClamp(originalW * m_viewportTransform.scale);
|
||||||
entry.height = NearestPowerOfTwoClamp(originalH * m_viewportTransform.scale);
|
entry.height = NearestPowerOfTwoClamp(originalH * m_viewportTransform.scale);
|
||||||
|
|
||||||
if (!ConvertAndUploadTexture(&entry.c3dTex, originalSurface, isUi, m_viewportTransform.scale)) {
|
if (!ConvertAndUploadTexture(
|
||||||
|
&entry.c3dTex,
|
||||||
|
originalSurface,
|
||||||
|
isUI,
|
||||||
|
scaleX * m_viewportTransform.scale,
|
||||||
|
scaleY * m_viewportTransform.scale
|
||||||
|
)) {
|
||||||
return NO_TEXTURE_ID;
|
return NO_TEXTURE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,7 +76,7 @@ void DirectX9Renderer::AddTextureDestroyCallback(Uint32 id, IDirect3DRMTexture*
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 DirectX9Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
Uint32 DirectX9Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
|
|||||||
@ -49,12 +49,12 @@ int GL11_GetMaxTextureSize()
|
|||||||
return maxTextureSize;
|
return maxTextureSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint GL11_UploadTextureData(void* pixels, int width, int height, bool isUi)
|
GLuint GL11_UploadTextureData(void* pixels, int width, int height, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
GLuint texId;
|
GLuint texId;
|
||||||
glGenTextures(1, &texId);
|
glGenTextures(1, &texId);
|
||||||
glBindTexture(GL_TEXTURE_2D, texId);
|
glBindTexture(GL_TEXTURE_2D, texId);
|
||||||
if (isUi) {
|
if (isUI) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
|||||||
@ -65,7 +65,7 @@ void GL11_InitState();
|
|||||||
void GL11_LoadExtensions();
|
void GL11_LoadExtensions();
|
||||||
void GL11_DestroyTexture(GLuint texId);
|
void GL11_DestroyTexture(GLuint texId);
|
||||||
int GL11_GetMaxTextureSize();
|
int GL11_GetMaxTextureSize();
|
||||||
GLuint GL11_UploadTextureData(void* pixels, int width, int height, bool isUI);
|
GLuint GL11_UploadTextureData(void* pixels, int width, int height, bool isUI, float scaleX, float scaleY);
|
||||||
void GL11_UploadMesh(GLMeshCacheEntry& cache, bool hasTexture);
|
void GL11_UploadMesh(GLMeshCacheEntry& cache, bool hasTexture);
|
||||||
void GL11_DestroyMesh(GLMeshCacheEntry& cache);
|
void GL11_DestroyMesh(GLMeshCacheEntry& cache);
|
||||||
void GL11_BeginFrame(const Matrix4x4* projection);
|
void GL11_BeginFrame(const Matrix4x4* projection);
|
||||||
|
|||||||
@ -119,7 +119,7 @@ static int NextPowerOfTwo(int v)
|
|||||||
return power;
|
return power;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Uint32 UploadTextureData(SDL_Surface* src, bool useNPOT, bool isUi)
|
static Uint32 UploadTextureData(SDL_Surface* src, bool useNPOT, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
SDL_Surface* working = src;
|
SDL_Surface* working = src;
|
||||||
if (src->format != SDL_PIXELFORMAT_RGBA32) {
|
if (src->format != SDL_PIXELFORMAT_RGBA32) {
|
||||||
@ -166,14 +166,14 @@ static Uint32 UploadTextureData(SDL_Surface* src, bool useNPOT, bool isUi)
|
|||||||
finalSurface = resized;
|
finalSurface = resized;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 texId = GL11_UploadTextureData(finalSurface->pixels, finalSurface->w, finalSurface->h, isUi);
|
Uint32 texId = GL11_UploadTextureData(finalSurface->pixels, finalSurface->w, finalSurface->h, isUI, scaleX, scaleY);
|
||||||
if (finalSurface != src) {
|
if (finalSurface != src) {
|
||||||
SDL_DestroySurface(finalSurface);
|
SDL_DestroySurface(finalSurface);
|
||||||
}
|
}
|
||||||
return texId;
|
return texId;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 OpenGL1Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
Uint32 OpenGL1Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
@ -183,7 +183,7 @@ Uint32 OpenGL1Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
|||||||
if (tex.texture == texture) {
|
if (tex.texture == texture) {
|
||||||
if (tex.version != texture->m_version) {
|
if (tex.version != texture->m_version) {
|
||||||
GL11_DestroyTexture(tex.glTextureId);
|
GL11_DestroyTexture(tex.glTextureId);
|
||||||
tex.glTextureId = UploadTextureData(surface->m_surface, m_useNPOT, isUi);
|
tex.glTextureId = UploadTextureData(surface->m_surface, m_useNPOT, isUI, scaleX, scaleY);
|
||||||
tex.version = texture->m_version;
|
tex.version = texture->m_version;
|
||||||
tex.width = surface->m_surface->w;
|
tex.width = surface->m_surface->w;
|
||||||
tex.height = surface->m_surface->h;
|
tex.height = surface->m_surface->h;
|
||||||
@ -192,7 +192,7 @@ Uint32 OpenGL1Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint texId = UploadTextureData(surface->m_surface, m_useNPOT, isUi);
|
GLuint texId = UploadTextureData(surface->m_surface, m_useNPOT, isUI, scaleX, scaleY);
|
||||||
|
|
||||||
for (Uint32 i = 0; i < m_textures.size(); ++i) {
|
for (Uint32 i = 0; i < m_textures.size(); ++i) {
|
||||||
auto& tex = m_textures[i];
|
auto& tex = m_textures[i];
|
||||||
|
|||||||
@ -321,7 +321,7 @@ void OpenGLES2Renderer::AddTextureDestroyCallback(Uint32 id, IDirect3DRMTexture*
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UploadTexture(SDL_Surface* source, GLuint& outTexId, bool isUi)
|
bool UploadTexture(SDL_Surface* source, GLuint& outTexId, bool isUI)
|
||||||
{
|
{
|
||||||
SDL_Surface* surf = source;
|
SDL_Surface* surf = source;
|
||||||
if (source->format != SDL_PIXELFORMAT_RGBA32) {
|
if (source->format != SDL_PIXELFORMAT_RGBA32) {
|
||||||
@ -335,7 +335,7 @@ bool UploadTexture(SDL_Surface* source, GLuint& outTexId, bool isUi)
|
|||||||
glBindTexture(GL_TEXTURE_2D, outTexId);
|
glBindTexture(GL_TEXTURE_2D, outTexId);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf->pixels);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w, surf->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf->pixels);
|
||||||
|
|
||||||
if (isUi) {
|
if (isUI) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
@ -362,7 +362,7 @@ bool UploadTexture(SDL_Surface* source, GLuint& outTexId, bool isUi)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 OpenGLES2Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
Uint32 OpenGLES2Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
@ -372,7 +372,7 @@ Uint32 OpenGLES2Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
|||||||
if (tex.texture == texture) {
|
if (tex.texture == texture) {
|
||||||
if (tex.version != texture->m_version) {
|
if (tex.version != texture->m_version) {
|
||||||
glDeleteTextures(1, &tex.glTextureId);
|
glDeleteTextures(1, &tex.glTextureId);
|
||||||
if (UploadTexture(surface->m_surface, tex.glTextureId, isUi)) {
|
if (UploadTexture(surface->m_surface, tex.glTextureId, isUI)) {
|
||||||
tex.version = texture->m_version;
|
tex.version = texture->m_version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -381,7 +381,7 @@ Uint32 OpenGLES2Renderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GLuint texId;
|
GLuint texId;
|
||||||
if (!UploadTexture(surface->m_surface, texId, isUi)) {
|
if (!UploadTexture(surface->m_surface, texId, isUI)) {
|
||||||
return NO_TEXTURE_ID;
|
return NO_TEXTURE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -499,7 +499,7 @@ SDL_GPUTexture* Direct3DRMSDL3GPURenderer::CreateTextureFromSurface(SDL_Surface*
|
|||||||
return texptr;
|
return texptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 Direct3DRMSDL3GPURenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
Uint32 Direct3DRMSDL3GPURenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
|
|||||||
@ -554,7 +554,7 @@ void Direct3DRMSoftwareRenderer::AddTextureDestroyCallback(Uint32 id, IDirect3DR
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint32 Direct3DRMSoftwareRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi)
|
Uint32 Direct3DRMSoftwareRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUI, float scaleX, float scaleY)
|
||||||
{
|
{
|
||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
|
|||||||
@ -78,11 +78,13 @@ HRESULT FrameBufferImpl::Blt(
|
|||||||
if (!surface) {
|
if (!surface) {
|
||||||
return DDERR_GENERIC;
|
return DDERR_GENERIC;
|
||||||
}
|
}
|
||||||
Uint32 textureId = DDRenderer->GetTextureId(surface->ToTexture(), true);
|
|
||||||
SDL_Rect srcRect =
|
SDL_Rect srcRect =
|
||||||
lpSrcRect ? ConvertRect(lpSrcRect) : SDL_Rect{0, 0, surface->m_surface->w, surface->m_surface->h};
|
lpSrcRect ? ConvertRect(lpSrcRect) : SDL_Rect{0, 0, surface->m_surface->w, surface->m_surface->h};
|
||||||
SDL_Rect dstRect =
|
SDL_Rect dstRect =
|
||||||
lpDestRect ? ConvertRect(lpDestRect) : SDL_Rect{0, 0, (int) m_virtualWidth, (int) m_virtualHeight};
|
lpDestRect ? ConvertRect(lpDestRect) : SDL_Rect{0, 0, (int) m_virtualWidth, (int) m_virtualHeight};
|
||||||
|
float scaleX = (float) dstRect.w / (float) srcRect.w;
|
||||||
|
float scaleY = (float) dstRect.h / (float) srcRect.h;
|
||||||
|
Uint32 textureId = DDRenderer->GetTextureId(surface->ToTexture(), true, scaleX, scaleY);
|
||||||
DDRenderer->Draw2DImage(textureId, srcRect, dstRect, {1.0f, 1.0f, 1.0f, 1.0f});
|
DDRenderer->Draw2DImage(textureId, srcRect, dstRect, {1.0f, 1.0f, 1.0f, 1.0f});
|
||||||
|
|
||||||
return DD_OK;
|
return DD_OK;
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class Direct3DRMRenderer : public IDirect3DDevice2 {
|
|||||||
virtual void PushLights(const SceneLight* vertices, size_t count) = 0;
|
virtual void PushLights(const SceneLight* vertices, size_t count) = 0;
|
||||||
virtual void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) = 0;
|
virtual void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) = 0;
|
||||||
virtual void SetFrustumPlanes(const Plane* frustumPlanes) = 0;
|
virtual void SetFrustumPlanes(const Plane* frustumPlanes) = 0;
|
||||||
virtual Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi = false) = 0;
|
virtual Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI = false, float scaleX = 0, float scaleY = 0) = 0;
|
||||||
virtual Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) = 0;
|
virtual Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) = 0;
|
||||||
int GetWidth() { return m_width; }
|
int GetWidth() { return m_width; }
|
||||||
int GetHeight() { return m_height; }
|
int GetHeight() { return m_height; }
|
||||||
|
|||||||
@ -32,7 +32,7 @@ class Citro3DRenderer : public Direct3DRMRenderer {
|
|||||||
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
||||||
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
||||||
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
||||||
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi) override;
|
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI, float scaleX, float scaleY) override;
|
||||||
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
||||||
HRESULT BeginFrame() override;
|
HRESULT BeginFrame() override;
|
||||||
void EnableTransparency() override;
|
void EnableTransparency() override;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class DirectX9Renderer : public Direct3DRMRenderer {
|
|||||||
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
||||||
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
||||||
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
||||||
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi) override;
|
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI, float scaleX, float scaleY) override;
|
||||||
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
||||||
HRESULT BeginFrame() override;
|
HRESULT BeginFrame() override;
|
||||||
void EnableTransparency() override;
|
void EnableTransparency() override;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ class OpenGL1Renderer : public Direct3DRMRenderer {
|
|||||||
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
||||||
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
||||||
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
||||||
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi) override;
|
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI, float scaleX, float scaleY) override;
|
||||||
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
||||||
HRESULT BeginFrame() override;
|
HRESULT BeginFrame() override;
|
||||||
void EnableTransparency() override;
|
void EnableTransparency() override;
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class OpenGLES2Renderer : public Direct3DRMRenderer {
|
|||||||
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
||||||
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
||||||
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
||||||
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi) override;
|
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI, float scaleX, float scaleY) override;
|
||||||
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
||||||
HRESULT BeginFrame() override;
|
HRESULT BeginFrame() override;
|
||||||
void EnableTransparency() override;
|
void EnableTransparency() override;
|
||||||
|
|||||||
@ -47,7 +47,7 @@ class Direct3DRMSDL3GPURenderer : public Direct3DRMRenderer {
|
|||||||
static Direct3DRMRenderer* Create(DWORD width, DWORD height);
|
static Direct3DRMRenderer* Create(DWORD width, DWORD height);
|
||||||
~Direct3DRMSDL3GPURenderer() override;
|
~Direct3DRMSDL3GPURenderer() override;
|
||||||
void PushLights(const SceneLight* vertices, size_t count) override;
|
void PushLights(const SceneLight* vertices, size_t count) override;
|
||||||
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi) override;
|
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI, float scaleX, float scaleY) override;
|
||||||
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
||||||
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
||||||
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class Direct3DRMSoftwareRenderer : public Direct3DRMRenderer {
|
|||||||
Direct3DRMSoftwareRenderer(DWORD width, DWORD height);
|
Direct3DRMSoftwareRenderer(DWORD width, DWORD height);
|
||||||
~Direct3DRMSoftwareRenderer() override;
|
~Direct3DRMSoftwareRenderer() override;
|
||||||
void PushLights(const SceneLight* vertices, size_t count) override;
|
void PushLights(const SceneLight* vertices, size_t count) override;
|
||||||
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUi) override;
|
Uint32 GetTextureId(IDirect3DRMTexture* texture, bool isUI, float scaleX, float scaleY) override;
|
||||||
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
Uint32 GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGroup) override;
|
||||||
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
void SetProjection(const D3DRMMATRIX4D& projection, D3DVALUE front, D3DVALUE back) override;
|
||||||
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
void SetFrustumPlanes(const Plane* frustumPlanes) override;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user