1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Updated the sf2dlib and sftdlib; Added the gfx.color.hex() function; Added the New3DS CPU mode control.

As the color order of the sf2dlib changed, you have to change it in your code, or use the color.hex() function.
To fix the problems, just change "0xRRGGBBAA" to "0xAABBGGRR".
Also, the shader compiler changed to Picasso, so you'll need it in order to compile.
https://github.com/fincs/picasso
This commit is contained in:
Firew0lf 2015-12-09 23:14:23 +01:00
parent 0105970ab7
commit b4d025d602
17 changed files with 205 additions and 131 deletions

View file

@ -125,15 +125,14 @@ $(OUTPUT) : $(OFILES)
# WARNING: This is not the right way to do this! TODO: Do it right!
#---------------------------------------------------------------------------------
%_vsh.h %.vsh.o : %.vsh
%.vsh.o : %.vsh
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@python ../../../aemstro/aemstro_as.py $< ../$(notdir $<).shbin
@bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@
@picasso -o $(notdir $<).shbin $<
@bin2s $(notdir $<).shbin | $(PREFIX)as -o $@
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
@rm ../$(notdir $<).shbin
-include $(DEPENDS)

View file

@ -1,39 +1,30 @@
; setup constants
.const c20, 0.0, 0.0, 0.0, 1.0
; Outputs
.out outpos position
.out outtc0 texcoord0
.out outclr color
; setup outmap
.out o0, result.position, 0xF
.out o1, result.texcoord0, 0x3
.out o2, result.color, 0xF
; Inputs
.alias inpos v0
.alias inarg v1
; setup uniform map (not required)
.uniform c0, c3, projection
; Uniforms
.fvec projection[4]
.vsh vmain, end_vmain
; Constants
.constf RGBA8_TO_FLOAT4(0.00392156862, 0, 0, 0)
;code
vmain:
; result.pos = projMtx * in.pos
dp4 o0, c0, v0 (0x0)
dp4 o0, c1, v0 (0x1)
dp4 o0, c2, v0 (0x2)
dp4 o0, c3, v0 (0x3)
; result.texcoord = in.texcoord
mov o1, v1 (0x5)
; result.color = in.color
mov o2, v1 (0x5)
nop
end
end_vmain:
;operand descriptors
.opdesc x___, xyzw, xyzw ; 0x0
.opdesc _y__, xyzw, xyzw ; 0x1
.opdesc __z_, xyzw, xyzw ; 0x2
.opdesc ___w, xyzw, xyzw ; 0x3
.opdesc xyz_, xyzw, xyzw ; 0x4
.opdesc xyzw, xyzw, xyzw ; 0x5
.opdesc x_zw, xyzw, xyzw ; 0x6
.opdesc xyzw, yyyw, xyzw ; 0x7
.opdesc xyz_, wwww, wwww ; 0x8
.opdesc xyz_, yyyy, xyzw ; 0x9
.proc main
; outpos = projection * in.pos
dp4 outpos.x, projection[0].wzyx, inpos
dp4 outpos.y, projection[1].wzyx, inpos
dp4 outpos.z, projection[2].wzyx, inpos
dp4 outpos.w, projection[3].wzyx, inpos
; outtc0 = in.texcoord
mov outtc0, inarg
; outclr = RGBA8_TO_FLOAT4(in.color)
mul outclr, RGBA8_TO_FLOAT4.xxxx, inarg
end
.end

View file

@ -23,7 +23,12 @@ extern "C" {
* @param b the blue component of the color to create
* @param a the alpha component of the color to create
*/
#define RGBA8(r, g, b, a) ((((r)&0xFF)<<24) | (((g)&0xFF)<<16) | (((b)&0xFF)<<8) | (((a)&0xFF)<<0))
#define RGBA8(r, g, b, a) ((((a)&0xFF)<<24) | (((b)&0xFF)<<16) | (((g)&0xFF)<<8) | (((r)&0xFF)<<0))
#define RGBA8_GET_R(c) (((c) >> 0) & 0xFF)
#define RGBA8_GET_G(c) (((c) >> 8) & 0xFF)
#define RGBA8_GET_B(c) (((c) >> 16) & 0xFF)
#define RGBA8_GET_A(c) (((c) >> 24) & 0xFF)
/**
* @brief Default size of the GPU commands FIFO buffer
@ -96,23 +101,13 @@ typedef struct {
} sf2d_vector_3f;
/**
* @brief Represents a four dimensional float vector
*/
typedef struct {
float r; /**< Red component of the vector/color */
float g; /**< Green component of the vector/color */
float b; /**< Blue component of the vector/color */
float a; /**< Alpha component of the vector/color */
} sf2d_vector_4f;
/**
* @brief Represents a vertex containing position and color attributes
* @brief Represents a vertex containing position (float)
* and color (unsigned int)
*/
typedef struct {
sf2d_vector_3f position; /**< Position of the vertex */
sf2d_vector_4f color; /**< Color of the vertex */
u32 color; /**< Color of the vertex */
} sf2d_vertex_pos_col;
/**
@ -132,6 +127,7 @@ typedef struct {
sf2d_place place; /**< Where the texture data resides, RAM or VRAM */
int tiled; /**< Whether the tetxure is tiled or not */
sf2d_texfmt pixel_format; /**< Pixel format */
u32 params; /**< Texture filters and wrapping */
int width; /**< Texture width */
int height; /**< Texture height */
int pow2_w; /**< Nearest power of 2 >= width */
@ -210,6 +206,15 @@ void *sf2d_pool_malloc(u32 size);
*/
void *sf2d_pool_memalign(u32 size, u32 alignment);
/**
* @brief Allocates aligned memory for an array from a temporary pool. Works as sf2d_pool_malloc
* @param nmemb the number of elements to allocate
* @param size the size (and alignment) of each element to allocate
* @note Unlike libc's calloc, this function does not initialize to 0,
* and returns a pointer aligned to size.
*/
void *sf2d_pool_calloc(u32 nmemb, u32 size);
/**
* @brief Returns the temporary pool's free space
* @return the temporary pool's free space
@ -282,6 +287,8 @@ void sf2d_draw_fill_circle(int x, int y, int radius, u32 color);
* @return a pointer to the newly created texture
* @note Before drawing the texture, it needs to be tiled
* by calling sf2d_texture_tile32.
* The default texture params are both min and mag filters
* GPU_NEAREST, and both S and T wrappings GPU_CLAMP_TO_BORDER.
*/
sf2d_texture *sf2d_create_texture(int width, int height, sf2d_texfmt pixel_format, sf2d_place place);
@ -336,6 +343,22 @@ void sf2d_bind_texture_color(const sf2d_texture *texture, GPU_TEXUNIT unit, u32
*/
void sf2d_bind_texture_parameters(const sf2d_texture *texture, GPU_TEXUNIT unit, unsigned int params);
/**
* @brief Changes the texture params (filters and wrapping)
* @param texture the texture to change the params
* @param params the new texture params to use. You can use the
* GPU_TEXTURE_[MIN,MAG]_FILTER and GPU_TEXTURE_WRAP_[S,T]
* macros as helpers.
*/
void sf2d_texture_set_params(sf2d_texture *texture, u32 params);
/**
* @brief Returns the texture params
* @param texture the texture to get the params
* @return the current texture params of texture
*/
int sf2d_texture_get_params(const sf2d_texture *texture);
/**
* @brief Draws a texture
* @param texture the texture to draw

View file

@ -4,7 +4,7 @@
static int sf2d_initialized = 0;
static u32 clear_color = RGBA8(0x00, 0x00, 0x00, 0xFF);
static u32 clear_color = 0;
static u32 *gpu_cmd = NULL;
//GPU init variables
static int gpu_cmd_size = 0;
@ -193,8 +193,9 @@ void sf2d_end_frame()
gspWaitForPPF();
//Clear the screen
GX_SetMemoryFill(NULL, gpu_fb_addr, clear_color, &gpu_fb_addr[0x2EE00],
0x201, gpu_depth_fb_addr, 0x00000000, &gpu_depth_fb_addr[0x2EE00], 0x201);
GX_SetMemoryFill(NULL,
gpu_fb_addr, clear_color, &gpu_fb_addr[240*400], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH,
gpu_depth_fb_addr, 0, &gpu_depth_fb_addr[240*400], GX_FILL_TRIGGER | GX_FILL_32BIT_DEPTH);
gspWaitForPSC0();
}
@ -245,6 +246,11 @@ void *sf2d_pool_memalign(u32 size, u32 alignment)
return NULL;
}
void *sf2d_pool_calloc(u32 nmemb, u32 size)
{
return sf2d_pool_memalign(nmemb * size, size);
}
unsigned int sf2d_pool_space_free()
{
return pool_size - pool_index;
@ -257,7 +263,11 @@ void sf2d_pool_reset()
void sf2d_set_clear_color(u32 color)
{
clear_color = color;
// GX_SetMemoryFill wants the color inverted?
clear_color = RGBA8_GET_R(color) << 24 |
RGBA8_GET_G(color) << 16 |
RGBA8_GET_B(color) << 8 |
RGBA8_GET_A(color) << 0;
}
void sf2d_set_scissor_test(GPU_SCISSORMODE mode, u32 x, u32 y, u32 w, u32 h)

View file

@ -4,7 +4,7 @@
void sf2d_draw_line(int x0, int y0, int x1, int y1, u32 color)
{
sf2d_vertex_pos_col *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_col));
sf2d_vertex_pos_col *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_col), 8);
if (!vertices) return;
vertices[0].position = (sf2d_vector_3f){(float)x0+1.0f, (float)y0+1.0f, SF2D_DEFAULT_DEPTH};
@ -12,12 +12,7 @@ void sf2d_draw_line(int x0, int y0, int x1, int y1, u32 color)
vertices[2].position = (sf2d_vector_3f){(float)x1+1.0f, (float)y1+1.0f, SF2D_DEFAULT_DEPTH};
vertices[3].position = (sf2d_vector_3f){(float)x1-1.0f, (float)y1-1.0f, SF2D_DEFAULT_DEPTH};
u8 r = (color>>24) & 0xFF;
u8 g = (color>>16) & 0xFF;
u8 b = (color>>8) & 0xFF;
u8 a = color & 0xFF;
vertices[0].color = (sf2d_vector_4f){r/255.0f, g/255.0f, b/255.0f, a/255.0f};
vertices[0].color = color;
vertices[1].color = vertices[0].color;
vertices[2].color = vertices[0].color;
vertices[3].color = vertices[0].color;
@ -35,7 +30,7 @@ void sf2d_draw_line(int x0, int y0, int x1, int y1, u32 color)
GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_FLOAT),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
1, //number of buffers
@ -49,7 +44,7 @@ void sf2d_draw_line(int x0, int y0, int x1, int y1, u32 color)
void sf2d_draw_rectangle(int x, int y, int w, int h, u32 color)
{
sf2d_vertex_pos_col *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_col));
sf2d_vertex_pos_col *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_col), 8);
if (!vertices) return;
vertices[0].position = (sf2d_vector_3f){(float)x, (float)y, SF2D_DEFAULT_DEPTH};
@ -57,12 +52,7 @@ void sf2d_draw_rectangle(int x, int y, int w, int h, u32 color)
vertices[2].position = (sf2d_vector_3f){(float)x, (float)y+h, SF2D_DEFAULT_DEPTH};
vertices[3].position = (sf2d_vector_3f){(float)x+w, (float)y+h, SF2D_DEFAULT_DEPTH};
u8 r = (color>>24) & 0xFF;
u8 g = (color>>16) & 0xFF;
u8 b = (color>>8) & 0xFF;
u8 a = color & 0xFF;
vertices[0].color = (sf2d_vector_4f){r/255.0f, g/255.0f, b/255.0f, a/255.0f};
vertices[0].color = color;
vertices[1].color = vertices[0].color;
vertices[2].color = vertices[0].color;
vertices[3].color = vertices[0].color;
@ -80,7 +70,7 @@ void sf2d_draw_rectangle(int x, int y, int w, int h, u32 color)
GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_FLOAT),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
1, //number of buffers
@ -94,7 +84,7 @@ void sf2d_draw_rectangle(int x, int y, int w, int h, u32 color)
void sf2d_draw_rectangle_rotate(int x, int y, int w, int h, u32 color, float rad)
{
sf2d_vertex_pos_col *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_col));
sf2d_vertex_pos_col *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_col), 8);
if (!vertices) return;
int w2 = w/2.0f;
@ -105,12 +95,7 @@ void sf2d_draw_rectangle_rotate(int x, int y, int w, int h, u32 color, float rad
vertices[2].position = (sf2d_vector_3f){(float)-w2, (float) h2, SF2D_DEFAULT_DEPTH};
vertices[3].position = (sf2d_vector_3f){(float) w2, (float) h2, SF2D_DEFAULT_DEPTH};
u8 r = (color>>24) & 0xFF;
u8 g = (color>>16) & 0xFF;
u8 b = (color>>8) & 0xFF;
u8 a = color & 0xFF;
vertices[0].color = (sf2d_vector_4f){r/255.0f, g/255.0f, b/255.0f, a/255.0f};
vertices[0].color = color;
vertices[1].color = vertices[0].color;
vertices[2].color = vertices[0].color;
vertices[3].color = vertices[0].color;
@ -138,7 +123,7 @@ void sf2d_draw_rectangle_rotate(int x, int y, int w, int h, u32 color, float rad
GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_FLOAT),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
1, //number of buffers
@ -153,17 +138,11 @@ void sf2d_draw_rectangle_rotate(int x, int y, int w, int h, u32 color, float rad
void sf2d_draw_fill_circle(int x, int y, int radius, u32 color)
{
static const int num_segments = 100;
sf2d_vertex_pos_col *vertices = sf2d_pool_malloc((num_segments + 2) * sizeof(sf2d_vertex_pos_col));
sf2d_vertex_pos_col *vertices = sf2d_pool_memalign((num_segments + 2) * sizeof(sf2d_vertex_pos_col), 8);
if (!vertices) return;
vertices[0].position = (sf2d_vector_3f){(float)x, (float)y, SF2D_DEFAULT_DEPTH};
u8 r = (color>>24) & 0xFF;
u8 g = (color>>16) & 0xFF;
u8 b = (color>>8) & 0xFF;
u8 a = color & 0xFF;
vertices[0].color = (sf2d_vector_4f){r/255.0f, g/255.0f, b/255.0f, a/255.0f};
vertices[0].color = color;
float theta = 2 * M_PI / (float)num_segments;
float c = cosf(theta);
@ -199,7 +178,7 @@ void sf2d_draw_fill_circle(int x, int y, int radius, u32 color)
GPU_SetAttributeBuffers(
2, // number of attributes
(u32*)osConvertVirtToPhys((u32)vertices),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_FLOAT),
GPU_ATTRIBFMT(0, 3, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE),
0xFFFC, //0b1100
0x10,
1, //number of buffers

View file

@ -24,16 +24,7 @@ void vector_mult_matrix4x4(const float *msrc, const sf2d_vector_3f *vsrc, sf2d_v
void matrix_gpu_set_uniform(const float *m, u32 startreg)
{
float mu[4*4];
int i, j;
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
mu[i*4 + j] = m[i*4 + (3-j)];
}
}
GPU_SetFloatUniform(GPU_VERTEX_SHADER, startreg, (u32 *)mu, 4);
GPU_SetFloatUniform(GPU_VERTEX_SHADER, startreg, (u32 *)m, 4);
}
void matrix_copy(float *dst, const float *src)
@ -109,7 +100,7 @@ void matrix_swap_xy(float *m)
void matrix_init_orthographic(float *m, float left, float right, float bottom, float top, float near, float far)
{
float mo[4*4], mp[4*4];
mo[0x0] = 2.0f/(right-left);
mo[0x1] = 0.0f;
mo[0x2] = 0.0f;
@ -129,7 +120,7 @@ void matrix_init_orthographic(float *m, float left, float right, float bottom, f
mo[0xD] = 0.0f;
mo[0xE] = 0.0f;
mo[0xF] = 1.0f;
matrix_identity4x4(mp);
mp[0xA] = 0.5;
mp[0xB] = -0.5;

View file

@ -71,6 +71,10 @@ sf2d_texture *sf2d_create_texture(int width, int height, sf2d_texfmt pixel_forma
texture->tiled = 0;
texture->place = place;
texture->pixel_format = pixel_format;
texture->params = GPU_TEXTURE_MAG_FILTER(GPU_NEAREST)
| GPU_TEXTURE_MIN_FILTER(GPU_NEAREST)
| GPU_TEXTURE_WRAP_S(GPU_CLAMP_TO_BORDER)
| GPU_TEXTURE_WRAP_T(GPU_CLAMP_TO_BORDER);
texture->width = width;
texture->height = height;
texture->pow2_w = pow2_w;
@ -145,7 +149,7 @@ void sf2d_bind_texture(const sf2d_texture *texture, GPU_TEXUNIT unit)
(u32 *)osConvertVirtToPhys((u32)texture->data),
texture->pow2_w,
texture->pow2_h,
GPU_TEXTURE_MAG_FILTER(GPU_NEAREST) | GPU_TEXTURE_MIN_FILTER(GPU_NEAREST),
texture->params,
texture->pixel_format
);
}
@ -161,7 +165,7 @@ void sf2d_bind_texture_color(const sf2d_texture *texture, GPU_TEXUNIT unit, u32
GPU_TEVOPERANDS(0, 0, 0),
GPU_TEVOPERANDS(0, 0, 0),
GPU_MODULATE, GPU_MODULATE,
__builtin_bswap32(color) //RGBA8 -> ABGR8
color
);
GPU_SetTexture(
@ -169,7 +173,7 @@ void sf2d_bind_texture_color(const sf2d_texture *texture, GPU_TEXUNIT unit, u32
(u32 *)osConvertVirtToPhys((u32)texture->data),
texture->pow2_w,
texture->pow2_h,
GPU_TEXTURE_MAG_FILTER(GPU_NEAREST) | GPU_TEXTURE_MIN_FILTER(GPU_NEAREST),
texture->params,
texture->pixel_format
);
}
@ -198,9 +202,19 @@ void sf2d_bind_texture_parameters(const sf2d_texture *texture, GPU_TEXUNIT unit,
);
}
void sf2d_texture_set_params(sf2d_texture *texture, u32 params)
{
texture->params = params;
}
int sf2d_texture_get_params(const sf2d_texture *texture)
{
return texture->params;
}
static inline void sf2d_draw_texture_generic(const sf2d_texture *texture, int x, int y)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
int w = texture->width;
@ -248,7 +262,7 @@ void sf2d_draw_texture_blend(const sf2d_texture *texture, int x, int y, u32 colo
static inline void sf2d_draw_texture_rotate_hotspot_generic(const sf2d_texture *texture, int x, int y, float rad, float center_x, float center_y)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
const float w = texture->width;
@ -332,7 +346,7 @@ void sf2d_draw_texture_rotate_blend(const sf2d_texture *texture, int x, int y, f
static inline void sf2d_draw_texture_part_generic(const sf2d_texture *texture, int x, int y, int tex_x, int tex_y, int tex_w, int tex_h)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
vertices[0].position = (sf2d_vector_3f){(float)x, (float)y, SF2D_DEFAULT_DEPTH};
@ -379,7 +393,7 @@ void sf2d_draw_texture_part_blend(const sf2d_texture *texture, int x, int y, int
static inline void sf2d_draw_texture_scale_generic(const sf2d_texture *texture, int x, int y, float x_scale, float y_scale)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
int ws = texture->width * x_scale;
@ -427,7 +441,7 @@ void sf2d_draw_texture_scale_blend(const sf2d_texture *texture, int x, int y, fl
static inline void sf2d_draw_texture_part_scale_generic(const sf2d_texture *texture, float x, float y, float tex_x, float tex_y, float tex_w, float tex_h, float x_scale, float y_scale)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
float u0 = tex_x/(float)texture->pow2_w;
@ -477,7 +491,7 @@ void sf2d_draw_texture_part_scale_blend(const sf2d_texture *texture, float x, fl
static inline void sf2d_draw_texture_part_rotate_scale_generic(const sf2d_texture *texture, int x, int y, float rad, int tex_x, int tex_y, int tex_w, int tex_h, float x_scale, float y_scale)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
int w2 = (tex_w * x_scale)/2.0f;
@ -537,7 +551,7 @@ void sf2d_draw_texture_part_rotate_scale_blend(const sf2d_texture *texture, int
static inline void sf2d_draw_texture_depth_generic(const sf2d_texture *texture, int x, int y, signed short z)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
int w = texture->width;
@ -587,7 +601,7 @@ void sf2d_draw_texture_depth_blend(const sf2d_texture *texture, int x, int y, si
void sf2d_draw_quad_uv(const sf2d_texture *texture, float left, float top, float right, float bottom, float u0, float v0, float u1, float v1, unsigned int params)
{
sf2d_vertex_pos_tex *vertices = sf2d_pool_malloc(4 * sizeof(sf2d_vertex_pos_tex));
sf2d_vertex_pos_tex *vertices = sf2d_pool_memalign(4 * sizeof(sf2d_vertex_pos_tex), 8);
if (!vertices) return;
vertices[0].position = (sf2d_vector_3f){left, top, SF2D_DEFAULT_DEPTH};
@ -641,9 +655,9 @@ void sf2d_set_pixel(sf2d_texture *texture, int x, int y, u32 new_color)
if (texture->tiled) {
u32 coarse_y = y & ~7;
u32 offset = get_morton_offset(x, y, 4) + coarse_y * texture->pow2_w * 4;
*(u32 *)(texture->data + offset) = __builtin_bswap32(new_color);
*(u32 *)(texture->data + offset) = new_color;
} else {
((u32 *)texture->data)[x + y * texture->pow2_w] = __builtin_bswap32(new_color);
((u32 *)texture->data)[x + y * texture->pow2_w] = new_color;
}
}
@ -653,9 +667,9 @@ u32 sf2d_get_pixel(sf2d_texture *texture, int x, int y)
if (texture->tiled) {
u32 coarse_y = y & ~7;
u32 offset = get_morton_offset(x, y, 4) + coarse_y * texture->pow2_w * 4;
return __builtin_bswap32(*(u32 *)(texture->data + offset));
return *(u32 *)(texture->data + offset);
} else {
return __builtin_bswap32(((u32 *)texture->data)[x + y * texture->pow2_w]);
return ((u32 *)texture->data)[x + y * texture->pow2_w];
}
}
@ -675,7 +689,7 @@ void sf2d_texture_tile32(sf2d_texture *texture)
u32 dst_offset = get_morton_offset(i, j, 4) + coarse_y * texture->pow2_w * 4;
u32 v = ((u32 *)texture->data)[i + (texture->pow2_h - 1 - j)*texture->pow2_w];
*(u32 *)(tmp + dst_offset) = __builtin_bswap32(v);
*(u32 *)(tmp + dst_offset) = __builtin_bswap32(v); /* RGBA8 -> ABGR8 */
}
}

