- [Psy-X] correctly implement VRAM clear, LoadImage2

- [Psy-X] fix framebuffer size bug
This commit is contained in:
Ilya Shurumov 2021-05-11 21:25:48 +06:00 committed by InspirationByte
parent fdef7bbfac
commit fdc9782530
3 changed files with 29 additions and 8 deletions

View File

@ -169,6 +169,7 @@ extern void GR_ReadVRAM(unsigned short* dst, int x, int y, int dst_w, int dst_
extern void GR_StoreFrameBuffer(int x, int y, int w, int h);
extern void GR_UpdateVRAM();
extern void GR_ReadFramebufferDataToVRAM();
extern TextureID GR_CreateRGBATexture(int width, int height, u_char* data /*= nullptr*/);
extern ShaderID GR_Shader_Compile(const char* source);

View File

@ -41,6 +41,7 @@ int DrawSync(int mode)
{
// Update VRAM seems needed to be here
GR_UpdateVRAM();
GR_ReadFramebufferDataToVRAM();
if (g_splitIndex > 0) // don't do flips if nothing to draw.
{
@ -65,7 +66,6 @@ int LoadImagePSX(RECT16* rect, u_long* p)
int LoadImage(RECT16* rect, u_long* p)
{
LoadImagePSX(rect, p);
return 0;
}
@ -73,7 +73,9 @@ int LoadImage2(RECT16* rect, u_long* p)
{
LoadImagePSX(rect, p);
// TODO: should I simulate immediate mode and wait for vsync?
// simulate immediate mode
GR_UpdateVRAM();
GR_ReadFramebufferDataToVRAM();
return 0;
}

View File

@ -1328,7 +1328,28 @@ void GR_DestroyTexture(TextureID texture)
void GR_Clear(int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned char b)
{
// TODO clear rect if it's necessary
vram_need_update = 1;
framebuffer_need_update = 1;
u_short* dst = vram + x + y * VRAM_WIDTH;
if (x+w > VRAM_WIDTH)
w = VRAM_WIDTH - x;
if (y+h > VRAM_HEIGHT)
h = VRAM_HEIGHT-y;
// clear VRAM region with given color
for (int i = 0; i < h; i++)
{
u_short* tmp = dst;
for (int j = 0; j < w; j++)
*tmp++ = r | (g << 5) | (b << 11);
dst += VRAM_WIDTH;
}
#if defined(USE_OPENGL)
glClearColor(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@ -1561,12 +1582,9 @@ void GR_StoreFrameBuffer(int x, int y, int w, int h)
{
#if defined(USE_OPENGL)
// set storage size first
if (g_PreviousFramebuffer.w != w &&
if (g_PreviousFramebuffer.w != w ||
g_PreviousFramebuffer.h != h)
{
//PBO_Destroy(g_glFBPBO);
//PBO_Init(g_glFBPBO, GL_RGBA, w, h, 1);
glBindTexture(GL_TEXTURE_2D, g_fbTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);