Commit Graph

465 Commits

Author SHA1 Message Date
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
f4b5e8a24e tests: Add test for cloned textures 2022-11-17 01:37:08 +00:00
Antonio Niño Díaz
2ab65d19d4 examples: Clean both examples that show 16 balls 2022-11-15 00:12:08 +00:00
Antonio Niño Díaz
b40edbebd3 library: Add function to make Nitro Engine free meshes
This is a way to let Nitro Engine know that it owns the buffer of the
mesh, and that it has to be freed with free().
2022-11-15 00:01:50 +00:00
Antonio Niño Díaz
e557225cce examples: Fix some main() function prototypes 2022-11-15 00:00:51 +00:00
Antonio Niño Díaz
57fccc3ec7 docs: Update Doxyfile
It has been done by simply running:

    cd documentation
    doxygen -u
2022-11-10 01:33:51 +00:00
Antonio Niño Díaz
d9ee26be4a library: docs: Update version number to 0.8.1 2022-11-10 01:31:00 +00:00
Antonio Niño Díaz
2e9ff26e6d examples: Add note to NFlib example 2022-11-10 01:30:01 +00:00
Antonio Niño Díaz
008af50119 docs: Update changelog 2022-11-10 01:27:58 +00:00
Antonio Niño Díaz
20682a18e0 examples: Add precompiled NFlib archive
Yes, this is a bad idea, but there is no other way to easily build all
examples in one go. I will eventually improve the organization of this
example so that this step is done automatically during the build.
2022-11-09 23:01:07 +00:00
Antonio Niño Díaz
bb04ea86a5 examples: docs: Add example of NFlib and NE integration
https://github.com/knightfox75/nds_nflib
2022-11-09 01:56:22 +00:00
Antonio Niño Díaz
72dca60154 library: Fix return code of function
Return the right code when there is an error.
2022-11-09 01:48:49 +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
7b9b119f73 examples: Add example of loading compressed textures 2022-10-31 02:18:02 +00: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
6e53a01d83 library: tests: Add function to search free space within a range
This is needed to load compressed textures, as it is needed to look for
empty space in two banks at the same time.
2022-10-29 14:10:35 +01: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
452f953bc8 docs: Add changelog
This contains all history, obtained from the following links:

- http://www.skylyrac.net/old-site/nitroengine.html

- https://github.com/AntonioND/nitro-engine/releases
2022-10-28 02:22:48 +01:00
Antonio Niño Díaz
22499c5ee5 library: Fix debug message and some comments 2022-10-28 02:05:24 +01:00
Antonio Niño Díaz
2affbe2c18 library: Simplify mesh handling for models
Instead of having two different flags to mean that the mesh needs to be
freed by Nitro Engine, use just one.
2022-10-28 01:59:00 +01:00
Antonio Niño Díaz
73787ec488 tests: Add one more allocation test 2022-10-28 01:29:21 +01:00
Antonio Niño Díaz
50ae7c30da tests: Test new function to allocate at specific addresses 2022-10-28 01:13:20 +01:00
Antonio Niño Díaz
307d6f87e3 test: Make allocator test use the debug version of the library 2022-10-28 01:13:01 +01:00
Antonio Niño Díaz
63a74c71f2 library: Support allocating chunks at specified addresses 2022-10-28 01:12:42 +01:00
Antonio Niño Díaz
8d512b55f6 library: Extract common code in allocation functions 2022-10-27 23:16:49 +01:00
Antonio Niño Díaz
3b09697a91 library: tests: Add function to allocate from end of pool
Add tests for it.
2022-10-27 23:07:28 +01:00
Antonio Niño Díaz
4ec6488068 library: Add comment 2022-10-27 01:32:58 +01:00
Antonio Niño Díaz
1caee47b6f tests: Add additional check to allocator test 2022-10-27 01:31:20 +01:00
Antonio Niño Díaz
b56c8dbf27 tests: Add tests for the memory allocator
The allocator in NEAlloc.c and NEAlloc.h didn't have tests, which made
it hard to refactor the code.
2022-10-27 01:24:09 +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
c2d427beeb library: Fix broken references when loading palettes fails
Instead of assigning the index before we know if the allocation was
successful, assign it afterwards.
2022-10-26 02:07:41 +01:00
Antonio Niño Díaz
7ff191fe42 examples: Improve specular material example
Show the models with diffuse and specular materials at the same time.
2022-10-25 23:50:50 +01:00
Antonio Niño Díaz
f1ed942ec9 example: Use new names of functions
The previous ones have just been deprecated.
2022-10-25 23:47:29 +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
65bdac84a5 examples: Prevent using an empty shininess table 2022-10-25 18:42:06 +01:00
Antonio Niño Díaz
567c30344b docs: Update screenshots in readme 2022-10-25 18:38:07 +01:00
Antonio Niño Díaz
6b992279d3 examples: Improve specular material example 2022-10-25 18:30:35 +01:00
Antonio Niño Díaz
0cea2a6b95 tools: img2ds: Extract palette class from main file 2022-10-25 02:00:07 +01:00
Antonio Niño Díaz
9e813fc6ef examples: Repurpose example as a specular material example
The model wasn't really high poly anyway, this example will be more
useful.
2022-10-24 23:01:13 +01:00
Antonio Niño Díaz
17e0288486 library: Support modifying shininess table 2022-10-24 22:59:33 +01:00
Antonio Niño Díaz
13e2fef76c library: Replace more GL functions by register writes 2022-10-24 22:51:44 +01:00
Antonio Niño Díaz
02f6123748 library: Replace more GL calls by register writes 2022-10-24 01:59:44 +01:00
Antonio Niño Díaz
eecfe1d7da library: Refactor viewport calculations
Use asynchronous division with the hardware divider as an optimization.
2022-10-24 01:41:56 +01:00