1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-06-07 17:11:50 +00:00

Introduce TEX_LEN macro for texture arrays lengths (#2541)

This commit is contained in:
Dragorn421 2025-05-25 18:33:24 +02:00 committed by GitHub
parent b44ff69ded
commit eeeaa77d3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 4 deletions

14
include/tex_len.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef TEX_LEN_H
#define TEX_LEN_H
/**
* Compute a length for an array holding a texture.
* `type` is the array's element type.
* `width`, `height` are the texture dimensions.
* `bpp` is the texture's pixel size, in bits per pixels.
* The calculation computes the size of the texture in bits `width * height * bpp`,
* then divides by 8 to get the size in bytes, then divides by the element type size.
*/
#define TEX_LEN(type, width, height, bpp) ((width) * (height) * (bpp) / 8 / sizeof(type))
#endif

View file

@ -275,12 +275,19 @@ class TextureResource(Resource):
self.width_name = f"{self.symbol_name}_WIDTH" self.width_name = f"{self.symbol_name}_WIDTH"
self.height_name = f"{self.symbol_name}_HEIGHT" self.height_name = f"{self.symbol_name}_HEIGHT"
def check_declare_length(self):
return (
hasattr(self, "HACK_IS_STATIC_ON") or EXPLICIT_DL_AND_TEX_SIZES
) and not self.is_tlut()
def get_c_declaration_base(self): def get_c_declaration_base(self):
if hasattr(self, "HACK_IS_STATIC_ON") and self.is_tlut(): if hasattr(self, "HACK_IS_STATIC_ON") and self.is_tlut():
raise NotImplementedError raise NotImplementedError
if hasattr(self, "HACK_IS_STATIC_ON") or EXPLICIT_DL_AND_TEX_SIZES: if self.check_declare_length():
if not self.is_tlut(): return (
return f"{self.elem_type} {self.symbol_name}[{self.height_name} * {self.width_name} * {self.siz.bpp} / 8 / sizeof({self.elem_type})]" f"{self.elem_type} {self.symbol_name}"
f"[TEX_LEN({self.elem_type}, {self.width_name}, {self.height_name}, {self.siz.bpp})]"
)
return f"{self.elem_type} {self.symbol_name}[]" return f"{self.elem_type} {self.symbol_name}[]"
def get_c_reference(self, resource_offset: int): def get_c_reference(self, resource_offset: int):
@ -518,7 +525,10 @@ class TextureResource(Resource):
super().write_c_declaration(h) super().write_c_declaration(h)
def get_h_includes(self): def get_h_includes(self):
return ("ultra64.h",) return (
"ultra64.h",
*(("tex_len.h",) if self.check_declare_length() else ()),
)
@reprlib.recursive_repr() @reprlib.recursive_repr()
def __repr__(self): def __repr__(self):