void C3D_ImmSendAttrib(float x, float y, float z, float w) { union { u32 packed[3]; struct { u8 x[3]; u8 y[3]; u8 z[3]; u8 w[3]; }; } param; // Convert the values to float24 write24(param.x, f32tof24(x)); write24(param.y, f32tof24(y)); write24(param.z, f32tof24(z)); write24(param.w, f32tof24(w)); // Reverse the packed words u32 p = param.packed[0]; param.packed[0] = param.packed[2]; param.packed[2] = p; // Send the attribute GPUCMD_AddIncrementalWrites(GPUREG_FIXEDATTRIB_DATA0, param.packed, 3); }
void draw(void) { // WARNING: DO **NOT** USE ANY C3D STUFF, ESPECIALLY NOTHING EFFECT RELATED! // FIXME: Enable alpha blend for 50% mixing with BG GPUCMD_AddWrite(GPUREG_BLEND_COLOR, color_blend ? 0x7F7F7F7F : 0x00000000); GPUCMD_AddWrite(GPUREG_BLEND_FUNC, (GPU_BLEND_ADD << 0) | (GPU_BLEND_ADD << 8) | (GPU_ONE_MINUS_CONSTANT_COLOR << 16) | (GPU_CONSTANT_COLOR << 20) | (GPU_ONE_MINUS_CONSTANT_ALPHA << 24) | (GPU_CONSTANT_ALPHA << 28)); GPUCMD_AddWrite(GPUREG_COLOR_OPERATION, (0x0E4 << 24) | (1 << 8)); uint32_t compare_mode = test_high ? GPU_GREATER : GPU_LESS; // Set color and depth mask + depth test { uint32_t mask_reg = (depth_mask ? 1 << 12 : 0) | ((color_mask & 0xF) << 8); GPUCMD_AddWrite(GPUREG_DEPTH_COLOR_MASK, mask_reg | ((compare_mode & 7) << 4) | (!!depth_test)); } // Set stencil mask + stencil test { uint32_t buffer_mask = stencil_mask ? 0x2A : 0x00; // Mask used for buffer write uint32_t mask = 0xFF; // Mask for comparison uint32_t ref = 0x80; GPUCMD_AddWrite(GPUREG_STENCIL_TEST, ((mask & 0xFF) << 24) | ((ref & 0xFF) << 16) | ((buffer_mask & 0xFF) << 8) | ((compare_mode & 7) << 4) | (!!stencil_test)); //0-2 unsigned, Fail operation //4-6 unsigned, Z-fail operation //8-10 unsigned, Z-pass operation GPUCMD_AddWrite(GPUREG_STENCIL_OP, (GPU_STENCIL_INVERT << 8) | (GPU_STENCIL_INVERT << 4) | (GPU_STENCIL_KEEP << 0)); } // Allow functions.. GPUCMD_AddWrite(GPUREG_DEPTHBUFFER_READ, (depth_read_allow ? 2 : 0) | (stencil_read_allow ? 1 : 0)); GPUCMD_AddWrite(GPUREG_DEPTHBUFFER_WRITE, (depth_write_allow ? 2 : 0) | (stencil_write_allow ? 1 : 0)); GPUCMD_AddWrite(GPUREG_COLORBUFFER_READ, color_read_allow); GPUCMD_AddWrite(GPUREG_COLORBUFFER_WRITE, color_write_allow); // Configure depth values (= will always return 0.5) bool w_buffer = true; float depth_scale = -1.0f; float depth_offset = 0.0f; #if 1 GPUCMD_AddWrite(GPUREG_DEPTHMAP_ENABLE, w_buffer ? 0x00000000 : 0x00000001); GPUCMD_AddWrite(GPUREG_DEPTHMAP_SCALE, f32tof24(depth_scale)); GPUCMD_AddWrite(GPUREG_DEPTHMAP_OFFSET, f32tof24(depth_offset)); #endif // Draw the VBO C3D_DrawArrays(GPU_TRIANGLES, 0, 3); }