2012-07-29 22:08:07 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-09 06:27:05 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch 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 Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
#include "../gfx/image.h"
|
2013-01-10 08:22:33 +00:00
|
|
|
#include "xdk_d3d.h"
|
2012-07-23 14:38:29 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
bool texture_image_load(const char *path, struct texture_image *out_img)
|
2012-07-22 17:54:04 +00:00
|
|
|
{
|
2012-07-23 14:38:29 +00:00
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
2013-01-09 06:27:05 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
D3DXIMAGE_INFO m_imageInfo;
|
2012-07-29 21:24:39 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
out_img->pixels = NULL;
|
|
|
|
out_img->vertex_buf = NULL;
|
2012-07-29 22:08:07 +00:00
|
|
|
|
2012-10-18 04:06:55 +00:00
|
|
|
HRESULT ret = D3DXCreateTextureFromFileExA(d3d->d3d_render_device,
|
2013-01-09 06:27:05 +00:00
|
|
|
path, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8,
|
|
|
|
D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, &m_imageInfo, NULL,
|
|
|
|
&out_img->pixels);
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
if(FAILED(ret))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Error occurred during D3DXCreateTextureFromFileExA().\n");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
// create a vertex buffer for the quad that will display the texture
|
2012-07-29 22:08:07 +00:00
|
|
|
ret = d3d->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats),
|
2013-01-09 06:27:05 +00:00
|
|
|
D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &out_img->vertex_buf);
|
2012-07-29 22:08:07 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
if (FAILED(ret))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Error occurred during CreateVertexBuffer().\n");
|
2012-08-05 15:18:19 +00:00
|
|
|
out_img->pixels->Release();
|
2012-08-04 01:50:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-09 06:27:05 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
out_img->width = m_imageInfo.Width;
|
|
|
|
out_img->height = m_imageInfo.Height;
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
return true;
|
2012-07-22 17:54:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
void texture_image_free(struct texture_image *out_img)
|
2012-07-22 17:54:04 +00:00
|
|
|
{
|
2012-08-04 01:50:10 +00:00
|
|
|
// free the vertex buffer
|
2012-08-05 15:18:19 +00:00
|
|
|
if (out_img->vertex_buf)
|
2012-08-04 01:50:10 +00:00
|
|
|
{
|
2012-08-05 15:18:19 +00:00
|
|
|
out_img->vertex_buf->Release();
|
|
|
|
out_img->vertex_buf = NULL;
|
2012-08-04 01:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// free the texture
|
2012-08-05 15:18:19 +00:00
|
|
|
if (out_img->pixels)
|
2012-08-04 01:50:10 +00:00
|
|
|
{
|
2012-08-05 15:18:19 +00:00
|
|
|
out_img->pixels->Release();
|
|
|
|
out_img->pixels = NULL;
|
2012-08-04 01:50:10 +00:00
|
|
|
}
|
2012-07-22 17:54:04 +00:00
|
|
|
}
|
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
bool texture_image_render(struct texture_image *out_img)
|
2012-07-22 17:54:04 +00:00
|
|
|
{
|
2012-07-23 14:38:29 +00:00
|
|
|
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)driver.video_data;
|
2012-07-29 22:08:07 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
if (out_img->pixels == NULL || out_img->vertex_buf == NULL)
|
2012-08-04 01:50:10 +00:00
|
|
|
return false;
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
int x = out_img->x;
|
|
|
|
int y = out_img->y;
|
|
|
|
int w = out_img->width;
|
|
|
|
int h = out_img->height;
|
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
float fX = static_cast<float>(x);
|
|
|
|
float fY = static_cast<float>(y);
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-10-18 04:06:55 +00:00
|
|
|
// create the new vertices
|
2012-07-29 21:24:39 +00:00
|
|
|
DrawVerticeFormats newVerts[] =
|
2012-08-04 01:50:10 +00:00
|
|
|
{
|
2012-10-18 04:06:55 +00:00
|
|
|
// x, y, z, color, u ,v
|
|
|
|
{fX, fY, 0.0f, 0, 0, 0},
|
|
|
|
{fX + w, fY, 0.0f, 0, 1, 0},
|
|
|
|
{fX + w, fY + h, 0.0f, 0, 1, 1},
|
|
|
|
{fX, fY + h, 0.0f, 0, 0, 1}
|
2012-08-04 01:50:10 +00:00
|
|
|
};
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
// load the existing vertices
|
2012-07-29 22:08:07 +00:00
|
|
|
DrawVerticeFormats *pCurVerts;
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
HRESULT ret = out_img->vertex_buf->Lock(0, 0, (unsigned char**)&pCurVerts, 0);
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
if (FAILED(ret))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Error occurred during m_pVertexBuffer->Lock().\n");
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-29 22:08:07 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
// copy the new verts over the old verts
|
|
|
|
memcpy(pCurVerts, newVerts, 4 * sizeof(DrawVerticeFormats));
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-05 15:18:19 +00:00
|
|
|
out_img->vertex_buf->Unlock();
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-07-23 14:38:29 +00:00
|
|
|
d3d->d3d_render_device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
2012-08-04 01:50:10 +00:00
|
|
|
d3d->d3d_render_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
|
|
|
d3d->d3d_render_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
// also blend the texture with the set alpha value
|
|
|
|
d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
|
|
|
d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
|
|
|
|
d3d->d3d_render_device->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
|
2012-07-22 17:54:04 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
// draw the quad
|
2012-08-05 15:18:19 +00:00
|
|
|
d3d->d3d_render_device->SetTexture(0, out_img->pixels);
|
|
|
|
d3d->d3d_render_device->SetStreamSource(0, out_img->vertex_buf, sizeof(DrawVerticeFormats));
|
2012-08-04 01:50:10 +00:00
|
|
|
d3d->d3d_render_device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
|
|
|
|
d3d->d3d_render_device->DrawPrimitive(D3DPT_QUADLIST, 0, 1);
|
2012-07-29 22:08:07 +00:00
|
|
|
|
2012-08-04 01:50:10 +00:00
|
|
|
return true;
|
2012-07-22 17:54:04 +00:00
|
|
|
}
|