Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_viewport.c
| Show All 32 Lines | |||||
| #include <string.h> | #include <string.h> | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_mempool.h" | #include "BLI_mempool.h" | ||||
| #include "BIF_gl.h" | |||||
| #include "DNA_vec_types.h" | #include "DNA_vec_types.h" | ||||
| #include "DNA_userdef_types.h" | #include "DNA_userdef_types.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "GPU_glew.h" | #include "GPU_glew.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| ▲ Show 20 Lines • Show All 467 Lines • ▼ Show 20 Lines | void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect) | ||||
| GPUTexture *color = dtxl->color; | GPUTexture *color = dtxl->color; | ||||
| const float w = (float)GPU_texture_width(color); | const float w = (float)GPU_texture_width(color); | ||||
| const float h = (float)GPU_texture_height(color); | const float h = (float)GPU_texture_height(color); | ||||
| BLI_assert(w == BLI_rcti_size_x(rect) + 1); | BLI_assert(w == BLI_rcti_size_x(rect) + 1); | ||||
| BLI_assert(h == BLI_rcti_size_y(rect) + 1); | BLI_assert(h == BLI_rcti_size_y(rect) + 1); | ||||
| /* wmOrtho for the screen has this same offset */ | |||||
| const float halfx = GLA_PIXEL_OFS / w; | |||||
| const float halfy = GLA_PIXEL_OFS / h; | |||||
| float x1 = rect->xmin; | float x1 = rect->xmin; | ||||
| float x2 = rect->xmin + w; | float x2 = rect->xmin + w; | ||||
| float y1 = rect->ymin; | float y1 = rect->ymin; | ||||
| float y2 = rect->ymin + h; | float y2 = rect->ymin + h; | ||||
| GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR); | GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR); | ||||
| GPU_shader_bind(shader); | GPU_shader_bind(shader); | ||||
| GPU_texture_bind(color, 0); | GPU_texture_bind(color, 0); | ||||
| glUniform1i(GPU_shader_get_uniform(shader, "image"), 0); | glUniform1i(GPU_shader_get_uniform(shader, "image"), 0); | ||||
| glUniform4f(GPU_shader_get_uniform(shader, "rect_icon"), 0.0f, 0.0f, 1.0f, 1.0f); | glUniform4f(GPU_shader_get_uniform(shader, "rect_icon"), halfx, halfy, 1.0f + halfx, 1.0f + halfy); | ||||
| glUniform4f(GPU_shader_get_uniform(shader, "rect_geom"), x1, y1, x2, y2); | glUniform4f(GPU_shader_get_uniform(shader, "rect_geom"), x1, y1, x2, y2); | ||||
| glUniform4f(GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_COLOR), 1.0f, 1.0f, 1.0f, 1.0f); | glUniform4f(GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_COLOR), 1.0f, 1.0f, 1.0f, 1.0f); | ||||
| GWN_draw_primitive(GWN_PRIM_TRI_STRIP, 4); | GWN_draw_primitive(GWN_PRIM_TRI_STRIP, 4); | ||||
| GPU_texture_unbind(color); | GPU_texture_unbind(color); | ||||
| } | } | ||||
| void GPU_viewport_unbind(GPUViewport *UNUSED(viewport)) | void GPU_viewport_unbind(GPUViewport *UNUSED(viewport)) | ||||
| { | { | ||||
| DRW_opengl_context_disable(); | DRW_opengl_context_disable(); | ||||
| } | } | ||||
| GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport) | |||||
| { | |||||
| DefaultFramebufferList *dfbl = viewport->fbl; | |||||
| if (dfbl->default_fb) { | |||||
| DefaultTextureList *dtxl = viewport->txl; | |||||
| return dtxl->color; | |||||
| } | |||||
| return NULL; | |||||
| } | |||||
| static void gpu_viewport_buffers_free( | static void gpu_viewport_buffers_free( | ||||
| FramebufferList *fbl, int fbl_len, | FramebufferList *fbl, int fbl_len, | ||||
| TextureList *txl, int txl_len) | TextureList *txl, int txl_len) | ||||
| { | { | ||||
| for (int i = 0; i < fbl_len; i++) { | for (int i = 0; i < fbl_len; i++) { | ||||
| GPUFrameBuffer *fb = fbl->framebuffers[i]; | GPUFrameBuffer *fb = fbl->framebuffers[i]; | ||||
| if (fb) { | if (fb) { | ||||
| GPU_framebuffer_free(fb); | GPU_framebuffer_free(fb); | ||||
| ▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines | |||||