Add getStaticVramBuffer getStaticVramTexture

This commit is contained in:
Wouter Wijsman
2024-07-12 13:22:13 +02:00
parent 5f8da2bec6
commit cf3894d3e5
3 changed files with 89 additions and 1 deletions

View File

@@ -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

View File

@@ -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)

52
src/gu/vram.c Normal file
View File

@@ -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 <pspge.h>
#include <pspgu.h>
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()));
}