View file

@ -153,7 +153,7 @@ run: $(BUILD)
@citra $(TARGET).3dsx
#---------------------------------------------------------------------------------
copy_cia: $(TARGET).cia
@cp $(TARGET).cia /mnt/GATEWAYNAND
@cp $(TARGET).cia /mnt/3DS
sync
#---------------------------------------------------------------------------------

View file

@ -20,6 +20,8 @@ extern const struct {
unsigned char pixel_data[];
} dice_img;
#define CONFIG_3D_SLIDERSTATE (*(float *)0x1FF81080)
int main()
{
// Set the random seed based on the time
@ -27,11 +29,13 @@ int main()
sf2d_init();
sf2d_set_clear_color(RGBA8(0x40, 0x40, 0x40, 0xFF));
sf2d_set_3D(1);
sf2d_texture *tex1 = sf2d_create_texture_mem_RGBA8(dice_img.pixel_data, dice_img.width, dice_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
sf2d_texture *tex2 = sf2d_create_texture_mem_RGBA8(citra_img.pixel_data, citra_img.width, citra_img.height, TEXFMT_RGBA8, SF2D_PLACE_RAM);
float offset3d = 0.0f;
float rad = 0.0f;
u16 touch_x = 320/2;
u16 touch_y = 240/2;
@ -55,7 +59,23 @@ int main()
sf2d_set_clear_color(RGBA8(rand()%255, rand()%255, rand()%255, 255));
}
offset3d = CONFIG_3D_SLIDERSTATE * 30.0f;
sf2d_start_frame(GFX_TOP, GFX_LEFT);
sf2d_draw_fill_circle(offset3d + 60, 100, 35, RGBA8(0x00, 0xFF, 0x00, 0xFF));
sf2d_draw_fill_circle(offset3d + 180, 120, 55, RGBA8(0xFF, 0xFF, 0x00, 0xFF));
sf2d_draw_rectangle_rotate(offset3d + 260, 20, 40, 40, RGBA8(0xFF, 0xFF, 0x00, 0xFF), -2.0f*rad);
sf2d_draw_rectangle(offset3d + 20, 60, 40, 40, RGBA8(0xFF, 0x00, 0x00, 0xFF));
sf2d_draw_rectangle(offset3d + 5, 5, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF));
sf2d_draw_texture_rotate(tex1, offset3d + 400/2 + circle.dx, 240/2 - circle.dy, rad);
sf2d_end_frame();
sf2d_start_frame(GFX_TOP, GFX_RIGHT);
sf2d_draw_fill_circle(60, 100, 35, RGBA8(0x00, 0xFF, 0x00, 0xFF));
sf2d_draw_fill_circle(180, 120, 55, RGBA8(0xFF, 0xFF, 0x00, 0xFF));
sf2d_draw_rectangle_rotate(260, 20, 40, 40, RGBA8(0xFF, 0xFF, 0x00, 0xFF), -2.0f*rad);
sf2d_draw_rectangle(20, 60, 40, 40, RGBA8(0xFF, 0x00, 0x00, 0xFF));
sf2d_draw_rectangle(5, 5, 30, 30, RGBA8(0x00, 0xFF, 0xFF, 0xFF));

View file

@ -13,7 +13,6 @@
static int sftd_initialized = 0;
static FT_Library ftlibrary;
static FTC_Manager ftcmanager;
typedef enum {
SFTD_LOAD_FROM_FILE,
@ -617,7 +616,7 @@ int sftd_width_wtext(sftd_font *font, unsigned int size, const wchar_t *text)
{
FTC_FaceID face_id = (FTC_FaceID)font;
FT_Face face;
FTC_Manager_LookupFace(ftcmanager, face_id, &face);
FTC_Manager_LookupFace(font->ftcmanager, face_id, &face);
FT_Int charmap_index;
charmap_index = FT_Get_Charmap_Index(face->charmap);

View file

@ -58,7 +58,8 @@ int texture_atlas_insert(texture_atlas *atlas, unsigned int character, const voi
int i, j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
sf2d_set_pixel(atlas->tex, pos.x + j, pos.y + i, *(unsigned int *)(image + (j + i*width)*4));
sf2d_set_pixel(atlas->tex, pos.x + j, pos.y + i,
__builtin_bswap32(*(unsigned int *)(image + (j + i*width)*4)));
}
}