mirror of https://github.com/sm64pc/sm64pc.git
Add support for scissor rects, fixes dialogue boxes.
This commit is contained in:
parent
4707be3e91
commit
36dc3c2c87
|
@ -45,13 +45,23 @@
|
|||
|
||||
// Instance flags.
|
||||
#define RT64_INSTANCE_RASTER_BACKGROUND 0x1
|
||||
#define RT64_INSTANCE_DISABLE_BACKFACE_CULLING 0x2
|
||||
#define RT64_INSTANCE_RASTER_USE_SCISSOR_RECT 0x2
|
||||
#define RT64_INSTANCE_DISABLE_BACKFACE_CULLING 0x4
|
||||
|
||||
// Light flags.
|
||||
#define RT64_LIGHT_GROUP_MASK_ALL 0xFFFFFFFF
|
||||
#define RT64_LIGHT_GROUP_DEFAULT 0x1
|
||||
#define RT64_LIGHT_MAX_SAMPLES 128
|
||||
|
||||
// Forward declaration of types.
|
||||
typedef struct RT64_DEVICE RT64_DEVICE;
|
||||
typedef struct RT64_VIEW RT64_VIEW;
|
||||
typedef struct RT64_SCENE RT64_SCENE;
|
||||
typedef struct RT64_INSTANCE RT64_INSTANCE;
|
||||
typedef struct RT64_MESH RT64_MESH;
|
||||
typedef struct RT64_TEXTURE RT64_TEXTURE;
|
||||
typedef struct RT64_INSPECTOR RT64_INSPECTOR;
|
||||
|
||||
typedef struct {
|
||||
float x, y;
|
||||
} RT64_VECTOR2;
|
||||
|
@ -75,6 +85,10 @@ typedef struct {
|
|||
RT64_VECTOR4 inputs[4];
|
||||
} RT64_VERTEX;
|
||||
|
||||
typedef struct {
|
||||
int x, y, w, h;
|
||||
} RT64_RECT;
|
||||
|
||||
typedef struct {
|
||||
int filterMode;
|
||||
int diffuseTexIndex;
|
||||
|
@ -135,16 +149,17 @@ typedef struct {
|
|||
unsigned int giBounces;
|
||||
float ambGiMixWeight;
|
||||
bool denoiserEnabled;
|
||||
} RT64_VIEW_CONFIG;
|
||||
} RT64_VIEW_DESC;
|
||||
|
||||
// Forward declaration of types.
|
||||
typedef struct RT64_DEVICE RT64_DEVICE;
|
||||
typedef struct RT64_VIEW RT64_VIEW;
|
||||
typedef struct RT64_SCENE RT64_SCENE;
|
||||
typedef struct RT64_INSTANCE RT64_INSTANCE;
|
||||
typedef struct RT64_MESH RT64_MESH;
|
||||
typedef struct RT64_TEXTURE RT64_TEXTURE;
|
||||
typedef struct RT64_INSPECTOR RT64_INSPECTOR;
|
||||
typedef struct {
|
||||
RT64_MESH *mesh;
|
||||
RT64_MATRIX4 transform;
|
||||
RT64_TEXTURE *diffuseTexture;
|
||||
RT64_TEXTURE *normalTexture;
|
||||
RT64_MATERIAL material;
|
||||
RT64_RECT scissorRect;
|
||||
unsigned int flags;
|
||||
} RT64_INSTANCE_DESC;
|
||||
|
||||
inline void RT64_ApplyMaterialAttributes(RT64_MATERIAL *dst, RT64_MATERIAL *src) {
|
||||
if (src->enabledAttributes & RT64_ATTRIBUTE_IGNORE_NORMAL_FACTOR) {
|
||||
|
@ -206,7 +221,7 @@ typedef void(*DrawDevicePtr)(RT64_DEVICE* device, int vsyncInterval);
|
|||
typedef void(*DestroyDevicePtr)(RT64_DEVICE* device);
|
||||
typedef RT64_VIEW* (*CreateViewPtr)(RT64_SCENE* scenePtr);
|
||||
typedef void(*SetViewPerspectivePtr)(RT64_VIEW *viewPtr, RT64_MATRIX4 viewMatrix, float fovRadians, float nearDist, float farDist);
|
||||
typedef void(*SetViewConfigurationPtr)(RT64_VIEW *viewPtr, RT64_VIEW_CONFIG viewConfig);
|
||||
typedef void(*SetViewDescriptionPtr)(RT64_VIEW *viewPtr, RT64_VIEW_DESC viewDesc);
|
||||
typedef RT64_INSTANCE* (*GetViewRaytracedInstanceAtPtr)(RT64_VIEW *viewPtr, int x, int y);
|
||||
typedef void(*DestroyViewPtr)(RT64_VIEW* viewPtr);
|
||||
typedef RT64_SCENE* (*CreateScenePtr)(RT64_DEVICE* devicePtr);
|
||||
|
@ -216,7 +231,7 @@ typedef RT64_MESH* (*CreateMeshPtr)(RT64_DEVICE* devicePtr, int flags);
|
|||
typedef void (*SetMeshPtr)(RT64_MESH* meshPtr, RT64_VERTEX* vertexArray, int vertexCount, unsigned int* indexArray, int indexCount);
|
||||
typedef void (*DestroyMeshPtr)(RT64_MESH* meshPtr);
|
||||
typedef RT64_INSTANCE* (*CreateInstancePtr)(RT64_SCENE* scenePtr);
|
||||
typedef void (*SetInstancePtr)(RT64_INSTANCE* instancePtr, RT64_MESH* meshPtr, RT64_MATRIX4 transform, RT64_TEXTURE* diffuseTexture, RT64_TEXTURE* normalTexture, RT64_MATERIAL material, unsigned int flags);
|
||||
typedef void (*SetInstanceDescriptionPtr)(RT64_INSTANCE* instancePtr, RT64_INSTANCE_DESC instanceDesc);
|
||||
typedef void (*DestroyInstancePtr)(RT64_INSTANCE* instancePtr);
|
||||
typedef RT64_TEXTURE* (*CreateTextureFromRGBA8Ptr)(RT64_DEVICE* devicePtr, const void* bytes, int width, int height, int stride);
|
||||
typedef void(*DestroyTexturePtr)(RT64_TEXTURE* texture);
|
||||
|
@ -235,7 +250,7 @@ typedef struct {
|
|||
DestroyDevicePtr DestroyDevice;
|
||||
CreateViewPtr CreateView;
|
||||
SetViewPerspectivePtr SetViewPerspective;
|
||||
SetViewConfigurationPtr SetViewConfiguration;
|
||||
SetViewDescriptionPtr SetViewDescription;
|
||||
GetViewRaytracedInstanceAtPtr GetViewRaytracedInstanceAt;
|
||||
DestroyViewPtr DestroyView;
|
||||
CreateScenePtr CreateScene;
|
||||
|
@ -245,7 +260,7 @@ typedef struct {
|
|||
SetMeshPtr SetMesh;
|
||||
DestroyMeshPtr DestroyMesh;
|
||||
CreateInstancePtr CreateInstance;
|
||||
SetInstancePtr SetInstance;
|
||||
SetInstanceDescriptionPtr SetInstanceDescription;
|
||||
DestroyInstancePtr DestroyInstance;
|
||||
CreateTextureFromRGBA8Ptr CreateTextureFromRGBA8;
|
||||
DestroyTexturePtr DestroyTexture;
|
||||
|
@ -272,7 +287,7 @@ inline RT64_LIBRARY RT64_LoadLibrary() {
|
|||
lib.DestroyDevice = (DestroyDevicePtr)(GetProcAddress(lib.handle, "RT64_DestroyDevice"));
|
||||
lib.CreateView = (CreateViewPtr)(GetProcAddress(lib.handle, "RT64_CreateView"));
|
||||
lib.SetViewPerspective = (SetViewPerspectivePtr)(GetProcAddress(lib.handle, "RT64_SetViewPerspective"));
|
||||
lib.SetViewConfiguration = (SetViewConfigurationPtr)(GetProcAddress(lib.handle, "RT64_SetViewConfiguration"));
|
||||
lib.SetViewDescription = (SetViewDescriptionPtr)(GetProcAddress(lib.handle, "RT64_SetViewDescription"));
|
||||
lib.GetViewRaytracedInstanceAt = (GetViewRaytracedInstanceAtPtr)(GetProcAddress(lib.handle, "RT64_GetViewRaytracedInstanceAt"));
|
||||
lib.DestroyView = (DestroyViewPtr)(GetProcAddress(lib.handle, "RT64_DestroyView"));
|
||||
lib.CreateScene = (CreateScenePtr)(GetProcAddress(lib.handle, "RT64_CreateScene"));
|
||||
|
@ -282,7 +297,7 @@ inline RT64_LIBRARY RT64_LoadLibrary() {
|
|||
lib.SetMesh = (SetMeshPtr)(GetProcAddress(lib.handle, "RT64_SetMesh"));
|
||||
lib.DestroyMesh = (DestroyMeshPtr)(GetProcAddress(lib.handle, "RT64_DestroyMesh"));
|
||||
lib.CreateInstance = (CreateInstancePtr)(GetProcAddress(lib.handle, "RT64_CreateInstance"));
|
||||
lib.SetInstance = (SetInstancePtr)(GetProcAddress(lib.handle, "RT64_SetInstance"));
|
||||
lib.SetInstanceDescription = (SetInstanceDescriptionPtr)(GetProcAddress(lib.handle, "RT64_SetInstanceDescription"));
|
||||
lib.DestroyInstance = (DestroyInstancePtr)(GetProcAddress(lib.handle, "RT64_DestroyInstance"));
|
||||
lib.CreateTextureFromRGBA8 = (CreateTextureFromRGBA8Ptr)(GetProcAddress(lib.handle, "RT64_CreateTextureFromRGBA8"));
|
||||
lib.DestroyTexture = (DestroyTexturePtr)(GetProcAddress(lib.handle, "RT64_DestroyTexture"));
|
||||
|
|
|
@ -159,6 +159,7 @@ struct {
|
|||
ShaderProgram *shaderProgram;
|
||||
bool background;
|
||||
RT64_VECTOR3 fogColor;
|
||||
RT64_RECT scissorRect;
|
||||
int16_t fogMul;
|
||||
int16_t fogOffset;
|
||||
RecordedMod *graphNodeMod;
|
||||
|
@ -680,13 +681,13 @@ static void onkeyup(WPARAM w_param, LPARAM l_param) {
|
|||
}
|
||||
|
||||
void gfx_rt64_apply_config() {
|
||||
RT64_VIEW_CONFIG config;
|
||||
config.resolutionScale = configRT64ResScale / 100.0f;
|
||||
config.softLightSamples = configRT64SphereLights ? 1 : 0;
|
||||
config.giBounces = configRT64GI ? 1 : 0;
|
||||
config.ambGiMixWeight = configRT64GIStrength / 100.0f;
|
||||
config.denoiserEnabled = configRT64Denoiser;
|
||||
RT64.lib.SetViewConfiguration(RT64.view, config);
|
||||
RT64_VIEW_DESC desc;
|
||||
desc.resolutionScale = configRT64ResScale / 100.0f;
|
||||
desc.softLightSamples = configRT64SphereLights ? 1 : 0;
|
||||
desc.giBounces = configRT64GI ? 1 : 0;
|
||||
desc.ambGiMixWeight = configRT64GIStrength / 100.0f;
|
||||
desc.denoiserEnabled = configRT64Denoiser;
|
||||
RT64.lib.SetViewDescription(RT64.view, desc);
|
||||
}
|
||||
|
||||
LRESULT CALLBACK gfx_rt64_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
|
@ -846,6 +847,7 @@ static void gfx_rt64_wapi_init(const char *window_title) {
|
|||
RT64.dropNextFrame = false;
|
||||
|
||||
// Initialize other attributes.
|
||||
RT64.scissorRect = { 0, 0, 0, 0 };
|
||||
RT64.instanceCount = 0;
|
||||
RT64.instanceAllocCount = 0;
|
||||
RT64.geoLayoutStackSize = 0;
|
||||
|
@ -1120,9 +1122,11 @@ static void gfx_rt64_rapi_set_zmode_decal(bool zmode_decal) {
|
|||
}
|
||||
|
||||
static void gfx_rt64_rapi_set_viewport(int x, int y, int width, int height) {
|
||||
//printf("gfx_rt64_rapi_set_viewport %d %d %d %d\n", x, y, width, height);
|
||||
}
|
||||
|
||||
static void gfx_rt64_rapi_set_scissor(int x, int y, int width, int height) {
|
||||
RT64.scissorRect = { x, y, width, height };
|
||||
}
|
||||
|
||||
static void gfx_rt64_rapi_set_use_alpha(bool use_alpha) {
|
||||
|
@ -1353,8 +1357,6 @@ static void gfx_rt64_rapi_apply_mod(RT64_MATERIAL *material, RT64_TEXTURE **norm
|
|||
}
|
||||
|
||||
static void gfx_rt64_rapi_draw_triangles_common(RT64_MATRIX4 transform, float buf_vbo[], size_t buf_vbo_len, size_t buf_vbo_num_tris, bool double_sided, bool raytrace) {
|
||||
RT64_TEXTURE *diffuseMapTexture = RT64.blankTexture;
|
||||
RT64_TEXTURE *normalMapTexture = nullptr;
|
||||
RecordedMod *textureMod = nullptr;
|
||||
bool linearFilter = false;
|
||||
uint32_t cms = 0, cmt = 0;
|
||||
|
@ -1362,6 +1364,13 @@ static void gfx_rt64_rapi_draw_triangles_common(RT64_MATRIX4 transform, float bu
|
|||
// Create the instance.
|
||||
RT64_INSTANCE *instance = gfx_rt64_rapi_add_instance();
|
||||
|
||||
// Describe the instance.
|
||||
RT64_INSTANCE_DESC instDesc;
|
||||
instDesc.transform = transform;
|
||||
instDesc.diffuseTexture = RT64.blankTexture;
|
||||
instDesc.normalTexture = nullptr;
|
||||
instDesc.scissorRect = RT64.scissorRect;
|
||||
|
||||
// Find all parameters associated to the texture if it's used.
|
||||
bool highlightMaterial = false;
|
||||
if (RT64.shaderProgram->used_textures[0]) {
|
||||
|
@ -1371,7 +1380,7 @@ static void gfx_rt64_rapi_draw_triangles_common(RT64_MATRIX4 transform, float bu
|
|||
cmt = recordedTexture.cmt;
|
||||
|
||||
if (recordedTexture.texture != nullptr) {
|
||||
diffuseMapTexture = recordedTexture.texture;
|
||||
instDesc.diffuseTexture = recordedTexture.texture;
|
||||
}
|
||||
|
||||
auto texModIt = RT64.texMods.find(recordedTexture.hash);
|
||||
|
@ -1388,36 +1397,39 @@ static void gfx_rt64_rapi_draw_triangles_common(RT64_MATRIX4 transform, float bu
|
|||
}
|
||||
|
||||
// Build material with applied mods.
|
||||
RT64_MATERIAL material = gfx_rt64_rapi_build_material(RT64.shaderProgram, linearFilter, cms, cmt);
|
||||
instDesc.material = gfx_rt64_rapi_build_material(RT64.shaderProgram, linearFilter, cms, cmt);
|
||||
if (RT64.graphNodeMod != nullptr) {
|
||||
gfx_rt64_rapi_apply_mod(&material, &normalMapTexture, RT64.graphNodeMod, transform);
|
||||
gfx_rt64_rapi_apply_mod(&instDesc.material, &instDesc.normalTexture, RT64.graphNodeMod, transform);
|
||||
}
|
||||
|
||||
if (textureMod != nullptr) {
|
||||
gfx_rt64_rapi_apply_mod(&material, &normalMapTexture, textureMod, transform);
|
||||
gfx_rt64_rapi_apply_mod(&instDesc.material, &instDesc.normalTexture, textureMod, transform);
|
||||
}
|
||||
|
||||
if (highlightMaterial) {
|
||||
material.diffuseColorMix = { 1.0f, 0.0f, 1.0f, 0.5f };
|
||||
material.selfLight = { 1.0f, 1.0f, 1.0f };
|
||||
material.lightGroupMaskBits = 0;
|
||||
instDesc.material.diffuseColorMix = { 1.0f, 0.0f, 1.0f, 0.5f };
|
||||
instDesc.material.selfLight = { 1.0f, 1.0f, 1.0f };
|
||||
instDesc.material.lightGroupMaskBits = 0;
|
||||
}
|
||||
|
||||
// Process the mesh that corresponds to the VBO.
|
||||
RT64_MESH *mesh = gfx_rt64_rapi_process_mesh(buf_vbo, buf_vbo_len, buf_vbo_num_tris, raytrace);
|
||||
instDesc.mesh = gfx_rt64_rapi_process_mesh(buf_vbo, buf_vbo_len, buf_vbo_num_tris, raytrace);
|
||||
|
||||
// Mark the right instance flags.
|
||||
unsigned int instanceFlags = 0;
|
||||
instDesc.flags = 0;
|
||||
if (RT64.background) {
|
||||
instanceFlags |= RT64_INSTANCE_RASTER_BACKGROUND;
|
||||
instDesc.flags |= RT64_INSTANCE_RASTER_BACKGROUND;
|
||||
}
|
||||
|
||||
if (double_sided) {
|
||||
instanceFlags |= RT64_INSTANCE_DISABLE_BACKFACE_CULLING;
|
||||
instDesc.flags |= RT64_INSTANCE_DISABLE_BACKFACE_CULLING;
|
||||
}
|
||||
|
||||
// Update the instance.
|
||||
RT64.lib.SetInstance(instance, mesh, transform, diffuseMapTexture, normalMapTexture, material, instanceFlags);
|
||||
if (!raytrace) {
|
||||
instDesc.flags |= RT64_INSTANCE_RASTER_USE_SCISSOR_RECT;
|
||||
}
|
||||
|
||||
RT64.lib.SetInstanceDescription(instance, instDesc);
|
||||
}
|
||||
|
||||
void gfx_rt64_rapi_set_fog(uint8_t fog_r, uint8_t fog_g, uint8_t fog_b, int16_t fog_mul, int16_t fog_offset) {
|
||||
|
|
Loading…
Reference in New Issue