restructure and rename some things
This commit is contained in:
parent
08a5a5f8ac
commit
ed20497b31
17
Makefile
17
Makefile
|
@ -85,14 +85,6 @@ version.o: ../.git/HEAD
|
|||
@ echo "_FXENGINE_VERSION = $(version_hash);" > $@.txt
|
||||
$(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@
|
||||
|
||||
#
|
||||
# Cleaning
|
||||
#
|
||||
|
||||
clean:
|
||||
@ rm -rf src version.o{,txt}
|
||||
distclean: clean
|
||||
@ rm -rf Makefile $(CONFIG) $(target)
|
||||
|
||||
#
|
||||
# Installing
|
||||
|
@ -105,14 +97,17 @@ ifeq "$(shell uname)" "Darwin"
|
|||
m644 :=
|
||||
endif
|
||||
|
||||
uninstall:
|
||||
rm -f $(PREFIX)/$(target)
|
||||
rm -rf $(PREFIX)/include/fxengine
|
||||
|
||||
install: $(target)
|
||||
@make uninstall
|
||||
install -d $(PREFIX)
|
||||
install $(target) $(m644) $(PREFIX)
|
||||
cp -r include/fxengine $(PREFIX)/include
|
||||
|
||||
uninstall:
|
||||
rm -f $(PREFIX)/$(target)
|
||||
rm -rf $(PREFIX)/include/fxengine
|
||||
|
||||
|
||||
#
|
||||
# Utilities
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
#ifndef RENDER_BITMAP
|
||||
#define RENDER_BITMAP
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* @brief bitmap rich type
|
||||
* transparency is in the layout
|
||||
* @warning Monochrome only !
|
||||
*/
|
||||
struct bitmap_rich
|
||||
{
|
||||
uint32_t size_px_x;
|
||||
uint32_t size_px_y;
|
||||
uint32_t size_o_y;
|
||||
|
||||
uint32_t * color;
|
||||
bool color_dynamic;
|
||||
uint32_t * layout;
|
||||
bool layout_dynamic;
|
||||
};
|
||||
typedef struct bitmap_rich bitmap_rich;
|
||||
|
||||
|
||||
/**
|
||||
* @brief { function_description }
|
||||
*
|
||||
* @param[in] size_px_x The width in px
|
||||
* @param[in] size_px_y The height in px
|
||||
* @param color color origin
|
||||
* @param[in] copy_color if you want to make a copy, or only to make a link
|
||||
* @param layout layout origin -> can be set as 0 if it isn't needed
|
||||
* @param[in] copy_layout if you want to make a copy, or to make a link
|
||||
*
|
||||
* @return a rich bitmap, ready to use !
|
||||
*/
|
||||
bitmap_rich* bitmap_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* color, bool copy_color,
|
||||
uint32_t *layout, bool copy_layout);
|
||||
|
||||
/**
|
||||
* @brief delete a rich bitmap created with bitmap_new_rich()
|
||||
*
|
||||
* @param bmp The bitmap to delete
|
||||
*/
|
||||
void bitmap_delete_rich(bitmap_rich* bmp);
|
||||
|
||||
|
||||
/**
|
||||
* @brief get the color of pixel from rich bitmap
|
||||
*
|
||||
* @param[in] bmp The bitmap
|
||||
* @param[in] x The bitmap x coordinate (in pixels)
|
||||
* @param[in] y The bitmap y coordinate (in pixels)
|
||||
*
|
||||
* @return the color coded in a unsigned char :
|
||||
* if (color >> 1)
|
||||
* switch (color%2)
|
||||
* {
|
||||
* case 0:
|
||||
* // WHITE
|
||||
* break;
|
||||
* case 1:
|
||||
* // BLACK
|
||||
* }
|
||||
* else
|
||||
*/
|
||||
uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y);
|
||||
|
||||
|
||||
/**
|
||||
* @brief display a specific rich bitmap pixel on the screen
|
||||
*
|
||||
* @param[in] bmp The bitmap
|
||||
* @param[in] bmp_x The bitmap x coordinate (in pixels)
|
||||
* @param[in] bmp_y The bitmap y coordinate (in pixels)
|
||||
* @param[in] x screen : x coordinate
|
||||
* @param[in] y screen : y coordinate
|
||||
*/
|
||||
void bitmap_display_pixel_r(const bitmap_rich * bmp, uint32_t bmp_x, uint32_t bmp_y, uint32_t x, uint32_t y);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,29 +1,29 @@
|
|||
#ifndef FE_FACE
|
||||
#define FE_FACE
|
||||
#ifndef FE_TRIANGLE
|
||||
#define FE_TRIANGLE
|
||||
|
||||
#include <fxengine/point.h>
|
||||
#include <fxengine/bitmap.h>
|
||||
#include <fxengine/texture.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* @brief Triangle struct used to render fonctions
|
||||
* @param[out] part choose the used texture half
|
||||
* @param[out] part choose the used texture half // currently not implemented
|
||||
* @param[out] clockwised choose the visible side of the face
|
||||
* @param[out] s1,s2,s3 three points
|
||||
* @param[out] texture used texture
|
||||
*/
|
||||
struct render_triangle
|
||||
struct fe_triangle
|
||||
{
|
||||
render_integer_position * s1;
|
||||
render_integer_position * s2;
|
||||
render_integer_position * s3;
|
||||
fe_integer_position * s1;
|
||||
fe_integer_position * s2;
|
||||
fe_integer_position * s3;
|
||||
|
||||
bitmap_rich * texture;
|
||||
fe_texture_rich * texture;
|
||||
|
||||
bool part;
|
||||
bool clockwised;
|
||||
};
|
||||
typedef struct render_triangle render_triangle;
|
||||
typedef struct fe_triangle fe_triangle;
|
||||
|
||||
|
||||
|
||||
|
@ -32,12 +32,14 @@ typedef struct render_triangle render_triangle;
|
|||
*
|
||||
* @param[in] face pointer to the face to draw
|
||||
*/
|
||||
void render_display_triangle(const render_triangle * face);
|
||||
void fe_display_triangle(const fe_triangle * face);
|
||||
|
||||
/**
|
||||
* @brief Clears vram, zbuffer
|
||||
*
|
||||
* @param[in] libprof_channel The libprof channel to be used to count_fps
|
||||
* if you don't use libprof channel, (default), you send what you want,
|
||||
* it doesn't matters ;)
|
||||
*/
|
||||
void fe_render_update(const uint32_t libprof_channel);
|
||||
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
#ifndef FXE_OBJECT
|
||||
#define FXE_OBJECT
|
||||
#ifndef FE_OBJECT
|
||||
#define FE_OBJECT
|
||||
|
||||
#include <fxengine/render/translate.h>
|
||||
#include <fxengine/render/triangle.h>
|
||||
#include <fxengine/point.h>
|
||||
#include <fxengine/triangle.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
struct fxe_object
|
||||
struct fe_object
|
||||
{
|
||||
render_triangle * faces;
|
||||
fe_triangle * faces;
|
||||
uint32_t f_size;
|
||||
bool f_owner;
|
||||
render_integer_point * points;
|
||||
fe_integer_point * points;
|
||||
uint32_t p_size;
|
||||
bool p_owner;
|
||||
};
|
||||
typedef struct fxe_object fxe_object;
|
||||
typedef struct fe_object fe_object;
|
||||
|
||||
void fxe_object_init(fxe_object * object);
|
||||
void fe_object_init(fe_object * object);
|
||||
|
||||
void fxe_object_set_points(fxe_object * object, render_integer_point * points, uint32_t n, bool copy);
|
||||
void fe_object_set_points(fe_object * object, fe_integer_point * points, uint32_t n, bool copy);
|
||||
|
||||
void fxe_object_set_faces(fxe_object * object, render_triangle * faces, uint32_t n, bool copy);
|
||||
void fe_object_set_faces(fe_object * object, fe_triangle * faces, uint32_t n, bool copy);
|
||||
|
||||
void fxe_object_delete(fxe_object * object);
|
||||
void fe_object_delete(fe_object * object);
|
||||
|
||||
void fxe_object_display(fxe_object * object);
|
||||
void fe_object_display(fe_object * object);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
|
||||
// Render param
|
||||
|
||||
#define render_width 128
|
||||
#define render_height 64
|
||||
#define render_x_mid ((render_width - 1) / 2) // depends on screen width
|
||||
#define render_y_mid ((render_height - 1) / 2)
|
||||
#define fe_width 128
|
||||
#define fe_height 64
|
||||
#define fe_x_mid ((fe_width - 1) / 2) // depends on screen width
|
||||
#define fe_y_mid ((fe_height - 1) / 2)
|
||||
|
||||
#define render_max_dist 3000
|
||||
#define render_min_dist 1
|
||||
#define fe_max_dist 3000
|
||||
#define fe_min_dist 1
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -11,26 +11,26 @@
|
|||
* is 32 bits
|
||||
* This is also the type used by the rendering triangles.
|
||||
*/
|
||||
struct render_integer_position
|
||||
struct fe_integer_position
|
||||
{
|
||||
int32_t x,
|
||||
y,
|
||||
z;
|
||||
};
|
||||
typedef struct render_integer_position render_integer_position;
|
||||
typedef struct fe_integer_position fe_integer_position;
|
||||
|
||||
/**
|
||||
* @brief this struct is a point in 3d, which has coords save as double
|
||||
* it is not recommended to use it for high performances rendering,
|
||||
* because of the sh3eb-elf architecture, which does not support natively floating calculation
|
||||
*/
|
||||
struct render_floating_position
|
||||
struct fe_floating_position
|
||||
{
|
||||
double x,
|
||||
y,
|
||||
z;
|
||||
};
|
||||
typedef struct render_floating_position render_floating_position;
|
||||
typedef struct fe_floating_position fe_floating_position;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -39,15 +39,24 @@ typedef struct render_floating_position render_floating_position;
|
|||
* the floating_points yet. (Maybe I will never add them)
|
||||
* To render a triangle, you have to set &point.translated as s1, s2 or even s3
|
||||
*/
|
||||
struct render_integer_point
|
||||
struct fe_integer_point
|
||||
{
|
||||
render_integer_position real;
|
||||
render_integer_position translated;
|
||||
fe_integer_position real,
|
||||
translated;
|
||||
};
|
||||
typedef struct render_integer_point render_integer_point;
|
||||
typedef struct fe_integer_point fe_integer_point;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Translate a point with camera settings
|
||||
*
|
||||
* @param point The point to translate
|
||||
*/
|
||||
void fe_point_translate(fe_integer_point * point);
|
||||
|
||||
/**
|
||||
* mathematics constants
|
||||
* TODO déplacer dans caméra
|
||||
*/
|
||||
extern const double pi, pi2, pi_sur_2;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* @param[in] roulis Optionnal rotation around the middle of the screen
|
||||
* @param[in] camera The camera's coordinates, as an integer position
|
||||
*/
|
||||
void render_set(const double dh, const double dv, const double roulis, const render_integer_position * camera);
|
||||
void render_set(const double dh, const double dv, const double roulis, const fe_integer_position * camera);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* effacer le z buffer pour un nouveau cycle de dessin
|
||||
* TODO : ajouter effacement avec le DMA Controller pour les modèles ayant un processeur SH4-A
|
||||
**/
|
||||
void render_zbuffer_clear();
|
||||
void fe_zbuffer_clear();
|
||||
|
||||
#include <stdbool.h>
|
||||
/** FE_zbuffer_set_dist
|
||||
|
@ -16,6 +16,6 @@ void render_zbuffer_clear();
|
|||
* retourne true si il faut dessiner le pixel
|
||||
* retourne false si le pixel est déjà existant
|
||||
**/
|
||||
bool render_zbuffer_set_px(const uint32_t x, const uint32_t y, const uint32_t dist); // if you are allowed to draw the pixel on vram
|
||||
bool fe_zbuffer_set_px(const uint32_t x, const uint32_t y, const uint32_t dist); // if you are allowed to draw the pixel on vram
|
||||
|
||||
#endif
|
||||
|
|
BIN
libfxengine.a
BIN
libfxengine.a
Binary file not shown.
15
src/bitmap.c
15
src/bitmap.c
|
@ -1,11 +1,12 @@
|
|||
#include <fxengine/texture.h>
|
||||
|
||||
#include <gint/display.h>
|
||||
#include <fxengine/bitmap.h>
|
||||
#include <gint/std/string.h>
|
||||
#include <gint/std/stdlib.h>
|
||||
|
||||
bitmap_rich* bitmap_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* color, bool copy_color, uint32_t *layout, bool copy_layout)
|
||||
fe_texture_rich* fe_texture_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* color, bool copy_color, uint32_t *layout, bool copy_layout)
|
||||
{
|
||||
bitmap_rich* bmp = malloc(sizeof(bitmap_rich));
|
||||
fe_texture_rich* bmp = malloc(sizeof(fe_texture_rich));
|
||||
if (!bmp)
|
||||
return 0;
|
||||
|
||||
|
@ -51,7 +52,7 @@ bitmap_rich* bitmap_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* c
|
|||
return bmp;
|
||||
}
|
||||
|
||||
void bitmap_delete_rich(bitmap_rich* bmp)
|
||||
void fe_texture_delete_rich(fe_texture_rich * bmp)
|
||||
{
|
||||
if (!bmp)
|
||||
return;
|
||||
|
@ -65,7 +66,7 @@ void bitmap_delete_rich(bitmap_rich* bmp)
|
|||
free(bmp);
|
||||
}
|
||||
|
||||
uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y)
|
||||
uint8_t fe_texture_get_pixel_r(const fe_texture_rich * bmp, uint32_t x, uint32_t y)
|
||||
{
|
||||
if (x >= bmp->size_px_x || y >= bmp->size_px_y)
|
||||
return 0;
|
||||
|
@ -81,9 +82,9 @@ uint8_t bitmap_get_pixel_r(const bitmap_rich * bmp, uint32_t x, uint32_t y)
|
|||
}
|
||||
|
||||
|
||||
void bitmap_display_pixel_r(const bitmap_rich * bmp, uint32_t bmp_x, uint32_t bmp_y, uint32_t x, uint32_t y)
|
||||
void fe_texture_display_pixel_r(const fe_texture_rich * bmp, uint32_t bmp_x, uint32_t bmp_y, uint32_t x, uint32_t y)
|
||||
{
|
||||
uint8_t color = bitmap_get_pixel_r(bmp, bmp_x, bmp_y);
|
||||
uint8_t color = fe_texture_get_pixel_r(bmp, bmp_x, bmp_y);
|
||||
if (color)
|
||||
dpixel(x, y, 3 * (color % 2));
|
||||
}
|
||||
|
|
|
@ -52,12 +52,12 @@ static double matrice[3][3]=
|
|||
{0,0,0}
|
||||
};
|
||||
|
||||
static render_integer_position delta;
|
||||
static fe_integer_position delta;
|
||||
|
||||
|
||||
void render_translate(render_integer_point * point)
|
||||
void fe_translate(fe_integer_point * point)
|
||||
{
|
||||
static render_integer_position temp;
|
||||
static fe_integer_position temp;
|
||||
temp.x = point->real.x - delta.x;
|
||||
temp.y = point->real.y - delta.y;
|
||||
temp.z = point->real.z - delta.z;
|
||||
|
@ -83,11 +83,11 @@ void render_translate(render_integer_point * point)
|
|||
//(point->translated.x*1024)/point->translated.z;
|
||||
//(point->translated.y*1024)/point->translated.z;
|
||||
|
||||
point->translated.x+=render_x_mid;
|
||||
point->translated.y+=render_y_mid;
|
||||
point->translated.x+=fe_x_mid;
|
||||
point->translated.y+=fe_y_mid;
|
||||
}
|
||||
|
||||
void render_set(const double dh, const double dv, const double roulis, const render_integer_position * camera)
|
||||
void fe_set(const double dh, const double dv, const double roulis, const fe_integer_position * camera)
|
||||
{
|
||||
const double A=cos(dv);
|
||||
const double B=sin(dv);
|
||||
|
@ -114,5 +114,5 @@ void render_set(const double dh, const double dv, const double roulis, const ren
|
|||
matrice[2][2]=A*C;
|
||||
|
||||
// assigner delta
|
||||
memcpy(&delta, camera, sizeof(render_integer_position));
|
||||
memcpy(&delta, camera, sizeof(fe_integer_position));
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
static uint32_t frame_interval_max=1;
|
||||
#endif
|
||||
|
||||
void render_update(const uint32_t libprof_channel)
|
||||
void fe_update(const uint32_t libprof_channel)
|
||||
{
|
||||
//dupdate();
|
||||
|
||||
|
@ -39,9 +39,9 @@ void render_update(const uint32_t libprof_channel)
|
|||
prof_clear(libprof_channel);
|
||||
prof_enter(libprof_channel);
|
||||
#endif
|
||||
render_zbuffer_clear();
|
||||
fe_zbuffer_clear();
|
||||
|
||||
///render_set(dh, dv, roulis, camera);
|
||||
///fe_set(dh, dv, roulis, camera);
|
||||
|
||||
//dclear(C_WHITE);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ void render_update(const uint32_t libprof_channel)
|
|||
*
|
||||
* @return if it is true the it is clockwised else it isn't clockwised
|
||||
*/
|
||||
static bool is_colckwised(render_triangle const * face)
|
||||
static bool is_colckwised(fe_triangle const * face)
|
||||
{
|
||||
int32_t area = 0;
|
||||
|
||||
|
@ -86,7 +86,7 @@ struct line
|
|||
* @param s1 The s 1
|
||||
* @param s2 The s 2
|
||||
*/
|
||||
static void line_set(line* l,render_integer_position const * s1, render_integer_position const * s2)
|
||||
static void line_set(line* l,fe_integer_position const * s1, fe_integer_position const * s2)
|
||||
{
|
||||
l->x = s1->x;
|
||||
l->y = s1->y;
|
||||
|
@ -141,7 +141,7 @@ static bool line_get_x(int32_t y, line const * l, int32_t * x)
|
|||
}
|
||||
|
||||
|
||||
void render_display_triangle(const render_triangle * face)
|
||||
void fe_display_triangle(const fe_triangle * face)
|
||||
{
|
||||
// backface culling
|
||||
if (is_colckwised(face) != face->clockwised)
|
||||
|
@ -150,11 +150,11 @@ void render_display_triangle(const render_triangle * face)
|
|||
// incomplete clipping
|
||||
if (face->s1->x < 0 && face->s2->x < 0 && face->s3->x < 0)
|
||||
return;
|
||||
if (face->s1->x >= render_width && face->s2->x >= render_width && face->s3->x >= render_width)
|
||||
if (face->s1->x >= fe_width && face->s2->x >= fe_width && face->s3->x >= fe_width)
|
||||
return;
|
||||
if (face->s1->y < 0 && face->s2->y < 0 && face->s3->y < 0)
|
||||
return;
|
||||
if (face->s1->y >= render_height && face->s2->y >= render_height && face->s3->y >= render_height)
|
||||
if (face->s1->y >= fe_height && face->s2->y >= fe_height && face->s3->y >= fe_height)
|
||||
return;
|
||||
if (face->s1->z <= 0 && face->s2->z <= 0 && face->s3->z <= 0)
|
||||
return;
|
||||
|
@ -218,7 +218,7 @@ void render_display_triangle(const render_triangle * face)
|
|||
if (color >> 1)
|
||||
{
|
||||
//dpixel(x,y, C_BLACK);
|
||||
if (render_zbuffer_set_px(x,y,z))
|
||||
if (fe_zbuffer_set_px(x,y,z))
|
||||
dpixel(x, y, 3 * (color % 2)); // 3* means cast to black and white, and vx,and vy casted between 0 and 7
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
|
||||
|
||||
static const int size_uint32 = render_width * render_height;
|
||||
static const int size_uint32 = fe_width * fe_height;
|
||||
|
||||
static const int size_char = size_uint32 * sizeof(uint32_t);
|
||||
|
||||
|
@ -24,23 +24,23 @@ static int32_t *zbuffer = (void *)0x88080000 - (((size_char >> 5) << 5) + 1);
|
|||
|
||||
extern void dma_memset(void *dst, uint32_t l, size_t size);
|
||||
|
||||
void render_zbuffer_clear()
|
||||
void fe_zbuffer_clear()
|
||||
{
|
||||
uint32_t indice = 0;
|
||||
|
||||
if (isSH3())
|
||||
for (indice = 0; indice < size_uint32; indice ++)
|
||||
zbuffer[indice] = render_max_dist;
|
||||
zbuffer[indice] = fe_max_dist;
|
||||
else
|
||||
dma_memset(zbuffer, render_max_dist, size_char);
|
||||
dma_memset(zbuffer, fe_max_dist, size_char);
|
||||
|
||||
}
|
||||
|
||||
bool render_zbuffer_set_px(const uint32_t x, const uint32_t y, const uint32_t dist)
|
||||
bool fe_zbuffer_set_px(const uint32_t x, const uint32_t y, const uint32_t dist)
|
||||
{
|
||||
const int indice = x * render_height + y;
|
||||
const int indice = x * fe_height + y;
|
||||
|
||||
if (zbuffer[indice]>dist && dist>=render_min_dist && dist<=render_max_dist)
|
||||
if (zbuffer[indice]>dist && dist>=fe_min_dist && dist<=fe_max_dist)
|
||||
{
|
||||
zbuffer[indice] = dist;
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue