Ejemplo n.º 1
0
/*
 * This automatically manages FBOs so that render targets are always given
 * an FBO that matches their width/height/format to maximize optimization
 */
static struct fbo_info *get_fbo(struct gs_device *device, texture_t tex)
{
	size_t i;
	uint32_t width, height;
	GLuint fbo;
	struct fbo_info *ptr;

	if (!get_tex_dimensions(tex, &width, &height))
		return NULL;

	for (i = 0; i < device->fbos.num; i++) {
		ptr = device->fbos.array[i];

		if (ptr->width  == width && ptr->height == height &&
		    ptr->format == tex->format)
			return ptr;
	}

	glGenFramebuffers(1, &fbo);
	if (!gl_success("glGenFramebuffers"))
		return NULL;

	ptr = bmalloc(sizeof(struct fbo_info));
	ptr->fbo                 = fbo;
	ptr->width               = width;
	ptr->height              = height;
	ptr->format              = tex->format;
	ptr->cur_render_target   = NULL;
	ptr->cur_render_side     = 0;
	ptr->cur_zstencil_buffer = NULL;

	da_push_back(device->fbos, &ptr);
	return ptr;
}
Ejemplo n.º 2
0
static inline struct fbo_info *get_fbo_by_tex(struct gs_device *device,
		gs_texture_t tex)
{
	uint32_t width, height;
	if (!get_tex_dimensions(tex, &width, &height))
		return NULL;

	return get_fbo(device, width, height, tex->format);
}