Skip to content

Commit

Permalink
add flag DISABLE ANTI_ALIASING but it won't work in viewers (need to …
Browse files Browse the repository at this point in the history
…change other calls of _resize_image for MacOS, similar to the PR linked to this commit

Similar to LeiaInc@f933ba1

mmatl#39
  • Loading branch information
zzyunzhi committed Sep 30, 2022
1 parent a59963e commit e41ae7f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions pyrender/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class RenderFlags(object):
"""Render the color buffer flat, with no lighting computations."""
SEG = 8192

"""Custom: disable anti-aliasing. """
# https://github.com/mmatl/pyrender/pull/175/files
DISABLE_ANTI_ALIASING = 16384


class TextAlign:
"""Text alignment options for captions.
Expand Down
39 changes: 27 additions & 12 deletions pyrender/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Author: Matthew Matl
"""
import sys
import os

import numpy as np
import PIL
Expand Down Expand Up @@ -335,7 +336,8 @@ def _forward_pass(self, scene, flags, seg_node_map=None):

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

if not bool(flags & RenderFlags.SEG):
if not bool(flags & RenderFlags.SEG) and not bool(flags & RenderFlags.DISABLE_ANTI_ALIASING):
# if not bool(flags & RenderFlags.SEG):
glEnable(GL_MULTISAMPLE)
else:
glDisable(GL_MULTISAMPLE)
Expand Down Expand Up @@ -1009,7 +1011,7 @@ def _configure_forward_pass_viewport(self, flags):

# If using offscreen render, bind main framebuffer
if flags & RenderFlags.OFFSCREEN:
self._configure_main_framebuffer()
self._configure_main_framebuffer(flags)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, self._main_fb_ms)
else:
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)
Expand Down Expand Up @@ -1051,7 +1053,7 @@ def _delete_shadow_framebuffer(self):
if self._shadow_fb is not None:
glDeleteFramebuffers(1, [self._shadow_fb])

def _configure_main_framebuffer(self):
def _configure_main_framebuffer(self, flags):
# If mismatch with prior framebuffer, delete it
if (self._main_fb is not None and
self.viewport_width != self._main_fb_dims[0] or
Expand Down Expand Up @@ -1089,15 +1091,27 @@ def _configure_main_framebuffer(self):
# Generate multisample buffer
self._main_cb_ms, self._main_db_ms = glGenRenderbuffers(2)
glBindRenderbuffer(GL_RENDERBUFFER, self._main_cb_ms)
glRenderbufferStorageMultisample(
GL_RENDERBUFFER, 4, GL_RGBA,
self.viewport_width, self.viewport_height
)
if not bool(flags & RenderFlags.DISABLE_ANTI_ALIASING):
glRenderbufferStorageMultisample(
GL_RENDERBUFFER, 4, GL_RGBA,
self.viewport_width, self.viewport_height
)
else:
glRenderbufferStorage(
GL_RENDERBUFFER, GL_RGBA,
self.viewport_width, self.viewport_height
)
glBindRenderbuffer(GL_RENDERBUFFER, self._main_db_ms)
glRenderbufferStorageMultisample(
GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT24,
self.viewport_width, self.viewport_height
)
if not bool(flags & RenderFlags.DISABLE_ANTI_ALIASING):
glRenderbufferStorageMultisample(
GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT24,
self.viewport_width, self.viewport_height
)
else:
glRenderbufferStorage(
GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
self.viewport_width, self.viewport_height
)
self._main_fb_ms = glGenFramebuffers(1)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, self._main_fb_ms)
glFramebufferRenderbuffer(
Expand Down Expand Up @@ -1187,7 +1201,8 @@ def _read_main_framebuffer(self, scene, flags):

# Resize for macos if needed
if sys.platform == 'darwin':
color_im = self._resize_image(color_im, True)
# color_im = self._resize_image(color_im, True)
color_im = self._resize_image(color_im, antialias=not bool(flags & RenderFlags.DISABLE_ANTI_ALIASING))

return color_im, depth_im

Expand Down

0 comments on commit e41ae7f

Please sign in to comment.