From cf3894d3e5ece3ff95e8bd7d2c6d0cf0e39b03c4 Mon Sep 17 00:00:00 2001 From: Wouter Wijsman Date: Fri, 12 Jul 2024 13:22:13 +0200 Subject: [PATCH] Add getStaticVramBuffer getStaticVramTexture --- src/gu/Makefile.am | 2 +- src/gu/pspgu.h | 36 ++++++++++++++++++++++++++++++++ src/gu/vram.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/gu/vram.c diff --git a/src/gu/Makefile.am b/src/gu/Makefile.am index d0f3484b..7e7b257e 100644 --- a/src/gu/Makefile.am +++ b/src/gu/Makefile.am @@ -31,5 +31,5 @@ libpspgu_a_SOURCES = callbackFin.c callbackSig.c guInternal.c resetValues.c sceG sceGuSignal.c sceGuSpecular.c sceGuStart.c sceGuStencilFunc.c sceGuStencilOp.c \ sceGuSwapBuffers.c sceGuSync.c sceGuTerm.c sceGuTexEnvColor.c sceGuTexFilter.c sceGuTexFlush.c sceGuTexFunc.c \ sceGuTexImage.c sceGuTexLevelMode.c sceGuTexMapMode.c sceGuTexMode.c sceGuTexOffset.c sceGuTexProjMapMode.c \ - sceGuTexScale.c sceGuTexSlope.c sceGuTexSync.c sceGuTexWrap.c sceGuViewport.c + sceGuTexScale.c sceGuTexSlope.c sceGuTexSync.c sceGuTexWrap.c sceGuViewport.c vram.c diff --git a/src/gu/pspgu.h b/src/gu/pspgu.h index d479b08f..530f1a83 100644 --- a/src/gu/pspgu.h +++ b/src/gu/pspgu.h @@ -1501,6 +1501,42 @@ void guSwapBuffersBehaviour(int behaviour); **/ void guSwapBuffersCallback(GuSwapBuffersCallback callback); +/** + * Allocate a draw buffer in vram + * + * Available pixel formats are: + * - GU_PSM_5650 - Hicolor, 16-bit + * - GU_PSM_5551 - Hicolor, 16-bit + * - GU_PSM_4444 - Hicolor, 16-bit + * - GU_PSM_8888 - Truecolor, 32-bit + * + * @param width - Width of the buffer, usually 512 (must be a power of 2) + * @param height - Height of the buffer, normally the height of the screen 272 (must be a power of 2) + * @param psm - Which pixel format to use + * + * @return A pointer to the buffer's relative to vram start (as required by sceGuDispBuffer, sceGuDrawBuffer, sceGuDepthBuffer and sceGuDrawBufferList) +**/ +void* getStaticVramBuffer(unsigned int width, unsigned int height, unsigned int psm); + +/** + * Allocate a texture buffer in vram + * + * Available texture-formats are: + * - GU_PSM_5650 - Hicolor, 16-bit + * - GU_PSM_5551 - Hicolor, 16-bit + * - GU_PSM_4444 - Hicolor, 16-bit + * - GU_PSM_8888 - Truecolor, 32-bit + * - GU_PSM_T4 - Indexed, 4-bit (2 pixels per byte) + * - GU_PSM_T8 - Indexed, 8-bit + * + * @param width - Width of the buffer (must be a power of 2) + * @param height - Height of the buffer (must be a power of 2) + * @param psm - Which pixel format to use + * + * @return A pointer to the buffer +**/ +void* getStaticVramTexture(unsigned int width, unsigned int height, unsigned int psm); + /**@}*/ #if defined(__cplusplus) diff --git a/src/gu/vram.c b/src/gu/vram.c new file mode 100644 index 00000000..020d5d04 --- /dev/null +++ b/src/gu/vram.c @@ -0,0 +1,52 @@ +/* + * PSP Software Development Kit - https://github.com/pspdev + * ----------------------------------------------------------------------- + * Licensed under the BSD license, see LICENSE in PSPSDK root for details. + * + * Copyright (c) 2010 Dan Peori + */ + +#include +#include + +static unsigned int staticOffset = 0; + +static unsigned int getMemorySize(unsigned int width, unsigned int height, unsigned int psm) +{ + switch (psm) + { + case GU_PSM_T4: + return (width * height) >> 1; + + case GU_PSM_T8: + return width * height; + + case GU_PSM_5650: + case GU_PSM_5551: + case GU_PSM_4444: + case GU_PSM_T16: + return 2 * width * height; + + case GU_PSM_8888: + case GU_PSM_T32: + return 4 * width * height; + + default: + return 0; + } +} + +void* getStaticVramBuffer(unsigned int width, unsigned int height, unsigned int psm) +{ + unsigned int memSize = getMemorySize(width,height,psm); + void* result = (void*)staticOffset; + staticOffset += memSize; + + return result; +} + +void* getStaticVramTexture(unsigned int width, unsigned int height, unsigned int psm) +{ + void* result = getStaticVramBuffer(width,height,psm); + return (void*)(((unsigned int)result) + ((unsigned int)sceGeEdramGetAddr())); +}