Nux

Merge lp:~loic.molinari/nux/nux-do-not-use-glBlendEquationSeparate-if-the-feature-is-not-available into lp:nux

Proposed by Loïc Molinari
Status: Merged
Merged at revision: 283
Proposed branch: lp:~loic.molinari/nux/nux-do-not-use-glBlendEquationSeparate-if-the-feature-is-not-available
Merge into: lp:nux
Diff against target: 148 lines (+33/-14)
4 files modified
NuxGraphics/GLRenderStates.cpp (+2/-1)
NuxGraphics/GLRenderStates.h (+15/-11)
NuxGraphics/GpuDevice.cpp (+3/-1)
NuxGraphics/GpuDevice.h (+13/-1)
To merge this branch: bzr merge lp:~loic.molinari/nux/nux-do-not-use-glBlendEquationSeparate-if-the-feature-is-not-available
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Review via email: mp+53845@code.launchpad.net

Description of the change

glBlendEquationSeparateEXT is used without checking if OpenGL 2.0 or if the GL_EXT_blend_equation_separate extension is available. If it's not, depending on the OpenGL implementation, it crashes.

This merge request fixes the issue.

To post a comment you must log in.
Revision history for this message
Loïc Molinari (loic.molinari) wrote :

It's very likely to fix lp:722391 as well.

Revision history for this message
Jay Taoko (jaytaoko) wrote :

In NuxGraphics/GpuDevice.h, No need for a second nux namespace block. Just put 'class GpuRenderStates' in the namespace block that already exist.

review: Approve
Revision history for this message
Loïc Molinari (loic.molinari) wrote :

Alright, I usually do that out of habit in order to clearly separate forward declarations and code.

275. By Loïc Molinari

Merged the forward declaration block with the nux namespace

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NuxGraphics/GLRenderStates.cpp'
2--- NuxGraphics/GLRenderStates.cpp 2011-03-08 01:22:58 +0000
3+++ NuxGraphics/GLRenderStates.cpp 2011-03-18 11:25:36 +0000
4@@ -109,9 +109,10 @@
5 } s_StateLUT;
6
7
8- GpuRenderStates::GpuRenderStates (GpuBrand board)
9+ GpuRenderStates::GpuRenderStates (GpuBrand board, GpuInfo* info)
10 {
11 _gpu_brand = board;
12+ _gpu_info = info;
13 Memcpy (&m_RenderStateChanges, &s_StateLUT.default_render_state, sizeof (m_RenderStateChanges) );
14 }
15
16
17=== modified file 'NuxGraphics/GLRenderStates.h'
18--- NuxGraphics/GLRenderStates.h 2011-03-16 00:03:18 +0000
19+++ NuxGraphics/GLRenderStates.h 2011-03-18 11:25:36 +0000
20@@ -24,6 +24,7 @@
21 #define GLRENDERSTATES_H
22
23 #include "NuxCore/NuxCore.h"
24+#include "NuxGraphics/GpuDevice.h"
25
26 namespace nux
27 {
28@@ -111,15 +112,6 @@
29 GFXSS_MAX_SAMPLERSTATES,
30 };
31
32- //! Brand of GPUs.
33- typedef enum
34- {
35- GPU_VENDOR_UNKNOWN = 0,
36- GPU_BRAND_AMD,
37- GPU_BRAND_NVIDIA,
38- GPU_BRAND_INTEL,
39- } GpuBrand;
40-
41 typedef enum
42 {
43 CLEAR = 0,
44@@ -148,7 +140,7 @@
45 class GpuRenderStates
46 {
47 public:
48- GpuRenderStates (GpuBrand board);
49+ GpuRenderStates (GpuBrand board, GpuInfo* info);
50 ~GpuRenderStates();
51
52 void ResetDefault();
53@@ -272,6 +264,7 @@
54 private:
55
56 GpuBrand _gpu_brand;
57+ GpuInfo *_gpu_info;
58
59 inline void HW__EnableAlphaTest (t_u32 b);
60
61@@ -953,7 +946,18 @@
62 (BlendOpAlpha_ == GL_MAX),
63 TEXT ("Error(HW__SetAlphaBlendOp): Invalid Blend Equation RenderState") );
64
65- CHECKGL (glBlendEquationSeparateEXT (BlendOpRGB_, BlendOpAlpha_) );
66+ if (_gpu_info->SupportOpenGL20 ())
67+ {
68+ CHECKGL (glBlendEquationSeparate (BlendOpRGB_, BlendOpAlpha_) );
69+ }
70+ else if (_gpu_info->Support_EXT_Blend_Equation_Separate ())
71+ {
72+ CHECKGL (glBlendEquationSeparateEXT (BlendOpRGB_, BlendOpAlpha_) );
73+ }
74+ else
75+ {
76+ CHECKGL (glBlendEquation (BlendOpRGB_) );
77+ }
78
79 SET_RS_VALUE (m_RenderStateChanges[GFXRS_BLENDOP], BlendOpRGB_);
80 SET_RS_VALUE (m_RenderStateChanges[GFXRS_BLENDOPALPHA], BlendOpAlpha_);
81
82=== modified file 'NuxGraphics/GpuDevice.cpp'
83--- NuxGraphics/GpuDevice.cpp 2011-03-10 04:28:21 +0000
84+++ NuxGraphics/GpuDevice.cpp 2011-03-18 11:25:36 +0000
85@@ -301,6 +301,8 @@
86 _support_arb_texture_rectangle = GLEW_ARB_texture_rectangle ? true : false;
87 _support_nv_texture_rectangle = GLEW_NV_texture_rectangle ? true : false;
88 _support_arb_pixel_buffer_object = GLEW_ARB_pixel_buffer_object ? true : false;
89+ _support_ext_blend_equation_separate = GLEW_EXT_blend_equation_separate ? true : false;
90+
91 }
92
93 #if defined (NUX_OS_WINDOWS)
94@@ -598,9 +600,9 @@
95 _UsePixelBufferObject = false;
96 }
97
98- _gpu_render_states = new GpuRenderStates (_gpu_brand);
99 _gpu_info = new GpuInfo ();
100 _gpu_info->Setup ();
101+ _gpu_render_states = new GpuRenderStates (_gpu_brand, _gpu_info);
102
103 #if defined(NUX_OS_WINDOWS)
104 OGL_EXT_SWAP_CONTROL = WGLEW_EXT_swap_control ? true : false;
105
106=== modified file 'NuxGraphics/GpuDevice.h'
107--- NuxGraphics/GpuDevice.h 2011-03-10 04:28:21 +0000
108+++ NuxGraphics/GpuDevice.h 2011-03-18 11:25:36 +0000
109@@ -26,12 +26,22 @@
110 #include "GLResource.h"
111 #include "GLDeviceFrameBufferObject.h"
112 #include "GLDeviceObjects.h"
113-#include "GLRenderStates.h"
114 #include "GLTextureStates.h"
115 #include "GLTemplatePrimitiveBuffer.h"
116
117 namespace nux
118 {
119+ class GpuRenderStates;
120+
121+ //! Brand of GPUs.
122+ typedef enum
123+ {
124+ GPU_VENDOR_UNKNOWN = 0,
125+ GPU_BRAND_AMD,
126+ GPU_BRAND_NVIDIA,
127+ GPU_BRAND_INTEL,
128+ } GpuBrand;
129+
130 template<typename T> class ObjectPtr;
131
132 struct STREAMSOURCE
133@@ -94,6 +104,7 @@
134 bool Support_EXT_Texture_Rectangle () const {return _support_ext_texture_rectangle;}
135 bool Support_NV_Texture_Rectangle () const {return _support_nv_texture_rectangle;}
136 bool Support_ARB_Pixel_Buffer_Object () const {return _support_arb_pixel_buffer_object;}
137+ bool Support_EXT_Blend_Equation_Separate () const {return _support_ext_blend_equation_separate;}
138
139 int GetMaxFboAttachment () {return _opengl_max_fb_attachment;}
140
141@@ -136,6 +147,7 @@
142 bool _support_arb_texture_rectangle; //!< Promoted from GL_EXT_TEXTURE_RECTANGLE to ARB.
143 bool _support_nv_texture_rectangle;
144 bool _support_arb_pixel_buffer_object;
145+ bool _support_ext_blend_equation_separate;
146
147 friend class GpuDevice;
148 };

Subscribers

People subscribed via source and target branches