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:
parent
b44ff69ded
commit
eeeaa77d3f
2 changed files with 28 additions and 4 deletions
14
include/tex_len.h
Normal file
14
include/tex_len.h
Normal 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
|
|
@ -275,12 +275,19 @@ class TextureResource(Resource):
|
|||
self.width_name = f"{self.symbol_name}_WIDTH"
|
||||
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):
|
||||
if hasattr(self, "HACK_IS_STATIC_ON") and self.is_tlut():
|
||||
raise NotImplementedError
|
||||
if hasattr(self, "HACK_IS_STATIC_ON") or EXPLICIT_DL_AND_TEX_SIZES:
|
||||
if not self.is_tlut():
|
||||
return f"{self.elem_type} {self.symbol_name}[{self.height_name} * {self.width_name} * {self.siz.bpp} / 8 / sizeof({self.elem_type})]"
|
||||
if self.check_declare_length():
|
||||
return (
|
||||
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}[]"
|
||||
|
||||
def get_c_reference(self, resource_offset: int):
|
||||
|
@ -518,7 +525,10 @@ class TextureResource(Resource):
|
|||
super().write_c_declaration(h)
|
||||
|
||||
def get_h_includes(self):
|
||||
return ("ultra64.h",)
|
||||
return (
|
||||
"ultra64.h",
|
||||
*(("tex_len.h",) if self.check_declare_length() else ()),
|
||||
)
|
||||
|
||||
@reprlib.recursive_repr()
|
||||
def __repr__(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue