mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-24 15:52:20 +00:00
Merge branch 'tpl'
This commit is contained in:
commit
278dc66ce0
5 changed files with 128 additions and 6 deletions
|
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
||||||
## [Unreleased][]
|
## [Unreleased][]
|
||||||
|
|
||||||
- Allow compilation and installation with cmake.
|
- Allow compilation and installation with cmake.
|
||||||
|
- Added `GRRLIB_LoadTextureTPL` to load TPL data (Texture Palette Library) into a `GRRLIB_texImg`.
|
||||||
- Added `GRRLIB_CreateEmptyTextureFmt()` to create an empty texture with a given format.
|
- Added `GRRLIB_CreateEmptyTextureFmt()` to create an empty texture with a given format.
|
||||||
|
|
||||||
## [4.5.1][] - 2024-03-02
|
## [4.5.1][] - 2024-03-02
|
||||||
|
|
|
@ -28,6 +28,64 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include <grrlib.h>
|
#include <grrlib.h>
|
||||||
|
|
||||||
|
#define TPL_HDR_VERSION_FIELD 0 /**< Version field. */
|
||||||
|
#define TPL_HDR_NTEXTURE_FIELD 4 /**< Texture field. */
|
||||||
|
#define TPL_HDR_HDRSIZE_FIELD 8 /**< Header size field. */
|
||||||
|
#define TPL_HDR_DESCR_FIELD 12 /**< Descriptor field. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture header.
|
||||||
|
*/
|
||||||
|
typedef struct _tplimgheader TPLImgHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture header.
|
||||||
|
*/
|
||||||
|
struct _tplimgheader {
|
||||||
|
u16 height; /**< Height of the texture in pixels. */
|
||||||
|
u16 width; /**< Width of the texture in pixels. */
|
||||||
|
u32 fmt; /**< Format of the texture. */
|
||||||
|
void *data; /**< Pointer to the texture data. */
|
||||||
|
u32 wraps; /**< Texture coordinate wrapping strategy in the S direction. */
|
||||||
|
u32 wrapt; /**< Texture coordinate wrapping strategy in the T direction. */
|
||||||
|
u32 minfilter; /**< Filter mode when the texel/pixel ratio is ≤ 1.0. */
|
||||||
|
u32 magfilter; /**< Filter mode when the texel/pixel ratio is > 1.0. */
|
||||||
|
f32 lodbias; /**< LOD bias. */
|
||||||
|
u8 edgelod; /**< Edge LOD. */
|
||||||
|
u8 minlod; /**< Minimum LOD value. */
|
||||||
|
u8 maxlod; /**< Maximum LOD value. */
|
||||||
|
u8 unpacked; /**< Internal flag. */
|
||||||
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture palette header.
|
||||||
|
*/
|
||||||
|
typedef struct _tplpalheader TPLPalHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture palette header.
|
||||||
|
*/
|
||||||
|
struct _tplpalheader {
|
||||||
|
u16 nitems; /**< Number of palette entries. */
|
||||||
|
u8 unpacked; /**< Internal flag. */
|
||||||
|
u8 pad; /**< Padding. */
|
||||||
|
u32 fmt; /**< Format of the color lookup table (CLUT). */
|
||||||
|
void *data; /**< Pointer to the color lookup table (CLUT) data. */
|
||||||
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture descriptor.
|
||||||
|
*/
|
||||||
|
typedef struct _tpldesc TPLDescHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Texture descriptor.
|
||||||
|
*/
|
||||||
|
struct _tpldesc {
|
||||||
|
TPLImgHeader *imghead; /**< Pointer to texture header structure. */
|
||||||
|
TPLPalHeader *palhead; /**< Pointer to color lookup table (CLUT) header. */
|
||||||
|
} ATTRIBUTE_PACKED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This structure contains information about the type, size, and layout of a file that containing a device-independent bitmap (DIB).
|
* This structure contains information about the type, size, and layout of a file that containing a device-independent bitmap (DIB).
|
||||||
*/
|
*/
|
||||||
|
@ -143,6 +201,44 @@ GRRLIB_texImg* GRRLIB_CreateEmptyTexture (const u32 width, const u32 height)
|
||||||
return GRRLIB_CreateEmptyTextureFmt(width, height, GX_TF_RGBA8);
|
return GRRLIB_CreateEmptyTextureFmt(width, height, GX_TF_RGBA8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set TPL data to a GRRLIB_texImg structure.
|
||||||
|
* @param my_tpl The TPL buffer to set.
|
||||||
|
* @param size Size of the TPL buffer to set.
|
||||||
|
* @param id ID of the TPL buffer to set.
|
||||||
|
* @return A GRRLIB_texImg structure filled with image information.
|
||||||
|
*/
|
||||||
|
GRRLIB_texImg* GRRLIB_LoadTextureTPL (const u8 *my_tpl, const int size, u32 id) {
|
||||||
|
if(my_tpl == NULL || size <= 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u32 ntextures = *(u32*)(my_tpl + TPL_HDR_NTEXTURE_FIELD);
|
||||||
|
if(id > ntextures) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
|
||||||
|
if (my_texture == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TPLDescHeader *deschead = (TPLDescHeader*)(my_tpl + TPL_HDR_DESCR_FIELD);
|
||||||
|
|
||||||
|
u32 pos = (u32)deschead[id].imghead;
|
||||||
|
const TPLImgHeader *imghead = (TPLImgHeader*)(my_tpl + pos);
|
||||||
|
|
||||||
|
pos = (u32)imghead->data;
|
||||||
|
my_texture->data = (u8*)(my_tpl + pos);
|
||||||
|
my_texture->w = imghead->width;
|
||||||
|
my_texture->h = imghead->height;
|
||||||
|
my_texture->format = imghead->fmt;
|
||||||
|
GRRLIB_SetHandle( my_texture, 0, 0 );
|
||||||
|
GRRLIB_FlushTex( my_texture );
|
||||||
|
|
||||||
|
return my_texture;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a texture from a buffer.
|
* Load a texture from a buffer.
|
||||||
* @param my_img The JPEG, PNG or Bitmap buffer to load.
|
* @param my_img The JPEG, PNG or Bitmap buffer to load.
|
||||||
|
|
|
@ -142,6 +142,7 @@ GRRLIB_texImg* GRRLIB_LoadTexturePNG (const u8 *my_png);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg);
|
GRRLIB_texImg* GRRLIB_LoadTextureJPG (const u8 *my_jpg);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size);
|
GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const u32 my_size);
|
||||||
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp);
|
GRRLIB_texImg* GRRLIB_LoadTextureBMP (const u8 *my_bmp);
|
||||||
|
GRRLIB_texImg* GRRLIB_LoadTextureTPL (const u8 *my_tpl, const int size, u32 id);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// GRRLIB_gecko.c - USB_Gecko output facilities
|
// GRRLIB_gecko.c - USB_Gecko output facilities
|
||||||
|
|
|
@ -19,6 +19,7 @@ TARGET := $(notdir $(CURDIR))
|
||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source
|
SOURCES := source
|
||||||
DATA := data
|
DATA := data
|
||||||
|
TEXTURES := textures
|
||||||
INCLUDES :=
|
INCLUDES :=
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
@ -54,7 +55,8 @@ ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(TEXTURES),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
@ -66,6 +68,8 @@ CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf)))
|
||||||
|
TPLFILES := $(SCFFILES:.scf=.tpl)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
@ -76,11 +80,11 @@ else
|
||||||
export LD := $(CXX)
|
export LD := $(CXX)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES))
|
||||||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
|
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
||||||
|
|
||||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES)))
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# build a list of include paths
|
# build a list of include paths
|
||||||
|
@ -142,6 +146,14 @@ $(OFILES_SOURCES) : $(HFILES)
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
$(bin2o)
|
$(bin2o)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# This rule links in binary data with the .tpl extension
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.tpl.o %_tpl.h : %.tpl
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(bin2o)
|
||||||
|
|
||||||
-include $(DEPENDS)
|
-include $(DEPENDS)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
|
|
@ -19,6 +19,7 @@ TARGET := $(notdir $(CURDIR))
|
||||||
BUILD := build
|
BUILD := build
|
||||||
SOURCES := source
|
SOURCES := source
|
||||||
DATA := data
|
DATA := data
|
||||||
|
TEXTURES := textures
|
||||||
INCLUDES :=
|
INCLUDES :=
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
@ -55,7 +56,8 @@ ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
export OUTPUT := $(CURDIR)/$(TARGET)
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
|
||||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(TEXTURES),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
@ -67,6 +69,8 @@ CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
|
||||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf)))
|
||||||
|
TPLFILES := $(SCFFILES:.scf=.tpl)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# use CXX for linking C++ projects, CC for standard C
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
@ -77,11 +81,11 @@ else
|
||||||
export LD := $(CXX)
|
export LD := $(CXX)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
|
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES))
|
||||||
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
|
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
|
||||||
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
|
||||||
|
|
||||||
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
|
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES)))
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
# build a list of include paths
|
# build a list of include paths
|
||||||
|
@ -143,6 +147,14 @@ $(OFILES_SOURCES) : $(HFILES)
|
||||||
@echo $(notdir $<)
|
@echo $(notdir $<)
|
||||||
$(bin2o)
|
$(bin2o)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# This rule links in binary data with the .tpl extension
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.tpl.o %_tpl.h : %.tpl
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
@$(bin2o)
|
||||||
|
|
||||||
-include $(DEPENDS)
|
-include $(DEPENDS)
|
||||||
|
|
||||||
#---------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue