Commit graph

187 commits

Author SHA1 Message Date
Gered 02349d09a2 add color type alias. add color fn variants using 4 color components
the color type aliases have been a long time coming. it might make
sense to re-work the various color functions into some traits that
these color type aliases implement.

added the color function variants that accept and/or return 4 color
component arrays to aide in code that is doing more complex color
manipulation where it just makes more sense to always be working with
4 color component arrays instead of always converting to/from packed
and unpacked formats
2023-04-19 15:40:07 -04:00
Gered 755d13eef9 update color functions to work with arrays instead of bare components 2023-04-18 16:42:13 -04:00
Gered 88bea61bab "fix" some compiler warnings
while these are not used currently, i'm not able to rule out the
possiblity that i'll want to use them in the near-ish future for future
tests.
2023-04-17 15:27:17 -04:00
Gered ef45992130 bump up version of bitflags 2023-04-17 15:26:15 -04:00
Gered 73e5b9c7bc tweak all internal pub mod / pub use and re-do the prelude module
this is based off what i saw some other libraries doing. i'm not sure
what is the "best practice" to be honest, but i definitely like this.
especially the prelude is now much simpler, which is nice.
2023-04-17 15:25:55 -04:00
Gered e8847d01be missed removal of one sub-prelude module. oops 2023-04-17 14:54:24 -04:00
Gered 78dd97cb12 all of these "tests" modules don't actually need to be public 2023-04-16 20:39:57 -04:00
Gered c6549e37a9 put all the prelude stuff into a single prelude module
i still don't like this
2023-04-16 20:39:10 -04:00
Gered fbf6d1e716 added "manual" integration tests for basic system/window verification
since i cannot think of any way to verify these tests in a automated
way, these are all set up currently as "ignored" tests which need to be
manually run (either directly via the IDE, e.g. CLion as I use, or via
the an ALTERNATIVE test runner via the CLI (such as nextest). these
cannot be run all together via `cargo test` (even if running with only
a single thread). `cargo test` can only be used to run them successfully
one test per invocation.
2023-04-14 13:18:47 -04:00
Gered 9a421f32a6 add #[inline] attributes to all the GeneralBitmap 1-line methods 2023-04-14 12:21:34 -04:00
Gered babb70cf30 add more useful methods to GeneralBitmap trait and impls 2023-04-14 12:19:28 -04:00
Gered e0a4ea9c5b increase MAX_KEYS constant to match underlying SDL key scancode max
SDL_NUM_SCANCODES is defined as 512 currently
2023-04-13 14:44:36 -04:00
Gered 43c921680b add num_derive's FromPrimitive derive to keyboard and mouse button enums
this has very limited use, outside of some tests i am writing right now,
but maybe it will be useful down the road.

(i suppose mostly, i just wanted to try this out for myself ...)
2023-04-13 14:43:13 -04:00
Gered 8e02fdd657 map our KeyModifiers bitflags struct to the original SDL values
rather then copy+pasting the constants. i doubt they'll change, but
you never know i guess ...
2023-04-12 15:20:24 -04:00
Gered db60579db4 fix mouse button event mapping
this was preventing applications from picking up basically all non-left
button states
2023-04-12 15:19:39 -04:00
Gered 4069a92843 add generic pixel type parameter to SystemResources
this has no immediate use, but i think it will be useful in the future
for writing generic constraints requiring 32-bit color support while
not forcing use of any specific SystemResources implementation
2023-04-09 20:33:44 -04:00
Gered cf6b7e5e3c minor crate import cleanups 2023-04-06 21:50:34 -04:00
Gered 231ba10f1e remove Copy trait from these event enums to be consistent with the rest
since the TextInput event cannot implement Copy, necessitating the
removal of the Copy trait from KeyboardEvent, it feels wrong to me to
have the other event enums implement Copy, because it is inconsistent.

so while this is less convenient potentially, it feels consistent.

probably not a big deal in the future one way or the other.
2023-04-05 12:45:09 -04:00
Gered 1c39832801 add keyboard TextInput event mapping 2023-04-05 12:42:57 -04:00
Gered f3b6ca46e1 move all of the triangle_2d draw implementations to their own functions
keeping the original single triangle_2d function taking the enum, but
also allowing separate functions to be called without the need for an
enum, which might be useful.

plus this also feels a bit better organized and easier to read when you
just need to look at one or two different triangle drawing
implementations.
2023-04-05 12:37:26 -04:00
Gered 097147c568 update visual reference test image affected by some recent changes 2023-04-04 21:06:41 -04:00
Gered 29e5a8b080 some similar changes in indexed triangle_2d drawing 2023-04-04 21:06:10 -04:00
Gered a0c1199264 changes for a bit more floating-point stability in triangle_2d rendering
in truth, there's a lot of per-pixel color munging going on in these
triangle renderers. maybe too much? we're doing a lot of operations that
are constantly deconstructing argb32 colors and then reconstructing, and
then deconstructing+reconstructing again. and some of the time we were
doing this as floats, via the "normalized" conversion functions. this
seemed to be adding a bit of "color jitter" that could be visible
at run-time when triangles were being animated somehow (e.g. resized).

also, the whole "inverse area" thing, while probably a bit of a
micro-optimization at best, was causing its own little bit of visible
"color jitter" sometimes, probably due to an increased level of
floating-point inaccuracy when representing the area as a fraction
like that.
2023-04-04 21:05:33 -04:00
Gered 8aefdd6f0d update triangle_2d benchmarks
- switch to use RgbaBitmaps
- add more, particularly some with blending. not all are here though.
2023-04-04 20:30:42 -04:00
Gered 4f58b68012 cleanup imports 2023-04-04 20:29:53 -04:00
Gered 7a631e6088 make both 2d triangle enums derive Copy 2023-04-04 18:37:10 -04:00
Gered 2b39f6ae88 add indexed triangle 2d visual reference tests 2023-04-04 18:26:38 -04:00
Gered f564721e46 add blended triangle_2d drawing operations for IndexedBitmaps 2023-04-04 18:25:38 -04:00
Gered d1fb0c6b2e add new blend function and rgba triangle 2d visual reference tests 2023-04-04 17:52:00 -04:00
Gered 1985afe040 add triangle_list_2d method for rendering lists of triangles 2023-04-04 17:50:48 -04:00
Gered 380bff59eb add BlendFunction::MultipliedBlend 2023-04-04 15:34:33 -04:00
Gered 173aaa2579 rename blend_source_by_value to blend_argb32_source_by
which is probably not objectively better or worse ...
2023-04-04 15:27:13 -04:00
Gered 30e7be38db add a bunch of color function tests
also moved the argb to/from conversion tests from the palette module
over to the color module
2023-04-04 13:02:38 -04:00
Gered 700f650561 add Display trait to our Pixel trait 2023-04-04 08:42:38 -04:00
Gered ce7d8edc6d slightly improve some primitive drawing operations
improve in the readability sense, not performance i don't think, since
this style of iterator looping is what the slice fill method does
anyway i'm pretty sure
2023-04-04 08:41:57 -04:00
Gered 725dc12424 fix 2d triangle inner loop behaviour when applying fill rule
we can't just do a `continue` as we need to ensure that we always update
the barycentric coordinates on every single iteration
2023-04-03 16:19:25 -04:00
Gered 39b788c564 fix 2d triangle clipping 2023-04-03 14:41:14 -04:00
Gered 4b91d494d0 add some #[inline] attributes to various math stuff
also switch away from #[inline(always)] to just #[inline]
2023-04-03 14:40:40 -04:00
Gered e5fda9cb25 small enhancement to nearly_equal 2023-04-03 13:50:41 -04:00
Gered ac9393d3a4 include alpha component in triangle per-vertex-color blending modes
otherwise the blend is wrong (basically doesn't blend at all)
2023-04-03 13:50:00 -04:00
Gered f8d00135b2 re-add middle-of-pixel triangle sampling, which got mistakenly dropped 2023-04-02 15:06:07 -04:00
Gered 68bbd8c13c implement top-left fill rules in triangle rendering 2023-04-02 15:03:45 -04:00
Gered 49a8b23568 should be testing with '<=' so that we also draw edge pixels
'< 0' gives us pixels inside the triangle. '== 0' gives us pixels on
the edges of the triangle
2023-04-02 15:03:17 -04:00
Gered 2280578904 add a bunch of extra RgbaBitmap textured triangle rendering options
variations on texturing with single-color/multi-color/blending/tinted
2023-04-01 22:17:34 -04:00
Gered 2695bf4679 add helper function to multiply two argb colors together 2023-04-01 22:10:39 -04:00
Gered 2c7d78f0d1 add RgbaBitmap triangle blending options 2023-04-01 21:37:00 -04:00
Gered a41fca5640 rename triangle SolidSingleColor enum variant to Solid 2023-04-01 21:36:19 -04:00
Gered 3e4b9affa0 redo triangle 2d drawing api to use enums. split indexed+rgba variants
i'm not *entirely* sold on this particular enum-based api, but i think
it could work. in the future i'd likely ALSO want something that could
work with triangle data as an offset from a larger buffer, but we can
solve that problem later when it comes up.

mainly i just didn't want to have a bunch of different triangle_2d
function variants exposed. same justification as with the blit enums,
basically.
2023-04-01 18:48:54 -04:00
Gered 7a5ea75e1f add color-component-to/from-packed functions for normalized components 2023-04-01 18:45:58 -04:00
Gered eef0b4f7a4 important comment documenting a difference in this triangle algorithm
the difference is important to note since most articles discussing
implementations of barycentric triangle rasterization show a test
for positive w0/w1/w2 to determine if you're inside the triangle or not.
they also usually use a slightly different formula in the `cross`
function if they assume counter-clockwise vertex winding.

since i'll admit i still don't *fully* grasp the math behind the edge
functions and that stuff that is used to calculate the a01/b01/a12/...
values, i wasn't sure how to adjust these for counter-clockwise winding
to keep a positive w0/w1/w2 check. so the simple solution is to use
the `cross` function as it is now, calculate a01/b01/a12/b12/a20/b20
as we are now, and do a negative w0/w1/w2 check and we get to keep
counter-clockwise vertex winding which i prefer. hooray!
2023-04-01 14:57:17 -04:00
Gered 6689f31146 implement triangle drawing "optimizations"
these don't actually improve performance at all judging from the
criterion benchmarks. lol.
2023-04-01 14:24:29 -04:00
Gered 67bcbec69b hack-fixes to triangle_2d_custom and bitmap texcoord sampling. ugh!
this is terrible but i do not currently know what the fuck is going on
2023-04-01 11:09:30 -04:00
Gered 80d3ae91e7 use bitmap sampling method instead of manually calculating it 2023-04-01 00:50:56 -04:00
Gered ed58dc39cd add Bitmap texture coordinate sampling convenience method
his has some off-by-one issues ... ? looks like it mostly works fine,
but i need to investigate more
2023-04-01 00:49:52 -04:00
Gered a106228517 sample in the middle of pixels, instead of the top-left 2023-04-01 00:40:05 -04:00
Gered 832daefbda add initial triangle_2d_textured method 2023-03-31 23:27:15 -04:00
Gered 69bb0c4830 this should be a mutable reference argument
to be honest, i'm not sure how this compiled successfully before, since
the value being passed in via Bitmap::triangle_2d_custom is clearly of
type `&mut PixelType` ... ? either way, this is now written consistently
and we get to remove an unnecessary unsafe block
2023-03-31 22:16:32 -04:00
Gered 4fcb6a9f0f add basic triangle_2d rendering criterion benchmark
just so i have it here for when i try to implement optimizations (again)
2023-03-31 22:11:37 -04:00
Gered 2b4c4d91dc fix broken criterion benchmarks 2023-03-31 22:10:42 -04:00
Gered ff9960d325 add basic 2d triangle rendering
only solid color support so far. and using an un-optimized algorithm
2023-03-31 22:01:02 -04:00
Gered ad1dbee5fd add RgbaBitmap::from_bytes with some limited pixel format support 2023-03-30 17:56:40 -04:00
Gered 1815a2236c update examples and doc comments code to reflect recent changes 2023-03-29 15:50:30 -04:00
Gered f2f1d83edf update Standard system resource with variable screen size support 2023-03-29 15:40:37 -04:00
Gered 7143430769 update DosLike system resource with variable screen size support
also re-did DosLikeConfig at the same time, making usage a bit clearer
2023-03-29 15:38:39 -04:00
Gered 7f19f4e7d4 fix a bunch of clippy warnings
but not all of them. just the easy ones for now!
2023-03-28 16:29:44 -04:00
Gered aa22786d43 update dependencies 2023-03-28 14:04:48 -04:00
Gered ceaefad030 lets try using rustfmt again ...
i unfortunately feel like i should really force myself to use rustfmt
even though i very much dislike it. most rust developers seem to use it
so i should probably get used to it ...

however, case-in-point for me is the amount of times i used either
#[rustfmt::skip] or adding a blank `//` comment to force separate
lines, etc, really proves how terrible basing almost all of your
formatting rules on arbitrary length thresholds really is. code
formatting is far more subjective than that.
2023-03-27 18:43:41 -04:00
Gered 36c4cc1a41 remove these two unneeded extern crate lines
i'm going to guess this was added early on automatically by clion
and i just never caught it. they'd been here since the project was
first committed to a git repo. oh well.
2023-03-27 16:59:55 -04:00
Gered e503cfb718 remove old display size constants as well as cargo feature flags
we'll be introducing variable display size features next, so these
screen dimension compile-time constants are not going to be useful.

the "low_res" and "wide" features were also tied to the idea of
compile-time constants for display sizing so these need to go too,
and will be brought back via runtime configuration
2023-03-27 16:58:37 -04:00
Gered e4608dee82 add visual tests for RgbaBitmap color tinted blit methods 2023-03-26 18:34:58 -04:00
Gered cf021aa1de add RgbaBitmap color tinted blit methods
BlendFunction has a tinted blend that is similar, but it is also
useful to be able to color tint without blending
2023-03-26 18:34:18 -04:00
Gered 7209907193 change to a better tint color used in visual test
figure it is best to use a color that contains all different and
non-zero RGB components
2023-03-26 17:59:42 -04:00
Gered b94ef4df4e add visual tests for BlendFunction blending 2023-03-26 17:45:22 -04:00
Gered d2bc28754f add visual tests for RgbaBitmap blended drawing primitives 2023-03-26 16:57:22 -04:00
Gered f233f810e6 add RgbaBitmap blended drawing primitives 2023-03-26 16:36:53 -04:00
Gered 5c2571755a update blended_pixel_drawing visual test to test an unchecked method too 2023-03-26 16:29:55 -04:00
Gered d238031166 update blended_rect visual test to reflect bug fix
the previous commit fixed a minor 1-pixel-off issue related to
clipping
2023-03-26 16:29:07 -04:00
Gered 3864f36706 update IndexedBitmap blended primitives to use new generic functions 2023-03-26 16:27:14 -04:00
Gered a667a657d2 add generic primitive drawing methods accepting custom pixel functions 2023-03-26 16:26:15 -04:00
Gered 847149607d some cleanups and fixes 2023-03-26 13:49:16 -04:00
Gered 48a76a59e0 add visual tests for the new blending RgbaBitmap blit methods
note that we're not testing all of the different blend combinations
for each blit method. specific BlendFunction visual tests will be added
2023-03-26 13:15:56 -04:00
Gered 0345571851 reorder blit method enums in a different and still arbitrary order 2023-03-26 12:37:54 -04:00
Gered b38a4b55bc add RgbaBitmap blending blit methods 2023-03-25 19:09:01 -04:00
Gered 050c2ac6e9 add color blending and tinting functions
this is definitely one of those things where i wonder if there are
probably better names (more standardized names) that could be used
here instead
2023-03-25 19:08:20 -04:00
Gered a087c35024 add pixel format option to RgbaBitmap png saving 2023-03-24 20:11:08 -04:00
Gered 29ab739323 update IndexedBitmap graphics visual tests to match the rgb tests 2023-03-21 21:20:35 -04:00
Gered 9dcfa91502 add graphics visual tests for RgbaBitmap drawing operations
obviously only for the operations implemented so far. there are going
to be more in the near future.
2023-03-21 21:19:37 -04:00
Gered bb4a3655dc update graphics visual test references images that used the vga palette
necessary after the previous change fixing the 6-bit to 8-bit
conversion
2023-03-21 18:21:26 -04:00
Gered 1f232c51bb fix 6-bit to 8-bit palette conversion
this now produces "full range" results, e.g. VGA color 15 (bright white)
now converts to 255,255,255 instead of 252,252,252.
2023-03-21 18:20:36 -04:00
Gered ba75ae04f1 set default pixel color for new Bitmap's differently based on type
this is mainly to prevent RgbaBitmap's from being initialized by
default to all black with alpha=0. this can still be manually done if
desired, but the assumption is that most of the time you'd want
alpha=255.

for the most part this doesn't matter one way or the other except when
we get to blending (not yet done for RgbaBitmaps, but coming soon) and
saving RgbaBitmap's to PNG files where it becomes blatantly obvious
when you have a bitmap with all/mostly alpha=0 pixels!
2023-03-21 16:55:57 -04:00
Gered 6a0be2756a add some useful rgba color constants
copied from the default VGA/EGA palette
2023-03-21 16:53:00 -04:00
Gered ec437974ee add RgbaBitmap::load_file 2023-03-21 15:40:31 -04:00
Gered 04f57cf8da convert graphics visual tests reference images to png
this just makes it a lot easier to open up in whatever graphics tool
is available during development
2023-03-21 15:25:25 -04:00
Gered b6e69ca084 allow png files to be loaded via IndexedBitmap::load_file 2023-03-21 15:23:47 -04:00
Gered 6829800caa organize test assets a little bit better 2023-03-21 15:09:47 -04:00
Gered 3d9d97db08 rename to avoid compiler warning
for now until we later fully implement this function and use these
arguments
2023-03-20 22:19:14 -04:00
Gered 11625f58a5 add png save tests 2023-03-20 22:18:15 -04:00
Gered a5c8af67ad set alpha component consistently with other colours during palette read
when reading palette files/streams, we set up the colour entries
using helper functions that automatically set an alpha component of 255.
however, we were first initializing the palette with 0 (alpha component
of 0 too).

this meant that if a palette of less than 256 colours was loaded, the
remaining entries (since Palette is always sized for 256 colours), were
black (0,0,0) with alpha components of 0.

this change makes all palette entries have a consistent alpha value
(which is never really used anyway ...) when loaded.
2023-03-20 22:18:02 -04:00
Gered 148a24ca42 implement png saving
note that we only allow RgbaBitmaps to save RGBA colour format pngs.
likewise, IndexedBitmaps can only save indexed-colour format pngs.
2023-03-20 21:47:02 -04:00
Gered ac4df9e8ed merge functionality of PixelDecoder and ScanlineBuffer together 2023-03-20 17:47:18 -04:00