(Xbox 1) Rewrite Surface.cpp

This commit is contained in:
twinaphex 2012-07-30 00:08:07 +02:00
parent 293740c4d5
commit 676f16b284
3 changed files with 105 additions and 137 deletions

View File

@ -1,52 +1,40 @@
/** /* RetroArch - A frontend for libretro.
* Surreal 64 Launcher (C) 2003 * Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* * Copyright (C) 2011-2012 - Daniel De Matteis
* 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 * RetroArch is free software: you can redistribute it and/or modify it under the terms
* Foundation; either version 2 of the License, or (at your option) any later * of the GNU General Public License as published by the Free Software Found-
* version. This program is distributed in the hope that it will be useful, but * ation, either version 3 of the License, or (at your option) any later version.
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* details. You should have received a copy of the GNU General Public License * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* along with this program; if not, write to the Free Software Foundation, Inc., * PURPOSE. See the GNU General Public License for more details.
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the *
* authors: email: buttza@hotmail.com, lantus@lantus-x.com * You should have received a copy of the GNU General Public License along with RetroArch.
* * If not, see <http://www.gnu.org/licenses/>.
* Additional code and cleanups: Surreal64 CE Team (http://www.emuxtras.net) */
*/
#include "Surface.h" #include "Surface.h"
#include "../../../general.h"
#include "../../xdk_d3d8.h" #include "../../xdk_d3d8.h"
CSurface::CSurface() bool d3d_surface_new(d3d_surface_t *surface, const char *filename)
{
m_pTexture = NULL;
m_pVertexBuffer = NULL;
m_byR = 255;
m_byG = 255;
m_byB = 255;
m_bLoaded = false;
m_x = 0;
m_y = 0;
}
CSurface::~CSurface()
{
Destroy();
}
bool CSurface::Create(const char *szFilename)
{ {
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
if (m_bLoaded) surface->m_pTexture = NULL;
Destroy(); surface->m_pVertexBuffer = NULL;
surface->m_byR = 255;
surface->m_byG = 255;
surface->m_byB = 255;
surface->m_bLoaded = false;
surface->m_x = 0;
surface->m_y = 0;
HRESULT g_hResult = D3DXCreateTextureFromFileExA(d3d->d3d_render_device, // d3d device HRESULT ret = D3DXCreateTextureFromFileExA(d3d->d3d_render_device, // d3d device
szFilename, // filename filename, // filename
D3DX_DEFAULT, D3DX_DEFAULT, // width/height D3DX_DEFAULT, // width
D3DX_DEFAULT, // height
D3DX_DEFAULT, // mipmaps D3DX_DEFAULT, // mipmaps
0, // usage 0, // usage
D3DFMT_A8R8G8B8, // format D3DFMT_A8R8G8B8, // format
@ -54,61 +42,56 @@ bool CSurface::Create(const char *szFilename)
D3DX_DEFAULT, // texture filter D3DX_DEFAULT, // texture filter
D3DX_DEFAULT, // mipmapping D3DX_DEFAULT, // mipmapping
0, // colorkey 0, // colorkey
&m_imageInfo, // image info &surface->m_imageInfo, // image info
NULL, // pallete NULL, // pallete
&m_pTexture); // texture &surface->m_pTexture); // texture
if (FAILED(g_hResult)) if (FAILED(ret))
{ {
RARCH_ERR("Error occurred during D3DXCreateTextureFromFileExA().\n"); RARCH_ERR("Error occurred during D3DXCreateTextureFromFileExA().\n");
return false; return false;
} }
// create a vertex buffer for the quad that will display the texture // create a vertex buffer for the quad that will display the texture
g_hResult = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), ret = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats),
D3DUSAGE_WRITEONLY, D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &surface->m_pVertexBuffer);
D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &m_pVertexBuffer); if (FAILED(ret))
if (FAILED(g_hResult))
{ {
RARCH_ERR("Error occurred during CreateVertexBuffer().\n"); RARCH_ERR("Error occurred during CreateVertexBuffer().\n");
m_pTexture->Release(); surface->m_pTexture->Release();
return false; return false;
} }
m_bLoaded = true; surface->m_bLoaded = true;
return true; return true;
} }
void CSurface::Destroy() void d3d_surface_free(d3d_surface_t *surface)
{ {
// free the vertex buffer // free the vertex buffer
if (m_pVertexBuffer) if (surface->m_pVertexBuffer)
{ {
m_pVertexBuffer->Release(); surface->m_pVertexBuffer->Release();
m_pVertexBuffer = NULL; surface->m_pVertexBuffer = NULL;
} }
// free the texture // free the texture
if (m_pTexture) if (surface->m_pTexture)
{ {
m_pTexture->Release(); surface->m_pTexture->Release();
m_pTexture = NULL; surface->m_pTexture = NULL;
} }
m_bLoaded = false; surface->m_bLoaded = false;
} }
bool CSurface::Render(int x, int y) bool d3d_surface_render(d3d_surface_t *surface, int x, int y, int32_t w, int32_t h)
{
return Render(x, y, m_imageInfo.Width, m_imageInfo.Height);
}
bool CSurface::Render(int x, int y, int32_t w, int32_t h)
{ {
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data; xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
if (m_pTexture == NULL || m_pVertexBuffer == NULL || m_bLoaded == false)
if (surface->m_pTexture == NULL || surface->m_pVertexBuffer == NULL || surface->m_bLoaded == false)
return false; return false;
float fX = static_cast<float>(x); float fX = static_cast<float>(x);
@ -117,28 +100,28 @@ bool CSurface::Render(int x, int y, int32_t w, int32_t h)
// create the new vertices // create the new vertices
DrawVerticeFormats newVerts[] = DrawVerticeFormats newVerts[] =
{ {
// x, y, z, color, u ,v // x, y, z, color, u ,v
{fX, fY, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 0, 0}, {fX, fY, 0.0f, 0, 0, 0},
{fX + w, fY, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 1, 0}, {fX + w, fY, 0.0f, 0, 1, 0},
{fX + w, fY + h, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 1, 1}, {fX + w, fY + h, 0.0f, 0, 1, 1},
{fX, fY + h, 0.0f, /*D3DCOLOR_ARGB(m_byOpacity, m_byR, m_byG, m_byB),*/ 0, 0, 1} {fX, fY + h, 0.0f, 0, 0, 1}
}; };
// load the existing vertices // load the existing vertices
/*CustomVertex*/DrawVerticeFormats *pCurVerts; DrawVerticeFormats *pCurVerts;
HRESULT g_hResult = m_pVertexBuffer->Lock(0, 0, (byte **)&pCurVerts, 0); HRESULT ret = surface->m_pVertexBuffer->Lock(0, 0, (unsigned char**)&pCurVerts, 0);
if (FAILED(g_hResult)) if (FAILED(ret))
{ {
RARCH_ERR("Error occurred during m_pVertexBuffer->Lock().\n"); RARCH_ERR("Error occurred during m_pVertexBuffer->Lock().\n");
return false; return false;
} }
// copy the new verts over the old verts // copy the new verts over the old verts
memcpy(pCurVerts, newVerts, 4 * sizeof(DrawVerticeFormats)); memcpy(pCurVerts, newVerts, 4 * sizeof(DrawVerticeFormats));
m_pVertexBuffer->Unlock(); surface->m_pVertexBuffer->Unlock();
d3d->d3d_render_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); d3d->d3d_render_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3d->d3d_render_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3d->d3d_render_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
@ -150,9 +133,10 @@ bool CSurface::Render(int x, int y, int32_t w, int32_t h)
d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
// draw the quad // draw the quad
d3d->d3d_render_device->SetTexture(0, m_pTexture); d3d->d3d_render_device->SetTexture(0, surface->m_pTexture);
d3d->d3d_render_device->SetStreamSource(0, m_pVertexBuffer, sizeof(DrawVerticeFormats)); d3d->d3d_render_device->SetStreamSource(0, surface->m_pVertexBuffer, sizeof(DrawVerticeFormats));
d3d->d3d_render_device->SetVertexShader(D3DFVF_CUSTOMVERTEX); d3d->d3d_render_device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
d3d->d3d_render_device->DrawPrimitive(D3DPT_QUADLIST, 0, 1); d3d->d3d_render_device->DrawPrimitive(D3DPT_QUADLIST, 0, 1);
return true; return true;
} }

View File

@ -1,58 +1,39 @@
/** /* RetroArch - A frontend for libretro.
* Surreal 64 Launcher (C) 2003 * Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* * Copyright (C) 2011-2012 - Daniel De Matteis
* 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 * RetroArch is free software: you can redistribute it and/or modify it under the terms
* Foundation; either version 2 of the License, or (at your option) any later * of the GNU General Public License as published by the Free Software Found-
* version. This program is distributed in the hope that it will be useful, but * ation, either version 3 of the License, or (at your option) any later version.
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* details. You should have received a copy of the GNU General Public License * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* along with this program; if not, write to the Free Software Foundation, Inc., * PURPOSE. See the GNU General Public License for more details.
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. To contact the *
* authors: email: buttza@hotmail.com, lantus@lantus-x.com * You should have received a copy of the GNU General Public License along with RetroArch.
* * If not, see <http://www.gnu.org/licenses/>.
* Additional code and cleanups: Surreal64 CE Team (http://www.emuxtras.net) */
*/
#pragma once #ifndef _D3D_SURFACE_H_
#define _D3D_SURFACE_H_
class CSurface #include "../../../xdk/xdk_defines.h"
typedef struct
{ {
public: LPDIRECT3DTEXTURE m_pTexture;
CSurface(); LPDIRECT3DVERTEXBUFFER m_pVertexBuffer;
~CSurface(); int m_x;
int m_y;
/**
* Do functions
*/
bool Create(const char *szFilename);
void Destroy();
bool Render(int x, int y);
bool Render(int x, int y, int32_t w, int32_t h);
private:
/**
* A d3d texture object that will contain the loaded texture
* and a d3d vertex buffer object that will contain the vertex
* buffer for the quad which will display the texture
*/
IDirect3DTexture8 *m_pTexture;
IDirect3DVertexBuffer8 *m_pVertexBuffer;
/**
* The default render position of the texture
*/
int m_x, m_y;
/**
* The width and height of the texture
*/
D3DXIMAGE_INFO m_imageInfo; D3DXIMAGE_INFO m_imageInfo;
byte m_byR, m_byG, m_byB; unsigned char m_byR;
unsigned char m_byG;
unsigned char m_byB;
bool m_bLoaded;
} d3d_surface_t;
/** bool d3d_surface_new(d3d_surface_t *surface, const char *filename);
* Whether the texture has been created or not void d3d_surface_free(d3d_surface_t *surface);
*/ bool d3d_surface_render(d3d_surface_t *surface, int x, int y, int32_t w, int32_t h);
bool m_bLoaded;
}; #endif

View File

@ -34,9 +34,9 @@
filebrowser_t browser; filebrowser_t browser;
// Rom selector panel with coords // Rom selector panel with coords
CSurface m_menuMainRomSelectPanel; d3d_surface_t m_menuMainRomSelectPanel;
// Background image with coords // Background image with coords
CSurface m_menuMainBG; d3d_surface_t m_menuMainBG;
// Rom list coords // Rom list coords
int m_menuMainRomListPos_x; int m_menuMainRomListPos_x;
@ -54,7 +54,8 @@ static uint16_t old_input_st = 0;
static void display_menubar(void) static void display_menubar(void)
{ {
//Render background image //Render background image
m_menuMainBG.Render(MENU_MAIN_BG_X, MENU_MAIN_BG_Y); d3d_surface_render(&m_menuMainBG, MENU_MAIN_BG_X, MENU_MAIN_BG_Y,
m_menuMainBG.m_imageInfo.Width, m_menuMainBG.m_imageInfo.Height);
} }
typedef enum { typedef enum {
@ -137,7 +138,7 @@ static void browser_render(filebrowser_t *b, float current_x, float current_y, f
//check if this is the currently selected file //check if this is the currently selected file
const char *current_pathname = filebrowser_get_current_path(b); const char *current_pathname = filebrowser_get_current_path(b);
if(strcmp(current_pathname, b->current_dir.list->elems[i].data) == 0) if(strcmp(current_pathname, b->current_dir.list->elems[i].data) == 0)
m_menuMainRomSelectPanel.Render(currentX, currentY, ROM_PANEL_WIDTH, ROM_PANEL_HEIGHT); d3d_surface_render(&m_menuMainRomSelectPanel, currentX, currentY, ROM_PANEL_WIDTH, ROM_PANEL_HEIGHT);
convert_char_to_wchar(rom_basename_w, rom_basename, sizeof(rom_basename_w)); convert_char_to_wchar(rom_basename_w, rom_basename, sizeof(rom_basename_w));
d3d->d3d_render_device->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &d3d->pFrontBuffer); d3d->d3d_render_device->GetBackBuffer(-1, D3DBACKBUFFER_TYPE_MONO, &d3d->pFrontBuffer);
@ -254,19 +255,19 @@ int menu_init(void)
// Load background image // Load background image
if(width == 640) if(width == 640)
{ {
m_menuMainBG.Create("D:\\Media\\menuMainBG.png"); d3d_surface_new(&m_menuMainBG, "D:\\Media\\menuMainBG.png");
m_menuMainRomListPos_x = 100; m_menuMainRomListPos_x = 100;
m_menuMainRomListPos_y = 100; m_menuMainRomListPos_y = 100;
} }
else if(width == 1280) else if(width == 1280)
{ {
m_menuMainBG.Create("D:\\Media\\menuMainBG_720p.png"); d3d_surface_new(&m_menuMainBG, "D:\\Media\\menuMainBG_720p.png");
m_menuMainRomListPos_x = 400; m_menuMainRomListPos_x = 400;
m_menuMainRomListPos_y = 150; m_menuMainRomListPos_y = 150;
} }
// Load rom selector panel // Load rom selector panel
m_menuMainRomSelectPanel.Create("D:\\Media\\menuMainRomSelectPanel.png"); d3d_surface_new(&m_menuMainRomSelectPanel, "D:\\Media\\menuMainRomSelectPanel.png");
g_console.mode_switch = MODE_MENU; g_console.mode_switch = MODE_MENU;
@ -276,6 +277,8 @@ int menu_init(void)
void menu_free(void) void menu_free(void)
{ {
filebrowser_free(&browser); filebrowser_free(&browser);
d3d_surface_free(&m_menuMainBG);
d3d_surface_free(&m_menuMainRomSelectPanel);
} }
void menu_loop(void) void menu_loop(void)