本文整理汇总了Python中kivy.graphics.RenderContext.ask_update方法的典型用法代码示例。如果您正苦于以下问题:Python RenderContext.ask_update方法的具体用法?Python RenderContext.ask_update怎么用?Python RenderContext.ask_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.graphics.RenderContext
的用法示例。
在下文中一共展示了RenderContext.ask_update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AndroidCameraPreview
# 需要导入模块: from kivy.graphics import RenderContext [as 别名]
# 或者: from kivy.graphics.RenderContext import ask_update [as 别名]
#.........这里部分代码省略.........
parameters = self._camera.getParameters()
#print parameters.flatten()
if parameters is None:
Logger.warning('Can''t read parameters')
return
supportedSizes = parameters.getSupportedVideoSizes()
if supportedSizes is None:
supportedSizes = parameters.getSupportedPreviewSizes()
sizes = []
if supportedSizes is not None:
iterator = supportedSizes.iterator()
while iterator.hasNext():
cameraSize = iterator.next()
sizes.append((cameraSize.width, cameraSize.height))
pickedSize = self._pick_optimal_size(sizes)
# Update texture according to picked size
self.resolution = list(pickedSize)
parameters.setPreviewSize(*pickedSize)
self._camera.setParameters(parameters)
self._camera.setPreviewTexture(self._previewTexture)
def get_camera(self):
return self._camera
def _resolution_changed(self, instance, value):
Logger.info('Resolution changed to ' + str(value))
self._init_texture(value)
def _camera_id_changed(self, instance, value):
Logger.info('Changed camera %d' % value)
if not IsAndroid:
return
# Transform orientation based on selected camera
if self.camera_id == 0:
sampleVec = ('1.0-tex_coord0.y','1.0-tex_coord0.x')
elif self.camera_id == 1:
sampleVec = ('tex_coord0.y','1.0-tex_coord0.x')
else:
raise Exception('Invalid camera id')
self.canvas.shader.fs = '''
#extension GL_OES_EGL_image_external : require
#ifdef GL_ES
precision highp float;
#endif
/* Outputs from the vertex shader */
varying vec4 frag_color;
varying vec2 tex_coord0;
/* uniform texture samplers */
uniform sampler2D texture0;
uniform samplerExternalOES texture1;
void main()
{
// Flip & Mirror coordinates to rotate source texture by 90 degress
gl_FragColor = texture2D(texture1, vec2(%s,%s));
}
''' % (sampleVec[0], sampleVec[1])
def _play_changed(self, instance, value):
Logger.info('camera %d _play_changed %d' % (self.camera_id, value))
if not IsAndroid:
return
if value:
if not self._camera:
self._init_camera(self.camera_id)
self._camera.startPreview()
Clock.schedule_interval(self._update_canvas, 1.0/30)
else:
if self._camera:
Clock.unschedule(self._update_canvas)
self._camera.stopPreview()
def _release_camera(self):
self.play = False
if self._camera:
self._camera.release()
self._camera = None
def _pick_optimal_size(self, sizes):
# Now just returns the one guaranteed support size
return sizes[0]
def _draw_callback(self, instr):
if self._previewTexture:
self._previewTexture.updateTexImage()
def _update_canvas(self, dt):
self.canvas.ask_update()
示例2: YuvVideo
# 需要导入模块: from kivy.graphics import RenderContext [as 别名]
# 或者: from kivy.graphics.RenderContext import ask_update [as 别名]
#.........这里部分代码省略.........
}
'''
fs = StringProperty(None)
textures = ListProperty([None, None, None])
format = OptionProperty(YUV_CHROMA_FORMAT[1], options=YUV_CHROMA_FORMAT)
colorfmt = OptionProperty(OUT_COLOR_FORMAT[1], options=OUT_COLOR_FORMAT)
yuv_size = ListProperty([0, 0])
yuv_fps = NumericProperty(30.)
def __init__(self, **kwargs):
self.register_event_type('on_load')
self.canvas = RenderContext(fs=self.FS_CONVERT_YUV)
self.canvas['tex_y'] = 1
self.canvas['tex_u'] = 2
self.canvas['tex_v'] = 3
super(YuvVideo, self).__init__(**kwargs)
if self.colorfmt == OUT_COLOR_FORMAT[0]:
self.fs = self.FS_CONVERT_RGB
elif self.format != YUV_CHROMA_FORMAT[0]:
self.fs = self.FS_CONVERT_YUV
else:
self.fs = self.FS_CONVERT_MONO
def seek(self, percent):
if self.eos == True:
self.eos = False
super(YuvVideo, self).seek(percent)
def on_load(self, *largs):
pass
def on_fs(self, instance, value):
shader = self.canvas.shader
old_value = shader.fs
shader.fs = value
if not shader.success:
shader.fs = old_value
raise Exception('failed')
def on_size(self, instance, value):
window = self.get_parent_window()
if window:
self.canvas['projection_mat'] = window.render_context['projection_mat']
def on_state(self, instance, value):
if not self._video:
return
if value == 'stop':
self._video.stop()
else:
super(YuvVideo, self).on_state(instance, value)
def _do_video_load(self, *largs):
if self._video:
self._video.stop()
if not self.source:
self._video = None
self.textures = [None, None, None]
self.texture = None
else:
filename = self.source
if filename.split(':')[0] not in (
'http', 'https', 'file', 'udp', 'rtp', 'rtsp'):
filename = resource_find(filename)
self._video = VideoYuv(filename=filename,
format=self.format,
colorfmt=self.colorfmt,
size=self.yuv_size,
fps=self.yuv_fps)
self._video.volume = self.volume
self._video.bind(on_load=self._on_video_load,
on_frame=self._on_video_frame,
on_eos=self._on_eos)
if self.state == 'play' or self.play:
self._video.play()
self.duration = 1.
self.position = 0.
def _on_video_load(self, *largs):
self._on_video_frame()
self.dispatch('on_load')
def _on_video_frame(self, *largs):
self.duration = self._video.duration
self.position = self._video.position
self.textures = self._video.texture
self.texture = self._video.texture[0]
self.canvas.ask_update()
def _on_eos(self, *largs):
self.duration = self._video.duration
self.position = self._video.position
self.state = 'pause'
self.eos = True
示例3: SMAA
# 需要导入模块: from kivy.graphics import RenderContext [as 别名]
# 或者: from kivy.graphics.RenderContext import ask_update [as 别名]
class SMAA(Widget):
debug = OptionProperty("", options=("", "edges", "blend", "source"))
"""Texture to show instead of the result:
- `edges` will show you the result of the edges detection shader
- `blend` will show you the result of the blending shader
- `source` will show you the initial drawing of children, before any pass.
"""
quality = OptionProperty("ultra", options=("low", "medium", "high", "ultra"))
"""Quality of the shader. The more you ask, the slower it will be.
"""
def __init__(self, **kwargs):
self._g_debug = []
self._g_debug_added = False
if "size" not in kwargs:
from kivy.core.window import Window
kwargs["size"] = Window.size
self.size = kwargs["size"]
self.init_smaa()
super(SMAA, self).__init__()
self.canvas.add(self.smaa_canvas)
self.canvas.ask_update()
def add_widget(self, *args):
canvas = self.smaa_canvas
self.canvas = self.albedo_fbo
super(SMAA, self).add_widget(*args)
self.canvas = canvas
def remove_widget(self, *args):
canvas = self.smaa_canvas
self.canvas = self.albedo_fbo
super(SMAA, self).remove_widget(*args)
self.canvas = canvas
def init_smaa(self):
curdir = dirname(__file__)
# load shaders sources
with open(join(curdir, "SMAA.h"), "r") as fd:
smaa_h = fd.read()
config = """
#version 410 compatibility
#define SMAA_PIXEL_SIZE vec2(1.0 / {width}, 1.0 / {height})
#define SMAA_PRESET_{quality} 1
#define SMAA_GLSL_4 1
""".format(
width=self.width, height=self.height, quality=self.quality.upper()
)
header_vs = (
config
+ """
#define SMAA_ONLY_COMPILE_VS 1
in vec2 vPosition;
in vec2 vTexCoords0;
uniform mat4 modelview_mat;
uniform mat4 projection_mat;
"""
+ smaa_h
)
header_fs = (
config
+ """
#define SMAA_ONLY_COMPILE_PS 1
"""
+ smaa_h
)
edge_vs = (
header_vs
+ """
out vec2 texcoord;
out vec4 offset[3];
out vec4 dummy2;
void main()
{
texcoord = vTexCoords0;
vec4 dummy1 = vec4(0);
SMAAEdgeDetectionVS(dummy1, dummy2, texcoord, offset);
gl_Position = projection_mat * modelview_mat * vec4(vPosition.xy, 0.0, 1.0);
}
"""
)
edge_fs = (
header_fs
+ """
uniform sampler2D albedo_tex;
in vec2 texcoord;
in vec4 offset[3];
in vec4 dummy2;
void main()
#.........这里部分代码省略.........