citro3d  1.2.0
tex3ds.h
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  * Copyright (c) 2017
3  * Michael Theall (mtheall)
4  *
5  * This file is part of citro3d.
6  *
7  * This software is provided 'as-is', without any express or implied warranty.
8  * In no event will the authors be held liable for any damages arising from the
9  * use of this software.
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute it
13  * freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must not
16  * claim that you wrote the original software. If you use this software in
17  * a product, an acknowledgment in the product documentation would be
18  * appreciated but is not required.
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  * misrepresented as being the original software.
21  * 3. This notice may not be removed or altered from any source distribution.
22  *----------------------------------------------------------------------------*/
26 #pragma once
27 #ifdef CITRO3D_BUILD
28 #include "c3d/texture.h"
29 #else
30 #include <citro3d.h>
31 #endif
32 
33 #include <stdint.h>
34 #include <stdio.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 typedef struct Tex3DS_SubTexture
44 {
45  u16 width;
46  u16 height;
47  float left;
48  float top;
49  float right;
50  float bottom;
52 
54 typedef struct Tex3DS_Texture_s* Tex3DS_Texture;
55 
64 Tex3DS_Texture Tex3DS_TextureImport(const void* input, size_t insize, C3D_Tex* tex, C3D_TexCube* texcube, bool vram);
65 
79 Tex3DS_Texture Tex3DS_TextureImportCallback(C3D_Tex* tex, C3D_TexCube* texcube, bool vram, decompressCallback callback, void* userdata);
80 
93 Tex3DS_Texture Tex3DS_TextureImportFD(int fd, C3D_Tex* tex, C3D_TexCube* texcube, bool vram);
94 
107 Tex3DS_Texture Tex3DS_TextureImportStdio(FILE* fp, C3D_Tex* tex, C3D_TexCube* texcube, bool vram);
108 
113 size_t Tex3DS_GetNumSubTextures(const Tex3DS_Texture texture);
114 
120 const Tex3DS_SubTexture* Tex3DS_GetSubTexture(const Tex3DS_Texture texture, size_t index);
121 
126 static inline bool
128 {
129  return subtex->top < subtex->bottom;
130 }
131 
137 static inline void
138 Tex3DS_SubTextureBottomLeft(const Tex3DS_SubTexture* subtex, float* u, float* v)
139 {
140  if (!Tex3DS_SubTextureRotated(subtex))
141  {
142  *u = subtex->left;
143  *v = subtex->bottom;
144  } else
145  {
146  *u = subtex->bottom;
147  *v = subtex->left;
148  }
149 }
150 
156 static inline void
157 Tex3DS_SubTextureBottomRight(const Tex3DS_SubTexture* subtex, float* u, float* v)
158 {
159  if (!Tex3DS_SubTextureRotated(subtex))
160  {
161  *u = subtex->right;
162  *v = subtex->bottom;
163  } else
164  {
165  *u = subtex->bottom;
166  *v = subtex->right;
167  }
168 }
169 
175 static inline void
176 Tex3DS_SubTextureTopLeft(const Tex3DS_SubTexture* subtex, float* u, float* v)
177 {
178  if (!Tex3DS_SubTextureRotated(subtex))
179  {
180  *u = subtex->left;
181  *v = subtex->top;
182  } else
183  {
184  *u = subtex->top;
185  *v = subtex->left;
186  }
187 }
188 
194 static inline void
195 Tex3DS_SubTextureTopRight(const Tex3DS_SubTexture* subtex, float* u, float* v)
196 {
197  if (!Tex3DS_SubTextureRotated(subtex))
198  {
199  *u = subtex->right;
200  *v = subtex->top;
201  } else
202  {
203  *u = subtex->top;
204  *v = subtex->right;
205  }
206 }
207 
211 void Tex3DS_TextureFree(Tex3DS_Texture texture);
212 
213 #ifdef __cplusplus
214 }
215 #endif
Definition: texture.h:5
Definition: texture.h:10
Subtexture.
Definition: tex3ds.h:44
u16 height
Sub-texture height (pixels)
Definition: tex3ds.h:46
float left
Left u-coordinate.
Definition: tex3ds.h:47
float right
Right u-coordinate.
Definition: tex3ds.h:49
float top
Top v-coordinate.
Definition: tex3ds.h:48
float bottom
Bottom v-coordinate.
Definition: tex3ds.h:50
u16 width
Sub-texture width (pixels)
Definition: tex3ds.h:45
Tex3DS texture.
Definition: tex3ds.c:35
static void Tex3DS_SubTextureBottomLeft(const Tex3DS_SubTexture *subtex, float *u, float *v)
Get bottom-left texcoords.
Definition: tex3ds.h:138
Tex3DS_Texture Tex3DS_TextureImportFD(int fd, C3D_Tex *tex, C3D_TexCube *texcube, bool vram)
Import Tex3DS texture.
Definition: tex3ds.c:213
static void Tex3DS_SubTextureBottomRight(const Tex3DS_SubTexture *subtex, float *u, float *v)
Get bottom-right texcoords.
Definition: tex3ds.h:157
Tex3DS_Texture Tex3DS_TextureImportStdio(FILE *fp, C3D_Tex *tex, C3D_TexCube *texcube, bool vram)
Import Tex3DS texture.
Definition: tex3ds.c:219
const Tex3DS_SubTexture * Tex3DS_GetSubTexture(const Tex3DS_Texture texture, size_t index)
Get subtexture.
Definition: tex3ds.c:231
void Tex3DS_TextureFree(Tex3DS_Texture texture)
Free Tex3DS texture.
Definition: tex3ds.c:238
Tex3DS_Texture Tex3DS_TextureImportCallback(C3D_Tex *tex, C3D_TexCube *texcube, bool vram, decompressCallback callback, void *userdata)
Import Tex3DS texture.
Definition: tex3ds.c:207
size_t Tex3DS_GetNumSubTextures(const Tex3DS_Texture texture)
Get number of subtextures.
Definition: tex3ds.c:225
static void Tex3DS_SubTextureTopRight(const Tex3DS_SubTexture *subtex, float *u, float *v)
Get top-right texcoords.
Definition: tex3ds.h:195
static void Tex3DS_SubTextureTopLeft(const Tex3DS_SubTexture *subtex, float *u, float *v)
Get top-left texcoords.
Definition: tex3ds.h:176
static bool Tex3DS_SubTextureRotated(const Tex3DS_SubTexture *subtex)
Check if subtexture is rotated.
Definition: tex3ds.h:127
Tex3DS_Texture Tex3DS_TextureImport(const void *input, size_t insize, C3D_Tex *tex, C3D_TexCube *texcube, bool vram)
Import Tex3DS texture.
Definition: tex3ds.c:201