diff --git a/libs/sf2dlib/libsf2d/Makefile b/libs/sf2dlib/libsf2d/Makefile index 99c44b9..a035946 100644 --- a/libs/sf2dlib/libsf2d/Makefile +++ b/libs/sf2dlib/libsf2d/Makefile @@ -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) diff --git a/libs/sf2dlib/libsf2d/data/shader.vsh b/libs/sf2dlib/libsf2d/data/shader.vsh index 2a604d5..3793136 100644 --- a/libs/sf2dlib/libsf2d/data/shader.vsh +++ b/libs/sf2dlib/libsf2d/data/shader.vsh @@ -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 diff --git a/libs/sf2dlib/libsf2d/include/sf2d.h b/libs/sf2dlib/libsf2d/include/sf2d.h index 9df8d08..6385b83 100644 --- a/libs/sf2dlib/libsf2d/include/sf2d.h +++ b/libs/sf2dlib/libsf2d/include/sf2d.h @@ -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 diff --git a/libs/sf2dlib/libsf2d/source/sf2d.c b/libs/sf2dlib/libsf2d/source/sf2d.c index 6f564fa..52e5309 100644 --- a/libs/sf2dlib/libsf2d/source/sf2d.c +++ b/libs/sf2dlib/libsf2d/source/sf2d.c @@ -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) diff --git a/libs/sf2dlib/libsf2d/source/sf2d_draw.c b/libs/sf2dlib/libsf2d/source/sf2d_draw.c index bf8f896..d84966b 100644 --- a/libs/sf2dlib/libsf2d/source/sf2d_draw.c +++ b/libs/sf2dlib/libsf2d/source/sf2d_draw.c @@ -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 diff --git a/libs/sf2dlib/libsf2d/source/sf2d_private.c b/libs/sf2dlib/libsf2d/source/sf2d_private.c index 44819a0..073c437 100644 --- a/libs/sf2dlib/libsf2d/source/sf2d_private.c +++ b/libs/sf2dlib/libsf2d/source/sf2d_private.c @@ -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; diff --git a/libs/sf2dlib/libsf2d/source/sf2d_texture.c b/libs/sf2dlib/libsf2d/source/sf2d_texture.c index 2dc9fce..9918953 100644 --- a/libs/sf2dlib/libsf2d/source/sf2d_texture.c +++ b/libs/sf2dlib/libsf2d/source/sf2d_texture.c @@ -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 */ } } diff --git a/libs/sf2dlib/sample/Makefile b/libs/sf2dlib/sample/Makefile index 840f32b..27ae68b 100644 --- a/libs/sf2dlib/sample/Makefile +++ b/libs/sf2dlib/sample/Makefile @@ -153,7 +153,7 @@ run: $(BUILD) @citra $(TARGET).3dsx #--------------------------------------------------------------------------------- copy_cia: $(TARGET).cia - @cp $(TARGET).cia /mnt/GATEWAYNAND + @cp $(TARGET).cia /mnt/3DS sync #--------------------------------------------------------------------------------- diff --git a/libs/sf2dlib/sample/source/main.c b/libs/sf2dlib/sample/source/main.c index fb96559..820888b 100644 --- a/libs/sf2dlib/sample/source/main.c +++ b/libs/sf2dlib/sample/source/main.c @@ -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)); diff --git a/libs/sftdlib/libsftd/source/sftd.c b/libs/sftdlib/libsftd/source/sftd.c index f8f2b4f..d0adf24 100644 --- a/libs/sftdlib/libsftd/source/sftd.c +++ b/libs/sftdlib/libsftd/source/sftd.c @@ -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); diff --git a/libs/sftdlib/libsftd/source/texture_atlas.c b/libs/sftdlib/libsftd/source/texture_atlas.c index c877c59..58f433d 100644 --- a/libs/sftdlib/libsftd/source/texture_atlas.c +++ b/libs/sftdlib/libsftd/source/texture_atlas.c @@ -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))); } } diff --git a/sdcard/3ds/ctruLua/examples/example.lua b/sdcard/3ds/ctruLua/examples/example.lua index 13298ce..9f5fc28 100644 --- a/sdcard/3ds/ctruLua/examples/example.lua +++ b/sdcard/3ds/ctruLua/examples/example.lua @@ -21,7 +21,7 @@ local function drawStuffIn3D(eye) -- 3D stuff local function d(depth) return math.ceil(eye * depth * dMul) end - gfx.color.setDefault(0x00FFFFFF) + gfx.color.setDefault(0xFFFFFF00) gfx.rectangle(240 + d(10), 150, 120, 10) gfx.point(10 + d(6), 20, 0xFF0000FF) @@ -70,7 +70,7 @@ while ctr.run() do local cx, cy = hid.circle() gfx.rectangle(40, 90, 60, 60, 0, 0xDDDDDDFF) - gfx.circle(70 + math.ceil(cx/156 * 30), 120 - math.ceil(cy/156 * 30), 10, 0x000000FF) + gfx.circle(70 + math.ceil(cx/156 * 30), 120 - math.ceil(cy/156 * 30), 10, 0xFF000000) gfx.endFrame() diff --git a/sdcard/3ds/ctruLua/libs/keyboard.lua b/sdcard/3ds/ctruLua/libs/keyboard.lua index e97b9c5..d77b611 100644 --- a/sdcard/3ds/ctruLua/libs/keyboard.lua +++ b/sdcard/3ds/ctruLua/libs/keyboard.lua @@ -69,7 +69,7 @@ return { if xTouch then if xTouch > xKey and xTouch < xKey + keyWidth then if yTouch > yKey and yTouch < yKey + keyHeight then - gfx.rectangle(xKey, yKey, keyWidth, keyHeight, 0, 0xFFFFFFDD) + gfx.rectangle(xKey, yKey, keyWidth, keyHeight, 0, 0xDDFFFFFF) local k = alias[key] or key if sticky[k] and layout[sticky[k]] then @@ -103,4 +103,4 @@ return { return ret ~= "" and ret or nil end -} \ No newline at end of file +} diff --git a/sdcard/3ds/ctruLua/libs/openfile.lua b/sdcard/3ds/ctruLua/libs/openfile.lua index 2f67bae..c08b842 100644 --- a/sdcard/3ds/ctruLua/libs/openfile.lua +++ b/sdcard/3ds/ctruLua/libs/openfile.lua @@ -33,7 +33,7 @@ return function(title, curdir, exts, type) local wasFont = gfx.font.getDefault() gfx.set3D(false) gfx.color.setDefault(0xFFFFFFFF) - gfx.color.setBackground(0x000000FF) + gfx.color.setBackground(0xFF000000) gfx.font.setDefault() while ctr.run() do diff --git a/source/color.c b/source/color.c index a044b99..41d809e 100644 --- a/source/color.c +++ b/source/color.c @@ -76,12 +76,32 @@ static int color_RGBA8(lua_State *L) { return 1; } +/*** +Return a color from a hexadecimal value. +@function hex +@tparam integer hex the hexadecimal color code: 0xRRGGBBAA +@treturn integer the color +*/ +static int color_hex(lua_State *L) { + u32 hex = luaL_checkinteger(L, 1); + + u8 r = (hex & 0xFF000000) >> 24; + u8 g = (hex & 0x00FF0000) >> 16; + u8 b = (hex & 0x0000FF00) >> 8; + u8 a = (hex & 0x000000FF); + + lua_pushinteger(L, RGBA8(r, g, b, a)); + + return 1; +} + static const struct luaL_Reg color_lib[] = { { "setDefault", color_setDefault }, { "getDefault", color_getDefault }, { "setBackground", color_setBackground }, { "getBackground", color_getBackground }, { "RGBA8", color_RGBA8 }, + { "hex", color_hex }, { NULL, NULL } }; @@ -92,4 +112,4 @@ int luaopen_color_lib(lua_State *L) { void load_color_lib(lua_State *L) { luaL_requiref(L, "ctr.gfx.color", luaopen_color_lib, false); -} \ No newline at end of file +} diff --git a/source/ptm.c b/source/ptm.c index 6182635..79099bd 100644 --- a/source/ptm.c +++ b/source/ptm.c @@ -17,6 +17,7 @@ Initialize the PTM module. */ static int ptm_init(lua_State *L) { ptmInit(); + ptmSysmInit(); return 0; } @@ -27,12 +28,13 @@ Disable the PTM module. */ static int ptm_shutdown(lua_State *L) { ptmExit(); + ptmSysmExit(); return 0; } /*** -Return the shell state. Don't care about this. +Return the shell state. @function getShellState @treturn number shell state */ @@ -101,6 +103,30 @@ static int ptm_getTotalStepCount(lua_State *L) { return 1; } +/*** +Setup the new 3DS CPU features (overclock, 4 cores ...) +@newonly +@function configureNew3DSCPU +@tparam boolean enable enable the New3DS CPU features +@treturn boolean `true` if everything went fine +*/ +static int ptm_configureNew3DSCPU(lua_State *L) { + u8 conf = false; + if (lua_isboolean(L, 1)) + conf = lua_toboolean(L, 1); + + Result ret = PTMSYSM_ConfigureNew3DSCPU(conf); + + if (ret) { + lua_pushboolean(L, false); + lua_pushinteger(L, ret); + return 2; + } + + lua_pushboolean(L, true); + return 1; +} + static const struct luaL_Reg ptm_lib[] = { {"init", ptm_init }, {"shutdown", ptm_shutdown }, @@ -109,6 +135,7 @@ static const struct luaL_Reg ptm_lib[] = { {"getBatteryChargeState", ptm_getBatteryChargeState}, {"getPedometerState", ptm_getPedometerState }, {"getTotalStepCount", ptm_getTotalStepCount }, + {"configureNew3DSCPU", ptm_configureNew3DSCPU }, {NULL, NULL} }; diff --git a/source/texture.c b/source/texture.c index a369737..651d242 100644 --- a/source/texture.c +++ b/source/texture.c @@ -35,13 +35,13 @@ int getType(const char *name) { Load a texture from a file. Supported formats: PNG, JPEG, BMP. @function load @tparam string path path to the image file -@tparam[opt=PLACE_RAM] number place where to put the loaded texture +@tparam[opt=PLACE_VRAM] number place where to put the loaded texture @tparam[opt=auto] number type type of the image @treturn texture the loaded texture object */ static int texture_load(lua_State *L) { const char *path = luaL_checkstring(L, 1); - u8 place = luaL_optinteger(L, 2, SF2D_PLACE_RAM); //place in ram by default + u8 place = luaL_optinteger(L, 2, SF2D_PLACE_VRAM); //place in vram by default u8 type = luaL_optinteger(L, 3, 3); //type 3 is "search at the end of the filename" texture_userdata *texture;