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.
This commit is contained in:
parent
00ef0a4d8e
commit
721a19d2b8
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue