Cleanup: GL Render (simplify internal logic)

Reduce code-paths so improvements to 3D view render apply to sequencer too.
This commit is contained in:
Campbell Barton
2015-11-11 21:56:25 +11:00
parent 497c35aa78
commit 145298e2d3
7 changed files with 60 additions and 76 deletions

View File

@@ -36,6 +36,7 @@ struct StripColorBalance;
struct Editing;
struct GSet;
struct GPUOffScreen;
struct GPUFX;
struct ImBuf;
struct Main;
struct Mask;
@@ -105,6 +106,7 @@ typedef struct SeqRenderData {
/* special case for OpenGL render */
struct GPUOffScreen *gpu_offscreen;
struct GPUFX *gpu_fx;
int gpu_samples;
} SeqRenderData;
@@ -417,7 +419,7 @@ typedef struct ImBuf *(*SequencerDrawView)(
struct Scene *, struct Object *, int, int,
unsigned int, int, bool, bool, bool,
int, int, const char *,
struct GPUOffScreen *, char[256]);
struct GPUFX *, struct GPUOffScreen *, char[256]);
extern SequencerDrawView sequencer_view3d_cb;
/* copy/paste */

View File

@@ -3222,7 +3222,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
(context->scene->r.seq_flag & R_SEQ_SOLID_TEX) != 0,
use_gpencil, true, scene->r.alphamode,
context->gpu_samples, viewname,
context->gpu_offscreen, err_out);
context->gpu_fx, context->gpu_offscreen, err_out);
if (ibuf == NULL) {
fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
}

View File

@@ -334,12 +334,12 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf(
struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey,
unsigned int flag, bool draw_background,
int alpha_mode, int samples, const char *viewname,
struct GPUOffScreen *ofs, char err_out[256]);
struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
struct Scene *scene, struct Object *camera, int width, int height,
unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
int alpha_mode, int samples, const char *viewname,
struct GPUOffScreen *ofs, char err_out[256]);
struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);

View File

@@ -253,7 +253,6 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
RegionView3D *rv3d = oglrender->rv3d;
Object *camera = NULL;
ImBuf *ibuf;
float winmat[4][4];
float *rectf = RE_RenderViewGetById(rr, oglrender->view_id)->rectf;
int sizex = oglrender->sizex;
int sizey = oglrender->sizey;
@@ -276,6 +275,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
context.gpu_offscreen = oglrender->ofs;
context.gpu_fx = oglrender->fx;
context.gpu_samples = oglrender->ofs_samples;
ibuf = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
@@ -337,61 +337,31 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
MEM_freeN(gp_rect);
}
}
else if (view_context) {
bool is_persp;
/* full copy */
GPUFXSettings fx_settings = v3d->fx_settings;
ED_view3d_draw_offscreen_init(scene, v3d);
GPU_offscreen_bind(oglrender->ofs, true); /* bind */
/* render 3d view */
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
#if 0
const bool is_ortho = (scene->r.mode & R_ORTHO) != 0;
#endif
camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
RE_GetCameraWindow(oglrender->re, camera, scene->r.cfra, winmat);
if (camera->type == OB_CAMERA) {
Camera *cam = camera->data;
is_persp = cam->type == CAM_PERSP;
}
else
is_persp = true;
BKE_camera_to_gpu_dof(camera, &fx_settings);
}
else {
rctf viewplane;
float clipsta, clipend;
bool is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
if (is_ortho) orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
else perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
is_persp = !is_ortho;
}
rect = MEM_mallocN(sizex * sizey * sizeof(unsigned char) * 4, "offscreen rect");
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, winmat,
draw_bgpic, draw_sky, is_persp, viewname,
oglrender->fx, &fx_settings,
oglrender->ofs);
GPU_offscreen_read_pixels(oglrender->ofs, GL_UNSIGNED_BYTE, rect);
GPU_offscreen_unbind(oglrender->ofs, true); /* unbind */
}
else {
/* shouldnt suddenly give errors mid-render but possible */
char err_out[256] = "unknown";
ImBuf *ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
scene, scene->camera, oglrender->sizex, oglrender->sizey,
IB_rect, OB_SOLID, false, true, true,
(draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
oglrender->ofs, err_out);
camera = scene->camera;
ImBuf *ibuf_view;
if (view_context) {
ibuf_view = ED_view3d_draw_offscreen_imbuf(
scene, v3d, ar, sizex, sizey,
IB_rect, draw_bgpic,
(draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
oglrender->fx, oglrender->ofs, err_out);
/* for stamp only */
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
}
}
else {
ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
scene, scene->camera, oglrender->sizex, oglrender->sizey,
IB_rect, OB_SOLID, false, true, true,
(draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
oglrender->fx, oglrender->ofs, err_out);
camera = scene->camera;
}
if (ibuf_view) {
/* steal rect reference from ibuf */

View File

@@ -5402,7 +5402,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
ibuf = ED_view3d_draw_offscreen_imbuf(
scene, CTX_wm_view3d(C), CTX_wm_region(C),
w, h, IB_rect, false, R_ALPHAPREMUL, 0, NULL,
NULL, err_out);
NULL, NULL, err_out);
if (!ibuf) {
/* Mostly happens when OpenGL offscreen buffer was failed to create, */
/* but could be other reasons. Should be handled in the future. nazgul */

View File

@@ -3296,13 +3296,18 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
unsigned int flag, bool draw_background,
int alpha_mode, int samples, const char *viewname,
/* output vars */
GPUOffScreen *ofs, char err_out[256])
GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
{
RegionView3D *rv3d = ar->regiondata;
ImBuf *ibuf;
const bool draw_sky = (alpha_mode == R_ADDSKY) && v3d && (v3d->flag3 & V3D_SHOW_WORLD);
const bool own_ofs = (ofs == NULL);
/* view state */
GPUFXSettings fx_settings = {NULL};
float winmat[4][4];
bool is_ortho;
if (UNLIKELY(v3d == NULL))
return NULL;
@@ -3325,7 +3330,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
/* render 3d view */
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
CameraParams params;
GPUFXSettings fx_settings = {NULL};
Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
BKE_camera_params_init(&params);
@@ -3339,19 +3343,29 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
BKE_camera_to_gpu_dof(camera, &fx_settings);
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, params.winmat,
draw_background, draw_sky, !params.is_ortho, viewname,
NULL, &fx_settings,
ofs);
is_ortho = params.is_ortho;
copy_m4_m4(winmat, params.winmat);
}
else {
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, NULL,
draw_background, draw_sky, true, viewname,
NULL, NULL, ofs);
rctf viewplane;
float clipsta, clipend;
fx_settings = v3d->fx_settings;
is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
if (is_ortho) {
orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
}
else {
perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
}
}
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, winmat,
draw_background, draw_sky, !is_ortho, viewname,
fx, &fx_settings, ofs);
/* read in pixels & stamp */
ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
@@ -3368,7 +3382,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
glPopAttrib();
}
if (ibuf->rect_float && ibuf->rect)
IMB_rect_from_float(ibuf);
@@ -3387,7 +3401,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
Scene *scene, Object *camera, int width, int height,
unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
int alpha_mode, int samples, const char *viewname,
GPUOffScreen *ofs, char err_out[256])
GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
{
View3D v3d = {NULL};
ARegion ar = {NULL};
@@ -3437,9 +3451,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
return ED_view3d_draw_offscreen_imbuf(
scene, &v3d, &ar, width, height, flag,
draw_background, alpha_mode, samples, viewname,
ofs, err_out);
// seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty);
fx, ofs, err_out);
}

View File

@@ -936,14 +936,14 @@ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **t
scene, scene->camera,
BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
IB_rect, OB_SOLID, false, false, false, R_ALPHAPREMUL, 0, NULL,
NULL, err_out);
NULL, NULL, err_out);
}
else {
ibuf = ED_view3d_draw_offscreen_imbuf(
scene, v3d, ar,
BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
IB_rect, false, R_ALPHAPREMUL, 0, NULL,
NULL, err_out);
NULL, NULL, err_out);
}
if (ibuf) {