395 Commits

Author SHA1 Message Date
Pawel Kolodziejski
b321938c7b TINYGL: Restored ability to create internal buffer based on pixel format 2020-10-05 08:09:20 +02:00
Pawel Kolodziejski
27e12d8a96 ALL: Eliminate LOCAL_PI macro 2020-09-23 23:20:23 +02:00
Mathias Parnaudeau
2cad855184 TINYGL: Fix wrong access to the list of dirty rects
The function end() of a list does not return the last element but a fake element
after the last one, for the need of the iterator.
Trying to access to the data of the element returned by end() and that has no
such field, that caused a stack buffer overflow, reading uninitialized data.

Called function back() instead, to get the last element of the list.
2020-02-21 07:20:11 +01:00
Bastien Bouclet
fc67541742 ALL: Silence some GCC7 fall through warnings 2017-09-02 15:24:01 +02:00
Vincent Pelletier
bcd1066540 TINYGL: Move initialisation code outside of loop
Readability-only change.
Clarifies that these variables will be initialised before they get
accessed in the loop.
Also, initialise update_left and update_right to true, and only clear the
one needed for given triangle.
2017-07-20 01:56:35 +00:00
Vincent Pelletier
218d3214d7 TINYGL: Move remaining line counter decrement near y increment
Readability-only change.
Both represent the same notion, and nb_lines is only accessed as loop
condition.
2017-07-20 01:53:34 +00:00
Vincent Pelletier
a6af3a38a3 TINYGL: Fix vertice color when clipped and lighting is disabled
longcurrent_color is assigned per vertex, but it is not saved on each
vertex on creation (unlike their "color" attribute, used when lighting
is enabled).
As a consequence, and because rendering happens asynchronously (rather,
following the draw call queue managed by zdirtyrect.cpp when requested
to flip current buffer), longcurrent_color at clipping time can be
different to the one at vertex declaration time, causing color artifacts.

The effect is most noticeable in EMI set shi, in the grog dispenser +
shipyard manager closeup angle, when Guybrush exits the screen by
crossing its right border: dark triangles become visible on his face.

Instead, always use the color attribute, which is already properly
initialised on vertex creation.
2017-07-20 01:51:07 +00:00
Vincent Pelletier
92130c138e TINYGL: Obey current shade model also when clipping lines.
The code was only interpolating color (in TGL_SMOOTH mode) when clipping
faces, extend it to lines.
Also, factorise color interpolation code.
No visual difference is expected in normal use, but it fixes wireframe
rendering when used for debugging.
2017-07-20 01:48:58 +00:00
Vincent Pelletier
009d3320b3 TINYGL: Compute surface pixel count once only in BlitImage::loadData
Cartesian coordinates are not actually needed here, so simplify
computations by just using a pixel offset.
2017-05-15 10:31:25 +00:00
Vincent Pelletier
77a4672530 TINYGL: Enable dirty rectangle by default. 2017-05-02 09:57:09 +00:00
Vincent Pelletier
d797461fa9 TINYGL: Clip dirty rectangle to render rectangle.
As all dirty rectangles are inflated by 1 pixel to the right and one to the
bottom, they may exceed render rectangle. So clip them again. There should
be very few rectangles at this point, so this should be cheap.
2017-05-02 09:57:09 +00:00
Vincent Pelletier
290d6a3b6d TINYGL: Initialise a1 in fillTriangleFlat code path
fillTriangleFlat has kDrawLogic == DRAW_FLAT and interpRGB == false,
causing this variable to be used uninitialised.
Found by removing default values on all locals.
2017-05-02 09:42:06 +00:00
Vincent Pelletier
7988c696d9 TINYGL: Drop unused Framebuffer pixelbits property 2017-05-01 08:34:53 +00:00
Vincent Pelletier
eeedf4de06 TINYGL: Deduplicate PixelFormat retrieval in zblit
For some reason, loadData hardcodes a pixel format.
At least avoid duplicating it in Line constructor.
Likewise, avoid duplicating access to framebuffer's pixel format when
constructing a Line from another.
Also, avoid over-allocating Line, as its size argument is counted in pixel,
not in bytes.
2017-05-01 08:34:53 +00:00
Vincent Pelletier
4bcc95f217 TINYGL: Fix ARGBST scaling.
I based ARGB scaling on ST scaling without giving it enough thought.
It accidentally uncovered an older bug in glopClear, which made me recheck
these formulas.
ST scaling maps [0.0, 1.0] to [0x01.0000, 0xff.0000], meaning the first and
last texture rows and columns are never shown.
Treating s and t as proportions of ST_MAX fixes this by mapping to
[0x00.0000, 0xff.fffc] (last two fractional bits being off-precision, as
there are only 14 bits), covering the whole available range.
2017-05-01 08:34:25 +00:00
Vincent Pelletier
8c1954359e TINYGL: Fix glopClear
ClearBufferDrawCall expects 0..255 color values, not the internal 16-bits
fixed-point format.
Also, fix a typo in glopClear on Z scaling.
2017-05-01 08:32:25 +00:00
Vincent Pelletier
92a54a5969 fixup! TINYGL: Fix line color
These shifts are now handled in zline (only user of this macri),
consistently with ztriangle.
I have removed this macro from my working copy, but I missed the breakage
while resolving the conflict.
2017-05-01 04:45:11 +00:00
Vincent Pelletier
39656ce5c5 TINYGL: Store colors with 8-bits integer part
Before this change vertex data (post-shading) was limited to 6 (green) or
5 (all others) bits of precision.
Interpolation happened with 8-bits precision, so the visual effect is
minor: about 4 off at vertices.
2017-05-01 02:22:17 +00:00
Vincent Pelletier
054a2bd920 TINYGL: Fix line color
As in ztriangle, vertex color must be shifted from internal 16-bits
fixed-point format to 8-bits colors.
To do so, define values similar to the ones describing for ST fixed-point
format.
Also, use these in tglClear instead of hard-coded multiplicands, as is
done in tglColor4f and gl_transform_to_viewport.
Also, make tglClear take into account requested clear depth.
2017-05-01 02:21:40 +00:00
Vincent Pelletier
1d3d581870 TINYGL: Use same default clear depth as OpenGL 2017-05-01 02:19:42 +00:00
Vincent Pelletier
df62c19a88 TINYGL: const-ify all vector API parameters 2017-04-29 14:04:13 +00:00
Vincent Pelletier
5f993ac66f TINYGL: TGL_LINE_STRIP and TGL_LINE_LOOP are one line appart 2017-04-28 21:54:11 +00:00
Vincent Pelletier
5ab94de318 TINYGL: Avoid unneeded calls in writePixel. 2017-04-26 13:11:00 +00:00
Vincent Pelletier
fc37fabf0d TINYGL: Fix assertion failure during EMI intro video.
This is a regression introduced by
commit 6a63f544f05d868cde2e5d4473ff6c33df5a2115
    TINYGL: Avoid duplicating gl_transform_to_viewport.
2017-04-25 00:58:24 +00:00
Vincent Pelletier
2a1ab0a622 TINYGL: Do not queue invisible draw calls.
When dirty rectangles are enabled, we know at this point whether a draw
operation will have any effect on screen. Do not queue it if it will not.
2017-04-23 12:30:00 +00:00
Vincent Pelletier
bf319b5437 TINYGL: Cache and clip dirty rect on all DrawCall subclasses.
getDirtyRegion will be called twice on each DrawCall instance, so make
repeated work as short as possible.
2017-04-23 12:30:00 +00:00
Vincent Pelletier
6a63f544f0 TINYGL: Avoid duplicating gl_transform_to_viewport.
Replace local implementation by always setting GLVertex zp property.
Replace pointInsideVolume by clip_code, allowing to properly handle
polygons whose vertices are all off-screen but still have a part visible.
Also, replace 2-pixels offset with a more accurate bounding box
computation.
2017-04-23 12:30:00 +00:00
Vincent Pelletier
50c5aef6e5 Revert "TINYGL: Reuse renderRect instead of accessing fb size."
This reverts commit ec418a976967ea5cab643c47471cbbcc3505b2ac.
2017-04-23 12:25:58 +00:00
Vincent Pelletier
ec418a9769 TINYGL: Reuse renderRect instead of accessing fb size. 2017-04-23 12:03:52 +00:00
Vincent Pelletier
064bd1d47b fixup! TINYGL: ClearBufferDrawCall should obey its parameters.
Fixes an undeclared property error.
2017-04-23 11:54:53 +00:00
Vincent Pelletier
6087492dbd TINYGL: Simplify setting & disabling scissors. 2017-04-23 10:35:04 +00:00
Vincent Pelletier
e1de3407f1 TINYGL: Make scissors follow Common::Rect semantics.
As per Common::Rect data model, right and bottom border are excluded, so:
- Make FrameBuffer::scissorPixel reject bottom & right borders.
- Update bounding rectangle definition for dirty rectangle operations
  ClearBufferDrawCall::getDirtyRegion is already correct.
- zblit was almost following, except for an off-by-one mistake.
2017-04-23 10:35:04 +00:00
Vincent Pelletier
3acde7d900 TINYGL: static-ify zdirtyrect.cpp 2017-04-23 10:35:04 +00:00
Vincent Pelletier
2fb2d87dc9 TINYGL: Skip drawing when there is no dirty rectangle 2017-04-23 10:35:04 +00:00
Vincent Pelletier
72389d23df TINYGL: Simplify _drawCallAllocator switch & reset. 2017-04-23 10:35:04 +00:00
Vincent Pelletier
580578fa20 TINYGL: Containment is just a special case of intersection. 2017-04-23 10:35:04 +00:00
Vincent Pelletier
3f4a22354e TINYGL: Remove redundant condition.
Empty call queue condition is tested in contained "for" loop already.
2017-04-23 10:35:04 +00:00
Vincent Pelletier
5cbdabb69d TINYGL: Continue comparing past first divergence
It is common that the same number of calls are done in the same order, so
do not stop comparing after the first divergence. This saves a significant
number of dirty rectangle in crowded scenes, like sets cn and bi where a few
calls may differ in the middle of call sequence, but later calls would stay
the same.
As a consequence, move current-frame-has-fewer-calls handling to its own
loop.
Also, factorise and extend code appending dirty rectangles.
Also, skip conseutive identical rectangles.
2017-04-23 10:35:04 +00:00
Vincent Pelletier
ce97ff4e8f TINYGL: ClearBufferDrawCall should obey its parameters.
Given dirty rectangle may cover more buffer area than what it was told to
clear.
2017-04-23 10:35:04 +00:00
Vincent Pelletier
cc42d5cb24 TINYGL: Fix scissor testing in ztriangle.
When dirty rectangles are enabled, fixes drawing outside (below) set scissor
rectangle.
y and pp1 must stay consistent for scissor testing to be relevant. y is
already incremented along with pp1, and pp1 does not get re-assigned on
part == 2, so do not set y either.
2017-04-23 10:35:04 +00:00
Vincent Pelletier
500803fc38 TINYGL: Implement tglDrawArrays. 2017-04-22 16:42:14 +00:00
Vincent Pelletier
0b823ac2e9 TINYGL: Expose array functions outside of TinyGL namespace.
And prefix them with "tgl" instead of "gl", as in header.
2017-04-22 16:42:14 +00:00
Vincent Pelletier
13ad766b31 Merge pull request #1294 from vpelletier/tinygl_memory
Tinygl memory
2016-08-27 04:58:56 +02:00
Vincent Pelletier
112ca82363 TINYGL: Manage BlitImages with a refcount.
So that zdirtyrect can keep an image alive for longer than its creator
intended.
2016-07-28 23:32:43 +00:00
Vincent Pelletier
8cd029aac7 TINYGL: Add support for 4-bytes words in FrameBuffer::clear{,Region} 2016-07-28 23:29:17 +00:00
Vincent Pelletier
7e51d78480 TINYGL: Fix FrameBuffer::clearRegion color clearing line length. 2016-07-28 15:26:14 +00:00
Vincent Pelletier
e7e1df886e TINYGL: Merge dead kInterpST code path into kInterpSTZ one.
Texture coordinates interpolation along Z coordinate is an extra behaviour
over texture coordinates interpolation along X and Y coordinates.
2016-07-28 02:46:41 +00:00
Vincent Pelletier
a577b4c6a6 TINYGL: Free disposed textures before images.
Reusing function already defined in zdirtyrect.cpp doing both.
2016-07-28 01:55:48 +00:00
Vincent Pelletier
47a1e826e7 TINYGL: Free draw call lists in glClose. 2016-07-28 01:55:48 +00:00
Vincent Pelletier
3221146de9 TINYGL: Always initialise normal and eye coordinates (valgrind) 2016-07-28 01:55:48 +00:00