GPUOffScreen: Remove the sample parameter
This is because the DRW module is no longer compatible with drawing using MSAA. This also change the Python API.
This commit is contained in:
parent
a4fe8ef236
commit
35481fde40
Notes:
blender-bot
2023-02-14 09:43:37 +01:00
Referenced by issue #77836, gpu.types.GPUOffscreen crashes Blender
|
@ -352,8 +352,7 @@ static bool gpencil_render_offscreen(tGPDfill *tgpf)
|
|||
round_v2i_v2fl(tgpf->center, center);
|
||||
|
||||
char err_out[256] = "unknown";
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(
|
||||
tgpf->sizex, tgpf->sizey, 0, true, false, err_out);
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(tgpf->sizex, tgpf->sizey, true, false, err_out);
|
||||
if (offscreen == NULL) {
|
||||
printf("GPencil - Fill - Unable to create fill buffer\n");
|
||||
return false;
|
||||
|
|
|
@ -766,7 +766,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
|
|||
|
||||
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
|
||||
DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
|
||||
ofs = GPU_offscreen_create(sizex, sizey, 0, true, true, err_out);
|
||||
ofs = GPU_offscreen_create(sizex, sizey, true, true, err_out);
|
||||
DRW_opengl_context_disable();
|
||||
|
||||
if (!ofs) {
|
||||
|
|
|
@ -611,7 +611,7 @@ static void screen_preview_draw(const bScreen *screen, int size_x, int size_y)
|
|||
void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, uint *r_rect)
|
||||
{
|
||||
char err_out[256] = "unknown";
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, 0, true, false, err_out);
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, true, false, err_out);
|
||||
|
||||
GPU_offscreen_bind(offscreen, true);
|
||||
GPU_clear_color(0.0, 0.0, 0.0, 0.0);
|
||||
|
|
|
@ -1888,7 +1888,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
|
|||
|
||||
if (own_ofs) {
|
||||
/* bind */
|
||||
ofs = GPU_offscreen_create(sizex, sizey, 0, true, false, err_out);
|
||||
ofs = GPU_offscreen_create(sizex, sizey, true, false, err_out);
|
||||
if (ofs == NULL) {
|
||||
DRW_opengl_context_disable();
|
||||
return NULL;
|
||||
|
|
|
@ -195,7 +195,7 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *fb,
|
|||
*/
|
||||
|
||||
GPUOffScreen *GPU_offscreen_create(
|
||||
int width, int height, int samples, bool depth, bool high_bitdepth, char err_out[256]);
|
||||
int width, int height, bool depth, bool high_bitdepth, char err_out[256]);
|
||||
void GPU_offscreen_free(GPUOffScreen *ofs);
|
||||
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
|
||||
void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
|
||||
|
|
|
@ -876,7 +876,7 @@ static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs)
|
|||
}
|
||||
|
||||
GPUOffScreen *GPU_offscreen_create(
|
||||
int width, int height, int samples, bool depth, bool high_bitdepth, char err_out[256])
|
||||
int width, int height, bool depth, bool high_bitdepth, char err_out[256])
|
||||
{
|
||||
GPUOffScreen *ofs;
|
||||
|
||||
|
@ -887,12 +887,11 @@ GPUOffScreen *GPU_offscreen_create(
|
|||
height = max_ii(1, height);
|
||||
width = max_ii(1, width);
|
||||
|
||||
ofs->color = GPU_texture_create_2d_multisample(
|
||||
width, height, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL, samples, err_out);
|
||||
ofs->color = GPU_texture_create_2d(
|
||||
width, height, (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL, err_out);
|
||||
|
||||
if (depth) {
|
||||
ofs->depth = GPU_texture_create_2d_multisample(
|
||||
width, height, GPU_DEPTH24_STENCIL8, NULL, samples, err_out);
|
||||
ofs->depth = GPU_texture_create_2d(width, height, GPU_DEPTH24_STENCIL8, NULL, err_out);
|
||||
}
|
||||
|
||||
if ((depth && !ofs->depth) || !ofs->color) {
|
||||
|
@ -993,48 +992,7 @@ void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
|
|||
|
||||
BLI_assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT);
|
||||
|
||||
if (GPU_texture_target(ofs->color) == GL_TEXTURE_2D_MULTISAMPLE) {
|
||||
/* For a multi-sample texture,
|
||||
* we need to create an intermediate buffer to blit to,
|
||||
* before its copied using 'glReadPixels' */
|
||||
GLuint fbo_blit = 0;
|
||||
GLuint tex_blit = 0;
|
||||
|
||||
/* create texture for new 'fbo_blit' */
|
||||
glGenTextures(1, &tex_blit);
|
||||
glBindTexture(GL_TEXTURE_2D, tex_blit);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, (type == GL_FLOAT) ? GL_RGBA16F : GL_RGBA8, w, h, 0, GL_RGBA, type, 0);
|
||||
|
||||
/* write into new single-sample buffer */
|
||||
glGenFramebuffers(1, &fbo_blit);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_blit);
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_blit, 0);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
goto finally;
|
||||
}
|
||||
|
||||
/* perform the copy */
|
||||
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
/* read the results */
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_blit);
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
|
||||
|
||||
/* restore the original frame-bufer */
|
||||
GPUFrameBuffer *ofs_fb = gpu_offscreen_fb_get(ofs);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, ofs_fb->object);
|
||||
|
||||
finally:
|
||||
/* cleanup */
|
||||
glDeleteTextures(1, &tex_blit);
|
||||
glDeleteFramebuffers(1, &fbo_blit);
|
||||
}
|
||||
else {
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
|
||||
}
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
|
||||
}
|
||||
|
||||
int GPU_offscreen_width(const GPUOffScreen *ofs)
|
||||
|
|
|
@ -86,17 +86,17 @@ static PyObject *bpygpu_offscreen_new(PyTypeObject *UNUSED(self), PyObject *args
|
|||
BPYGPU_IS_INIT_OR_ERROR_OBJ;
|
||||
|
||||
GPUOffScreen *ofs = NULL;
|
||||
int width, height, samples = 0;
|
||||
int width, height;
|
||||
char err_out[256];
|
||||
|
||||
static const char *_keywords[] = {"width", "height", "samples", NULL};
|
||||
static const char *_keywords[] = {"width", "height", NULL};
|
||||
static _PyArg_Parser _parser = {"ii|i:GPUOffScreen.__new__", _keywords, 0};
|
||||
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &width, &height, &samples)) {
|
||||
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &width, &height)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (GPU_context_active_get()) {
|
||||
ofs = GPU_offscreen_create(width, height, samples, true, false, err_out);
|
||||
ofs = GPU_offscreen_create(width, height, true, false, err_out);
|
||||
}
|
||||
else {
|
||||
strncpy(err_out, "No active GPU context found", 256);
|
||||
|
@ -345,16 +345,14 @@ static struct PyMethodDef bpygpu_offscreen_methods[] = {
|
|||
};
|
||||
|
||||
PyDoc_STRVAR(bpygpu_offscreen_doc,
|
||||
".. class:: GPUOffScreen(width, height, samples=0)\n"
|
||||
".. class:: GPUOffScreen(width, height)\n"
|
||||
"\n"
|
||||
" This object gives access to off screen buffers.\n"
|
||||
"\n"
|
||||
" :arg width: Horizontal dimension of the buffer.\n"
|
||||
" :type width: `int`\n"
|
||||
" :arg height: Vertical dimension of the buffer.\n"
|
||||
" :type height: `int`\n"
|
||||
" :arg samples: OpenGL samples to use for MSAA or zero to disable.\n"
|
||||
" :type samples: `int`\n");
|
||||
" :type height: `int`\n");
|
||||
PyTypeObject BPyGPUOffScreen_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUOffScreen",
|
||||
.tp_basicsize = sizeof(BPyGPUOffScreen),
|
||||
|
|
|
@ -443,7 +443,7 @@ static void wm_draw_region_buffer_create(ARegion *region, bool stereo, bool use_
|
|||
* depth or multisample buffers. 3D view creates own buffers with
|
||||
* the data it needs. */
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(
|
||||
region->winx, region->winy, 0, false, false, NULL);
|
||||
region->winx, region->winy, false, false, NULL);
|
||||
if (!offscreen) {
|
||||
return;
|
||||
}
|
||||
|
@ -861,7 +861,7 @@ static void wm_draw_window(bContext *C, wmWindow *win)
|
|||
* stereo methods, but it's less efficient than drawing directly. */
|
||||
const int width = WM_window_pixels_x(win);
|
||||
const int height = WM_window_pixels_y(win);
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(width, height, 0, false, false, NULL);
|
||||
GPUOffScreen *offscreen = GPU_offscreen_create(width, height, false, false, NULL);
|
||||
|
||||
if (offscreen) {
|
||||
GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
|
||||
|
|
|
@ -340,7 +340,7 @@ bool wm_xr_session_surface_offscreen_ensure(wmXrSurfaceData *surface_data,
|
|||
}
|
||||
|
||||
if (!(surface_data->offscreen = GPU_offscreen_create(
|
||||
draw_view->width, draw_view->height, 0, true, false, err_out))) {
|
||||
draw_view->width, draw_view->height, true, false, err_out))) {
|
||||
failure = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue