Commit af32ea8b authored by Dalai Felinto's avatar Dalai Felinto
Browse files

use preview scale and remove viewport from reset_view

parent d770ba7f
......@@ -109,7 +109,7 @@ def view_setup():
gluLookAt(0.0, 0.0, 1.0, 0.0,0.0,0.0, 0.0,1.0,0.0)
def view_reset(viewport):
def view_reset():
# Get texture info
glMatrixMode(GL_PROJECTION)
glPopMatrix()
......@@ -120,8 +120,6 @@ def view_reset(viewport):
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
# ##################
# FBO related routines
......@@ -237,7 +235,8 @@ class FBO:
glDisable(GL_TEXTURE_2D)
glDisable(GL_DEPTH_TEST)
view_reset(viewport)
view_reset()
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
# unbinding
glBindFramebuffer(GL_FRAMEBUFFER, act_fbo[0])
......
......@@ -286,7 +286,7 @@ def view_setup():
gluLookAt(0.0, 0.0, 1.0, 0.0,0.0,0.0, 0.0,1.0,0.0)
def view_reset(viewport):
def view_reset():
# Get texture info
glMatrixMode(GL_PROJECTION)
glPopMatrix()
......@@ -297,8 +297,6 @@ def view_reset(viewport):
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
def draw_rectangle_rainbow(zed=0.0):
texco = [(1, 1), (0, 1), (0, 0), (1,0)]
......@@ -371,7 +369,9 @@ def draw_callback_px(self, context):
glUseProgram(0)
glActiveTexture(act_tex[0])
glBindTexture(GL_TEXTURE_2D, 0)
view_reset(self.viewport)
view_reset()
glViewport(self.viewport[0], self.viewport[1], self.viewport[2], self.viewport[3])
glMatrixMode(GL_MODELVIEW)
glTranslatef(-cam_pos[0], -cam_pos[1], -cam_pos[2])
......@@ -54,7 +54,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
if event.type == 'TIMER':
self.loop()
if vr.use_preview:
if vr.preview_scale:
context.area.tag_redraw()
return {'PASS_THROUGH'}
......@@ -167,8 +167,7 @@ class VirtualRealityDisplayOperator(bpy.types.Operator):
wm = context.window_manager
vr = wm.virtual_reality
if vr.use_preview:
self._preview.loop()
self._preview.loop(vr.preview_scale)
# ############################################################
......@@ -181,11 +180,15 @@ class VirtualRealityInfo(bpy.types.PropertyGroup):
default=False,
)
use_preview = bpy.props.BoolProperty(
name="Preview",
default=False,
preview_scale = bpy.props.IntProperty(
name="Preview Scale",
min=0,
max=100,
default=100,
subtype='PERCENTAGE',
)
# ############################################################
# Callbacks
# ############################################################
......
......@@ -59,47 +59,30 @@ class Preview:
self._width = width
self._height = height
def _getScissor(self, viewport, offset_x, offset_y, width, height):
"""
Fit scissor inside viewport
"""
scissor = [0,0,0,0]
scissor[0] = max(offset_x, viewport[0])
scissor[1] = max(offset_y, viewport[1])
scissor[2] = min(width, viewport[2] - (scissor[0] - viewport[0]))
scissor[3] = min(height, viewport[3] - (scissor[1] - viewport[1]))
return scissor
def loop(self):
def loop(self, scale):
"""
Draw in the preview window
"""
texture = self._texture
width = self._width
height = self._height
if not scale:
return
offset_x, offset_y = 100, 100 # this is window offset, not viewport offset
texture = self._texture
act_tex = Buffer(GL_INT, 1)
glGetIntegerv(GL_ACTIVE_TEXTURE, act_tex)
viewport = Buffer(GL_INT, 4)
glGetIntegerv(GL_VIEWPORT, viewport)
if scale != 100:
viewport = Buffer(GL_INT, 4)
glGetIntegerv(GL_VIEWPORT, viewport)
glViewport(
max(offset_x, viewport[0]),
max(offset_x, viewport[1]),
width,
height,
)
width = int(scale * 0.01 * viewport[2])
height = int(scale * 0.01 * viewport[3])
scissor = self._getScissor(viewport, offset_x, offset_y, width, height)
glScissor(scissor[0], scissor[1], scissor[2], scissor[3])
glViewport(viewport[0], viewport[1], width, height)
glScissor(viewport[0], viewport[1], width, height)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LESS)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LESS)
view_setup()
......@@ -114,8 +97,9 @@ class Preview:
glDisable(GL_TEXTURE_2D)
glDisable(GL_DEPTH_TEST)
view_reset(viewport)
view_reset()
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
glScissor(viewport[0], viewport[1], viewport[2], viewport[3])
if scale != 100:
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
glScissor(viewport[0], viewport[1], viewport[2], viewport[3])
......@@ -23,8 +23,9 @@ class VirtualRealityPanel(bpy.types.Panel):
col.operator("view3d.virtual_reality_display", text="Virtual Reality", icon="PLAY").action='ENABLE'
else:
col.operator("view3d.virtual_reality_display", text="Virtual Reality", icon="X").action='DISABLE'
col.separator()
col.prop(vr, "use_preview")
col.prop(vr, "preview_scale", text="Preview")
# ############################################################
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment