Commit Graph

41 Commits

Author SHA1 Message Date
Antonio Niño Díaz
dce5e99f0f library: Optimize copy of NE_RGB5 textures to VRAM
This is the same optimization made by asie here:

479ca8fb77
2024-06-05 02:28:40 +01:00
Antonio Niño Díaz
82171bbf69 chore: Simplify copyright years in notices
Instead of listing every individual year, keep only the first and last
years.
2024-03-09 01:42:29 +00:00
Antonio Niño Díaz
30ac9ab8e9 library: Don't expect palette objects when loading GRF files
Currently, if the user wants to load a GRF file with a palette, the
function NE_MaterialTexLoadGRF() will fail unless it is provided a palette
object.

With this change, if a palette object isn't provided, it will be created
and marked for automatic deletion when the material is deleted.
2024-03-06 22:17:49 +00:00
Antonio Niño Díaz
951f0f87ca library: Support autodeleting palettes
In many cases the developer doesn't want to keep track of palettes and
materials as two different objects. This is only required if a palette
needs to be shared between multiple materials.

In cases where there a palette is only used by one material, this new
function can be used so that the developer doesn't need to keep track of
the palette object, only the material.
2024-03-02 12:42:31 +00:00
Antonio Niño Díaz
e7fc9f8203 library: Silence warnings of unused variables 2024-03-02 12:42:08 +00:00
Antonio Niño Díaz
25fc0bcff3 library: Update usage of GRF libnds functions 2024-02-15 17:49:50 +00:00
Antonio Niño Díaz
83dd805fe8 examples: library: docs: Fix "properties" typo everywhere
Function names have also been changed, but this patch adds defines to
preserve compatibility with old names for the time being.
2024-02-05 01:45:14 +00:00
Antonio Niño Díaz
488f5c7d8f library: Small style fixes 2024-01-27 19:34:15 +00:00
Antonio Niño Díaz
8e6d64d2d9 library: Disable GRF loading function outside of BlocksDS
This isn't supported in devkitPro.
2024-01-25 18:28:07 +00:00
Antonio Niño Díaz
640d2441f6 library: Add helper to load textures in GRF format 2024-01-25 02:42:38 +00:00
Antonio Niño Díaz
a57af044f4 library: Make some pointers void and const
It doesn't make sense to use other types because the modified functions
treat the data as a constant binary blob.
2024-01-22 02:26:57 +00:00
Antonio Niño Díaz
65b4eb55a3 library: Add alternate functions to load Texel 4x4 textures
They can be used to load textures where the 3 chunks are stored as
different files.
2024-01-21 17:00:12 +00:00
Antonio Niño Díaz
6fde18d712 library: examples: Use stdint.h types 2023-11-17 01:00:40 +01:00
Antonio Niño Díaz
e1662b7357 library: Refactor library initialization state handling
Now that there are 4 different possibilities (not initialized, single
screen 3D mode, dual 3D mode, safe dual 3D mode) it is better to have an
enum instead of multiple bools.
2023-10-09 01:32:06 +01:00
Antonio Niño Díaz
f57fa76576 library: Handle failures correctly
The previous code relied too much on assertions, even for things that
are just regular things that may happen while the application is running
(like running out of memory).

- Many assertions have been turned into permanent checks
- Some functions now return "success" or "failure".
- NE_Init3D() and NE_InitDual3D() (and others) have been reworked to
  handle failures gracefully.
2023-04-21 18:19:02 +01:00
Antonio Niño Díaz
9f6c719373 library: Decouple meshes from models
Until now, a mesh was always owned by one single model. This made it
very difficult to clone models, because the mesh was always owned by one
of them. Whenever you deleted that model, the mesh was also deleted, and
all the cloned models would be unusable.

With the new system, there is a list of meshes with counters of how many
models use them. This way no matter how many models use the mesh, the
mesh will only be deleted when the last model is deleted.

In addition, in a similar way as before, a mesh has a flag that signals
if free() has to be called on the mesh data when the mesh is deleted.
This is useful when the mesh is loaded from a filesystem and stored in a
buffer allocated with malloc(), which is what Nitro Engine does.

Note that this code should be considered experimental for the time
being, until some tests are added.
2022-11-18 01:23:57 +00:00
Antonio Niño Díaz
bc2a564f77 library: Assign palettes to materials instead of textures
Previously it wasn't possible to load one texture to a material, clone the
material, and assign different palettes to each clone of the material.

With this change, it is possible to have the same texture with different
palettes.
2022-11-05 01:22:53 +01:00
Antonio Niño Díaz
9651dbd032 library: Fix typos 2022-10-31 02:10:57 +00:00
Antonio Niño Díaz
1da7ff399c library: Support compressed textures 2022-10-31 02:05:01 +00:00
Antonio Niño Díaz
2ced018926 library: Cleanup palette loading functions 2022-10-31 01:40:45 +00:00
Antonio Niño Díaz
8aa6b382d2 library: examples: Simplify texture loading code
This is done to make it easier to implement compressed texture loading.

The main change is to stop allowing widths that aren't a power of two:

- Supporting them complicates the loading code a lot.

- Compressed textures can't really be expanded because they are composed
  by many 4x4 sub-images.

- They don't save space in VRAM.

- They save space in the final ROM, but you can achieve the same effect
  compressing them with LZSS compression, for example.

The example incomplete_texture has been updated to reflect the new
limitations.
2022-10-29 02:13:21 +01:00
Antonio Niño Díaz
68588dd2fa Library: Don't set texture index to 0 on failure
It should be kept as NE_NO_TEXTURE.
2022-10-29 01:33:52 +01:00
Antonio Niño Díaz
f031319694 library: Refactor VRAM locking in texture init code 2022-10-29 01:33:10 +01:00
Antonio Niño Díaz
96e7948970 library: Fail on release builds when textures can't be loaded 2022-10-29 01:32:23 +01:00
Antonio Niño Díaz
f3f4af0daf library: Refactor allocator
Remove support for asking for a specific alignment. Now, the only
supported alignment is 16 bytes, and all sizes are rounded up to 16
bytes. This is the minimum alignment needed for some palettes, which is
the most restrictive case.

This change is a bit wasteful, but it only really matters for 4-color
palettes and textures, which can be aligned to 8 bytes, and it isn't a
problem because:

- 4-color palettes, which can be aligned to 8 bytes, would rarely use
  fewer than 4 colors. Even if they do use fewer than 4 colors, it would
  only waste 8 bytes.

- Textures: It's impossible that a texture doesn't have a size that is
  multiple of 16. It can only happen if the texture has a width of 8
  pixels and a height that isn't a multiple of two... which is a very
  unusual situation.

The benefit of this change is that the code is much easier to understand
and much more maintainable, which will be needed when support for
compressed textures is added, as the code will need to support more
features.
2022-10-27 01:14:40 +01:00
Antonio Niño Díaz
406364d3db library: Simplify internal handling of material properties 2022-10-26 21:30:41 +01:00
Antonio Niño Díaz
b3440e9526 library: Rename some functions for consistency
NE_MaterialClone() clones everything, not just the texture.

NE_MaterialSetPalette() sets the palette of the material, not the
palette of the texture (different materials may use the same texture but
different palettes.
2022-10-25 23:45:03 +01:00
Antonio Niño Díaz
ae650b6bab library: Copy all material with NE_MaterialTexClone()
Previously it only copied the texture, not the material properties or
the palette.
2022-10-25 23:43:20 +01:00
Antonio Niño Díaz
17f026bb8f library: Make many function parameters const
This helps the compiler issue warning if there is some logical error in
the code, and it helps the developer realize if some assumption with
the code is wrong.
2022-10-20 22:36:58 +01:00
Antonio Niño Díaz
3ebcac15ba library: examples: Add enums for texture formats and parameters
This helps discover the possible options.
2022-10-20 01:51:19 +01:00
Antonio Niño Díaz
ccc8a67caf library: Cleanup the final source files 2022-10-16 13:55:06 +01:00
Antonio Niño Díaz
fd95ee34fe Replace malloc() by calloc() where it makes sense
If the memory is going to be cleared right away it is better to use
calloc(), as it does it automatically.
2019-06-10 17:17:08 +01:00
Antonio Niño Díaz
029587a061 Clean code style of texture subsystem 2019-06-10 00:56:10 +01:00
Antonio Niño Díaz
976cf4d4c6 Simplify NE_DebugPrint messages
The function name is now part of the macro.
2019-06-05 14:19:04 +01:00
Antonio Niño Díaz
a9ae923fff Simplify NE_Assert messages
The function name is now part of the macro.
2019-06-05 14:06:10 +01:00
Antonio Niño Díaz
700971beef Simplify NE_AssertPointer messages
Now the name of the function is added as part of the macro.
2019-06-05 13:41:35 +01:00
Antonio Niño Díaz
68d90b44c9 Remove occurrences of inline keyword
Let the compiler decide about it.
2019-06-04 18:24:22 +01:00
Antonio Niño Díaz
51bacc1648 Fix compilation errors and warnings
Now the library can be compiled again.
2019-06-04 15:41:51 +01:00
Antonio Niño Díaz
5be032ed44 Fix coding style of library
With a bit of help of `indent -linux`, but mostly by hand. Also used
`iconv -f ISO-8859-1 -t UTF-8//TRANSLIT` to convert to UTF-8.

There is still some refactoring left to do.
2019-06-04 01:02:56 +01:00
Antonio Niño Díaz
8f8bf4d249 Run dos2unix on library source files 2019-05-30 18:45:00 +01:00
Antonio Niño Díaz
f042d0be3e
Initial dump of code of v0.6.1
This commit is a simple dump of the files of [1]. This needs to undergo
some reorganization.

[1] http://www.skylyrac.net/old-site/nitroengine.html
2019-05-29 01:01:57 +01:00