run clang format

This commit is contained in:
olebeck 2025-06-28 03:39:00 +02:00
parent 4744142c9d
commit 7c15d4f9d8
5 changed files with 616 additions and 525 deletions

View File

@ -102,7 +102,7 @@ jobs:
- name: Configure (CMake)
run: |
if [ "${{ matrix.vita }}" = "true" ]; then
PRESET=--preset vita-debug
PRESET="--preset vita-debug"
fi
${{ matrix.cmake-wrapper || '' }} cmake $PRESET -S . -B build -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \

View File

@ -1,15 +1,13 @@
#include "memory.h"
#include "utils.h"
#include <psp2/gxm.h>
#include <SDL3/SDL_stdinc.h>
#include <psp2/gxm.h>
static SceUID cdramPoolUID = -1;
static SceClibMspace cdramPool = NULL;
void* patcher_host_alloc(void* user_data, unsigned int size)
{
void* mem = SDL_malloc(size);
@ -23,20 +21,17 @@ void patcher_host_free(void *user_data, void *mem)
SDL_free(mem);
}
void* vita_mem_alloc(
unsigned int type,
size_t size,
size_t alignment,
int attribs,
SceUID *uid
) {
void* vita_mem_alloc(unsigned int type, size_t size, size_t alignment, int attribs, SceUID* uid)
{
void* mem;
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
size = ALIGN(size, 256 * 1024);
} else if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW) {
}
else if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_MAIN_PHYCONT_NC_RW) {
size = ALIGN(size, 1024 * 1024);
} else {
}
else {
size = ALIGN(size, 4 * 1024);
}
@ -123,7 +118,8 @@ void vita_mem_fragment_usse_free(SceUID uid)
sceKernelFreeMemBlock(uid);
}
bool cdramPool_init() {
bool cdramPool_init()
{
if (cdramPool) {
return true;
}
@ -153,13 +149,18 @@ bool cdramPool_init() {
if (!cdramPool) {
return false;
}
ret = sceGxmMapMemory(mem, poolsize, (SceGxmMemoryAttribFlags)(SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE));
ret = sceGxmMapMemory(
mem,
poolsize,
(SceGxmMemoryAttribFlags) (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE)
);
if (ret < 0) {
return false;
}
return true;
}
SceClibMspace cdramPool_get() {
SceClibMspace cdramPool_get()
{
return cdramPool;
}

View File

@ -1,20 +1,14 @@
#pragma once
#include <psp2/types.h>
#include <psp2/kernel/sysmem.h>
#include <psp2/kernel/clib.h>
#include <SDL3/SDL_stdinc.h>
#include <psp2/kernel/clib.h>
#include <psp2/kernel/sysmem.h>
#include <psp2/types.h>
void* patcher_host_alloc(void* user_data, unsigned int size);
void patcher_host_free(void* user_data, void* mem);
void* vita_mem_alloc(
unsigned int type,
size_t size,
size_t alignment,
int attribs,
SceUID* uid
);
void* vita_mem_alloc(unsigned int type, size_t size, size_t alignment, int attribs, SceUID* uid);
void vita_mem_free(SceUID uid);
void* vita_mem_vertex_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset);

View File

@ -1,17 +1,15 @@
#include "d3drmrenderer_gxm.h"
#include "memory.h"
#include "meshutils.h"
#include "utils.h"
#include <SDL3/SDL.h>
#include <algorithm>
#include <string>
#include <psp2/gxm.h>
#include <psp2/display.h>
#include <psp2/types.h>
#include <psp2/gxm.h>
#include <psp2/kernel/modulemgr.h>
#include "utils.h"
#include "memory.h"
#include <psp2/types.h>
#include <string>
#define INCBIN_PREFIX _inc_
#include "incbin.h"
@ -25,8 +23,6 @@ bool with_razor = false;
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
INCBIN(main_vert_gxp, "shaders/main.vert.gxp");
INCBIN(main_frag_gxp, "shaders/main.frag.gxp");
INCBIN(color_frag_gxp, "shaders/color.frag.gxp");
@ -63,7 +59,8 @@ extern "C" int sceRazorGpuCaptureSetTriggerNextFrame(const char* path);
static GXMRendererContext gxm_renderer_context;
static void display_callback(const void *callback_data) {
static void display_callback(const void* callback_data)
{
const GXMDisplayData* display_data = (const GXMDisplayData*) callback_data;
SceDisplayFrameBuf framebuf;
@ -78,7 +75,8 @@ static void display_callback(const void *callback_data) {
sceDisplayWaitSetFrameBuf();
}
static void load_razor() {
static void load_razor()
{
int mod_id = _sceKernelLoadModule("app0:librazorcapture_es4.suprx", 0, nullptr);
int status;
if (!SCE_ERR(sceKernelStartModule, mod_id, 0, nullptr, 0, nullptr, &status)) {
@ -91,7 +89,8 @@ static void load_razor() {
}
bool gxm_initialized = false;
bool gxm_init() {
bool gxm_init()
{
if (gxm_initialized) {
return true;
}
@ -116,7 +115,8 @@ bool gxm_init() {
return cdramPool_init();
}
static bool create_gxm_context() {
static bool create_gxm_context()
{
GXMRendererContext* data = &gxm_renderer_context;
if (data->context) {
return true;
@ -164,7 +164,8 @@ static bool create_gxm_context() {
data->fragmentUsseRingBuffer = vita_mem_fragment_usse_alloc(
SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE,
&data->fragmentUsseRingBufferUid,
&data->fragmentUsseRingBufferOffset);
&data->fragmentUsseRingBufferOffset
);
// create context
SceGxmContextParams contextParams;
@ -195,15 +196,14 @@ static bool create_gxm_context() {
&data->patcherBufferUid
);
data->patcherVertexUsse = vita_mem_vertex_usse_alloc(
patcherVertexUsseSize,
&data->patcherVertexUsseUid,
&data->patcherVertexUsseOffset);
data->patcherVertexUsse =
vita_mem_vertex_usse_alloc(patcherVertexUsseSize, &data->patcherVertexUsseUid, &data->patcherVertexUsseOffset);
data->patcherFragmentUsse = vita_mem_fragment_usse_alloc(
patcherFragmentUsseSize,
&data->patcherFragmentUsseUid,
&data->patcherFragmentUsseOffset);
&data->patcherFragmentUsseOffset
);
SceGxmShaderPatcherParams patcherParams;
memset(&patcherParams, 0, sizeof(SceGxmShaderPatcherParams));
@ -231,7 +231,8 @@ static bool create_gxm_context() {
return true;
}
static void destroy_gxm_context() {
static void destroy_gxm_context()
{
sceGxmShaderPatcherDestroy(gxm_renderer_context.shaderPatcher);
sceGxmDestroyContext(gxm_renderer_context.context);
vita_mem_fragment_usse_free(gxm_renderer_context.fragmentUsseRingBufferUid);
@ -241,7 +242,8 @@ static void destroy_gxm_context() {
SDL_free(gxm_renderer_context.contextHostMem);
}
bool get_gxm_context(SceGxmContext** context, SceGxmShaderPatcher** shaderPatcher, SceClibMspace* cdramPool) {
bool get_gxm_context(SceGxmContext** context, SceGxmShaderPatcher** shaderPatcher, SceClibMspace* cdramPool)
{
if (!create_gxm_context()) {
return false;
}
@ -292,7 +294,8 @@ Direct3DRMRenderer* GXMRenderer::Create(DWORD width, DWORD height)
return new GXMRenderer(width, height);
}
GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
GXMRenderer::GXMRenderer(DWORD width, DWORD height)
{
m_width = VITA_GXM_SCREEN_WIDTH;
m_height = VITA_GXM_SCREEN_HEIGHT;
m_virtualWidth = width;
@ -303,7 +306,9 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
const unsigned int sampleCount = alignedWidth * alignedHeight;
const unsigned int depthStrideInSamples = alignedWidth;
if(!get_gxm_context(&this->context, &this->shaderPatcher, &this->cdramPool)) return;
if (!get_gxm_context(&this->context, &this->shaderPatcher, &this->cdramPool)) {
return;
}
// render target
SceGxmRenderTargetParams renderTargetParams;
@ -315,7 +320,9 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
renderTargetParams.multisampleMode = 0;
renderTargetParams.multisampleLocations = 0;
renderTargetParams.driverMemBlock = -1; // Invalid UID
if(SCE_ERR(sceGxmCreateRenderTarget, &renderTargetParams, &this->renderTarget)) return;
if (SCE_ERR(sceGxmCreateRenderTarget, &renderTargetParams, &this->renderTarget)) {
return;
}
for (int i = 0; i < VITA_GXM_DISPLAY_BUFFER_COUNT; i++) {
this->displayBuffers[i] = vita_mem_alloc(
@ -326,20 +333,25 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
&this->displayBuffersUid[i]
);
if(SCE_ERR(sceGxmColorSurfaceInit,
if (SCE_ERR(
sceGxmColorSurfaceInit,
&this->displayBuffersSurface[i],
SCE_GXM_COLOR_FORMAT_A8B8G8R8,
SCE_GXM_COLOR_SURFACE_LINEAR,
SCE_GXM_COLOR_SURFACE_SCALE_NONE,
SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
m_width, m_height,
m_width,
m_height,
m_width,
this->displayBuffers[i]
)) return;
if(SCE_ERR(sceGxmSyncObjectCreate, &this->displayBuffersSync[i])) return;
)) {
return;
}
if (SCE_ERR(sceGxmSyncObjectCreate, &this->displayBuffersSync[i])) {
return;
}
}
// depth & stencil
this->depthBufferData = vita_mem_alloc(
@ -358,21 +370,51 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
&this->stencilBufferUid
);
if(SCE_ERR(sceGxmDepthStencilSurfaceInit,
if (SCE_ERR(
sceGxmDepthStencilSurfaceInit,
&this->depthSurface,
SCE_GXM_DEPTH_STENCIL_FORMAT_S8D24,
SCE_GXM_DEPTH_STENCIL_SURFACE_TILED,
depthStrideInSamples,
this->depthBufferData,
this->stencilBufferData
)) return;
)) {
return;
}
// register shader programs
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, colorFragmentProgramGxp, &this->colorFragmentProgramId)) return;
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, mainVertexProgramGxp, &this->mainVertexProgramId)) return;
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, mainFragmentProgramGxp, &this->mainFragmentProgramId)) return;
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, imageFragmentProgramGxp, &this->imageFragmentProgramId)) return;
if (SCE_ERR(
sceGxmShaderPatcherRegisterProgram,
this->shaderPatcher,
colorFragmentProgramGxp,
&this->colorFragmentProgramId
)) {
return;
}
if (SCE_ERR(
sceGxmShaderPatcherRegisterProgram,
this->shaderPatcher,
mainVertexProgramGxp,
&this->mainVertexProgramId
)) {
return;
}
if (SCE_ERR(
sceGxmShaderPatcherRegisterProgram,
this->shaderPatcher,
mainFragmentProgramGxp,
&this->mainFragmentProgramId
)) {
return;
}
if (SCE_ERR(
sceGxmShaderPatcherRegisterProgram,
this->shaderPatcher,
imageFragmentProgramGxp,
&this->imageFragmentProgramId
)) {
return;
}
// main shader
{
@ -406,17 +448,23 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
vertexStreams[0].stride = sizeof(Vertex);
vertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
if(SCE_ERR(sceGxmShaderPatcherCreateVertexProgram,
if (SCE_ERR(
sceGxmShaderPatcherCreateVertexProgram,
this->shaderPatcher,
this->mainVertexProgramId,
vertexAttributes, 3,
vertexStreams, 1,
vertexAttributes,
3,
vertexStreams,
1,
&this->mainVertexProgram
)) return;
)) {
return;
}
}
// main opaque
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
if (SCE_ERR(
sceGxmShaderPatcherCreateFragmentProgram,
this->shaderPatcher,
this->mainFragmentProgramId,
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
@ -424,10 +472,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
&blendInfoOpaque,
mainVertexProgramGxp,
&this->opaqueFragmentProgram
)) return;
)) {
return;
}
// main transparent
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
if (SCE_ERR(
sceGxmShaderPatcherCreateFragmentProgram,
this->shaderPatcher,
this->mainFragmentProgramId,
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
@ -435,10 +486,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
&blendInfoTransparent,
mainVertexProgramGxp,
&this->transparentFragmentProgram
)) return;
)) {
return;
}
// image
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
if (SCE_ERR(
sceGxmShaderPatcherCreateFragmentProgram,
this->shaderPatcher,
this->imageFragmentProgramId,
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
@ -446,10 +500,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
&blendInfoTransparent,
mainVertexProgramGxp,
&this->imageFragmentProgram
)) return;
)) {
return;
}
// color
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
if (SCE_ERR(
sceGxmShaderPatcherCreateFragmentProgram,
this->shaderPatcher,
this->colorFragmentProgramId,
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
@ -457,7 +514,9 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
NULL,
mainVertexProgramGxp,
&this->colorFragmentProgram
)) return;
)) {
return;
}
// vertex uniforms
this->uModelViewMatrix = sceGxmProgramFindParameterByName(mainVertexProgramGxp, "uModelViewMatrix");
@ -495,7 +554,8 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
m_initialized = true;
}
GXMRenderer::~GXMRenderer() {
GXMRenderer::~GXMRenderer()
{
if (!m_initialized) {
return;
}
@ -547,7 +607,15 @@ void GXMRenderer::AddTextureDestroyCallback(Uint32 id, IDirect3DRMTexture* textu
);
}
static void convertTextureMetadata(SDL_Surface* surface, bool* supportedFormat, SceGxmTextureFormat* textureFormat, size_t* textureSize, size_t* textureAlignment, size_t* textureStride) {
static void convertTextureMetadata(
SDL_Surface* surface,
bool* supportedFormat,
SceGxmTextureFormat* textureFormat,
size_t* textureSize,
size_t* textureAlignment,
size_t* textureStride
)
{
*supportedFormat = true;
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
switch (surface->format) {
@ -574,7 +642,8 @@ static void convertTextureMetadata(SDL_Surface* surface, bool* supportedFormat,
}
}
void copySurfaceTo(SDL_Surface* src, void* dstData, size_t textureStride) {
void copySurfaceTo(SDL_Surface* src, void* dstData, size_t textureStride)
{
SDL_Surface* dst = SDL_CreateSurfaceFrom(src->w, src->h, SDL_PIXELFORMAT_ABGR8888, dstData, textureStride);
SDL_BlitSurface(src, nullptr, dst, nullptr);
SDL_DestroySurface(dst);
@ -585,7 +654,6 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
bool supportedFormat;
size_t textureSize;
size_t textureAlignment;
@ -594,7 +662,14 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
int textureWidth = surface->m_surface->w;
int textureHeight = surface->m_surface->h;
convertTextureMetadata(surface->m_surface, &supportedFormat, &textureFormat, &textureSize, &textureAlignment, &textureStride);
convertTextureMetadata(
surface->m_surface,
&supportedFormat,
&textureFormat,
&textureSize,
&textureAlignment,
&textureStride
);
if (!supportedFormat) {
textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
@ -610,7 +685,8 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
void* textureData = sceGxmTextureGetData(&tex.gxmTexture);
if (!supportedFormat) {
copySurfaceTo(surface->m_surface, textureData, textureStride);
} else {
}
else {
memcpy(textureData, surface->m_surface->pixels, textureSize);
}
tex.version = texture->m_version;
@ -619,19 +695,26 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
}
}
SDL_Log("Create Texture %s w=%d h=%d s=%d",
SDL_GetPixelFormatName(surface->m_surface->format), textureWidth, textureHeight, textureStride);
SDL_Log(
"Create Texture %s w=%d h=%d s=%d",
SDL_GetPixelFormatName(surface->m_surface->format),
textureWidth,
textureHeight,
textureStride
);
// allocate gpu memory
void* textureData = sceClibMspaceMemalign(this->cdramPool, textureAlignment, textureSize);
uint8_t* paletteData = nullptr;
if (!supportedFormat) {
SDL_Log("unsupported SDL texture format %s, falling back on SDL_PIXELFORMAT_ABGR8888", SDL_GetPixelFormatName(surface->m_surface->format));
SDL_Log(
"unsupported SDL texture format %s, falling back on SDL_PIXELFORMAT_ABGR8888",
SDL_GetPixelFormatName(surface->m_surface->format)
);
copySurfaceTo(surface->m_surface, textureData, textureStride);
}
else if(surface->m_surface->format == SDL_PIXELFORMAT_INDEX8)
{
else if (surface->m_surface->format == SDL_PIXELFORMAT_INDEX8) {
LPDIRECTDRAWPALETTE _palette;
surface->GetPalette(&_palette);
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
@ -644,14 +727,21 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
paletteData = (uint8_t*) textureData + pixelsSize + alignBytes;
memcpy(paletteData, palette->m_palette->colors, palette->m_palette->ncolors * sizeof(SDL_Color));
}
else
{
else {
SDL_Log("copying texture data from=%p to=%p", surface->m_surface->pixels, textureData);
memcpy(textureData, surface->m_surface->pixels, textureSize);
}
SceGxmTexture gxmTexture;
SCE_ERR(sceGxmTextureInitLinearStrided, &gxmTexture, textureData, textureFormat, textureWidth, textureHeight, textureStride);
SCE_ERR(
sceGxmTextureInitLinearStrided,
&gxmTexture,
textureData,
textureFormat,
textureWidth,
textureHeight,
textureStride
);
// sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
if (paletteData) {
@ -713,17 +803,20 @@ GXMMeshCacheEntry GXMRenderer::GXMUploadMesh(const MeshGroup& meshGroup)
for (int i = 0; i < vertices.size(); i++) {
D3DRMVERTEX vertex = vertices.data()[i];
vertexBuffer[i] = Vertex{
.position = {
.position =
{
vertex.position.x,
vertex.position.y,
vertex.position.z,
},
.normal = {
.normal =
{
vertex.normal.x,
vertex.normal.y,
vertex.normal.z,
},
.texCoord = {
.texCoord =
{
vertex.tu,
vertex.tv,
}
@ -801,15 +894,18 @@ void GXMRenderer::GetDesc(D3DDEVICEDESC* halDesc, D3DDEVICEDESC* helDesc)
memset(helDesc, 0, sizeof(D3DDEVICEDESC));
}
const char* GXMRenderer::GetName() {
const char* GXMRenderer::GetName()
{
return "GXM";
}
bool razor_triggered = false;
void GXMRenderer::StartScene() {
if(sceneStarted) return;
void GXMRenderer::StartScene()
{
if (sceneStarted) {
return;
}
sceGxmBeginScene(
this->context,
0,
@ -827,7 +923,8 @@ void GXMRenderer::StartScene() {
this->activeUniformBuffer = (this->activeUniformBuffer + 1) % VITA_GXM_UNIFORM_BUFFER_COUNT;
sceGxmNotificationWait(&this->fragmentNotifications[this->activeUniformBuffer]);
//sceClibPrintf("this->activeUniformBuffer: %d notification: %d\n", this->activeUniformBuffer, this->fragmentNotifications[this->activeUniformBuffer].value);
// sceClibPrintf("this->activeUniformBuffer: %d notification: %d\n", this->activeUniformBuffer,
// this->fragmentNotifications[this->activeUniformBuffer].value);
}
int frames = 0;
@ -869,15 +966,19 @@ HRESULT GXMRenderer::BeginFrame()
return DD_OK;
}
void GXMRenderer::EnableTransparency() {
void GXMRenderer::EnableTransparency()
{
this->transparencyEnabled = true;
}
static void transpose4x4(const float src[4][4], float dst[4][4]) {
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 4; ++j)
static void transpose4x4(const float src[4][4], float dst[4][4])
{
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
dst[j][i] = src[i][j];
}
}
}
static const D3DRMMATRIX4D identity4x4 = {
{1.0, 0.0, 0.0, 0.0},
@ -892,7 +993,6 @@ static const Matrix3x3 identity3x3 = {
{0.0, 0.0, 1.0},
};
void GXMRenderer::SubmitDraw(
DWORD meshId,
const D3DRMMATRIX4D& modelViewMatrix,
@ -900,7 +1000,8 @@ void GXMRenderer::SubmitDraw(
const D3DRMMATRIX4D& viewMatrix,
const Matrix3x3& normalMatrix,
const Appearance& appearance
) {
)
{
auto& mesh = m_meshes[meshId];
char marker[256];
@ -910,7 +1011,8 @@ void GXMRenderer::SubmitDraw(
sceGxmSetVertexProgram(this->context, this->mainVertexProgram);
if (this->transparencyEnabled) {
sceGxmSetFragmentProgram(this->context, this->transparentFragmentProgram);
} else {
}
else {
sceGxmSetFragmentProgram(this->context, this->opaqueFragmentProgram);
}
@ -940,29 +1042,26 @@ void GXMRenderer::SubmitDraw(
}
sceGxmSetVertexStream(this->context, 0, mesh.vertexBuffer);
sceGxmDraw(
this->context,
SCE_GXM_PRIMITIVE_TRIANGLES,
SCE_GXM_INDEX_FORMAT_U16,
mesh.indexBuffer,
mesh.indexCount
);
sceGxmDraw(this->context, SCE_GXM_PRIMITIVE_TRIANGLES, SCE_GXM_INDEX_FORMAT_U16, mesh.indexBuffer, mesh.indexCount);
sceGxmPopUserMarker(this->context);
}
HRESULT GXMRenderer::FinalizeFrame() {
HRESULT GXMRenderer::FinalizeFrame()
{
return DD_OK;
}
void GXMRenderer::Resize(int width, int height, const ViewportTransform& viewportTransform) {
void GXMRenderer::Resize(int width, int height, const ViewportTransform& viewportTransform)
{
m_width = width;
m_height = height;
m_viewportTransform = viewportTransform;
SDL_Log("GXMRenderer::Resize TODO");
}
void GXMRenderer::Clear(float r, float g, float b) {
void GXMRenderer::Clear(float r, float g, float b)
{
this->StartScene();
char marker[256];
@ -1001,17 +1100,13 @@ void GXMRenderer::Clear(float r, float g, float b) {
quadVertices[3] = Vertex{.position = {x2, y2, -1.0}, .normal = {0, 0, 0}, .texCoord = {0, 0}};
sceGxmSetVertexStream(this->context, 0, quadVertices);
sceGxmDraw(
this->context,
SCE_GXM_PRIMITIVE_TRIANGLE_STRIP,
SCE_GXM_INDEX_FORMAT_U16,
this->quadIndices, 4
);
sceGxmDraw(this->context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, this->quadIndices, 4);
sceGxmPopUserMarker(this->context);
}
void GXMRenderer::Flip() {
void GXMRenderer::Flip()
{
if (!this->sceneStarted) {
this->Clear(0, 0, 0);
}
@ -1023,7 +1118,8 @@ void GXMRenderer::Flip() {
this->context,
nullptr, //&this->vertexNotifications[this->activeUniformBuffer],
// nullptr
&this->fragmentNotifications[this->activeUniformBuffer] // wait for fragment processing to finish for this buffer, otherwise lighting corrupts
&this->fragmentNotifications[this->activeUniformBuffer] // wait for fragment processing to finish for this
// buffer, otherwise lighting corrupts
);
sceGxmPadHeartbeat(
&this->displayBuffersSurface[this->backBufferIndex],
@ -1045,7 +1141,8 @@ void GXMRenderer::Flip() {
this->backBufferIndex = (this->backBufferIndex + 1) % VITA_GXM_DISPLAY_BUFFER_COUNT;
}
void GXMRenderer::Draw2DImage(Uint32 textureId, const SDL_Rect& srcRect, const SDL_Rect& dstRect) {
void GXMRenderer::Draw2DImage(Uint32 textureId, const SDL_Rect& srcRect, const SDL_Rect& dstRect)
{
this->StartScene();
char marker[256];
@ -1113,17 +1210,13 @@ void GXMRenderer::Draw2DImage(Uint32 textureId, const SDL_Rect& srcRect, const S
sceGxmSetVertexStream(this->context, 0, quadVertices);
sceGxmSetFrontDepthWriteEnable(this->context, SCE_GXM_DEPTH_WRITE_DISABLED);
sceGxmDraw(
this->context,
SCE_GXM_PRIMITIVE_TRIANGLE_STRIP,
SCE_GXM_INDEX_FORMAT_U16,
this->quadIndices, 4
);
sceGxmDraw(this->context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, this->quadIndices, 4);
sceGxmSetFrontDepthWriteEnable(this->context, SCE_GXM_DEPTH_WRITE_ENABLED);
sceGxmPopUserMarker(this->context);
}
void GXMRenderer::Download(SDL_Surface* target) {
void GXMRenderer::Download(SDL_Surface* target)
{
SDL_Rect srcRect = {
static_cast<int>(m_viewportTransform.offsetX),
static_cast<int>(m_viewportTransform.offsetY),
@ -1131,9 +1224,11 @@ void GXMRenderer::Download(SDL_Surface* target) {
static_cast<int>(target->h * m_viewportTransform.scale),
};
SDL_Surface* src = SDL_CreateSurfaceFrom(
this->m_width, this->m_height,
this->m_width,
this->m_height,
SDL_PIXELFORMAT_RGBA32,
this->displayBuffers[this->frontBufferIndex], VITA_GXM_SCREEN_STRIDE
this->displayBuffers[this->frontBufferIndex],
VITA_GXM_SCREEN_STRIDE
);
SDL_BlitSurfaceScaled(src, &srcRect, target, nullptr, SDL_SCALEMODE_NEAREST);
SDL_DestroySurface(src);

View File

@ -4,7 +4,8 @@
#include <psp2/gxm.h>
#include <psp2/kernel/clib.h>
#define SCE_ERR(func, ...) ({ \
#define SCE_ERR(func, ...) \
({ \
sceClibPrintf(#func "\n"); \
int __sce_err_ret_val = func(__VA_ARGS__); \
if (__sce_err_ret_val < 0) { \
@ -17,7 +18,6 @@
#define ALIGNMENT(n, a) (((a) - ((n) % (a))) % (a))
#define SET_UNIFORM(buffer, param, value) \
do { \
size_t __offset = sceGxmProgramParameterGetResourceIndex(param); \
@ -32,7 +32,8 @@
return ret; \
}
static void printMatrix4x4(const float mat[4][4]) {
static void printMatrix4x4(const float mat[4][4])
{
sceClibPrintf("mat4{\n");
for (int i = 0; i < 4; i++) {
sceClibPrintf("%f %f %f %f\n", mat[i][0], mat[i][1], mat[i][2], mat[i][3]);