Skip to content

Tweaks to fix gl2 rendering artifacts#114

Closed
HunterZ wants to merge 2 commits intolibtcod:mainfrom
HunterZ:hz-gl2
Closed

Tweaks to fix gl2 rendering artifacts#114
HunterZ wants to merge 2 commits intolibtcod:mainfrom
HunterZ:hz-gl2

Conversation

@HunterZ
Copy link

@HunterZ 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
@HexDecimal
Copy link
Collaborator

I'm having a hard time understanding TILE_PADDING. I'm expecting a constant like this to be padding per-side.

I wouldn't mind hard-coding a pixel of padding on each side of a tile.

@HexDecimal HexDecimal marked this pull request as draft March 26, 2022 18:15
@codecov
Copy link

codecov bot commented Mar 26, 2022

Codecov Report

Merging #114 (704e450) into develop (713817b) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

❗ Current head 704e450 differs from pull request most recent head 57719a2. Consider uploading reports for the commit 57719a2 to get more accurate results

@@             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     
Impacted Files Coverage Δ
src/libtcod/renderer_gl.c 0.00% <0.00%> (ø)
src/libtcod/renderer_gl2.c 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 713817b...57719a2. Read the comment docs.

@HexDecimal
Copy link
Collaborator

clang-tidy should be run on this code before you commit it.

Don't comment out code on version control, it should be deleted or stashed.

Comment on lines 262 to 263
columns = (new_size - TILE_PADDING) / (atlas->tileset->tile_width + TILE_PADDING);
rows = (new_size - TILE_PADDING) / (atlas->tileset->tile_height + TILE_PADDING);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy should 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)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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#
##########

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I might be wrong with the exact math. I often program iteratively.

Copy link
Author

@HunterZ HunterZ Mar 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +15 to +17
if(MINGW)
set(LINK_TCOD mingw32 "${LINK_TCOD}")
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand where this fix comes from. Why is mingw32 hard coded here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@HexDecimal
Copy link
Collaborator

I warned you this wasn't ready for primetime!

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
@HexDecimal HexDecimal changed the base branch from develop to main August 11, 2022 12:38
@HexDecimal
Copy link
Collaborator

Closed because the OpenGL renderers have been removed by #137.

@HexDecimal HexDecimal closed this Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants