Skip to content

Conversation

@tryone144
Copy link
Collaborator

Similar to the changes in #349 and as discussed over there, this PR sets the viewport to the maximum supported dimensions in the new OpenGL backend. In contrast to #349, the projection matrix in each shader has to be set only once when setting up the shader program and not for each draw call.

Changes

  • Query maximum supported dimensions of glViewport() when initializing
    so we don't have to worry about differently sized textures when
    rendering (usually the same as the maximum supported texture size, but
    dependend on the driver).
  • Set projection matrix in all shaders at startup to queried viewport
    dimensions. Allows using screen coordinates for all vertex positions
    without having to keep track of framebuffer dimensions.
  • Follow recommendations and set glViewport() to queried maximum dimensions
    for each draw call (glDraw*(), glClear()).

Rationale

Instead of keeping track of all framebuffer/texture sizes and updating the viewport and projection matrix for each shader and draw call, we set them up once to "cancel each other out" regardless of the actual buffer dimensions.
glViewport() itself is only responsible for the transformation from NDC to screen space, so setting it to larger-than-screen dimensions has no effect on video memory. Since the maximum dimensions are usually the same as the maximum supported texture sizes and not that much bigger than actual screen sizes (OpenGL Hardware Database) there is no loss in precision to be expected. Initial testing showed that window coordinates are clipped to screen dimensions regardless, so that we aren't even trying to render outside the screen bounds.

Related to #382

Having a unified viewport simplifies rendering passes for the dual-filter kawase blur algorithm.

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #388 into next will increase coverage by 0.17%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next     #388      +/-   ##
==========================================
+ Coverage   37.13%   37.31%   +0.17%     
==========================================
  Files          45       45              
  Lines        8569     8571       +2     
==========================================
+ Hits         3182     3198      +16     
+ Misses       5387     5373      -14     
Impacted Files Coverage Δ
src/backend/gl/gl_common.c 0.00% <0.00%> (ø)
src/backend/gl/gl_common.h 0.00% <ø> (ø)
src/win.c 64.43% <0.00%> (-0.32%) ⬇️
src/opengl.h 53.48% <0.00%> (+2.32%) ⬆️
src/utils.h 73.68% <0.00%> (+21.05%) ⬆️
src/log.h 68.75% <0.00%> (+25.00%) ⬆️
src/x.h 78.94% <0.00%> (+26.31%) ⬆️
src/win.h 41.66% <0.00%> (+41.66%) ⬆️

Copy link
Owner

@yshui yshui left a comment

Choose a reason for hiding this comment

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

LGTM

@yshui
Copy link
Owner

yshui commented Apr 23, 2020

@tryone144 is there no way to nudge gl_average_texture_color to work the same way?

@tryone144
Copy link
Collaborator Author

@tryone144 is there no way to nudge gl_average_texture_color to work the same way?

There was some logic I am not too sure about, but in theory it should be possible. I'll take a look into it.

@yshui
Copy link
Owner

yshui commented Apr 23, 2020

@tryone144 Ok, I will merge this first.

- Query maximum supported dimensions of `glViewport()` when initializing
so we don't have to worry about differently sized textures when
rendering (usually the same as the maximum supported texture size, but
dependend on the driver).
- Set projection matrix in all shaders at startup to queried viewport
dimensions. Allows using screen coordinates for all vertex positions
without having to keep track of framebuffer dimensions.
- Follow recommendations and set `glViewport()` to queried maximum dimensions
for each draw call (`glDraw*()`, `glClear()`).

Related: yshui#349
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