Browse Source

restrucure to use simply in a project

(just as a lib)
no makefile yet
undefined
milang 1 month ago
parent
commit
3853da3ac5
Signed by: milang <milan.garnier@orange.fr> GPG Key ID: D287C9D6C33D9035
19 changed files with 174 additions and 3006 deletions
  1. 0
    8
      .gitignore
  2. 0
    2536
      Doxyfile
  3. 0
    228
      LICENSE
  4. 0
    148
      Makefile
  5. 0
    86
      configure
  6. 0
    0
      face.h
  7. BIN
      libfxengine.a
  8. 64
    0
      object.c
  9. 0
    0
      object.h
  10. 0
    0
      parameters.h
  11. 0
    0
      point.h
  12. 26
    0
      texture.c
  13. 84
    0
      texture.h
  14. 0
    0
      translate.c
  15. 0
    0
      translate.h
  16. 0
    0
      triangle.c
  17. 0
    0
      triangle.h
  18. 0
    0
      zbuffer.c
  19. 0
    0
      zbuffer.h

+ 0
- 8
.gitignore View File

@@ -1,11 +1,3 @@
# Specify filepatterns you want git to ignore.

/build/*

*.c.o
*.c.d

Doxyfile

*.tar.xz
*.cfg

+ 0
- 2536
Doxyfile
File diff suppressed because it is too large
View File


+ 0
- 228
LICENSE View File

@@ -1,228 +0,0 @@
Creative Commons Attribution-NonCommercial 2.0 CREATIVE COMMONS CORPORATION
IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS
LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS
PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING
FROM ITS USE.

License

THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS
PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR
OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS
LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO
BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS
CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

a. "Collective Work" means a work, such as a periodical issue, anthology or
encyclopedia, in which the Work in its entirety in unmodified form, along
with a number of other contributions, constituting separate and independent
works in themselves, are assembled into a collective whole. A work that constitutes
a Collective Work will not be considered a Derivative Work (as defined below)
for the purposes of this License.

b. "Derivative Work" means a work based upon the Work or upon the Work and
other pre-existing works, such as a translation, musical arrangement, dramatization,
fictionalization, motion picture version, sound recording, art reproduction,
abridgment, condensation, or any other form in which the Work may be recast,
transformed, or adapted, except that a work that constitutes a Collective
Work will not be considered a Derivative Work for the purpose of this License.
For the avoidance of doubt, where the Work is a musical composition or sound
recording, the synchronization of the Work in timed-relation with a moving
image ("synching") will be considered a Derivative Work for the purpose of
this License.

c. "Licensor" means the individual or entity that offers the Work under the
terms of this License.

d. "Original Author" means the individual or entity who created the Work.

e. "Work" means the copyrightable work of authorship offered under the terms
of this License.

f. "You" means an individual or entity exercising rights under this License
who has not previously violated the terms of this License with respect to
the Work, or who has received express permission from the Licensor to exercise
rights under this License despite a previous violation.

2. Fair Use Rights. Nothing in this license is intended to reduce, limit,
or restrict any rights arising from fair use, first sale or other limitations
on the exclusive rights of the copyright owner under copyright law or other
applicable laws.

3. License Grant. Subject to the terms and conditions of this License, Licensor
hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for
the duration of the applicable copyright) license to exercise the rights in
the Work as stated below:

a. to reproduce the Work, to incorporate the Work into one or more Collective
Works, and to reproduce the Work as incorporated in the Collective Works;

b. to create and reproduce Derivative Works;

c. to distribute copies or phonorecords of, display publicly, perform publicly,
and perform publicly by means of a digital audio transmission the Work including
as incorporated in Collective Works;

d. to distribute copies or phonorecords of, display publicly, perform publicly,
and perform publicly by means of a digital audio transmission Derivative Works;

The above rights may be exercised in all media and formats whether now known
or hereafter devised. The above rights include the right to make such modifications
as are technically necessary to exercise the rights in other media and formats.
All rights not expressly granted by Licensor are hereby reserved, including
but not limited to the rights set forth in Sections 4(d) and 4(e).

4. Restrictions.The license granted in Section 3 above is expressly made subject
to and limited by the following restrictions:

a. You may distribute, publicly display, publicly perform, or publicly digitally
perform the Work only under the terms of this License, and You must include
a copy of, or the Uniform Resource Identifier for, this License with every
copy or phonorecord of the Work You distribute, publicly display, publicly
perform, or publicly digitally perform. You may not offer or impose any terms
on the Work that alter or restrict the terms of this License or the recipients'
exercise of the rights granted hereunder. You may not sublicense the Work.
You must keep intact all notices that refer to this License and to the disclaimer
of warranties. You may not distribute, publicly display, publicly perform,
or publicly digitally perform the Work with any technological measures that
control access or use of the Work in a manner inconsistent with the terms
of this License Agreement. The above applies to the Work as incorporated in
a Collective Work, but this does not require the Collective Work apart from
the Work itself to be made subject to the terms of this License. If You create
a Collective Work, upon notice from any Licensor You must, to the extent practicable,
remove from the Collective Work any reference to such Licensor or the Original
Author, as requested. If You create a Derivative Work, upon notice from any
Licensor You must, to the extent practicable, remove from the Derivative Work
any reference to such Licensor or the Original Author, as requested.

b. You may not exercise any of the rights granted to You in Section 3 above
in any manner that is primarily intended for or directed toward commercial
advantage or private monetary compensation. The exchange of the Work for other
copyrighted works by means of digital file-sharing or otherwise shall not
be considered to be intended for or directed toward commercial advantage or
private monetary compensation, provided there is no payment of any monetary
compensation in connection with the exchange of copyrighted works.

c. If you distribute, publicly display, publicly perform, or publicly digitally
perform the Work or any Derivative Works or Collective Works, You must keep
intact all copyright notices for the Work and give the Original Author credit
reasonable to the medium or means You are utilizing by conveying the name
(or pseudonym if applicable) of the Original Author if supplied; the title
of the Work if supplied; to the extent reasonably practicable, the Uniform
Resource Identifier, if any, that Licensor specifies to be associated with
the Work, unless such URI does not refer to the copyright notice or licensing
information for the Work; and in the case of a Derivative Work, a credit identifying
the use of the Work in the Derivative Work (e.g., "French translation of the
Work by Original Author," or "Screenplay based on original Work by Original
Author"). Such credit may be implemented in any reasonable manner; provided,
however, that in the case of a Derivative Work or Collective Work, at a minimum
such credit will appear where any other comparable authorship credit appears
and in a manner at least as prominent as such other comparable authorship
credit.

d. For the avoidance of doubt, where the Work is a musical composition:

i. Performance Royalties Under Blanket Licenses. Licensor reserves the exclusive
right to collect, whether individually or via a performance rights society
(e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital
performance (e.g. webcast) of the Work if that performance is primarily intended
for or directed toward commercial advantage or private monetary compensation.

ii. Mechanical Rights and Statutory Royalties. Licensor reserves the exclusive
right to collect, whether individually or via a music rights agency or designated
agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from
the Work ("cover version") and distribute, subject to the compulsory license
created by 17 USC Section 115 of the US Copyright Act (or the equivalent in
other jurisdictions), if Your distribution of such cover version is primarily
intended for or directed toward commercial advantage or private monetary compensation.
Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where
the Work is a sound recording, Licensor reserves the exclusive right to collect,
whether individually or via a performance-rights society (e.g. SoundExchange),
royalties for the public digital performance (e.g. webcast) of the Work, subject
to the compulsory license created by 17 USC Section 114 of the US Copyright
Act (or the equivalent in other jurisdictions), if Your public digital performance
is primarily intended for or directed toward commercial advantage or private
monetary compensation.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS
THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING
THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT,
OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE
OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW,
IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS
LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY
OF SUCH DAMAGES.

7. Termination

a. This License and the rights granted hereunder will terminate automatically
upon any breach by You of the terms of this License. Individuals or entities
who have received Derivative Works or Collective Works from You under this
License, however, will not have their licenses terminated provided such individuals
or entities remain in full compliance with those licenses. Sections 1, 2,
5, 6, 7, and 8 will survive any termination of this License.

b. Subject to the above terms and conditions, the license granted here is
perpetual (for the duration of the applicable copyright in the Work). Notwithstanding
the above, Licensor reserves the right to release the Work under different
license terms or to stop distributing the Work at any time; provided, however
that any such election will not serve to withdraw this License (or any other
license that has been, or is required to be, granted under the terms of this
License), and this License will continue in full force and effect unless terminated
as stated above.

8. Miscellaneous

a. Each time You distribute or publicly digitally perform the Work or a Collective
Work, the Licensor offers to the recipient a license to the Work on the same
terms and conditions as the license granted to You under this License.

b. Each time You distribute or publicly digitally perform a Derivative Work,
Licensor offers to the recipient a license to the original Work on the same
terms and conditions as the license granted to You under this License.

c. If any provision of this License is invalid or unenforceable under applicable
law, it shall not affect the validity or enforceability of the remainder of
the terms of this License, and without further action by the parties to this
agreement, such provision shall be reformed to the minimum extent necessary
to make such provision valid and enforceable.

d. No term or provision of this License shall be deemed waived and no breach
consented to unless such waiver or consent shall be in writing and signed
by the party to be charged with such waiver or consent.

e. This License constitutes the entire agreement between the parties with
respect to the Work licensed here. There are no understandings, agreements
or representations with respect to the Work not specified here. Licensor shall
not be bound by any additional provisions that may appear in any communication
from You. This License may not be modified without the mutual written agreement
of the Licensor and You.

Creative Commons is not a party to this License, and makes no warranty whatsoever
in connection with the Work. Creative Commons will not be liable to You or
any party on any legal theory for any damages whatsoever, including without
limitation any general, special, incidental or consequential damages arising
in connection to this license. Notwithstanding the foregoing two (2) sentences,
if Creative Commons has expressly identified itself as the Licensor hereunder,
it shall have all rights and obligations of Licensor.

Except for the limited purpose of indicating to the public that the Work is
licensed under the CCPL, neither party will use the trademark "Creative Commons"
or any related trademark or logo of Creative Commons without the prior written
consent of Creative Commons. Any permitted use will be in compliance with
Creative Commons' then-current trademark usage guidelines, as may be published
on its website or otherwise made available upon request from time to time.

Creative Commons may be contacted at http://creativecommons.org/.

+ 0
- 148
Makefile View File

@@ -1,148 +0,0 @@
include Makefile.cfg

target=fx9860g

CONFIG.TARGET = fx
CONFIG.TARGET.LONG = fx9860g
PREFIX = /usr/lib/gcc/sh3eb-elf/9.1.0/
toolchain = sh3eb-elf
CONFIG.MACROS = -DFX9860G

machine := -m3 -mb


# Compiler flags, assembler flags, dependency generation, archiving
cflags := $(machine) -ffreestanding -nostdlib -Wall -Wextra -std=c11 -Os \
-fstrict-volatile-bitfields -I include $(CONFIG.MACROS) \
$(CONFIG.CFLAGS) $(PROFILING)
sflags := $(CONFIG.MACROS)
dflags = -MMD -MT $@ -MF $(@:.o=.d) -MP
arflags :=


# Target file
target := libfxengine.a

# Automatic names for object and dependency files
src2obj = $(1:src/%=build/%).o
src2dep = $(1:src/%=build/%).d

# Source files
src := $(shell find src \
-name '*.[csS]' -print)
src_obj := $(foreach s,$(src),$(call src2obj,$s))


# All object files
obj := $(src_obj) $(spe_obj)


#
# Toolchain
#

gcc = $(toolchain)-gcc
as = $(toolchain)-as
ld = $(toolchain)-ld
ar = $(toolchain)-ar
objcopy = $(toolchain)-objcopy


#
# Version management
#

# Version symbol is obtained by using the last commit hash on 7 nibbles
version_hash = 0x0$(shell git rev-parse --short HEAD)


#
# Build rules
#

all: $(target)

$(target): $(obj)
$(call cmd_l,ar,$@) $(ar) rcs $(arflags) $@ $^

# Assembler sources
build/%.s.o: src/%.s build/%.s.d
@ mkdir -p $(dir $@)
$(call cmd_b,as,$*.s) $(gcc) -c $< -o $@ $(sflags)
build/%.S.o: src/%.S build/%.S.d
@ mkdir -p $(dir $@)
$(call cmd_b,as,$*.S) $(gcc) -c $< -o $@ $(sflags)

# C sources
build/%.c.o: src/%.c build/%.c.d
@ mkdir -p $(dir $@)
$(call cmd_b,gcc,$*.c) $(gcc) -c $< -o $@ $(dflags) $(cflags)

# Version symbol. ld generates a .stack section for unknown reasons; I remove
# it in the linker script.
version.o: ../.git/HEAD
@ mkdir -p $(dir $@)
@ echo "_FXENGINE_VERSION = $(version_hash);" > $@.txt
$(call cmd_b,ld,$@) $(ld) -r -R $@.txt -o $@


#
# Installing
#

m644 := -m 644

# Disable -m on Mac OS
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



#
# Utilities
#

# Directories: make conveniently leaves a '/' at the end of $(dir ...)
%/:
@ mkdir -p $@
# Don't try to unlink directories once they're built (that wouldn't work =p)
.PRECIOUS: %/

# Dependency information
-include $(shell [ -d src ] && find src -name *.d)
build/%.d: ;
.PRECIOUS: build/%.d

.PHONY: all clean distclean

# Do not output full commands by default
VERBOSE ?=



















+ 0
- 86
configure View File

@@ -1,86 +0,0 @@
#! /bin/bash

#
# Basic configuration
#



output="Makefile.cfg"

#
# Help screen
#

help()
{
cat << EOF
Configuration script for the fxengine library.
Usage: $0 [options...]

You should build out-of-tree by creating a build directory and configuring from
there.


Build option:

--enable-profiling

By default, profiling is disabled, tht means you will not have access to fps. :(

This option enables fps count, but you need to have libprof (by Lephenixnoir) installed


EOF
exit 0
}

if [[ "$@" == "--help" ]]; then
help
exit 1
fi

#
# Parsing arguments
#

add_cflags=

fail=false
for arg; do case "$arg" in
-h | -? | --help)
help;;


--enable-profiling)
add_cflags=-DUSE_LIBPROF;;

*)
echo "error: unrecognized argument '$arg'";
fail=true;;
esac; done

#
# Checking mandatory arguments
#

if $fail; then
echo "Oops ! Maybe a wrong option..."
exit 1
fi


#
# Output config
#

output_config()
{
echo -n "PROFILING ="
echo -n " $(echo $add_cflags)"
echo ""
}

output_config > $output

echo "Configuration saved in $output, ready to make!"

include/fxengine/face.h → face.h View File


BIN
libfxengine.a View File


+ 64
- 0
object.c View File

@@ -0,0 +1,64 @@
#include <fxengine/object.h>

#include <gint/std/stdlib.h>
#include <gint/std/stdio.h>
#include <gint/std/string.h>

void fe_object_init(fe_object * object)
{
memset(object, 0, sizeof(fe_object));
}


void fe_object_set_points(fe_object * object, fe_integer_point * points, uint32_t n, bool copy)
{

if (copy)
{
object->points = malloc(n*sizeof(fe_integer_point));
if (!object->points)
return;
memcpy(object->points, points, n*sizeof(fe_integer_point));
//memcpy()
}

object->p_owner = copy;
object->p_size = n;
}


void fe_object_set_faces(fe_object * object, fe_triangle * faces, uint32_t n, bool copy)
{
if (copy)
{
object->faces = malloc(n*sizeof(fe_integer_point));
if (!object->faces)
return;
memcpy(object->faces, faces, n*sizeof(fe_integer_point));
}

object->f_owner = copy;
object->f_size = n;
}


void fe_object_delete(fe_object * object)
{
if (object->points && object->p_owner)
free(object->points);

if (object->faces && object->f_owner)
free(object->faces);

fe_object_init(object);
}


void fe_object_display(fe_object * object)
{
//for (int i = 0; i < object->p_size; i++)
// fe_translate(&object->points[i]);

for (int i = 0; i < object->f_size; i++)
fe_display_triangle(&object->faces[i]);
}

include/fxengine/object.h → object.h View File


include/fxengine/parameters.h → parameters.h View File


include/fxengine/point.h → point.h View File


src/bitmap.c → texture.c View File

@@ -52,6 +52,32 @@ fe_texture_rich* fe_texture_new_rich(uint32_t size_px_x, uint32_t size_px_y, uin
return bmp;
}

void fe_texture_debug(fe_texture_rich * txtr)
{
dclear(C_WHITE);
if (txtr)
{
char text[21];
sprintf(text, "ADDRESS : %p", txtr);
dtext(1,1, text, C_BLACK, C_NONE);

sprintf(text, " - size : %d x %d", txtr->size_px_x, txtr->size_px_y);
dtext(1,8, text, C_BLACK, C_NONE);

sprintf(text, " - color : %p x %d", txtr->color, txtr->color_dynamic);
dtext(1,15, text, C_BLACK, C_NONE);

sprintf(text, " - layout : %p x %d", txtr->layout, txtr->layout_dynamic);
dtext(1,15, text, C_BLACK, C_NONE);
}
else
{
dtext(1,1, "Texture set as NULL", C_BLACK, C_NONE);
}
dupdate();
getkey();
}

void fe_texture_delete_rich(fe_texture_rich * bmp)
{
if (!bmp)

+ 84
- 0
texture.h View File

@@ -0,0 +1,84 @@
#ifndef FE_TEXTURE
#define FE_TEXTURE

#include <stdint.h>
#include <stdbool.h>

/**
* @brief texture rich type
* transparency is in the layout
* @warning Monochrome only !
*/
struct fe_texture_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 fe_texture_rich fe_texture_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 texture, ready to use !
*/
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);

/**
* @brief delete a rich texture created with texture_new_rich()
*
* @param txtr The texture to delete
*/
void fe_texture_delete_rich(fe_texture_rich * txtr);


/**
* @brief get the color of pixel from rich texture
*
* @param[in] txtr The texture
* @param[in] x The texture x coordinate (in pixels)
* @param[in] y The texture 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 fe_texture_get_pixel_r(const fe_texture_rich * txtr, uint32_t x, uint32_t y);


/**
* @brief display a specific rich texture pixel on the screen (on vram)
*
* @param[in] txtr The texture
* @param[in] txtr_x The texture x coordinate (in pixels)
* @param[in] txtr_y The texture y coordinate (in pixels)
* @param[in] x screen : x coordinate
* @param[in] y screen : y coordinate
*/
void fe_texture_display_pixel_r(const fe_texture_rich * txtr, uint32_t txtr_x, uint32_t txtr_y, uint32_t x, uint32_t y);

void fe_texture_debug(fe_texture_rich * txtr);

#endif

src/translate.c → translate.c View File


include/render/translate.h → translate.h View File


src/triangle.c → triangle.c View File


include/fxengine/triangle.h → triangle.h View File


src/zbuffer.c → zbuffer.c View File


include/render/zbuffer.h → zbuffer.h View File


Loading…
Cancel
Save