mirror of
https://github.com/switchbrew/libnx.git
synced 2025-07-04 10:32:15 +02:00
Added VnViewport
This commit is contained in:
parent
5083c015cd
commit
ad473cce01
@ -62,6 +62,7 @@ extern "C" {
|
||||
#include "switch/nvidia/channel.h"
|
||||
#include "switch/nvidia/info.h"
|
||||
#include "switch/nvidia/fence.h"
|
||||
#include "switch/nvidia/rect.h"
|
||||
#include "switch/nvidia/gpu/cmd_list.h"
|
||||
#include "switch/nvidia/gpu/gpfifo.h"
|
||||
#include "switch/nvidia/gpu/zcull_ctx.h"
|
||||
@ -73,6 +74,7 @@ extern "C" {
|
||||
#include "switch/nvidia/cmds/3d.h"
|
||||
#include "switch/nvidia/cmds/3d_init.h"
|
||||
#include "switch/nvidia/cmds/3d_rendertarget.h"
|
||||
#include "switch/nvidia/cmds/3d_viewport.h"
|
||||
#include "switch/nvidia/cmds/3d_clear.h"
|
||||
|
||||
#include "switch/runtime/env.h"
|
||||
|
38
nx/include/switch/nvidia/cmds/3d_viewport.h
Normal file
38
nx/include/switch/nvidia/cmds/3d_viewport.h
Normal file
@ -0,0 +1,38 @@
|
||||
typedef struct {
|
||||
float scale[3];
|
||||
float translate[3];
|
||||
u16_rect window;
|
||||
float near;
|
||||
float far;
|
||||
} VnViewportConfig;
|
||||
|
||||
static inline void vnViewportSetScale(VnViewportConfig* c, float x, float y, float z) {
|
||||
c->scale[0] = x;
|
||||
c->scale[1] = y;
|
||||
c->scale[2] = z;
|
||||
}
|
||||
|
||||
static inline void vnViewportSetTranslate(VnViewportConfig* c, float x, float y, float z) {
|
||||
c->translate[0] = x;
|
||||
c->translate[1] = y;
|
||||
c->translate[2] = z;
|
||||
}
|
||||
|
||||
static inline void vnViewportSetWindow(VnViewportConfig* c, u16_rect r) {
|
||||
c->window = r;
|
||||
}
|
||||
|
||||
static inline void vnViewportSetDepth(VnViewportConfig* c, float near, float far) {
|
||||
c->near = near;
|
||||
c->far = far;
|
||||
}
|
||||
|
||||
static inline void vnViewportSetDefaults(VnViewportConfig* c) {
|
||||
vnViewportSetScale(c, 0.5, 0.5, 0.5);
|
||||
vnViewportSetTranslate(c, 0.5, 0.5, 0.5);
|
||||
vnViewportSetWindow(c, (u16_rect) { 0, 0, 0xFFFF, 0xFFFF });
|
||||
vnViewportSetDepth(c, 0, 0); //?
|
||||
}
|
||||
|
||||
void vnSetViewport(Vn* vn, size_t index, VnViewportConfig* c);
|
||||
|
12
nx/include/switch/nvidia/rect.h
Normal file
12
nx/include/switch/nvidia/rect.h
Normal file
@ -0,0 +1,12 @@
|
||||
#define MAKE_RECT(type) \
|
||||
typedef struct { \
|
||||
type x; \
|
||||
type y; \
|
||||
type w; \
|
||||
type h; \
|
||||
} type##_rect;
|
||||
|
||||
MAKE_RECT(u16);
|
||||
MAKE_RECT(u32);
|
||||
MAKE_RECT(float);
|
||||
MAKE_RECT(double);
|
28
nx/source/nvidia/cmds/3d_viewport.c
Normal file
28
nx/source/nvidia/cmds/3d_viewport.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <switch.h>
|
||||
#include <string.h>
|
||||
|
||||
void vnSetViewport(Vn* vn, size_t index, VnViewportConfig* c) {
|
||||
VnCmd(
|
||||
vn,
|
||||
NvIncr(
|
||||
0,
|
||||
NvReg3D_ViewportScaleX(index),
|
||||
c->scale[0], // ScaleX
|
||||
c->scale[1], // ScaleY
|
||||
c->scale[2], // ScaleZ
|
||||
c->translate[0], // TranslateX
|
||||
c->translate[1], // TranslateY
|
||||
c->translate[2], // TranslateZ
|
||||
0, // Swizzles
|
||||
0 // SubpixelPrecisionBias
|
||||
),
|
||||
NvIncr(
|
||||
0,
|
||||
NvReg3D_ViewportHorizontal(index),
|
||||
(c->window.w << 16) | c->window.x,
|
||||
(c->window.h << 16) | c->window.y,
|
||||
c->near,
|
||||
c->far
|
||||
)
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user