コード例 #1
0
ファイル: gl-stagesurf.c プロジェクト: Tyrrr/obs-studio
void device_stage_texture(device_t device, stagesurf_t dst, texture_t src)
{
	struct gs_texture_2d *tex2d = (struct gs_texture_2d*)src;
	if (!can_stage(dst, tex2d))
		goto failed;

	if (!gl_copy_texture(device, dst->texture, GL_TEXTURE_2D,
				tex2d->base.texture, GL_TEXTURE_2D,
				dst->width, dst->height))
		goto failed;

	if (!gl_bind_texture(GL_TEXTURE_2D, dst->texture))
		goto failed;
	if (!gl_bind_buffer(GL_PIXEL_PACK_BUFFER, dst->pack_buffer))
		goto failed;

	glGetTexImage(GL_TEXTURE_2D, 0, dst->gl_format, dst->gl_type, 0);
	if (!gl_success("glGetTexImage"))
		goto failed;

	gl_bind_buffer(GL_PIXEL_PACK_BUFFER, 0);
	gl_bind_texture(GL_TEXTURE_2D, 0);
	return;

failed:
	gl_bind_buffer(GL_PIXEL_PACK_BUFFER, 0);
	gl_bind_texture(GL_TEXTURE_2D, 0);
	blog(LOG_ERROR, "device_stage_texture (GL) failed");
}
コード例 #2
0
ファイル: gl-stagesurf.c プロジェクト: Arkkis/obs-studio
/* Apparently for mac, PBOs won't do an asynchronous transfer unless you use
 * FBOs aong with glReadPixels, which is really dumb. */
void device_stage_texture(device_t device, stagesurf_t dst, texture_t src)
{
	struct gs_texture_2d *tex2d = (struct gs_texture_2d*)src;
	struct fbo_info *fbo;
	GLint last_fbo;
	bool success = false;

	if (!can_stage(dst, tex2d))
		goto failed;

	if (!gl_bind_buffer(GL_PIXEL_PACK_BUFFER, dst->pack_buffer))
		goto failed;

	fbo = get_fbo(device, dst->width, dst->height, dst->format);

	if (!gl_get_integer_v(GL_READ_FRAMEBUFFER_BINDING, &last_fbo))
		goto failed_unbind_buffer;
	if (!gl_bind_framebuffer(GL_READ_FRAMEBUFFER, fbo->fbo))
		goto failed_unbind_buffer;

	glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + 0,
			src->gl_target, src->texture, 0);
	if (!gl_success("glFrameBufferTexture2D"))
		goto failed_unbind_all;

	glReadPixels(0, 0, dst->width, dst->height, dst->gl_format,
			dst->gl_type, 0);
	if (!gl_success("glReadPixels"))
		goto failed_unbind_all;

	success = true;

failed_unbind_all:
	gl_bind_framebuffer(GL_READ_FRAMEBUFFER, last_fbo);

failed_unbind_buffer:
	gl_bind_buffer(GL_PIXEL_PACK_BUFFER, 0);

failed:
	if (!success)
		blog(LOG_ERROR, "device_stage_texture (GL) failed");
}