mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
* Load and display save image in save/load menu
* Add help math function * Add draw function in PPGe without texture and with alternative texture. * Change hardcoded atlas texture size in PPGe
This commit is contained in:
parent
ffdc96a06a
commit
67c88d7b33
@ -247,3 +247,28 @@ void Matrix44::Multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &result)
|
||||
MatrixMul(4, a.data, b.data, result.data);
|
||||
}
|
||||
|
||||
int Pow2roundup(int x)
|
||||
{
|
||||
if (x < 0)
|
||||
return 0;
|
||||
--x;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
return x+1;
|
||||
}
|
||||
|
||||
int GetPow2(int x)
|
||||
{
|
||||
int ret = 0;
|
||||
int val = 1;
|
||||
while(x > val)
|
||||
{
|
||||
ret++;
|
||||
val *= 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -146,6 +146,8 @@ struct Rectangle
|
||||
|
||||
inline float pow2f(float x) {return x * x;}
|
||||
inline double pow2(double x) {return x * x;}
|
||||
int Pow2roundup(int x);
|
||||
int GetPow2(int x);
|
||||
|
||||
|
||||
/*
|
||||
@ -163,7 +165,6 @@ float MathFloatVectorSum(const std::vector<float>&);
|
||||
#define ROUND_UP(x, a) (((x) + (a) - 1) & ~((a) - 1))
|
||||
#define ROUND_DOWN(x, a) ((x) & ~((a) - 1))
|
||||
|
||||
|
||||
// Tiny matrix/vector library.
|
||||
// Used for things like Free-Look in the gfx backend.
|
||||
|
||||
|
@ -129,7 +129,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove)
|
||||
int displayCount = 0;
|
||||
for(int i = 0; i < param.GetFilenameCount(); i++)
|
||||
{
|
||||
int textureColor = 0xFF000000; // Hack for differencing save existing and not while real texture not displayed
|
||||
int textureColor = 0xFFFFFFFF;
|
||||
|
||||
if(param.GetFileInfo(i).size == 0)
|
||||
{
|
||||
@ -154,8 +154,23 @@ void PSPSaveDialog::DisplaySaveList(bool canMove)
|
||||
y += 90 + 50 * (displayCount - currentSelectedSave - 1);
|
||||
}
|
||||
|
||||
PPGeDraw4Patch(I_BUTTON, x, y, w, h, textureColor); // TODO : Display save texture image, or default if no save
|
||||
|
||||
int tw = 256;
|
||||
int th = 256;
|
||||
if(param.GetFileInfo(i).textureData != 0)
|
||||
{
|
||||
tw = param.GetFileInfo(i).textureWidth;
|
||||
th = param.GetFileInfo(i).textureHeight;
|
||||
PPGeSetTexture(param.GetFileInfo(i).textureData, param.GetFileInfo(i).textureWidth, param.GetFileInfo(i).textureHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
PPGeDisableTexture();
|
||||
}
|
||||
PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor);
|
||||
if(param.GetFileInfo(i).textureData != 0)
|
||||
{
|
||||
PPGeSetDefaultTexture();
|
||||
}
|
||||
displayCount++;
|
||||
}
|
||||
|
||||
@ -174,7 +189,7 @@ void PSPSaveDialog::DisplaySaveList(bool canMove)
|
||||
|
||||
void PSPSaveDialog::DisplaySaveIcon()
|
||||
{
|
||||
int textureColor = 0xFF000000; // Hack for differencing save existing and not while real texture not displayed
|
||||
int textureColor = 0xFFFFFFFF;
|
||||
|
||||
if(param.GetFileInfo(currentSelectedSave).size == 0)
|
||||
{
|
||||
@ -187,8 +202,23 @@ void PSPSaveDialog::DisplaySaveIcon()
|
||||
int x = 20;
|
||||
int y = 80;
|
||||
|
||||
PPGeDraw4Patch(I_BUTTON, x, y, w, h, textureColor); // TODO : Display save texture image, or default if no save
|
||||
|
||||
int tw = 256;
|
||||
int th = 256;
|
||||
if(param.GetFileInfo(currentSelectedSave).textureData != 0)
|
||||
{
|
||||
tw = param.GetFileInfo(currentSelectedSave).textureWidth;
|
||||
th = param.GetFileInfo(currentSelectedSave).textureHeight;
|
||||
PPGeSetTexture(param.GetFileInfo(currentSelectedSave).textureData, param.GetFileInfo(currentSelectedSave).textureWidth, param.GetFileInfo(currentSelectedSave).textureHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
PPGeDisableTexture();
|
||||
}
|
||||
PPGeDrawImage(x, y, w, h, 0, 0 ,1 ,1 ,tw, th, textureColor);
|
||||
if(param.GetFileInfo(currentSelectedSave).textureData != 0)
|
||||
{
|
||||
PPGeSetDefaultTexture();
|
||||
}
|
||||
}
|
||||
|
||||
void PSPSaveDialog::DisplaySaveDataInfo1()
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
#include "SavedataParam.h"
|
||||
#include "../System.h"
|
||||
#include "image/png_load.h"
|
||||
#include "../HLE/sceKernelMemory.h"
|
||||
|
||||
std::string icon0Name = "ICON0.PNG";
|
||||
std::string icon1Name = "ICON1.PNG";
|
||||
@ -259,10 +261,30 @@ bool SavedataParam::GetList(SceUtilitySavedataParam* param)
|
||||
return true;
|
||||
}
|
||||
|
||||
void SavedataParam::Clear()
|
||||
{
|
||||
if(saveDataList)
|
||||
{
|
||||
for(int i = 0; i < saveNameListDataCount; i++)
|
||||
{
|
||||
if(saveDataList[i].textureData != 0)
|
||||
kernelMemory.Free(saveDataList[i].textureData);
|
||||
saveDataList[i].textureData = 0;
|
||||
}
|
||||
|
||||
delete[] saveDataList;
|
||||
saveDataList = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SavedataParam::SetPspParam(SceUtilitySavedataParam* param)
|
||||
{
|
||||
pspParam = param;
|
||||
if(!pspParam) return;
|
||||
if(!pspParam)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
bool listEmptyFile = true;
|
||||
if(param->mode == SCE_UTILITY_SAVEDATA_TYPE_LISTLOAD ||
|
||||
@ -282,8 +304,7 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param)
|
||||
count++;
|
||||
} while(saveNameListData[count][0] != 0);
|
||||
|
||||
if(saveDataList)
|
||||
delete[] saveDataList;
|
||||
Clear();
|
||||
saveDataList = new SaveFileInfo[count];
|
||||
|
||||
// get and stock file info for each file
|
||||
@ -300,6 +321,32 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param)
|
||||
saveDataList[realCount].size = info.size;
|
||||
saveDataList[realCount].saveName = saveNameListData[i];
|
||||
saveDataList[realCount].idx = i;
|
||||
|
||||
// Search save image icon0
|
||||
std::string fileDataPath2 = savePath+GetGameName(param)+saveNameListData[i]+"/"+icon0Name;
|
||||
PSPFileInfo info2 = pspFileSystem.GetFileInfo(fileDataPath2);
|
||||
if(info2.exists)
|
||||
{
|
||||
u8* textureDataPNG = new u8[info2.size];
|
||||
int handle = pspFileSystem.OpenFile(fileDataPath2,FILEACCESS_READ);
|
||||
pspFileSystem.ReadFile(handle,textureDataPNG,info2.size);
|
||||
unsigned char* textureData;
|
||||
int w,h;
|
||||
pngLoadPtr(textureDataPNG, info2.size, &w, &h, &textureData, false);
|
||||
delete[] textureDataPNG;
|
||||
u32 texSize = w*h*4;
|
||||
u32 atlasPtr = kernelMemory.Alloc(texSize, true, "SaveData Icon");
|
||||
saveDataList[realCount].textureData = atlasPtr;
|
||||
Memory::Memcpy(atlasPtr, textureData, texSize);
|
||||
free(textureData);
|
||||
saveDataList[realCount].textureWidth = w;
|
||||
saveDataList[realCount].textureHeight = h;
|
||||
}
|
||||
else
|
||||
{
|
||||
saveDataList[realCount].textureData = 0;
|
||||
}
|
||||
|
||||
DEBUG_LOG(HLE,"%s Exist",fileDataPath.c_str());
|
||||
realCount++;
|
||||
}
|
||||
@ -310,6 +357,7 @@ void SavedataParam::SetPspParam(SceUtilitySavedataParam* param)
|
||||
saveDataList[realCount].size = 0;
|
||||
saveDataList[realCount].saveName = saveNameListData[i];
|
||||
saveDataList[realCount].idx = i;
|
||||
saveDataList[realCount].textureData = 0;
|
||||
DEBUG_LOG(HLE,"Don't Exist");
|
||||
realCount++;
|
||||
}
|
||||
|
@ -123,6 +123,10 @@ struct SaveFileInfo
|
||||
int size;
|
||||
char* saveName;
|
||||
int idx;
|
||||
|
||||
u32 textureData;
|
||||
int textureWidth;
|
||||
int textureHeight;
|
||||
};
|
||||
|
||||
class SavedataParam
|
||||
@ -153,6 +157,8 @@ public:
|
||||
void SetSelectedSave(int idx);
|
||||
|
||||
private:
|
||||
void Clear();
|
||||
|
||||
SceUtilitySavedataParam* pspParam;
|
||||
int selectedSave;
|
||||
char (*saveNameListData)[20];
|
||||
|
@ -27,8 +27,11 @@
|
||||
#include "gfx/texture_atlas.h"
|
||||
#include "gfx/gl_common.h"
|
||||
#include "../System.h"
|
||||
#include "MathUtil.h"
|
||||
|
||||
static u32 atlasPtr;
|
||||
static int atlasWidth;
|
||||
static int atlasHeight;
|
||||
|
||||
struct PPGeVertex {
|
||||
u16 u, v;
|
||||
@ -78,11 +81,11 @@ static void BeginVertexData() {
|
||||
vertexStart = dataWritePtr;
|
||||
}
|
||||
|
||||
static void Vertex(float x, float y, float u, float v, u32 color = 0xFFFFFFFF)
|
||||
static void Vertex(float x, float y, float u, float v, int tw, int th, u32 color = 0xFFFFFFFF)
|
||||
{
|
||||
PPGeVertex vtx;
|
||||
vtx.x = x - 0.5f; vtx.y = y - 0.5f; vtx.z = 0;
|
||||
vtx.u = u * 256 - 0.5f; vtx.v = v * 256 - 0.5f;
|
||||
vtx.u = u * tw - 0.5f; vtx.v = v * th - 0.5f;
|
||||
vtx.color = color;
|
||||
Memory::WriteStruct(dataWritePtr, &vtx);
|
||||
vertexCount++;
|
||||
@ -112,6 +115,8 @@ void __PPGeInit()
|
||||
}
|
||||
|
||||
u32 atlasSize = height * width * 2; // it's a 4444 texture
|
||||
atlasWidth = width;
|
||||
atlasHeight = height;
|
||||
dlPtr = kernelMemory.Alloc(dlSize, false, "PPGe Display List");
|
||||
dataPtr = kernelMemory.Alloc(dataSize, false, "PPGe Vertex Data");
|
||||
atlasPtr = kernelMemory.Alloc(atlasSize, false, "PPGe Atlas Texture");
|
||||
@ -173,17 +178,7 @@ void PPGeBegin()
|
||||
WriteCmd(GE_CMD_CULLFACEENABLE, 0);
|
||||
WriteCmd(GE_CMD_CLEARMODE, 0); // Normal mode
|
||||
|
||||
WriteCmd(GE_CMD_TEXTUREMAPENABLE, 1);
|
||||
WriteCmd(GE_CMD_TEXSIZE0, 8 | (8 << 8)); // 1 << (7+1) = 256
|
||||
WriteCmd(GE_CMD_TEXMAPMODE, 0 | (1 << 8));
|
||||
WriteCmd(GE_CMD_TEXMODE, 0);
|
||||
WriteCmd(GE_CMD_TEXFORMAT, 2); // 4444
|
||||
WriteCmd(GE_CMD_TEXFILTER, (1 << 8) | 1); // mag = LINEAR min = LINEAR
|
||||
WriteCmd(GE_CMD_TEXWRAP, (1 << 8) | 1); // clamp texture wrapping
|
||||
WriteCmd(GE_CMD_TEXFUNC, (0 << 16) | (1 << 8) | 0); // RGBA texture reads, modulate, no color doubling
|
||||
WriteCmd(GE_CMD_TEXADDR0, atlasPtr & 0xFFFFF0);
|
||||
WriteCmd(GE_CMD_TEXBUFWIDTH0, 256 | ((atlasPtr & 0xFF000000) >> 8));
|
||||
WriteCmd(GE_CMD_TEXFLUSH, 0);
|
||||
PPGeSetDefaultTexture();
|
||||
|
||||
WriteCmd(GE_CMD_SCISSOR1, (0 << 10) | 0);
|
||||
WriteCmd(GE_CMD_SCISSOR2, (1023 << 10) | 1023);
|
||||
@ -271,8 +266,8 @@ void PPGeDrawText(const char *text, float x, float y, int align, float scale, u3
|
||||
float cy1 = y + c.oy * scale;
|
||||
float cx2 = x + (c.ox + c.pw) * scale;
|
||||
float cy2 = y + (c.oy + c.ph) * scale;
|
||||
Vertex(cx1, cy1, c.sx, c.sy, color);
|
||||
Vertex(cx2, cy2, c.ex, c.ey, color);
|
||||
Vertex(cx1, cy1, c.sx, c.sy, 256, 256, color);
|
||||
Vertex(cx2, cy2, c.ex, c.ey, 256, 256, color);
|
||||
x += c.wx * scale;
|
||||
}
|
||||
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
|
||||
@ -296,26 +291,26 @@ void PPGeDraw4Patch(int atlasImage, float x, float y, float w, float h, u32 colo
|
||||
float y2 = y + h;
|
||||
BeginVertexData();
|
||||
// Top row
|
||||
Vertex(x, y, u1, v1, color);
|
||||
Vertex(xmid1, ymid1, uhalf, vhalf, color);
|
||||
Vertex(xmid1, y, uhalf, v1, color);
|
||||
Vertex(xmid2, ymid1, uhalf, vhalf, color);
|
||||
Vertex(xmid2, y, uhalf, v1, color);
|
||||
Vertex(x2, ymid1, u2, vhalf, color);
|
||||
Vertex(x, y, u1, v1, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid1, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid1, y, uhalf, v1, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid2, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid2, y, uhalf, v1, atlasWidth, atlasHeight, color);
|
||||
Vertex(x2, ymid1, u2, vhalf, atlasWidth, atlasHeight, color);
|
||||
// Middle row
|
||||
Vertex(x, ymid1, u1, vhalf, color);
|
||||
Vertex(xmid1, ymid2, uhalf, vhalf, color);
|
||||
Vertex(xmid1, ymid1, uhalf, vhalf, color);
|
||||
Vertex(xmid2, ymid2, uhalf, vhalf, color);
|
||||
Vertex(xmid2, ymid1, uhalf, vhalf, color);
|
||||
Vertex(x2, ymid2, u2, v2, color);
|
||||
Vertex(x, ymid1, u1, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid1, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid1, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid2, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid2, ymid1, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(x2, ymid2, u2, v2, atlasWidth, atlasHeight, color);
|
||||
// Bottom row
|
||||
Vertex(x, ymid2, u1, vhalf, color);
|
||||
Vertex(xmid1, y2, uhalf, v2, color);
|
||||
Vertex(xmid1, ymid2, uhalf, vhalf, color);
|
||||
Vertex(xmid2, y2, uhalf, v2, color);
|
||||
Vertex(xmid2, ymid2, uhalf, vhalf, color);
|
||||
Vertex(x2, y2, u2, v2, color);
|
||||
Vertex(x, ymid2, u1, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid1, y2, uhalf, v2, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid1, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid2, y2, uhalf, v2, atlasWidth, atlasHeight, color);
|
||||
Vertex(xmid2, ymid2, uhalf, vhalf, atlasWidth, atlasHeight, color);
|
||||
Vertex(x2, y2, u2, v2, atlasWidth, atlasHeight, color);
|
||||
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
|
||||
}
|
||||
|
||||
@ -329,8 +324,8 @@ void PPGeDrawImage(int atlasImage, float x, float y, int align, u32 color)
|
||||
float w = img.w;
|
||||
float h = img.h;
|
||||
BeginVertexData();
|
||||
Vertex(x, y, img.u1, img.v1, color);
|
||||
Vertex(x + w, y + h, img.u2, img.v2, color);
|
||||
Vertex(x, y, img.u1, img.v1, atlasWidth, atlasHeight, color);
|
||||
Vertex(x + w, y + h, img.u2, img.v2, atlasWidth, atlasHeight, color);
|
||||
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
|
||||
}
|
||||
|
||||
@ -341,8 +336,57 @@ void PPGeDrawImage(int atlasImage, float x, float y, float w, float h, int align
|
||||
|
||||
const AtlasImage &img = ppge_atlas.images[atlasImage];
|
||||
BeginVertexData();
|
||||
Vertex(x, y, img.u1, img.v1, color);
|
||||
Vertex(x + w, y + h, img.u2, img.v2, color);
|
||||
Vertex(x, y, img.u1, img.v1, atlasWidth, atlasHeight, color);
|
||||
Vertex(x + w, y + h, img.u2, img.v2, atlasWidth, atlasHeight, color);
|
||||
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
|
||||
}
|
||||
|
||||
void PPGeDrawImage(float x, float y, float w, float h, float u1, float v1, float u2, float v2, int tw, int th, u32 color)
|
||||
{
|
||||
if (!dlPtr)
|
||||
return;
|
||||
BeginVertexData();
|
||||
Vertex(x, y, u1, v1, tw, th, color);
|
||||
Vertex(x + w, y + h, u2, v2, tw, th, color);
|
||||
EndVertexDataAndDraw(GE_PRIM_RECTANGLES);
|
||||
}
|
||||
|
||||
void PPGeSetDefaultTexture()
|
||||
{
|
||||
WriteCmd(GE_CMD_TEXTUREMAPENABLE, 1);
|
||||
int wp2 = GetPow2(atlasWidth);
|
||||
int hp2 = GetPow2(atlasHeight);
|
||||
WriteCmd(GE_CMD_TEXSIZE0, wp2 | (hp2 << 8)); // 1 << (7+1) = 256
|
||||
WriteCmd(GE_CMD_TEXMAPMODE, 0 | (1 << 8));
|
||||
WriteCmd(GE_CMD_TEXMODE, 0);
|
||||
WriteCmd(GE_CMD_TEXFORMAT, 2); // 4444
|
||||
WriteCmd(GE_CMD_TEXFILTER, (1 << 8) | 1); // mag = LINEAR min = LINEAR
|
||||
WriteCmd(GE_CMD_TEXWRAP, (1 << 8) | 1); // clamp texture wrapping
|
||||
WriteCmd(GE_CMD_TEXFUNC, (0 << 16) | (1 << 8) | 0); // RGBA texture reads, modulate, no color doubling
|
||||
WriteCmd(GE_CMD_TEXADDR0, atlasPtr & 0xFFFFF0);
|
||||
WriteCmd(GE_CMD_TEXBUFWIDTH0, atlasWidth | ((atlasPtr & 0xFF000000) >> 8));
|
||||
WriteCmd(GE_CMD_TEXFLUSH, 0);
|
||||
}
|
||||
|
||||
void PPGeSetTexture(u32 dataAddr, int width, int height)
|
||||
{
|
||||
WriteCmd(GE_CMD_TEXTUREMAPENABLE, 1);
|
||||
int wp2 = GetPow2(width);
|
||||
int hp2 = GetPow2(height);
|
||||
WriteCmd(GE_CMD_TEXSIZE0, wp2 | (hp2 << 8)); // 1 << (7+1) = 256
|
||||
WriteCmd(GE_CMD_TEXMAPMODE, 0 | (1 << 8));
|
||||
WriteCmd(GE_CMD_TEXMODE, 0);
|
||||
WriteCmd(GE_CMD_TEXFORMAT, GE_TFMT_8888); // 4444
|
||||
WriteCmd(GE_CMD_TEXFILTER, (1 << 8) | 1); // mag = LINEAR min = LINEAR
|
||||
WriteCmd(GE_CMD_TEXWRAP, (1 << 8) | 1); // clamp texture wrapping
|
||||
WriteCmd(GE_CMD_TEXFUNC, (0 << 16) | (1 << 8) | 0); // RGBA texture reads, modulate, no color doubling
|
||||
WriteCmd(GE_CMD_TEXADDR0, dataAddr & 0xFFFFF0);
|
||||
WriteCmd(GE_CMD_TEXBUFWIDTH0, width | ((dataAddr & 0xFF000000) >> 8));
|
||||
WriteCmd(GE_CMD_TEXFLUSH, 0);
|
||||
}
|
||||
|
||||
void PPGeDisableTexture()
|
||||
{
|
||||
WriteCmd(GE_CMD_TEXTUREMAPENABLE, 0);
|
||||
}
|
||||
|
||||
|
@ -68,4 +68,9 @@ void PPGeDraw4Patch(int atlasImage, float x, float y, float w, float h, u32 colo
|
||||
// Just blits an image to the screen, multiplied with the color.
|
||||
void PPGeDrawImage(int atlasImage, float x, float y, int align, u32 color = 0xFFFFFFFF);
|
||||
void PPGeDrawImage(int atlasImage, float x, float y, float w, float h, int align, u32 color = 0xFFFFFFFF);
|
||||
void PPGeDrawImage(float x, float y, float w, float h, float u1, float v1, float u2, float v2, int tw, int th, u32 color);
|
||||
|
||||
void PPGeSetDefaultTexture();
|
||||
void PPGeSetTexture(u32 dataAddr, int width, int height);
|
||||
void PPGeDisableTexture();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user