Commit Graph

26 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
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