Tweaks to fix gl2 rendering artifacts#114
Conversation
HunterZ
commented
Mar 26, 2022
- CMakeLists.txt:
- MinGW compat fix
- src/libtcod/renderer_gl.c:
- implement optional atlas padding support
- add more comments
- src/libtcod/renderer_gl.h:
- add optional TILE_PADDING macro to configure atlas padding support
- src/libtcod/renderer_gl2.c:
- fragment shader: use atlas pixel dimensions instead of row/col index
- fragment shader: remove clamping logic
- fragment shader: use texture2DLod to force disable mipmap use
- encode atlas pixel coordinates in ch buffer texture instead of row/col indexes
- send actual atlas texture size to fragment shader instead of recalculating
- CMakeLists.txt: - MinGW compat fix - src/libtcod/renderer_gl.c: - implement optional atlas padding support - add more comments - src/libtcod/renderer_gl.h: - add optional TILE_PADDING macro to configure atlas padding support - src/libtcod/renderer_gl2.c: - fragment shader: use atlas pixel dimensions instead of row/col index - fragment shader: remove clamping logic - fragment shader: use texture2DLod to force disable mipmap use - encode atlas pixel coordinates in ch buffer texture instead of row/col indexes - send actual atlas texture size to fragment shader instead of recalculating
|
I'm having a hard time understanding I wouldn't mind hard-coding a pixel of padding on each side of a tile. |
Codecov Report
@@ Coverage Diff @@
## develop #114 +/- ##
===========================================
- Coverage 12.56% 12.52% -0.05%
===========================================
Files 124 124
Lines 13240 13283 +43
===========================================
Hits 1664 1664
- Misses 11576 11619 +43
Continue to review full report at Codecov.
|
|
Don't comment out code on version control, it should be deleted or stashed. |
src/libtcod/renderer_gl.c
Outdated
| columns = (new_size - TILE_PADDING) / (atlas->tileset->tile_width + TILE_PADDING); | ||
| rows = (new_size - TILE_PADDING) / (atlas->tileset->tile_height + TILE_PADDING); |
There was a problem hiding this comment.
This can't be something simpler? Like columns = new_size / (atlas->tileset->tile_width + TILE_PADDING * 2);?
I assume that the total tile size is the tile size plus the padding.
There was a problem hiding this comment.
clang-tidyshould be run on this code before you commit it.Don't comment out code on version control, it should be deleted or stashed.
I warned you this wasn't ready for primetime!
This can't be something simpler? Like
columns = new_size / (atlas->tileset->tile_width + TILE_PADDING * 2);?I assume that the total tile size is the tile size plus the padding.
No. There needs to be padding along one side of each dimension of the atlas, plus per-tile padding along the opposite sides of each dimension of each tile.
The total atlas size in a given dimension is therefore padding_size + numTiles.dimension * (tile_size.dimension + padding_size)
There was a problem hiding this comment.
I assume that if the tiles are laid out like this:
111222
111222
111222
A pixel of padding will be applied like this:
##########
#111##222#
#111##222#
#111##222#
##########
There was a problem hiding this comment.
But I might be wrong with the exact math. I often program iteratively.
There was a problem hiding this comment.
PADDING=2 with my approach, used with 2x2 tiles:
##########
##########
##11##22##
##11##22##
##########
##########
##33##44##
##33##44##
##########
##########
Your suggestion would be less compact:
############
############
##11####22##
##11####22##
############
############
############
############
##33####44##
##33####44##
############
############
Your approach would allow for odd numbered padding values though, which I didn't consider. Let me know if you think this is worth pursuing.
There was a problem hiding this comment.
I'd like to go with my approach and then hardcode a padding value of 1.
Alternatively I'd like to figure out framebuffers so that I can skip padding entirely, but I can try that on my PR.
There was a problem hiding this comment.
Fixed. Also verified that (at least with texture2DLod) TILE_PADDING value of 1 works for both GL_NEAREST and GL_LINEAR, and that commenting out the macro still works.
| if(MINGW) | ||
| set(LINK_TCOD mingw32 "${LINK_TCOD}") | ||
| endif() |
There was a problem hiding this comment.
I don't understand where this fix comes from. Why is mingw32 hard coded here?
There was a problem hiding this comment.
Because when compiling SDL2 with MinGW in the MSYS2 environment, you need to link libmingw32.a first, or else the linker stage will fail. This is a widely-known issue.
That's not a problem. I'm just pointing it out now so that I don't need to mention it later. I'll handle anything that you miss. |
- renderer_gl.c: - assume each tile has its own TILE_PADDING pixels of padding around all sides in the atlas texture - remove commented out code - slight optimizations and comments / parameter name tweaks - renderer_gl.h: - default to a TILE_PADDING value of 1 - renderer_gl2.c: - assume each tile has its own TILE_PADDING pixels of padding around all sides in the atlas texture - remove commented out code - tweak comments
|
Closed because the OpenGL renderers have been removed by #137. |