library: Cleanup the final source files

This commit is contained in:
Antonio Niño Díaz 2022-10-16 13:55:06 +01:00
parent 76ccdc379e
commit ccc8a67caf
3 changed files with 755 additions and 721 deletions

View File

@ -56,6 +56,7 @@ void NE_TextResetSystem(void);
/// @param y Column.
/// @param color Text color.
/// @param text Text to print.
/// @return Returns the number of characters printed.
int NE_TextPrint(int slot, int x, int y, u32 color, const char *text);
/// Prints text within the limits of a rectangle.
@ -70,6 +71,7 @@ int NE_TextPrint(int slot, int x, int y, u32 color, const char *text);
/// @param color Text color.
/// @param charnum Number of characters to print. If -1 it prints everything.
/// @param text Text to print.
/// @return Returns the number of characters printed.
int NE_TextPrintBox(int slot, int x, int y, int endx, int endy, u32 color,
int charnum, const char *text);
@ -82,6 +84,7 @@ int NE_TextPrintBox(int slot, int x, int y, int endx, int endy, u32 color,
/// @param y (x, y) Start position in pixels.
/// @param color Text color.
/// @param text Text to print.
/// @return Returns the number of characters printed.
int NE_TextPrintFree(int slot, int x, int y, u32 color, const char *text);
/// Prints text which isn't restricted to any row or column, within a rectangle.
@ -94,6 +97,7 @@ int NE_TextPrintFree(int slot, int x, int y, u32 color, const char *text);
/// @param color Text color.
/// @param charnum Number of characters to print. If -1 it prints everything.
/// @param text Text to print.
/// @return Returns the number of characters printed.
int NE_TextPrintBoxFree(int slot, int x, int y, int endx, int endy, u32 color,
int charnum, const char *text);

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
// Copyright (c) 2008-2011, 2019, 2022 Antonio Niño Díaz
//
// This file is part of Nitro Engine
@ -10,271 +10,280 @@
#include <nds.h>
#include "NEPalette.h"
/*! \file NETexture.h
* \brief Texture and material functions.
*/
/// @file NETexture.h
/// @brief Texture and material functions.
/*! @defgroup texture_system Texture system
*
* Texture manipulation functions. A material is just a texture with a color.
*
* @{
*/
/// @defgroup material_system Material system
///
/// Material manipulation system. A material is composed of a texture and,
/// optionally, a palette. It also has diffuse, ambient, specular and emission
/// properties.
///
/// @{
/*! \def #define NE_DEFAULT_TEXTURES 128 */
#define NE_DEFAULT_TEXTURES 128
#define NE_DEFAULT_TEXTURES 128 ///< Default max number of materials
/*! \def #define NE_NO_PALETTE -1 */
#define NE_NO_PALETTE -1
#define NE_NO_PALETTE -1 ///< Value that represents a lack of palettes
/*! \struct NE_Material
* \brief Information of one material.
*/
/// Holds information of one material.
typedef struct {
int texindex;
u32 color;
u32 diffuse, ambient, specular, emission;
bool vtxcolor, useshininess;
int texindex; ///< Index to internal texture object
u32 color; ///< Color of this material
u32 diffuse; ///< Diffuse lighting material color
u32 ambient; ///< Ambient lighting material color
u32 specular; ///< Specular lighting material color
u32 emission; ///< Emission lighting material color
bool vtxcolor; ///< Set Diffuse Reflection Color as Vertex Color
bool useshininess; ///< Use shininess table
} NE_Material;
/*! \fn NE_Material *NE_MaterialCreate(void);
* \brief Returns a pointer to a new NE_Material struct.
*/
/// Creates a new material object.
///
/// @return Pointer to the newly created material.
NE_Material *NE_MaterialCreate(void);
/*! \fn void NE_MaterialColorSet(NE_Material *tex, u32 color);
* \brief Apply color to material.
* \param tex Material.
* \param color Color.
*/
/// Applies a color to a material.
///
/// Note that the color will only be displayed if no normal commands are used.
/// Any model with normals will ignore this color.
///
/// @param tex Material.
/// @param color Color.
void NE_MaterialColorSet(NE_Material *tex, u32 color);
/*! \fn void NE_MaterialColorDelete(NE_Material *tex);
* \brief Remove color of a material.
* \param tex Material.
*/
/// Removes the color of a material (sets it back to white).
///
/// @param tex Material.
void NE_MaterialColorDelete(NE_Material *tex);
/*! \fn int NE_MaterialTexLoadFAT(NE_Material *tex,
* GL_TEXTURE_TYPE_ENUM type, int sizeX,
* int sizeY, int param, char * path);
* \brief Load a texture from FAT and set it to a NE_Material struct. Returns 1
* if OK, 0 if error.
* \param tex Material.
* \param type Texture type.
* \param sizeX (sizeX, sizeY) Texture size. It doesn't need to be a power of 2
* \param sizeY (sizeX, sizeY) Texture size. It doesn't need to be a power of 2
* \param param Parameters of the texture.
* \param path Path of the texture file.
*/
/// Loads a texture from the filesystem and assigns it to a material object.
///
/// The sizes don't need to be a power of two, but it will be much more
/// efficient if the width is a power of two. Textures with a non-power-of-two
/// width need to be resized manually, and they don't save any VRAM when loaded.
/// Textures with a non-power-of-two height don't need to be resized, and they
/// actually save VRAM space.
///
/// @param tex Material.
/// @param type Texture type.
/// @param sizeX (sizeX, sizeY) Texture size.
/// @param sizeY (sizeX, sizeY) Texture size.
/// @param param Parameters of the texture.
/// @param path Path of the texture file.
/// @return It returns 1 on success, 0 on error.
int NE_MaterialTexLoadFAT(NE_Material *tex, GL_TEXTURE_TYPE_ENUM type,
int sizeX, int sizeY, int param, char *path);
int sizeX, int sizeY, int param, char *path);
/*! \fn int NE_MaterialTexLoad(NE_Material *tex, GL_TEXTURE_TYPE_ENUM type,
* int sizeX, int sizeY, int param,
* void *texture);
* \brief Load a texture from RAM and set it to a NE_Material struct. Returns 1
* if OK, 0 if error.
* \param tex Material.
* \param type Texture type.
* \param sizeX (sizeX, sizeY) Texture size. It doesn't need to be a power of 2
* \param sizeY (sizeX, sizeY) Texture size. It doesn't need to be a power of 2
* \param param Parameters of the texture.
* \param texture Pointer to the texture.
*/
int NE_MaterialTexLoad(NE_Material *tex, GL_TEXTURE_TYPE_ENUM type, int sizeX,
int sizeY, int param, void *texture);
/// Loads a texture from RAM and assigns it to a material object.
///
/// The sizes don't need to be a power of two, but it will be much more
/// efficient if the width is a power of two. Textures with a non-power-of-two
/// width need to be resized manually, and they don't save any VRAM when loaded.
/// Textures with a non-power-of-two height don't need to be resized, and they
/// actually save VRAM space.
///
/// @param tex Material.
/// @param type Texture type.
/// @param sizeX (sizeX, sizeY) Texture size.
/// @param sizeY (sizeX, sizeY) Texture size.
/// @param param Parameters of the texture.
/// @param texture Pointer to the texture data.
/// @return It returns 1 on success, 0 on error.
int NE_MaterialTexLoad(NE_Material *tex, GL_TEXTURE_TYPE_ENUM type,
int sizeX, int sizeY, int param, void *texture);
/*! \fn void NE_MaterialTexClone(NE_Material *source, NE_Material *dest);
* \brief Copies the texture of a material into another material. You can
* delete them as usual.
* \param source Source.
* \param dest Destination.
*/
/// Copies the texture of a material into another material.
///
/// Unlike with models, you can delete the source and destination materials as
/// desired. Nitro Engine will keep track of how many materials use any specific
/// texture and palette and it will remove them when no more materials are using
/// them.
///
/// @param source Source.
/// @param dest Destination.
void NE_MaterialTexClone(NE_Material *source, NE_Material *dest);
/*! \fn void NE_MaterialTexSetPal(NE_Material *tex, NE_Palette *pal);
* \brief Set palete to a texture.
* \param tex Material with the texture.
* \param pal Palette. */
/// Assign a palette to a material.
///
/// @param tex Material.
/// @param pal Palette.
void NE_MaterialTexSetPal(NE_Material *tex, NE_Palette *pal);
/*! \fn void NE_MaterialUse(NE_Material *tex);
* \brief Set next models to be drawn next to use the material.
* \param tex Material to be used.
*
* If NULL, it will disable textures and new polygons won't be affected by them
* until it is called again.
*/
/// Set active material to use when drawing polygons.
///
/// If the pointer passed is NULL the function will disable textures and new
/// polygons won't be affected by them until this function is called again with
/// a valid material.
///
/// @param tex Material to be used.
void NE_MaterialUse(NE_Material *tex);
/*! \enum NE_VRAMBankFlags
* \brief Enum to choose what banks can use Nitro Engine to allocate textures.
*/
/// Flags to choose which VRAM banks Nitro Engine can use to allocate textures.
typedef enum {
NE_VRAM_A = (1 << 0), /*!< Use bank A. */
NE_VRAM_B = (1 << 1), /*!< Use bank B. */
NE_VRAM_C = (1 << 2), /*!< Use bank C. */
NE_VRAM_D = (1 << 3), /*!< Use bank D. */
NE_VRAM_A = (1 << 0), ///< Bank A
NE_VRAM_B = (1 << 1), ///< Bank B
NE_VRAM_C = (1 << 2), ///< Bank C
NE_VRAM_D = (1 << 3), ///< Bank D
NE_VRAM_AB = NE_VRAM_A | NE_VRAM_B, /*!< Use banks A and B. */
NE_VRAM_AC = NE_VRAM_A | NE_VRAM_C, /*!< Use banks A and C. */
NE_VRAM_AD = NE_VRAM_A | NE_VRAM_D, /*!< Use banks A and D. */
NE_VRAM_BC = NE_VRAM_B | NE_VRAM_C, /*!< Use banks B and C. */
NE_VRAM_BD = NE_VRAM_B | NE_VRAM_D, /*!< Use banks B and D. */
NE_VRAM_CD = NE_VRAM_C | NE_VRAM_D, /*!< Use banks C and D. */
NE_VRAM_AB = NE_VRAM_A | NE_VRAM_B, ///< Banks A and B
NE_VRAM_AC = NE_VRAM_A | NE_VRAM_C, ///< Banks A and C
NE_VRAM_AD = NE_VRAM_A | NE_VRAM_D, ///< Banks A and D
NE_VRAM_BC = NE_VRAM_B | NE_VRAM_C, ///< Banks B and C
NE_VRAM_BD = NE_VRAM_B | NE_VRAM_D, ///< Banks B and D
NE_VRAM_CD = NE_VRAM_C | NE_VRAM_D, ///< Banks C and D
NE_VRAM_ABC = NE_VRAM_A | NE_VRAM_B | NE_VRAM_C, /*!< Use banks A, B and C. */
NE_VRAM_ABD = NE_VRAM_A | NE_VRAM_B | NE_VRAM_D, /*!< Use banks A, B and D. */
NE_VRAM_ACD = NE_VRAM_A | NE_VRAM_C | NE_VRAM_D, /*!< Use banks A, C and D. */
NE_VRAM_BCD = NE_VRAM_B | NE_VRAM_C | NE_VRAM_D, /*!< Use banks B, C and D. */
NE_VRAM_ABC = NE_VRAM_A | NE_VRAM_B | NE_VRAM_C, ///< Banks A, B and C
NE_VRAM_ABD = NE_VRAM_A | NE_VRAM_B | NE_VRAM_D, ///< Banks A, B and D
NE_VRAM_ACD = NE_VRAM_A | NE_VRAM_C | NE_VRAM_D, ///< Banks A, C and D
NE_VRAM_BCD = NE_VRAM_B | NE_VRAM_C | NE_VRAM_D, ///< Banks B, C and D
NE_VRAM_ABCD = NE_VRAM_A | NE_VRAM_B | NE_VRAM_C | NE_VRAM_D, /*!< Use the 4 main banks. */
NE_VRAM_ABCD = NE_VRAM_A | NE_VRAM_B | NE_VRAM_C | NE_VRAM_D, ///< All main banks
} NE_VRAMBankFlags;
/*! \fn void NE_TextureSystemReset(int texture_number, int palette_number,
* NE_VRAMBankFlags bank_flags);
* \brief Resets texture and palette system.
* \param texture_number Max number of textures. If lower than 1, it will
* create space for NE_DEFAULT_TEXTURES.
* \param palette_number Max number of palettes. If lower than 1, it will
* create space for NE_DEFAULT_PALETTES.
* \param bank_flags VRAM banks where Nitro Engine can allocate textures.
* In Dual 3D mode, only A and B are available. If you are planning to
* use a depth BMP, you can only use banks A and B. If you don't tell
* Nitro Engine to use at least a valid bank, it will use the default
* ones.
*/
void NE_TextureSystemReset(int texture_number, int palette_number,
NE_VRAMBankFlags bank_flags);
/// Resets the material system and sets the new max number of objects.
///
/// In Dual 3D mode, only VRAM A and B are available for textures.
///
/// If no VRAM banks are specified in this function, all VRAM banks A to D will
/// be used for textures (or just A and B in dual 3D mode).
///
/// @param max_textures Max number of textures. If lower than 1, it will
/// create space for NE_DEFAULT_TEXTURES.
/// @param max_palettes Max number of palettes. If lower than 1, it will
/// create space for NE_DEFAULT_PALETTES.
/// @param bank_flags VRAM banks where Nitro Engine can allocate textures.
void NE_TextureSystemReset(int max_textures, int max_palettes,
NE_VRAMBankFlags bank_flags);
/*! \fn void NE_MaterialUse(NE_Material *tex);
* \brief Delete material.
* \param tex Material.
*/
/// Deletes a material object.
///
/// @param tex Pointer to the material object.
void NE_MaterialDelete(NE_Material *tex);
/*! \fn int NE_TextureFreeMem(void);
* \brief Returns total free space for textures.
*/
/// Returns the available free memory for textures.
///
/// Note that, even if it is all available, it may not be contiguous, so you may
/// not be able to load a texture because there isn't enough space in any free
/// gap.
///
/// @return Returns the available memory in bytes.
int NE_TextureFreeMem(void);
/*! \fn int NE_TextureFreeMemPercent(void);
* \brief Returns percent of free space for textures.
*/
/// Returns the percentage of available free memory for textures.
///
/// @return Returns the percentage of available memory (0-100).
int NE_TextureFreeMemPercent(void);
/*! \fn void NE_TextureDefragMem(void);
* \brief Defragment VRAM used by textures. It may take some time to finish.
*
* WARNING: This function doesn't currently work.
*/
/// Defragment memory used for textures.
///
/// WARNING: This function is currently not working.
void NE_TextureDefragMem(void);
/*! \fn void NE_TextureSystemEnd(void);
* \brief Terminates texture and palette system and frees memory used by them.
*/
/// End texture system and free all memory used by it.
void NE_TextureSystemEnd(void);
/*! \fn int NE_TextureGetSizeX(NE_Material *tex);
* \brief Returns used X size of texture.
* \param tex Material.
*/
/// Returns the width of a texture.
///
/// This is the size given when the texture was loaded.
///
/// @param tex Material.
/// @return Returns the size in pixels.
int NE_TextureGetSizeX(NE_Material *tex);
/*! \fn int NE_TextureGetSizeY(NE_Material *tex);
* \brief Returns used Y size of texture.
* \param tex Material.
*/
/// Returns the height of a texture.
///
/// This is the size given when the texture was loaded.
///
/// @param tex Material.
/// @return Returns the size in pixels.
int NE_TextureGetSizeY(NE_Material *tex);
/*! \fn int NE_TextureGetRealSizeX(NE_Material *tex);
* \brief Returns real X size of a texture.
* \param tex Material.
*/
/// Returns the real width of a texture.
///
/// This is the internal size given to the GPU when the texture is used, not the
/// size used to load the texture, which may have been smaller.
///
/// @param tex Material.
/// @return Returns the size in pixels.
int NE_TextureGetRealSizeX(NE_Material *tex);
/*! \fn int NE_TextureGetRealSizeY(NE_Material *tex);
* \brief Returns real Y size of a texture.
* \param tex Material.
*/
/// Returns the real height size of a texture.
///
/// This is the internal size given to the GPU when the texture is used, not the
/// size used to load the texture, which may have been smaller.
///
/// @param tex Material.
/// @return Returns the size in pixels.
int NE_TextureGetRealSizeY(NE_Material *tex);
/*! \fn void NE_MaterialSetPropierties(NE_Material *tex, u32 diffuse,
* u32 ambient, u32 specular,
* u32 emission, bool vtxcolor,
* bool useshininess);
* \brief Sets propierties of this material.
* \param tex Material.
* \param diffuse Set diffuse color, lights that directly hits the polygon.
* \param ambient Set ambient color, lights that indirectly hits the polygon
* (walls reflections...).
* \param specular Set specular color, lights reflected towards the camera,
* like a mirror.
* \param emission Set emission color, light emitted by the polygon.
* \param vtxcolor If true, diffuse reflection will work as color command.
* \param useshininess If true, specular reflection will use the shininess
* table.
*/
/// Sets lighting propierties of this material.
///
/// @param tex Material to modify.
/// @param diffuse Set diffuse color: lights that directly hits the polygon.
/// @param ambient Set ambient color: lights that indirectly hit the polygon
/// (reflections from the walls, etc).
/// @param specular Set specular color: lights reflected towards the camera,
/// like a mirror.
/// @param emission Set emission color: light emitted by the polygon.
/// @param vtxcolor If true, diffuse reflection will work as a color command.
/// @param useshininess If true, specular reflection will use the shininess
/// table.
void NE_MaterialSetPropierties(NE_Material *tex, u32 diffuse, u32 ambient,
u32 specular, u32 emission, bool vtxcolor,
bool useshininess);
u32 specular, u32 emission, bool vtxcolor,
bool useshininess);
/*! \fn void NE_MaterialSetDefaultPropierties(u32 diffuse, u32 ambient,
* u32 specular, u32 emission,
* bool vtxcolor,
* bool useshininess);
* \brief Sets default propierties of materials when they are loaded.
* \param diffuse Set diffuse color, lights that directly hits the polygon.
* \param ambient Set ambient color, lights that indirectly hits the polygon
* (walls reflections...).
* \param specular Set specular color, lights reflected towards the camera,
* like a mirror.
* \param emission Set emission color, light emitted by the polygon.
* \param vtxcolor If true, diffuse reflection will work as color command.
* \param useshininess If true, specular reflection will use the shininess
* table.
*/
/// Sets default lighting propierties of materials when they are created.
///
/// @param diffuse Set diffuse color: lights that directly hits the polygon.
/// @param ambient Set ambient color: lights that indirectly hit the polygon
/// (reflections from the walls, etc).
/// @param specular Set specular color: lights reflected towards the camera,
/// like a mirror.
/// @param emission Set emission color: light emitted by the polygon.
/// @param vtxcolor If true, diffuse reflection will work as a color command.
/// @param useshininess If true, specular reflection will use the shininess
/// table.
void NE_MaterialSetDefaultPropierties(u32 diffuse, u32 ambient, u32 specular,
u32 emission, bool vtxcolor,
bool useshininess);
u32 emission, bool vtxcolor,
bool useshininess);
/*! \fn void *NE_TextureDrawingStart(NE_Material *tex);
* \brief Enables drawing for given texture. Returns a pointer to the data.
* \param tex Texture to draw.
*
* Use this DURING VBL. YOU MUST USE NE_TextureDrawingEnd() WHEN YOU FINISH
* DRAWING. IF YOU DON'T, GPU WON'T BE ABLE TO RENDER ANY TEXTURE TO SCREEN.
*/
/// Enables modification of the specified texture.
///
/// Use this during VBL. Remember to use NE_TextureDrawingEnd() when you finish.
/// If you don't, the GPU won't be able to render textures to the screen.
///
/// @param tex Texture to modify.
/// @return Returns a pointer to the base address of the texture in VRAM.
void *NE_TextureDrawingStart(NE_Material *tex);
/*! \fn void NE_TexturePutPixelRGBA(u32 x, u32 y, u16 color);
* \brief Puts a pixel to given RGBA texture.
* \param x (x, y) Coordinates.
* \param y (x, y) Coordinates.
* \param color Color in RGB15. Bit 15 must be set to make the pixel visible.
*
* Use this DURING VBL.
*/
/// Sets the specified pixel to the specified color.
///
/// This only works for textures in RGBA/RGB format.
///
/// Use this during VBL.
///
/// @param x (x, y) Pixel coordinates.
/// @param y (x, y) Pixel coordinates.
/// @param color Color in RGB15. Bit 15 must be set to make the pixel visible.
void NE_TexturePutPixelRGBA(u32 x, u32 y, u16 color);
/*! \fn void NE_TexturePutPixelRGB256(u32 x, u32 y, u8 palettecolor);
* \brief Sets given pixel to "palettecolor".
* \param x (x,y) Pixel coordinates.
* \param y (x,y) Pixel coordinates.
* \param palettecolor New palette color index.
*
* Use this DURING VBL.
*/
/// Sets the specified pixel to the specified palette color index.
///
/// This only works for textures in RGB256 format.
///
/// Use this during VBL.
///
/// @param x (x,y) Pixel coordinates.
/// @param y (x,y) Pixel coordinates.
/// @param palettecolor New palette color index.
void NE_TexturePutPixelRGB256(u32 x, u32 y, u8 palettecolor);
/*! \fn void NE_TextureDrawingEnd(void);
* \brief Ends texture drawing.
*
* Use this DURING VBL.
*/
/// Disables modification of textures.
///
/// Use this during VBL.
void NE_TextureDrawingEnd(void);
/*! @} */
/// @}
#endif // NE_TEXTURE_H__

File diff suppressed because it is too large Load Diff