mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-20 22:21:15 +00:00
run clang format
This commit is contained in:
parent
4744142c9d
commit
7c15d4f9d8
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -102,7 +102,7 @@ jobs:
|
|||||||
- name: Configure (CMake)
|
- name: Configure (CMake)
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ matrix.vita }}" = "true" ]; then
|
if [ "${{ matrix.vita }}" = "true" ]; then
|
||||||
PRESET=--preset vita-debug
|
PRESET="--preset vita-debug"
|
||||||
fi
|
fi
|
||||||
${{ matrix.cmake-wrapper || '' }} cmake $PRESET -S . -B build -GNinja \
|
${{ matrix.cmake-wrapper || '' }} cmake $PRESET -S . -B build -GNinja \
|
||||||
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
|
-DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \
|
||||||
|
|||||||
@ -1,42 +1,37 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <psp2/gxm.h>
|
|
||||||
|
|
||||||
#include <SDL3/SDL_stdinc.h>
|
#include <SDL3/SDL_stdinc.h>
|
||||||
|
#include <psp2/gxm.h>
|
||||||
|
|
||||||
static SceUID cdramPoolUID = -1;
|
static SceUID cdramPoolUID = -1;
|
||||||
static SceClibMspace cdramPool = NULL;
|
static SceClibMspace cdramPool = NULL;
|
||||||
|
|
||||||
|
void* patcher_host_alloc(void* user_data, unsigned int size)
|
||||||
void *patcher_host_alloc(void *user_data, unsigned int size)
|
|
||||||
{
|
{
|
||||||
void *mem = SDL_malloc(size);
|
void* mem = SDL_malloc(size);
|
||||||
(void)user_data;
|
(void) user_data;
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void patcher_host_free(void *user_data, void *mem)
|
void patcher_host_free(void* user_data, void* mem)
|
||||||
{
|
{
|
||||||
(void)user_data;
|
(void) user_data;
|
||||||
SDL_free(mem);
|
SDL_free(mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* vita_mem_alloc(
|
void* vita_mem_alloc(unsigned int type, size_t size, size_t alignment, int attribs, SceUID* uid)
|
||||||
unsigned int type,
|
{
|
||||||
size_t size,
|
void* mem;
|
||||||
size_t alignment,
|
|
||||||
int attribs,
|
|
||||||
SceUID *uid
|
|
||||||
) {
|
|
||||||
void *mem;
|
|
||||||
|
|
||||||
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
|
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
|
||||||
size = ALIGN(size, 256 * 1024);
|
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);
|
size = ALIGN(size, 1024 * 1024);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
size = ALIGN(size, 4 * 1024);
|
size = ALIGN(size, 4 * 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +46,7 @@ void* vita_mem_alloc(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sceGxmMapMemory(mem, size, (SceGxmMemoryAttribFlags)attribs) < 0) {
|
if (sceGxmMapMemory(mem, size, (SceGxmMemoryAttribFlags) attribs) < 0) {
|
||||||
SDL_Log("sceGxmMapMemory 0x%x 0x%x %d failed", mem, size, attribs);
|
SDL_Log("sceGxmMapMemory 0x%x 0x%x %d failed", mem, size, attribs);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -61,7 +56,7 @@ void* vita_mem_alloc(
|
|||||||
|
|
||||||
void vita_mem_free(SceUID uid)
|
void vita_mem_free(SceUID uid)
|
||||||
{
|
{
|
||||||
void *mem = NULL;
|
void* mem = NULL;
|
||||||
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
|
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -69,9 +64,9 @@ void vita_mem_free(SceUID uid)
|
|||||||
sceKernelFreeMemBlock(uid);
|
sceKernelFreeMemBlock(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
|
void* vita_mem_vertex_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset)
|
||||||
{
|
{
|
||||||
void *mem = NULL;
|
void* mem = NULL;
|
||||||
|
|
||||||
size = ALIGN(size, 4096);
|
size = ALIGN(size, 4096);
|
||||||
*uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
|
*uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
|
||||||
@ -88,7 +83,7 @@ void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *u
|
|||||||
|
|
||||||
void vita_mem_vertex_usse_free(SceUID uid)
|
void vita_mem_vertex_usse_free(SceUID uid)
|
||||||
{
|
{
|
||||||
void *mem = NULL;
|
void* mem = NULL;
|
||||||
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
|
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -96,9 +91,9 @@ void vita_mem_vertex_usse_free(SceUID uid)
|
|||||||
sceKernelFreeMemBlock(uid);
|
sceKernelFreeMemBlock(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
|
void* vita_mem_fragment_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset)
|
||||||
{
|
{
|
||||||
void *mem = NULL;
|
void* mem = NULL;
|
||||||
|
|
||||||
size = ALIGN(size, 4096);
|
size = ALIGN(size, 4096);
|
||||||
*uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
|
*uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
|
||||||
@ -115,7 +110,7 @@ void *vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int
|
|||||||
|
|
||||||
void vita_mem_fragment_usse_free(SceUID uid)
|
void vita_mem_fragment_usse_free(SceUID uid)
|
||||||
{
|
{
|
||||||
void *mem = NULL;
|
void* mem = NULL;
|
||||||
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
|
if (sceKernelGetMemBlockBase(uid, &mem) < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -123,8 +118,9 @@ void vita_mem_fragment_usse_free(SceUID uid)
|
|||||||
sceKernelFreeMemBlock(uid);
|
sceKernelFreeMemBlock(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cdramPool_init() {
|
bool cdramPool_init()
|
||||||
if(cdramPool) {
|
{
|
||||||
|
if (cdramPool) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int poolsize;
|
int poolsize;
|
||||||
@ -153,13 +149,18 @@ bool cdramPool_init() {
|
|||||||
if (!cdramPool) {
|
if (!cdramPool) {
|
||||||
return false;
|
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) {
|
if (ret < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SceClibMspace cdramPool_get() {
|
SceClibMspace cdramPool_get()
|
||||||
|
{
|
||||||
return cdramPool;
|
return cdramPool;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psp2/types.h>
|
|
||||||
#include <psp2/kernel/sysmem.h>
|
|
||||||
#include <psp2/kernel/clib.h>
|
|
||||||
#include <SDL3/SDL_stdinc.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_alloc(void* user_data, unsigned int size);
|
||||||
void patcher_host_free(void *user_data, void *mem);
|
void patcher_host_free(void* user_data, void* mem);
|
||||||
|
|
||||||
void* vita_mem_alloc(
|
void* vita_mem_alloc(unsigned int type, size_t size, size_t alignment, int attribs, SceUID* uid);
|
||||||
unsigned int type,
|
|
||||||
size_t size,
|
|
||||||
size_t alignment,
|
|
||||||
int attribs,
|
|
||||||
SceUID* uid
|
|
||||||
);
|
|
||||||
void vita_mem_free(SceUID uid);
|
void vita_mem_free(SceUID uid);
|
||||||
|
|
||||||
void *vita_mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset);
|
void* vita_mem_vertex_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset);
|
||||||
void vita_mem_vertex_usse_free(SceUID uid);
|
void vita_mem_vertex_usse_free(SceUID uid);
|
||||||
void *vita_mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset);
|
void* vita_mem_fragment_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset);
|
||||||
void vita_mem_fragment_usse_free(SceUID uid);
|
void vita_mem_fragment_usse_free(SceUID uid);
|
||||||
|
|
||||||
bool cdramPool_init();
|
bool cdramPool_init();
|
||||||
|
|||||||
@ -1,17 +1,15 @@
|
|||||||
#include "d3drmrenderer_gxm.h"
|
#include "d3drmrenderer_gxm.h"
|
||||||
|
#include "memory.h"
|
||||||
#include "meshutils.h"
|
#include "meshutils.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <psp2/gxm.h>
|
|
||||||
#include <psp2/display.h>
|
#include <psp2/display.h>
|
||||||
#include <psp2/types.h>
|
#include <psp2/gxm.h>
|
||||||
#include <psp2/kernel/modulemgr.h>
|
#include <psp2/kernel/modulemgr.h>
|
||||||
|
#include <psp2/types.h>
|
||||||
#include "utils.h"
|
#include <string>
|
||||||
#include "memory.h"
|
|
||||||
#define INCBIN_PREFIX _inc_
|
#define INCBIN_PREFIX _inc_
|
||||||
#include "incbin.h"
|
#include "incbin.h"
|
||||||
|
|
||||||
@ -25,17 +23,15 @@ bool with_razor = false;
|
|||||||
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
|
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
|
||||||
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
|
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
INCBIN(main_vert_gxp, "shaders/main.vert.gxp");
|
INCBIN(main_vert_gxp, "shaders/main.vert.gxp");
|
||||||
INCBIN(main_frag_gxp, "shaders/main.frag.gxp");
|
INCBIN(main_frag_gxp, "shaders/main.frag.gxp");
|
||||||
INCBIN(color_frag_gxp, "shaders/color.frag.gxp");
|
INCBIN(color_frag_gxp, "shaders/color.frag.gxp");
|
||||||
INCBIN(image_frag_gxp, "shaders/image.frag.gxp");
|
INCBIN(image_frag_gxp, "shaders/image.frag.gxp");
|
||||||
|
|
||||||
const SceGxmProgram* mainVertexProgramGxp = (const SceGxmProgram*)_inc_main_vert_gxpData;
|
const SceGxmProgram* mainVertexProgramGxp = (const SceGxmProgram*) _inc_main_vert_gxpData;
|
||||||
const SceGxmProgram* mainFragmentProgramGxp = (const SceGxmProgram*)_inc_main_frag_gxpData;
|
const SceGxmProgram* mainFragmentProgramGxp = (const SceGxmProgram*) _inc_main_frag_gxpData;
|
||||||
const SceGxmProgram* colorFragmentProgramGxp = (const SceGxmProgram*)_inc_color_frag_gxpData;
|
const SceGxmProgram* colorFragmentProgramGxp = (const SceGxmProgram*) _inc_color_frag_gxpData;
|
||||||
const SceGxmProgram* imageFragmentProgramGxp = (const SceGxmProgram*)_inc_image_frag_gxpData;
|
const SceGxmProgram* imageFragmentProgramGxp = (const SceGxmProgram*) _inc_image_frag_gxpData;
|
||||||
|
|
||||||
static const SceGxmBlendInfo blendInfoOpaque = {
|
static const SceGxmBlendInfo blendInfoOpaque = {
|
||||||
.colorMask = SCE_GXM_COLOR_MASK_ALL,
|
.colorMask = SCE_GXM_COLOR_MASK_ALL,
|
||||||
@ -63,8 +59,9 @@ extern "C" int sceRazorGpuCaptureSetTriggerNextFrame(const char* path);
|
|||||||
|
|
||||||
static GXMRendererContext gxm_renderer_context;
|
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;
|
{
|
||||||
|
const GXMDisplayData* display_data = (const GXMDisplayData*) callback_data;
|
||||||
|
|
||||||
SceDisplayFrameBuf framebuf;
|
SceDisplayFrameBuf framebuf;
|
||||||
SDL_memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
|
SDL_memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
|
||||||
@ -78,21 +75,23 @@ static void display_callback(const void *callback_data) {
|
|||||||
sceDisplayWaitSetFrameBuf();
|
sceDisplayWaitSetFrameBuf();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_razor() {
|
static void load_razor()
|
||||||
|
{
|
||||||
int mod_id = _sceKernelLoadModule("app0:librazorcapture_es4.suprx", 0, nullptr);
|
int mod_id = _sceKernelLoadModule("app0:librazorcapture_es4.suprx", 0, nullptr);
|
||||||
int status;
|
int status;
|
||||||
if(!SCE_ERR(sceKernelStartModule, mod_id, 0, nullptr, 0, nullptr, &status)) {
|
if (!SCE_ERR(sceKernelStartModule, mod_id, 0, nullptr, 0, nullptr, &status)) {
|
||||||
with_razor = true;
|
with_razor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(with_razor) {
|
if (with_razor) {
|
||||||
sceRazorGpuCaptureEnableSalvage("ux0:data/gpu_crash.sgx");
|
sceRazorGpuCaptureEnableSalvage("ux0:data/gpu_crash.sgx");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gxm_initialized = false;
|
bool gxm_initialized = false;
|
||||||
bool gxm_init() {
|
bool gxm_init()
|
||||||
if(gxm_initialized) {
|
{
|
||||||
|
if (gxm_initialized) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +115,14 @@ bool gxm_init() {
|
|||||||
return cdramPool_init();
|
return cdramPool_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool create_gxm_context() {
|
static bool create_gxm_context()
|
||||||
|
{
|
||||||
GXMRendererContext* data = &gxm_renderer_context;
|
GXMRendererContext* data = &gxm_renderer_context;
|
||||||
if(data->context) {
|
if (data->context) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!gxm_init()) {
|
if (!gxm_init()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ static bool create_gxm_context() {
|
|||||||
const unsigned int patcherFragmentUsseSize = 64 * 1024;
|
const unsigned int patcherFragmentUsseSize = 64 * 1024;
|
||||||
|
|
||||||
data->cdramPool = cdramPool_get();
|
data->cdramPool = cdramPool_get();
|
||||||
if(!data->cdramPool) {
|
if (!data->cdramPool) {
|
||||||
SDL_Log("failed to allocate cdramPool");
|
SDL_Log("failed to allocate cdramPool");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -164,7 +164,8 @@ static bool create_gxm_context() {
|
|||||||
data->fragmentUsseRingBuffer = vita_mem_fragment_usse_alloc(
|
data->fragmentUsseRingBuffer = vita_mem_fragment_usse_alloc(
|
||||||
SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE,
|
SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE,
|
||||||
&data->fragmentUsseRingBufferUid,
|
&data->fragmentUsseRingBufferUid,
|
||||||
&data->fragmentUsseRingBufferOffset);
|
&data->fragmentUsseRingBufferOffset
|
||||||
|
);
|
||||||
|
|
||||||
// create context
|
// create context
|
||||||
SceGxmContextParams contextParams;
|
SceGxmContextParams contextParams;
|
||||||
@ -181,7 +182,7 @@ static bool create_gxm_context() {
|
|||||||
contextParams.fragmentUsseRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE;
|
contextParams.fragmentUsseRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE;
|
||||||
contextParams.fragmentUsseRingBufferOffset = data->fragmentUsseRingBufferOffset;
|
contextParams.fragmentUsseRingBufferOffset = data->fragmentUsseRingBufferOffset;
|
||||||
|
|
||||||
if(SCE_ERR(sceGxmCreateContext, &contextParams, &data->context)) {
|
if (SCE_ERR(sceGxmCreateContext, &contextParams, &data->context)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
data->contextHostMem = contextParams.hostMem;
|
data->contextHostMem = contextParams.hostMem;
|
||||||
@ -195,15 +196,14 @@ static bool create_gxm_context() {
|
|||||||
&data->patcherBufferUid
|
&data->patcherBufferUid
|
||||||
);
|
);
|
||||||
|
|
||||||
data->patcherVertexUsse = vita_mem_vertex_usse_alloc(
|
data->patcherVertexUsse =
|
||||||
patcherVertexUsseSize,
|
vita_mem_vertex_usse_alloc(patcherVertexUsseSize, &data->patcherVertexUsseUid, &data->patcherVertexUsseOffset);
|
||||||
&data->patcherVertexUsseUid,
|
|
||||||
&data->patcherVertexUsseOffset);
|
|
||||||
|
|
||||||
data->patcherFragmentUsse = vita_mem_fragment_usse_alloc(
|
data->patcherFragmentUsse = vita_mem_fragment_usse_alloc(
|
||||||
patcherFragmentUsseSize,
|
patcherFragmentUsseSize,
|
||||||
&data->patcherFragmentUsseUid,
|
&data->patcherFragmentUsseUid,
|
||||||
&data->patcherFragmentUsseOffset);
|
&data->patcherFragmentUsseOffset
|
||||||
|
);
|
||||||
|
|
||||||
SceGxmShaderPatcherParams patcherParams;
|
SceGxmShaderPatcherParams patcherParams;
|
||||||
memset(&patcherParams, 0, sizeof(SceGxmShaderPatcherParams));
|
memset(&patcherParams, 0, sizeof(SceGxmShaderPatcherParams));
|
||||||
@ -225,13 +225,14 @@ static bool create_gxm_context() {
|
|||||||
patcherParams.fragmentUsseMemSize = patcherFragmentUsseSize;
|
patcherParams.fragmentUsseMemSize = patcherFragmentUsseSize;
|
||||||
patcherParams.fragmentUsseOffset = data->patcherFragmentUsseOffset;
|
patcherParams.fragmentUsseOffset = data->patcherFragmentUsseOffset;
|
||||||
|
|
||||||
if(SCE_ERR(sceGxmShaderPatcherCreate, &patcherParams, &data->shaderPatcher)) {
|
if (SCE_ERR(sceGxmShaderPatcherCreate, &patcherParams, &data->shaderPatcher)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_gxm_context() {
|
static void destroy_gxm_context()
|
||||||
|
{
|
||||||
sceGxmShaderPatcherDestroy(gxm_renderer_context.shaderPatcher);
|
sceGxmShaderPatcherDestroy(gxm_renderer_context.shaderPatcher);
|
||||||
sceGxmDestroyContext(gxm_renderer_context.context);
|
sceGxmDestroyContext(gxm_renderer_context.context);
|
||||||
vita_mem_fragment_usse_free(gxm_renderer_context.fragmentUsseRingBufferUid);
|
vita_mem_fragment_usse_free(gxm_renderer_context.fragmentUsseRingBufferUid);
|
||||||
@ -241,8 +242,9 @@ static void destroy_gxm_context() {
|
|||||||
SDL_free(gxm_renderer_context.contextHostMem);
|
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()) {
|
{
|
||||||
|
if (!create_gxm_context()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*context = gxm_renderer_context.context;
|
*context = gxm_renderer_context.context;
|
||||||
@ -285,14 +287,15 @@ Direct3DRMRenderer* GXMRenderer::Create(DWORD width, DWORD height)
|
|||||||
SDL_Log("GXMRenderer::Create width=%d height=%d", width, height);
|
SDL_Log("GXMRenderer::Create width=%d height=%d", width, height);
|
||||||
|
|
||||||
bool success = gxm_init();
|
bool success = gxm_init();
|
||||||
if(!success) {
|
if (!success) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GXMRenderer(width, 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_width = VITA_GXM_SCREEN_WIDTH;
|
||||||
m_height = VITA_GXM_SCREEN_HEIGHT;
|
m_height = VITA_GXM_SCREEN_HEIGHT;
|
||||||
m_virtualWidth = width;
|
m_virtualWidth = width;
|
||||||
@ -303,7 +306,9 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
const unsigned int sampleCount = alignedWidth * alignedHeight;
|
const unsigned int sampleCount = alignedWidth * alignedHeight;
|
||||||
const unsigned int depthStrideInSamples = alignedWidth;
|
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
|
// render target
|
||||||
SceGxmRenderTargetParams renderTargetParams;
|
SceGxmRenderTargetParams renderTargetParams;
|
||||||
@ -315,9 +320,11 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
renderTargetParams.multisampleMode = 0;
|
renderTargetParams.multisampleMode = 0;
|
||||||
renderTargetParams.multisampleLocations = 0;
|
renderTargetParams.multisampleLocations = 0;
|
||||||
renderTargetParams.driverMemBlock = -1; // Invalid UID
|
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++) {
|
for (int i = 0; i < VITA_GXM_DISPLAY_BUFFER_COUNT; i++) {
|
||||||
this->displayBuffers[i] = vita_mem_alloc(
|
this->displayBuffers[i] = vita_mem_alloc(
|
||||||
SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
|
SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW,
|
||||||
4 * VITA_GXM_SCREEN_STRIDE * VITA_GXM_SCREEN_HEIGHT,
|
4 * VITA_GXM_SCREEN_STRIDE * VITA_GXM_SCREEN_HEIGHT,
|
||||||
@ -326,20 +333,25 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
&this->displayBuffersUid[i]
|
&this->displayBuffersUid[i]
|
||||||
);
|
);
|
||||||
|
|
||||||
if(SCE_ERR(sceGxmColorSurfaceInit,
|
if (SCE_ERR(
|
||||||
|
sceGxmColorSurfaceInit,
|
||||||
&this->displayBuffersSurface[i],
|
&this->displayBuffersSurface[i],
|
||||||
SCE_GXM_COLOR_FORMAT_A8B8G8R8,
|
SCE_GXM_COLOR_FORMAT_A8B8G8R8,
|
||||||
SCE_GXM_COLOR_SURFACE_LINEAR,
|
SCE_GXM_COLOR_SURFACE_LINEAR,
|
||||||
SCE_GXM_COLOR_SURFACE_SCALE_NONE,
|
SCE_GXM_COLOR_SURFACE_SCALE_NONE,
|
||||||
SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
|
SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
|
||||||
m_width, m_height,
|
m_width,
|
||||||
|
m_height,
|
||||||
m_width,
|
m_width,
|
||||||
this->displayBuffers[i]
|
this->displayBuffers[i]
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
if(SCE_ERR(sceGxmSyncObjectCreate, &this->displayBuffersSync[i])) return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SCE_ERR(sceGxmSyncObjectCreate, &this->displayBuffersSync[i])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// depth & stencil
|
// depth & stencil
|
||||||
this->depthBufferData = vita_mem_alloc(
|
this->depthBufferData = vita_mem_alloc(
|
||||||
@ -358,27 +370,57 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
&this->stencilBufferUid
|
&this->stencilBufferUid
|
||||||
);
|
);
|
||||||
|
|
||||||
if(SCE_ERR(sceGxmDepthStencilSurfaceInit,
|
if (SCE_ERR(
|
||||||
|
sceGxmDepthStencilSurfaceInit,
|
||||||
&this->depthSurface,
|
&this->depthSurface,
|
||||||
SCE_GXM_DEPTH_STENCIL_FORMAT_S8D24,
|
SCE_GXM_DEPTH_STENCIL_FORMAT_S8D24,
|
||||||
SCE_GXM_DEPTH_STENCIL_SURFACE_TILED,
|
SCE_GXM_DEPTH_STENCIL_SURFACE_TILED,
|
||||||
depthStrideInSamples,
|
depthStrideInSamples,
|
||||||
this->depthBufferData,
|
this->depthBufferData,
|
||||||
this->stencilBufferData
|
this->stencilBufferData
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// register shader programs
|
// register shader programs
|
||||||
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, colorFragmentProgramGxp, &this->colorFragmentProgramId)) return;
|
if (SCE_ERR(
|
||||||
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, mainVertexProgramGxp, &this->mainVertexProgramId)) return;
|
sceGxmShaderPatcherRegisterProgram,
|
||||||
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, mainFragmentProgramGxp, &this->mainFragmentProgramId)) return;
|
this->shaderPatcher,
|
||||||
if(SCE_ERR(sceGxmShaderPatcherRegisterProgram, this->shaderPatcher, imageFragmentProgramGxp, &this->imageFragmentProgramId)) return;
|
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
|
// main shader
|
||||||
{
|
{
|
||||||
GET_SHADER_PARAM(positionAttribute, mainVertexProgramGxp, "aPosition",);
|
GET_SHADER_PARAM(positionAttribute, mainVertexProgramGxp, "aPosition", );
|
||||||
GET_SHADER_PARAM(normalAttribute, mainVertexProgramGxp, "aNormal",);
|
GET_SHADER_PARAM(normalAttribute, mainVertexProgramGxp, "aNormal", );
|
||||||
GET_SHADER_PARAM(texCoordAttribute, mainVertexProgramGxp, "aTexCoord",);
|
GET_SHADER_PARAM(texCoordAttribute, mainVertexProgramGxp, "aTexCoord", );
|
||||||
|
|
||||||
SceGxmVertexAttribute vertexAttributes[3];
|
SceGxmVertexAttribute vertexAttributes[3];
|
||||||
SceGxmVertexStream vertexStreams[1];
|
SceGxmVertexStream vertexStreams[1];
|
||||||
@ -406,17 +448,23 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
vertexStreams[0].stride = sizeof(Vertex);
|
vertexStreams[0].stride = sizeof(Vertex);
|
||||||
vertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
|
vertexStreams[0].indexSource = SCE_GXM_INDEX_SOURCE_INDEX_16BIT;
|
||||||
|
|
||||||
if(SCE_ERR(sceGxmShaderPatcherCreateVertexProgram,
|
if (SCE_ERR(
|
||||||
|
sceGxmShaderPatcherCreateVertexProgram,
|
||||||
this->shaderPatcher,
|
this->shaderPatcher,
|
||||||
this->mainVertexProgramId,
|
this->mainVertexProgramId,
|
||||||
vertexAttributes, 3,
|
vertexAttributes,
|
||||||
vertexStreams, 1,
|
3,
|
||||||
|
vertexStreams,
|
||||||
|
1,
|
||||||
&this->mainVertexProgram
|
&this->mainVertexProgram
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// main opaque
|
// main opaque
|
||||||
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
|
if (SCE_ERR(
|
||||||
|
sceGxmShaderPatcherCreateFragmentProgram,
|
||||||
this->shaderPatcher,
|
this->shaderPatcher,
|
||||||
this->mainFragmentProgramId,
|
this->mainFragmentProgramId,
|
||||||
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
||||||
@ -424,10 +472,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
&blendInfoOpaque,
|
&blendInfoOpaque,
|
||||||
mainVertexProgramGxp,
|
mainVertexProgramGxp,
|
||||||
&this->opaqueFragmentProgram
|
&this->opaqueFragmentProgram
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// main transparent
|
// main transparent
|
||||||
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
|
if (SCE_ERR(
|
||||||
|
sceGxmShaderPatcherCreateFragmentProgram,
|
||||||
this->shaderPatcher,
|
this->shaderPatcher,
|
||||||
this->mainFragmentProgramId,
|
this->mainFragmentProgramId,
|
||||||
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
||||||
@ -435,10 +486,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
&blendInfoTransparent,
|
&blendInfoTransparent,
|
||||||
mainVertexProgramGxp,
|
mainVertexProgramGxp,
|
||||||
&this->transparentFragmentProgram
|
&this->transparentFragmentProgram
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// image
|
// image
|
||||||
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
|
if (SCE_ERR(
|
||||||
|
sceGxmShaderPatcherCreateFragmentProgram,
|
||||||
this->shaderPatcher,
|
this->shaderPatcher,
|
||||||
this->imageFragmentProgramId,
|
this->imageFragmentProgramId,
|
||||||
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
||||||
@ -446,10 +500,13 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
&blendInfoTransparent,
|
&blendInfoTransparent,
|
||||||
mainVertexProgramGxp,
|
mainVertexProgramGxp,
|
||||||
&this->imageFragmentProgram
|
&this->imageFragmentProgram
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// color
|
// color
|
||||||
if(SCE_ERR(sceGxmShaderPatcherCreateFragmentProgram,
|
if (SCE_ERR(
|
||||||
|
sceGxmShaderPatcherCreateFragmentProgram,
|
||||||
this->shaderPatcher,
|
this->shaderPatcher,
|
||||||
this->colorFragmentProgramId,
|
this->colorFragmentProgramId,
|
||||||
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
SCE_GXM_OUTPUT_REGISTER_FORMAT_UCHAR4,
|
||||||
@ -457,7 +514,9 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
NULL,
|
NULL,
|
||||||
mainVertexProgramGxp,
|
mainVertexProgramGxp,
|
||||||
&this->colorFragmentProgram
|
&this->colorFragmentProgram
|
||||||
)) return;
|
)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// vertex uniforms
|
// vertex uniforms
|
||||||
this->uModelViewMatrix = sceGxmProgramFindParameterByName(mainVertexProgramGxp, "uModelViewMatrix");
|
this->uModelViewMatrix = sceGxmProgramFindParameterByName(mainVertexProgramGxp, "uModelViewMatrix");
|
||||||
@ -475,28 +534,29 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) {
|
|||||||
this->colorShader_uColor = sceGxmProgramFindParameterByName(colorFragmentProgramGxp, "uColor"); // vec4
|
this->colorShader_uColor = sceGxmProgramFindParameterByName(colorFragmentProgramGxp, "uColor"); // vec4
|
||||||
|
|
||||||
this->lights = static_cast<decltype(this->lights)>(sceClibMspaceMalloc(this->cdramPool, sizeof(*this->lights)));
|
this->lights = static_cast<decltype(this->lights)>(sceClibMspaceMalloc(this->cdramPool, sizeof(*this->lights)));
|
||||||
for(int i = 0; i < VITA_GXM_UNIFORM_BUFFER_COUNT; i++) {
|
for (int i = 0; i < VITA_GXM_UNIFORM_BUFFER_COUNT; i++) {
|
||||||
this->quadVertices[i] = (Vertex*)sceClibMspaceMalloc(this->cdramPool, sizeof(Vertex)*4*50);
|
this->quadVertices[i] = (Vertex*) sceClibMspaceMalloc(this->cdramPool, sizeof(Vertex) * 4 * 50);
|
||||||
}
|
}
|
||||||
this->quadIndices = (uint16_t*)sceClibMspaceMalloc(this->cdramPool, sizeof(uint16_t)*4);
|
this->quadIndices = (uint16_t*) sceClibMspaceMalloc(this->cdramPool, sizeof(uint16_t) * 4);
|
||||||
this->quadIndices[0] = 0;
|
this->quadIndices[0] = 0;
|
||||||
this->quadIndices[1] = 1;
|
this->quadIndices[1] = 1;
|
||||||
this->quadIndices[2] = 2;
|
this->quadIndices[2] = 2;
|
||||||
this->quadIndices[3] = 3;
|
this->quadIndices[3] = 3;
|
||||||
|
|
||||||
volatile uint32_t *const notificationMem = sceGxmGetNotificationRegion();
|
volatile uint32_t* const notificationMem = sceGxmGetNotificationRegion();
|
||||||
for (uint32_t i = 0; i < VITA_GXM_UNIFORM_BUFFER_COUNT; i++) {
|
for (uint32_t i = 0; i < VITA_GXM_UNIFORM_BUFFER_COUNT; i++) {
|
||||||
this->fragmentNotifications[i].address = notificationMem + (i*2);
|
this->fragmentNotifications[i].address = notificationMem + (i * 2);
|
||||||
this->fragmentNotifications[i].value = 0;
|
this->fragmentNotifications[i].value = 0;
|
||||||
this->vertexNotifications[i].address = notificationMem + (i*2)+1;
|
this->vertexNotifications[i].address = notificationMem + (i * 2) + 1;
|
||||||
this->vertexNotifications[i].value = 0;
|
this->vertexNotifications[i].value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GXMRenderer::~GXMRenderer() {
|
GXMRenderer::~GXMRenderer()
|
||||||
if(!m_initialized) {
|
{
|
||||||
|
if (!m_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,10 +607,18 @@ 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;
|
*supportedFormat = true;
|
||||||
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
*textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
||||||
switch(surface->format) {
|
switch (surface->format) {
|
||||||
case SDL_PIXELFORMAT_ABGR8888: {
|
case SDL_PIXELFORMAT_ABGR8888: {
|
||||||
*textureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR;
|
*textureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR;
|
||||||
*textureSize = surface->h * surface->pitch;
|
*textureSize = surface->h * surface->pitch;
|
||||||
@ -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_Surface* dst = SDL_CreateSurfaceFrom(src->w, src->h, SDL_PIXELFORMAT_ABGR8888, dstData, textureStride);
|
||||||
SDL_BlitSurface(src, nullptr, dst, nullptr);
|
SDL_BlitSurface(src, nullptr, dst, nullptr);
|
||||||
SDL_DestroySurface(dst);
|
SDL_DestroySurface(dst);
|
||||||
@ -585,7 +654,6 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
|
|||||||
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
auto texture = static_cast<Direct3DRMTextureImpl*>(iTexture);
|
||||||
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
auto surface = static_cast<DirectDrawSurfaceImpl*>(texture->m_surface);
|
||||||
|
|
||||||
|
|
||||||
bool supportedFormat;
|
bool supportedFormat;
|
||||||
size_t textureSize;
|
size_t textureSize;
|
||||||
size_t textureAlignment;
|
size_t textureAlignment;
|
||||||
@ -594,9 +662,16 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
|
|||||||
int textureWidth = surface->m_surface->w;
|
int textureWidth = surface->m_surface->w;
|
||||||
int textureHeight = surface->m_surface->h;
|
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) {
|
if (!supportedFormat) {
|
||||||
textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT;
|
||||||
textureStride = textureWidth * 4;
|
textureStride = textureWidth * 4;
|
||||||
textureSize = textureHeight * textureStride;
|
textureSize = textureHeight * textureStride;
|
||||||
@ -608,9 +683,10 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
|
|||||||
if (tex.texture == texture) {
|
if (tex.texture == texture) {
|
||||||
if (tex.version != texture->m_version) {
|
if (tex.version != texture->m_version) {
|
||||||
void* textureData = sceGxmTextureGetData(&tex.gxmTexture);
|
void* textureData = sceGxmTextureGetData(&tex.gxmTexture);
|
||||||
if(!supportedFormat) {
|
if (!supportedFormat) {
|
||||||
copySurfaceTo(surface->m_surface, textureData, textureStride);
|
copySurfaceTo(surface->m_surface, textureData, textureStride);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
memcpy(textureData, surface->m_surface->pixels, textureSize);
|
memcpy(textureData, surface->m_surface->pixels, textureSize);
|
||||||
}
|
}
|
||||||
tex.version = texture->m_version;
|
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_Log(
|
||||||
SDL_GetPixelFormatName(surface->m_surface->format), textureWidth, textureHeight, textureStride);
|
"Create Texture %s w=%d h=%d s=%d",
|
||||||
|
SDL_GetPixelFormatName(surface->m_surface->format),
|
||||||
|
textureWidth,
|
||||||
|
textureHeight,
|
||||||
|
textureStride
|
||||||
|
);
|
||||||
|
|
||||||
// allocate gpu memory
|
// allocate gpu memory
|
||||||
void* textureData = sceClibMspaceMemalign(this->cdramPool, textureAlignment, textureSize);
|
void* textureData = sceClibMspaceMemalign(this->cdramPool, textureAlignment, textureSize);
|
||||||
uint8_t* paletteData = nullptr;
|
uint8_t* paletteData = nullptr;
|
||||||
|
|
||||||
if(!supportedFormat) {
|
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);
|
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;
|
LPDIRECTDRAWPALETTE _palette;
|
||||||
surface->GetPalette(&_palette);
|
surface->GetPalette(&_palette);
|
||||||
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
|
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
|
||||||
@ -641,20 +724,27 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
|
|||||||
SDL_Log("copying indexed texture data from=%p to=%p", surface->m_surface->pixels, textureData);
|
SDL_Log("copying indexed texture data from=%p to=%p", surface->m_surface->pixels, textureData);
|
||||||
memcpy(textureData, surface->m_surface->pixels, pixelsSize);
|
memcpy(textureData, surface->m_surface->pixels, pixelsSize);
|
||||||
|
|
||||||
paletteData = (uint8_t*)textureData + pixelsSize + alignBytes;
|
paletteData = (uint8_t*) textureData + pixelsSize + alignBytes;
|
||||||
memcpy(paletteData, palette->m_palette->colors, palette->m_palette->ncolors*sizeof(SDL_Color));
|
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);
|
SDL_Log("copying texture data from=%p to=%p", surface->m_surface->pixels, textureData);
|
||||||
memcpy(textureData, surface->m_surface->pixels, textureSize);
|
memcpy(textureData, surface->m_surface->pixels, textureSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
SceGxmTexture gxmTexture;
|
SceGxmTexture gxmTexture;
|
||||||
SCE_ERR(sceGxmTextureInitLinearStrided, &gxmTexture, textureData, textureFormat, textureWidth, textureHeight, textureStride);
|
SCE_ERR(
|
||||||
//sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
sceGxmTextureInitLinearStrided,
|
||||||
|
&gxmTexture,
|
||||||
|
textureData,
|
||||||
|
textureFormat,
|
||||||
|
textureWidth,
|
||||||
|
textureHeight,
|
||||||
|
textureStride
|
||||||
|
);
|
||||||
|
// sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
||||||
sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR);
|
||||||
if(paletteData) {
|
if (paletteData) {
|
||||||
sceGxmTextureSetPalette(&gxmTexture, paletteData);
|
sceGxmTextureSetPalette(&gxmTexture, paletteData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,33 +793,36 @@ GXMMeshCacheEntry GXMRenderer::GXMUploadMesh(const MeshGroup& meshGroup)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t vertexBufferSize = sizeof(Vertex)*vertices.size();
|
size_t vertexBufferSize = sizeof(Vertex) * vertices.size();
|
||||||
size_t indexBufferSize = sizeof(uint16_t)*indices.size();
|
size_t indexBufferSize = sizeof(uint16_t) * indices.size();
|
||||||
void* meshData = sceClibMspaceMemalign(this->cdramPool, 4, vertexBufferSize+indexBufferSize);
|
void* meshData = sceClibMspaceMemalign(this->cdramPool, 4, vertexBufferSize + indexBufferSize);
|
||||||
|
|
||||||
Vertex* vertexBuffer = (Vertex*)meshData;
|
Vertex* vertexBuffer = (Vertex*) meshData;
|
||||||
uint16_t* indexBuffer = (uint16_t*)((uint8_t*)meshData + vertexBufferSize);
|
uint16_t* indexBuffer = (uint16_t*) ((uint8_t*) meshData + vertexBufferSize);
|
||||||
|
|
||||||
for(int i = 0; i < vertices.size(); i++) {
|
for (int i = 0; i < vertices.size(); i++) {
|
||||||
D3DRMVERTEX vertex = vertices.data()[i];
|
D3DRMVERTEX vertex = vertices.data()[i];
|
||||||
vertexBuffer[i] = Vertex{
|
vertexBuffer[i] = Vertex{
|
||||||
.position = {
|
.position =
|
||||||
|
{
|
||||||
vertex.position.x,
|
vertex.position.x,
|
||||||
vertex.position.y,
|
vertex.position.y,
|
||||||
vertex.position.z,
|
vertex.position.z,
|
||||||
},
|
},
|
||||||
.normal = {
|
.normal =
|
||||||
|
{
|
||||||
vertex.normal.x,
|
vertex.normal.x,
|
||||||
vertex.normal.y,
|
vertex.normal.y,
|
||||||
vertex.normal.z,
|
vertex.normal.z,
|
||||||
},
|
},
|
||||||
.texCoord = {
|
.texCoord =
|
||||||
|
{
|
||||||
vertex.tu,
|
vertex.tu,
|
||||||
vertex.tv,
|
vertex.tv,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
memcpy(indexBuffer, indices.data(), indices.size()*sizeof(uint16_t));
|
memcpy(indexBuffer, indices.data(), indices.size() * sizeof(uint16_t));
|
||||||
|
|
||||||
cache.meshData = meshData;
|
cache.meshData = meshData;
|
||||||
cache.vertexBuffer = vertexBuffer;
|
cache.vertexBuffer = vertexBuffer;
|
||||||
@ -801,15 +894,18 @@ void GXMRenderer::GetDesc(D3DDEVICEDESC* halDesc, D3DDEVICEDESC* helDesc)
|
|||||||
memset(helDesc, 0, sizeof(D3DDEVICEDESC));
|
memset(helDesc, 0, sizeof(D3DDEVICEDESC));
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* GXMRenderer::GetName() {
|
const char* GXMRenderer::GetName()
|
||||||
|
{
|
||||||
return "GXM";
|
return "GXM";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool razor_triggered = false;
|
bool razor_triggered = false;
|
||||||
|
|
||||||
void GXMRenderer::StartScene() {
|
void GXMRenderer::StartScene()
|
||||||
if(sceneStarted) return;
|
{
|
||||||
|
if (sceneStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
sceGxmBeginScene(
|
sceGxmBeginScene(
|
||||||
this->context,
|
this->context,
|
||||||
0,
|
0,
|
||||||
@ -827,15 +923,16 @@ void GXMRenderer::StartScene() {
|
|||||||
this->activeUniformBuffer = (this->activeUniformBuffer + 1) % VITA_GXM_UNIFORM_BUFFER_COUNT;
|
this->activeUniformBuffer = (this->activeUniformBuffer + 1) % VITA_GXM_UNIFORM_BUFFER_COUNT;
|
||||||
sceGxmNotificationWait(&this->fragmentNotifications[this->activeUniformBuffer]);
|
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;
|
int frames = 0;
|
||||||
HRESULT GXMRenderer::BeginFrame()
|
HRESULT GXMRenderer::BeginFrame()
|
||||||
{
|
{
|
||||||
frames++;
|
frames++;
|
||||||
if(with_razor) {
|
if (with_razor) {
|
||||||
if(!razor_triggered && frames == 10) {
|
if (!razor_triggered && frames == 10) {
|
||||||
SDL_Log("trigger razor");
|
SDL_Log("trigger razor");
|
||||||
sceRazorGpuCaptureSetTriggerNextFrame("ux0:/data/capture.sgx");
|
sceRazorGpuCaptureSetTriggerNextFrame("ux0:/data/capture.sgx");
|
||||||
razor_triggered = true;
|
razor_triggered = true;
|
||||||
@ -869,14 +966,18 @@ HRESULT GXMRenderer::BeginFrame()
|
|||||||
return DD_OK;
|
return DD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GXMRenderer::EnableTransparency() {
|
void GXMRenderer::EnableTransparency()
|
||||||
|
{
|
||||||
this->transparencyEnabled = true;
|
this->transparencyEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void transpose4x4(const float src[4][4], float dst[4][4]) {
|
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)
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
for (int j = 0; j < 4; ++j) {
|
||||||
dst[j][i] = src[i][j];
|
dst[j][i] = src[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const D3DRMMATRIX4D identity4x4 = {
|
static const D3DRMMATRIX4D identity4x4 = {
|
||||||
@ -892,7 +993,6 @@ static const Matrix3x3 identity3x3 = {
|
|||||||
{0.0, 0.0, 1.0},
|
{0.0, 0.0, 1.0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void GXMRenderer::SubmitDraw(
|
void GXMRenderer::SubmitDraw(
|
||||||
DWORD meshId,
|
DWORD meshId,
|
||||||
const D3DRMMATRIX4D& modelViewMatrix,
|
const D3DRMMATRIX4D& modelViewMatrix,
|
||||||
@ -900,7 +1000,8 @@ void GXMRenderer::SubmitDraw(
|
|||||||
const D3DRMMATRIX4D& viewMatrix,
|
const D3DRMMATRIX4D& viewMatrix,
|
||||||
const Matrix3x3& normalMatrix,
|
const Matrix3x3& normalMatrix,
|
||||||
const Appearance& appearance
|
const Appearance& appearance
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
auto& mesh = m_meshes[meshId];
|
auto& mesh = m_meshes[meshId];
|
||||||
|
|
||||||
char marker[256];
|
char marker[256];
|
||||||
@ -908,9 +1009,10 @@ void GXMRenderer::SubmitDraw(
|
|||||||
sceGxmPushUserMarker(this->context, marker);
|
sceGxmPushUserMarker(this->context, marker);
|
||||||
|
|
||||||
sceGxmSetVertexProgram(this->context, this->mainVertexProgram);
|
sceGxmSetVertexProgram(this->context, this->mainVertexProgram);
|
||||||
if(this->transparencyEnabled) {
|
if (this->transparencyEnabled) {
|
||||||
sceGxmSetFragmentProgram(this->context, this->transparentFragmentProgram);
|
sceGxmSetFragmentProgram(this->context, this->transparentFragmentProgram);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sceGxmSetFragmentProgram(this->context, this->opaqueFragmentProgram);
|
sceGxmSetFragmentProgram(this->context, this->opaqueFragmentProgram);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -934,35 +1036,32 @@ void GXMRenderer::SubmitDraw(
|
|||||||
|
|
||||||
int useTexture = appearance.textureId != NO_TEXTURE_ID ? 1 : 0;
|
int useTexture = appearance.textureId != NO_TEXTURE_ID ? 1 : 0;
|
||||||
SET_UNIFORM(fragUniforms, this->uUseTexture, useTexture);
|
SET_UNIFORM(fragUniforms, this->uUseTexture, useTexture);
|
||||||
if(useTexture) {
|
if (useTexture) {
|
||||||
auto& texture = m_textures[appearance.textureId];
|
auto& texture = m_textures[appearance.textureId];
|
||||||
sceGxmSetFragmentTexture(this->context, 0, &texture.gxmTexture);
|
sceGxmSetFragmentTexture(this->context, 0, &texture.gxmTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
sceGxmSetVertexStream(this->context, 0, mesh.vertexBuffer);
|
sceGxmSetVertexStream(this->context, 0, mesh.vertexBuffer);
|
||||||
sceGxmDraw(
|
sceGxmDraw(this->context, SCE_GXM_PRIMITIVE_TRIANGLES, SCE_GXM_INDEX_FORMAT_U16, mesh.indexBuffer, mesh.indexCount);
|
||||||
this->context,
|
|
||||||
SCE_GXM_PRIMITIVE_TRIANGLES,
|
|
||||||
SCE_GXM_INDEX_FORMAT_U16,
|
|
||||||
mesh.indexBuffer,
|
|
||||||
mesh.indexCount
|
|
||||||
);
|
|
||||||
|
|
||||||
sceGxmPopUserMarker(this->context);
|
sceGxmPopUserMarker(this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GXMRenderer::FinalizeFrame() {
|
HRESULT GXMRenderer::FinalizeFrame()
|
||||||
|
{
|
||||||
return DD_OK;
|
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_width = width;
|
||||||
m_height = height;
|
m_height = height;
|
||||||
m_viewportTransform = viewportTransform;
|
m_viewportTransform = viewportTransform;
|
||||||
SDL_Log("GXMRenderer::Resize TODO");
|
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();
|
this->StartScene();
|
||||||
|
|
||||||
char marker[256];
|
char marker[256];
|
||||||
@ -986,7 +1085,7 @@ void GXMRenderer::Clear(float r, float g, float b) {
|
|||||||
SET_UNIFORM(vertUniforms, this->uNormalMatrix, normal); // float3x3
|
SET_UNIFORM(vertUniforms, this->uNormalMatrix, normal); // float3x3
|
||||||
SET_UNIFORM(vertUniforms, this->uProjectionMatrix, projection); // float4x4
|
SET_UNIFORM(vertUniforms, this->uProjectionMatrix, projection); // float4x4
|
||||||
|
|
||||||
float color[] = {r,g,b,1};
|
float color[] = {r, g, b, 1};
|
||||||
SET_UNIFORM(fragUniforms, this->colorShader_uColor, color);
|
SET_UNIFORM(fragUniforms, this->colorShader_uColor, color);
|
||||||
|
|
||||||
float x1 = 0;
|
float x1 = 0;
|
||||||
@ -995,25 +1094,21 @@ void GXMRenderer::Clear(float r, float g, float b) {
|
|||||||
float y2 = y1 + 1.0;
|
float y2 = y1 + 1.0;
|
||||||
|
|
||||||
Vertex* quadVertices = this->QuadVerticesBuffer();
|
Vertex* quadVertices = this->QuadVerticesBuffer();
|
||||||
quadVertices[0] = Vertex{ .position = {x1, y1, -1.0}, .normal = {0,0,0}, .texCoord = {0,0}};
|
quadVertices[0] = Vertex{.position = {x1, y1, -1.0}, .normal = {0, 0, 0}, .texCoord = {0, 0}};
|
||||||
quadVertices[1] = Vertex{ .position = {x2, y1, -1.0}, .normal = {0,0,0}, .texCoord = {0,0}};
|
quadVertices[1] = Vertex{.position = {x2, y1, -1.0}, .normal = {0, 0, 0}, .texCoord = {0, 0}};
|
||||||
quadVertices[2] = Vertex{ .position = {x1, y2, -1.0}, .normal = {0,0,0}, .texCoord = {0,0}};
|
quadVertices[2] = Vertex{.position = {x1, y2, -1.0}, .normal = {0, 0, 0}, .texCoord = {0, 0}};
|
||||||
quadVertices[3] = Vertex{ .position = {x2, y2, -1.0}, .normal = {0,0,0}, .texCoord = {0,0}};
|
quadVertices[3] = Vertex{.position = {x2, y2, -1.0}, .normal = {0, 0, 0}, .texCoord = {0, 0}};
|
||||||
|
|
||||||
sceGxmSetVertexStream(this->context, 0, quadVertices);
|
sceGxmSetVertexStream(this->context, 0, quadVertices);
|
||||||
sceGxmDraw(
|
sceGxmDraw(this->context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, this->quadIndices, 4);
|
||||||
this->context,
|
|
||||||
SCE_GXM_PRIMITIVE_TRIANGLE_STRIP,
|
|
||||||
SCE_GXM_INDEX_FORMAT_U16,
|
|
||||||
this->quadIndices, 4
|
|
||||||
);
|
|
||||||
|
|
||||||
sceGxmPopUserMarker(this->context);
|
sceGxmPopUserMarker(this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GXMRenderer::Flip() {
|
void GXMRenderer::Flip()
|
||||||
if(!this->sceneStarted) {
|
{
|
||||||
this->Clear(0,0,0);
|
if (!this->sceneStarted) {
|
||||||
|
this->Clear(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// end scene
|
// end scene
|
||||||
@ -1022,8 +1117,9 @@ void GXMRenderer::Flip() {
|
|||||||
sceGxmEndScene(
|
sceGxmEndScene(
|
||||||
this->context,
|
this->context,
|
||||||
nullptr, //&this->vertexNotifications[this->activeUniformBuffer],
|
nullptr, //&this->vertexNotifications[this->activeUniformBuffer],
|
||||||
//nullptr
|
// 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(
|
sceGxmPadHeartbeat(
|
||||||
&this->displayBuffersSurface[this->backBufferIndex],
|
&this->displayBuffersSurface[this->backBufferIndex],
|
||||||
@ -1045,7 +1141,8 @@ void GXMRenderer::Flip() {
|
|||||||
this->backBufferIndex = (this->backBufferIndex + 1) % VITA_GXM_DISPLAY_BUFFER_COUNT;
|
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();
|
this->StartScene();
|
||||||
|
|
||||||
char marker[256];
|
char marker[256];
|
||||||
@ -1065,8 +1162,8 @@ void GXMRenderer::Draw2DImage(Uint32 textureId, const SDL_Rect& srcRect, const S
|
|||||||
float top = -this->m_viewportTransform.offsetY / this->m_viewportTransform.scale;
|
float top = -this->m_viewportTransform.offsetY / this->m_viewportTransform.scale;
|
||||||
float bottom = (this->m_height - this->m_viewportTransform.offsetY) / this->m_viewportTransform.scale;
|
float bottom = (this->m_height - this->m_viewportTransform.offsetY) / this->m_viewportTransform.scale;
|
||||||
|
|
||||||
#define virtualToNDCX(x) (((x - left) / (right - left)));
|
#define virtualToNDCX(x) (((x - left) / (right - left)));
|
||||||
#define virtualToNDCY(y) (((y - top) / (bottom - top)));
|
#define virtualToNDCY(y) (((y - top) / (bottom - top)));
|
||||||
|
|
||||||
float x1_virtual = static_cast<float>(dstRect.x);
|
float x1_virtual = static_cast<float>(dstRect.x);
|
||||||
float y1_virtual = static_cast<float>(dstRect.y);
|
float y1_virtual = static_cast<float>(dstRect.y);
|
||||||
@ -1105,25 +1202,21 @@ void GXMRenderer::Draw2DImage(Uint32 textureId, const SDL_Rect& srcRect, const S
|
|||||||
float v2 = static_cast<float>(srcRect.y + srcRect.h) / texH;
|
float v2 = static_cast<float>(srcRect.y + srcRect.h) / texH;
|
||||||
|
|
||||||
Vertex* quadVertices = this->QuadVerticesBuffer();
|
Vertex* quadVertices = this->QuadVerticesBuffer();
|
||||||
quadVertices[0] = Vertex{ .position = {x1, y1, 0}, .normal = {0,0,0}, .texCoord = {u1, v1}};
|
quadVertices[0] = Vertex{.position = {x1, y1, 0}, .normal = {0, 0, 0}, .texCoord = {u1, v1}};
|
||||||
quadVertices[1] = Vertex{ .position = {x2, y1, 0}, .normal = {0,0,0}, .texCoord = {u2, v1}};
|
quadVertices[1] = Vertex{.position = {x2, y1, 0}, .normal = {0, 0, 0}, .texCoord = {u2, v1}};
|
||||||
quadVertices[2] = Vertex{ .position = {x1, y2, 0}, .normal = {0,0,0}, .texCoord = {u1, v2}};
|
quadVertices[2] = Vertex{.position = {x1, y2, 0}, .normal = {0, 0, 0}, .texCoord = {u1, v2}};
|
||||||
quadVertices[3] = Vertex{ .position = {x2, y2, 0}, .normal = {0,0,0}, .texCoord = {u2, v2}};
|
quadVertices[3] = Vertex{.position = {x2, y2, 0}, .normal = {0, 0, 0}, .texCoord = {u2, v2}};
|
||||||
|
|
||||||
sceGxmSetVertexStream(this->context, 0, quadVertices);
|
sceGxmSetVertexStream(this->context, 0, quadVertices);
|
||||||
|
|
||||||
sceGxmSetFrontDepthWriteEnable(this->context, SCE_GXM_DEPTH_WRITE_DISABLED);
|
sceGxmSetFrontDepthWriteEnable(this->context, SCE_GXM_DEPTH_WRITE_DISABLED);
|
||||||
sceGxmDraw(
|
sceGxmDraw(this->context, SCE_GXM_PRIMITIVE_TRIANGLE_STRIP, SCE_GXM_INDEX_FORMAT_U16, this->quadIndices, 4);
|
||||||
this->context,
|
|
||||||
SCE_GXM_PRIMITIVE_TRIANGLE_STRIP,
|
|
||||||
SCE_GXM_INDEX_FORMAT_U16,
|
|
||||||
this->quadIndices, 4
|
|
||||||
);
|
|
||||||
sceGxmSetFrontDepthWriteEnable(this->context, SCE_GXM_DEPTH_WRITE_ENABLED);
|
sceGxmSetFrontDepthWriteEnable(this->context, SCE_GXM_DEPTH_WRITE_ENABLED);
|
||||||
sceGxmPopUserMarker(this->context);
|
sceGxmPopUserMarker(this->context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GXMRenderer::Download(SDL_Surface* target) {
|
void GXMRenderer::Download(SDL_Surface* target)
|
||||||
|
{
|
||||||
SDL_Rect srcRect = {
|
SDL_Rect srcRect = {
|
||||||
static_cast<int>(m_viewportTransform.offsetX),
|
static_cast<int>(m_viewportTransform.offsetX),
|
||||||
static_cast<int>(m_viewportTransform.offsetY),
|
static_cast<int>(m_viewportTransform.offsetY),
|
||||||
@ -1131,9 +1224,11 @@ void GXMRenderer::Download(SDL_Surface* target) {
|
|||||||
static_cast<int>(target->h * m_viewportTransform.scale),
|
static_cast<int>(target->h * m_viewportTransform.scale),
|
||||||
};
|
};
|
||||||
SDL_Surface* src = SDL_CreateSurfaceFrom(
|
SDL_Surface* src = SDL_CreateSurfaceFrom(
|
||||||
this->m_width, this->m_height,
|
this->m_width,
|
||||||
|
this->m_height,
|
||||||
SDL_PIXELFORMAT_RGBA32,
|
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_BlitSurfaceScaled(src, &srcRect, target, nullptr, SDL_SCALEMODE_NEAREST);
|
||||||
SDL_DestroySurface(src);
|
SDL_DestroySurface(src);
|
||||||
|
|||||||
@ -4,37 +4,38 @@
|
|||||||
#include <psp2/gxm.h>
|
#include <psp2/gxm.h>
|
||||||
#include <psp2/kernel/clib.h>
|
#include <psp2/kernel/clib.h>
|
||||||
|
|
||||||
#define SCE_ERR(func, ...) ({ \
|
#define SCE_ERR(func, ...) \
|
||||||
|
({ \
|
||||||
sceClibPrintf(#func "\n"); \
|
sceClibPrintf(#func "\n"); \
|
||||||
int __sce_err_ret_val = func(__VA_ARGS__); \
|
int __sce_err_ret_val = func(__VA_ARGS__); \
|
||||||
if (__sce_err_ret_val < 0) { \
|
if (__sce_err_ret_val < 0) { \
|
||||||
sceClibPrintf(#func " error: 0x%x\n", __sce_err_ret_val); \
|
sceClibPrintf(#func " error: 0x%x\n", __sce_err_ret_val); \
|
||||||
} \
|
} \
|
||||||
__sce_err_ret_val < 0; \
|
__sce_err_ret_val < 0; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define ALIGN(x, a) (((x) + ((a)-1)) & ~((a)-1))
|
#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
|
||||||
|
|
||||||
#define ALIGNMENT(n, a) (((a) - ((n) % (a))) % (a))
|
#define ALIGNMENT(n, a) (((a) - ((n) % (a))) % (a))
|
||||||
|
|
||||||
|
|
||||||
#define SET_UNIFORM(buffer, param, value) \
|
#define SET_UNIFORM(buffer, param, value) \
|
||||||
do { \
|
do { \
|
||||||
size_t __offset = sceGxmProgramParameterGetResourceIndex(param); \
|
size_t __offset = sceGxmProgramParameterGetResourceIndex(param); \
|
||||||
void* __dst = (uint8_t*)(buffer) + (__offset * sizeof(uint32_t)); \
|
void* __dst = (uint8_t*) (buffer) + (__offset * sizeof(uint32_t)); \
|
||||||
memcpy(__dst, reinterpret_cast<const void*>(&(value)), sizeof(value)); \
|
memcpy(__dst, reinterpret_cast<const void*>(&(value)), sizeof(value)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define GET_SHADER_PARAM(var, gxp, name, ret) \
|
#define GET_SHADER_PARAM(var, gxp, name, ret) \
|
||||||
const SceGxmProgramParameter* var = sceGxmProgramFindParameterByName(gxp, name); \
|
const SceGxmProgramParameter* var = sceGxmProgramFindParameterByName(gxp, name); \
|
||||||
if(!var) { \
|
if (!var) { \
|
||||||
SDL_Log("Failed to find param %s", name); \
|
SDL_Log("Failed to find param %s", name); \
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printMatrix4x4(const float mat[4][4]) {
|
static void printMatrix4x4(const float mat[4][4])
|
||||||
|
{
|
||||||
sceClibPrintf("mat4{\n");
|
sceClibPrintf("mat4{\n");
|
||||||
for(int i = 0; i < 4; i++) {
|
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]);
|
sceClibPrintf("%f %f %f %f\n", mat[i][0], mat[i][1], mat[i][2], mat[i][3]);
|
||||||
}
|
}
|
||||||
sceClibPrintf("}\n");
|
sceClibPrintf("}\n");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user