Files
mtgodot-poc/extension/src/platform/EterLib/RenderCommands3D.h
T
2026-09-27 19:44:41 -07:00

100 lines
4.4 KiB
C++

#pragma once
#include <cstdint>
#include <string>
#include <vector>
// The 3D draw calls the ported game render (CPythonApplication::RenderGame) issues through
// CStateManager, recorded by the platform's IDirect3DDevice8 (RecordingDevice.cpp) and consumed by
// Godot. Like UIRenderCommands.h this header stays free of D3D and godot-cpp types.
//
// Matrices are D3D8's row-vector layout (translation in elements 12..14), exactly as 40250 set them.
struct Render3DDraw {
// Stable source-buffer identity and content version. Zero key means an immediate-mode draw
// without a reusable D3D buffer. Geometry may be reused only while both values match.
std::uint64_t geometry_key = 0;
std::uint64_t geometry_revision = 0;
float world[16];
float view[16];
float proj[16];
float viewport[4] = {}; // x, y, width, height
// Stage 0/1 textures, named like UIRenderTextureName: the pack path of a file texture or
// "mem:<id>@<revision>"; empty when the stage has no texture.
std::string texture0;
std::string texture1;
// The referenced vertices, rebased so indices start at 0. normals/uv0/uv1/diffuse are empty when
// the vertex format has no such element. pretransformed: D3DFVF_XYZRHW (screen-space x, y, z, rhw
// in positions + rhw).
bool pretransformed = false;
std::vector<float> positions; // x, y, z
std::vector<float> rhw;
std::vector<float> normals; // x, y, z
std::vector<float> uv0; // u, v
std::vector<float> uv1; // u, v
std::vector<std::uint32_t> diffuse; // 0xAARRGGBB
std::vector<std::uint32_t> indices; // triangle list (strips and fans are expanded), or line list
std::vector<std::uint8_t> bone_indices; // 4 uint8 per vertex (mesh-local bone palette index)
std::vector<float> bone_weights; // 4 floats per vertex
std::vector<float> bone_matrices; // 16 floats per bone in the mesh's palette (D3D row-vector layout)
bool lines = false;
// D3DRS_* / D3DTSS_* values in effect for the draw.
std::uint32_t alpha_blend = 0, src_blend = 0, dest_blend = 0;
std::uint32_t alpha_test = 0, alpha_ref = 0, alpha_func = 0;
std::uint32_t cull_mode = 0, z_enable = 0, z_write = 0, z_func = 0;
std::uint32_t lighting = 0, texture_factor = 0, fog_enable = 0;
std::uint32_t fog_color = 0, fog_vertex_mode = 0, fog_table_mode = 0, fog_range_enable = 0;
float fog_start = 0, fog_end = 0, fog_density = 0;
std::uint32_t color_op[2] = {}, color_arg1[2] = {}, color_arg2[2] = {};
std::uint32_t alpha_op[2] = {}, alpha_arg1[2] = {}, alpha_arg2[2] = {};
std::uint32_t address_u[2] = {}, address_v[2] = {};
std::uint32_t min_filter[2] = {}, mag_filter[2] = {}, mip_filter[2] = {};
// D3DMATERIAL8 diffuse/ambient/emissive (r, g, b, a) and light 0 when enabled.
float material_diffuse[4] = {1, 1, 1, 1};
float material_ambient[4] = {};
float material_emissive[4] = {};
bool light0 = false;
float light0_direction[3] = {};
float light0_diffuse[4] = {};
float light0_ambient[4] = {};
std::uint32_t ambient = 0; // D3DRS_AMBIENT
struct Light {
std::uint32_t type = 0; // zero when disabled; D3DLIGHT_POINT/SPOT/DIRECTIONAL otherwise
float position[3] = {};
float direction[3] = {};
float diffuse[4] = {};
float ambient[4] = {};
float attenuation[3] = {};
float range = 0;
float theta = 0, phi = 0, falloff = 0;
} lights[2];
std::uint32_t diffuse_material_source = 0;
std::uint32_t ambient_material_source = 0;
std::uint32_t color_vertex = 0;
};
struct GpuSkinSubrangeView {
std::uint64_t source_mesh_key = 0;
std::uint32_t mesh_base_vertex = 0;
std::uint32_t mesh_vertex_count = 0;
const std::uint8_t* bone_indices = nullptr; // mesh_vertex_count * 4
const float* bone_weights = nullptr; // mesh_vertex_count * 4
const float* bone_matrices = nullptr; // bone_count * 16
std::uint32_t bone_count = 0;
};
void SetNativeTerrainRenderEnabled(bool enabled);
bool IsNativeTerrainRenderEnabled();
void SetGpuSkinningEnabled(bool enabled);
bool IsGpuSkinningEnabled();
bool LookupGpuSkinSubrange(const void* vertex_buffer_base, std::uint32_t stride,
std::uint32_t lo_vertex, std::uint32_t hi_vertex,
GpuSkinSubrangeView* out_view);
void Render3DBeginFrame();
void Render3DAdd(Render3DDraw draw);
const std::vector<Render3DDraw>& Render3DDraws();