[Bf-blender-cvs] [721a19d2b8a] blender2.8: GPU: Add safety check for max line width
Clément Foucault
noreply at git.blender.org
Fri Nov 2 15:59:47 CET 2018
Commit: 721a19d2b8a7784c48c753d57dfbf984524a54de
Author: Clément Foucault
Date: Fri Nov 2 14:58:49 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB721a19d2b8a7784c48c753d57dfbf984524a54de
GPU: Add safety check for max line width
On some platform does not support line width > 1.0 and can even throw and
error. Better check an at least display something rather than no lines at
all.
===================================================================
M source/blender/gpu/GPU_extensions.h
M source/blender/gpu/intern/gpu_extensions.c
M source/blender/gpu/intern/gpu_state.c
===================================================================
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 805023e31df..07d8a5f8c8b 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -49,6 +49,7 @@ int GPU_max_color_texture_samples(void);
int GPU_max_cube_map_size(void);
int GPU_max_ubo_binds(void);
int GPU_max_ubo_size(void);
+float GPU_max_line_width(void);
int GPU_color_depth(void);
void GPU_get_dfdy_factors(float fac[2]);
bool GPU_mip_render_workaround(void);
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 36e69f96b78..2237a6ea49c 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -80,6 +80,7 @@ static struct GPUGlobal {
GPUDeviceType device;
GPUOSType os;
GPUDriverType driver;
+ float line_width_range[2];
/* workaround for different calculation of dfdy factors on GPUs. Some GPUs/drivers
* calculate dfdy in shader differently when drawing to an offscreen buffer. First
* number is factor on screen and second is off-screen */
@@ -190,6 +191,11 @@ int GPU_max_ubo_size(void)
return GG.maxubosize;
}
+float GPU_max_line_width(void)
+{
+ return GG.line_width_range[1];
+}
+
void GPU_get_dfdy_factors(float fac[2])
{
copy_v2_v2(fac, GG.dfdyfactors);
@@ -230,6 +236,8 @@ void gpu_extensions_init(void)
glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GG.maxubobinds);
glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GG.maxubosize);
+ glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, GG.line_width_range);
+
#ifndef NDEBUG
GLint ret;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
diff --git a/source/blender/gpu/intern/gpu_state.c b/source/blender/gpu/intern/gpu_state.c
index 0f07b2debc3..afc8570356b 100644
--- a/source/blender/gpu/intern/gpu_state.c
+++ b/source/blender/gpu/intern/gpu_state.c
@@ -29,6 +29,7 @@
#include "GPU_glew.h"
#include "GPU_state.h"
+#include "GPU_extensions.h"
static GLenum gpu_get_gl_blendfunction(GPUBlendFunction blend)
{
@@ -118,7 +119,13 @@ void GPU_line_stipple(bool enable)
void GPU_line_width(float width)
{
- glLineWidth(width * U.pixelsize);
+ float max_size = GPU_max_line_width();
+ float final_size = width * U.pixelsize;
+ /* Fix opengl errors on certain platform / drivers. */
+ if (max_size < final_size) {
+ final_size = max_size;
+ }
+ glLineWidth(final_size);
}
void GPU_point_size(float size)
More information about the Bf-blender-cvs
mailing list