Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_framebuffer.cc')
-rw-r--r--source/blender/gpu/intern/gpu_framebuffer.cc83
1 files changed, 38 insertions, 45 deletions
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index 44994c2cabf..88779dead28 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -28,7 +28,7 @@
#include "BLI_utildefines.h"
#include "GPU_batch.h"
-#include "GPU_extensions.h"
+#include "GPU_capabilities.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
@@ -194,21 +194,20 @@ GPUFrameBuffer *GPU_framebuffer_create(const char *name)
{
/* We generate the FB object later at first use in order to
* create the frame-buffer in the right opengl context. */
- return (GPUFrameBuffer *)GPUBackend::get()->framebuffer_alloc(name);
+ return wrap(GPUBackend::get()->framebuffer_alloc(name));
}
void GPU_framebuffer_free(GPUFrameBuffer *gpu_fb)
{
- delete reinterpret_cast<FrameBuffer *>(gpu_fb);
+ delete unwrap(gpu_fb);
}
/* ---------- Binding ----------- */
void GPU_framebuffer_bind(GPUFrameBuffer *gpu_fb)
{
- FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
const bool enable_srgb = true;
- fb->bind(enable_srgb);
+ unwrap(gpu_fb)->bind(enable_srgb);
}
/**
@@ -216,9 +215,8 @@ void GPU_framebuffer_bind(GPUFrameBuffer *gpu_fb)
*/
void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *gpu_fb)
{
- FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
const bool enable_srgb = false;
- fb->bind(enable_srgb);
+ unwrap(gpu_fb)->bind(enable_srgb);
}
/**
@@ -226,7 +224,7 @@ void GPU_framebuffer_bind_no_srgb(GPUFrameBuffer *gpu_fb)
*/
void GPU_backbuffer_bind(eGPUBackBuffer buffer)
{
- GPUContext *ctx = GPU_context_active_get();
+ Context *ctx = Context::get();
if (buffer == GPU_BACKBUFFER_LEFT) {
ctx->back_left->bind(false);
@@ -238,20 +236,20 @@ void GPU_backbuffer_bind(eGPUBackBuffer buffer)
void GPU_framebuffer_restore(void)
{
- GPU_context_active_get()->back_left->bind(false);
+ Context::get()->back_left->bind(false);
}
GPUFrameBuffer *GPU_framebuffer_active_get(void)
{
- GPUContext *ctx = GPU_context_active_get();
- return reinterpret_cast<GPUFrameBuffer *>(ctx ? ctx->active_fb : NULL);
+ Context *ctx = Context::get();
+ return wrap(ctx ? ctx->active_fb : NULL);
}
/* Returns the default frame-buffer. Will always exists even if it's just a dummy. */
GPUFrameBuffer *GPU_framebuffer_back_get(void)
{
- GPUContext *ctx = GPU_context_active_get();
- return reinterpret_cast<GPUFrameBuffer *>(ctx ? ctx->back_left : NULL);
+ Context *ctx = Context::get();
+ return wrap(ctx ? ctx->back_left : NULL);
}
bool GPU_framebuffer_bound(GPUFrameBuffer *gpu_fb)
@@ -263,14 +261,14 @@ bool GPU_framebuffer_bound(GPUFrameBuffer *gpu_fb)
bool GPU_framebuffer_check_valid(GPUFrameBuffer *gpu_fb, char err_out[256])
{
- return reinterpret_cast<FrameBuffer *>(gpu_fb)->check(err_out);
+ return unwrap(gpu_fb)->check(err_out);
}
void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb, GPUAttachment attachment, int slot)
{
Texture *tex = reinterpret_cast<Texture *>(attachment.tex);
GPUAttachmentType type = tex->attachment_type(slot);
- reinterpret_cast<FrameBuffer *>(gpu_fb)->attachment_set(type, attachment);
+ unwrap(gpu_fb)->attachment_set(type, attachment);
}
void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
@@ -293,10 +291,9 @@ void GPU_framebuffer_texture_cubeface_attach(
GPU_framebuffer_texture_attach_ex(fb, attachment, slot);
}
-void GPU_framebuffer_texture_detach(GPUFrameBuffer *gpu_fb, GPUTexture *tex)
+void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
{
- FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
- reinterpret_cast<Texture *>(tex)->detach_from(fb);
+ unwrap(tex)->detach_from(unwrap(fb));
}
/**
@@ -309,7 +306,7 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb,
const GPUAttachment *config,
int config_len)
{
- FrameBuffer *fb = reinterpret_cast<FrameBuffer *>(gpu_fb);
+ FrameBuffer *fb = unwrap(gpu_fb);
const GPUAttachment &depth_attachment = config[0];
Span<GPUAttachment> color_attachments(config + 1, config_len - 1);
@@ -346,12 +343,12 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *gpu_fb,
void GPU_framebuffer_viewport_set(GPUFrameBuffer *gpu_fb, int x, int y, int width, int height)
{
int viewport_rect[4] = {x, y, width, height};
- reinterpret_cast<FrameBuffer *>(gpu_fb)->viewport_set(viewport_rect);
+ unwrap(gpu_fb)->viewport_set(viewport_rect);
}
void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
{
- reinterpret_cast<FrameBuffer *>(gpu_fb)->viewport_get(r_viewport);
+ unwrap(gpu_fb)->viewport_get(r_viewport);
}
/**
@@ -359,7 +356,7 @@ void GPU_framebuffer_viewport_get(GPUFrameBuffer *gpu_fb, int r_viewport[4])
*/
void GPU_framebuffer_viewport_reset(GPUFrameBuffer *gpu_fb)
{
- reinterpret_cast<FrameBuffer *>(gpu_fb)->viewport_reset();
+ unwrap(gpu_fb)->viewport_reset();
}
/* ---------- Framebuffer Operations ----------- */
@@ -370,7 +367,7 @@ void GPU_framebuffer_clear(GPUFrameBuffer *gpu_fb,
float clear_depth,
uint clear_stencil)
{
- reinterpret_cast<FrameBuffer *>(gpu_fb)->clear(buffers, clear_col, clear_depth, clear_stencil);
+ unwrap(gpu_fb)->clear(buffers, clear_col, clear_depth, clear_stencil);
}
/**
@@ -378,25 +375,26 @@ void GPU_framebuffer_clear(GPUFrameBuffer *gpu_fb,
*/
void GPU_framebuffer_multi_clear(GPUFrameBuffer *gpu_fb, const float (*clear_cols)[4])
{
- reinterpret_cast<FrameBuffer *>(gpu_fb)->clear_multi(clear_cols);
+ unwrap(gpu_fb)->clear_multi(clear_cols);
}
void GPU_clear_color(float red, float green, float blue, float alpha)
{
float clear_col[4] = {red, green, blue, alpha};
- GPU_context_active_get()->active_fb->clear(GPU_COLOR_BIT, clear_col, 0.0f, 0x0);
+ Context::get()->active_fb->clear(GPU_COLOR_BIT, clear_col, 0.0f, 0x0);
}
void GPU_clear_depth(float depth)
{
float clear_col[4] = {0};
- GPU_context_active_get()->active_fb->clear(GPU_DEPTH_BIT, clear_col, depth, 0x0);
+ Context::get()->active_fb->clear(GPU_DEPTH_BIT, clear_col, depth, 0x0);
}
-void GPU_framebuffer_read_depth(GPUFrameBuffer *gpu_fb, int x, int y, int w, int h, float *data)
+void GPU_framebuffer_read_depth(
+ GPUFrameBuffer *gpu_fb, int x, int y, int w, int h, eGPUDataFormat format, void *data)
{
int rect[4] = {x, y, w, h};
- reinterpret_cast<FrameBuffer *>(gpu_fb)->read(GPU_DEPTH_BIT, GPU_DATA_FLOAT, rect, 1, 1, data);
+ unwrap(gpu_fb)->read(GPU_DEPTH_BIT, format, rect, 1, 1, data);
}
void GPU_framebuffer_read_color(GPUFrameBuffer *gpu_fb,
@@ -410,7 +408,7 @@ void GPU_framebuffer_read_color(GPUFrameBuffer *gpu_fb,
void *data)
{
int rect[4] = {x, y, w, h};
- reinterpret_cast<FrameBuffer *>(gpu_fb)->read(GPU_COLOR_BIT, format, rect, channels, slot, data);
+ unwrap(gpu_fb)->read(GPU_COLOR_BIT, format, rect, channels, slot, data);
}
/* TODO(fclem) rename to read_color. */
@@ -418,7 +416,7 @@ void GPU_frontbuffer_read_pixels(
int x, int y, int w, int h, int channels, eGPUDataFormat format, void *data)
{
int rect[4] = {x, y, w, h};
- GPU_context_active_get()->front_left->read(GPU_COLOR_BIT, format, rect, channels, 0, data);
+ Context::get()->front_left->read(GPU_COLOR_BIT, format, rect, channels, 0, data);
}
/* read_slot and write_slot are only used for color buffers. */
@@ -429,11 +427,11 @@ void GPU_framebuffer_blit(GPUFrameBuffer *gpufb_read,
int write_slot,
eGPUFrameBufferBits blit_buffers)
{
- FrameBuffer *fb_read = reinterpret_cast<FrameBuffer *>(gpufb_read);
- FrameBuffer *fb_write = reinterpret_cast<FrameBuffer *>(gpufb_write);
+ FrameBuffer *fb_read = unwrap(gpufb_read);
+ FrameBuffer *fb_write = unwrap(gpufb_write);
BLI_assert(blit_buffers != 0);
- FrameBuffer *prev_fb = GPU_context_active_get()->active_fb;
+ FrameBuffer *prev_fb = Context::get()->active_fb;
#ifndef NDEBUG
GPUTexture *read_tex, *write_tex;
@@ -454,11 +452,6 @@ void GPU_framebuffer_blit(GPUFrameBuffer *gpufb_read,
BLI_assert(GPU_texture_stencil(read_tex) && GPU_texture_stencil(write_tex));
BLI_assert(GPU_texture_format(read_tex) == GPU_texture_format(write_tex));
}
- if (GPU_texture_samples(write_tex) != 0 || GPU_texture_samples(read_tex) != 0) {
- /* Can only blit multisample textures to another texture of the same size. */
- BLI_assert((GPU_texture_width(write_tex) == GPU_texture_width(read_tex)) &&
- (GPU_texture_height(write_tex) == GPU_texture_height(read_tex)));
- }
#endif
fb_read->blit_to(blit_buffers, read_slot, fb_write, write_slot, 0, 0);
@@ -477,7 +470,7 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *gpu_fb,
void (*callback)(void *userData, int level),
void *userData)
{
- reinterpret_cast<FrameBuffer *>(gpu_fb)->recursive_downsample(max_lvl, callback, userData);
+ unwrap(gpu_fb)->recursive_downsample(max_lvl, callback, userData);
}
/** \} */
@@ -516,7 +509,7 @@ static GPUFrameBuffer *gpuPopFrameBuffer(void)
struct GPUOffScreen {
struct {
- GPUContext *ctx;
+ Context *ctx;
GPUFrameBuffer *fb;
} framebuffers[MAX_CTX_FB_LEN];
@@ -529,7 +522,7 @@ struct GPUOffScreen {
*/
static GPUFrameBuffer *gpu_offscreen_fb_get(GPUOffScreen *ofs)
{
- GPUContext *ctx = GPU_context_active_get();
+ Context *ctx = Context::get();
BLI_assert(ctx);
for (int i = 0; i < MAX_CTX_FB_LEN; i++) {
@@ -620,9 +613,9 @@ void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
{
if (save) {
GPUFrameBuffer *fb = GPU_framebuffer_active_get();
- gpuPushFrameBuffer(reinterpret_cast<GPUFrameBuffer *>(fb));
+ gpuPushFrameBuffer(fb);
}
- reinterpret_cast<FrameBuffer *>(gpu_offscreen_fb_get(ofs))->bind(false);
+ unwrap(gpu_offscreen_fb_get(ofs))->bind(false);
}
void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore)
@@ -642,8 +635,8 @@ void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore)
void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
{
- GPUContext *ctx = GPU_context_active_get();
- FrameBuffer *ofs_fb = reinterpret_cast<FrameBuffer *>(gpu_offscreen_fb_get(ofs));
+ Context *ctx = Context::get();
+ FrameBuffer *ofs_fb = unwrap(gpu_offscreen_fb_get(ofs));
ofs_fb->blit_to(GPU_COLOR_BIT, 0, ctx->active_fb, 0, x, y);
}