Nux

Merge lp:~hikiko/nux/arb-srgba-shader into lp:nux

Proposed by Eleni Maria Stea
Status: Needs review
Proposed branch: lp:~hikiko/nux/arb-srgba-shader
Merge into: lp:nux
Diff against target: 913 lines (+419/-44) (has conflicts)
7 files modified
NuxGraphics/GraphicsEngine.cpp (+1/-0)
NuxGraphics/GraphicsEngine.h (+28/-0)
NuxGraphics/RenderingPipe.cpp (+15/-0)
NuxGraphics/RenderingPipeAsm.cpp (+147/-42)
NuxGraphics/RenderingPipeGLSL.cpp (+106/-0)
gputests/Makefile.am (+5/-2)
gputests/gamma_correction.cpp (+117/-0)
Text conflict in NuxGraphics/GraphicsEngine.h
Text conflict in NuxGraphics/RenderingPipe.cpp
To merge this branch: bzr merge lp:~hikiko/nux/arb-srgba-shader
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Tim Penhey (community) Needs Fixing
Review via email: mp+123701@code.launchpad.net

Commit message

needs to be merged with: lp:~nicolas-doffay/nux/to-sRGB-conversion-shader branch first, it's extending nicolas-doffay's changes.

Description of the change

added a test program in gputests (gamma_correction.cpp) that tests the assembly sRGB pixel shader
fixed the assembly sRGB pixel shader in NuxGraphics

To post a comment you must log in.
lp:~hikiko/nux/arb-srgba-shader updated
657. By Eleni Maria Stea

fixed the test program (can now get gamma as en argument)

658. By Eleni Maria Stea

made gamma a parameter of the gamma_correction test program

659. By Eleni Maria Stea

checking that the gamma_correction argv[1] is actually a number

Revision history for this message
Tim Penhey (thumper) wrote :

  NuxGraphics/GraphicsEngine.cpp

Take a look at the merge proposal diff. You can see that you
have a few tabs there instead of spaces :-)

> NuxGraphics/RenderingPipe.cpp

Please keep the # directives in line at the start of the line.

As a general curiousity, how does this method work? It doesn't
return anything. Is it modifying the texture passed in as
the "tex" param?

> void GraphicsEngine::InitAsmSRGBShader()

For the shaders here... please use "const char*" instead
of "std::string". It expresses intent perfectly fine, we are not
modifying the string at all, and it means you don't need the
.c_str() call in the load shader commands. I've been talking
with Michi about this too, and I think we will be changing them
all soonish.

Same thing for the other init shader methods.

gputests/Makefile.am also has tabs

as does teh gamma_correction.cpp file.

review: Needs Fixing
lp:~hikiko/nux/arb-srgba-shader updated
660. By Eleni Maria Stea

fixed InitAsmSRGBShader position

661. By Eleni Maria Stea

changed std::string to char* in InitAsmSRGBShader

662. By Eleni Maria Stea

expandtab, retab

663. By Eleni Maria Stea

replaced tabs with spaces in Makefile.am

664. By Eleni Maria Stea

expandtab, retab

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

664. By Eleni Maria Stea

expandtab, retab

663. By Eleni Maria Stea

replaced tabs with spaces in Makefile.am

662. By Eleni Maria Stea

expandtab, retab

661. By Eleni Maria Stea

changed std::string to char* in InitAsmSRGBShader

660. By Eleni Maria Stea

fixed InitAsmSRGBShader position

659. By Eleni Maria Stea

checking that the gamma_correction argv[1] is actually a number

658. By Eleni Maria Stea

made gamma a parameter of the gamma_correction test program

657. By Eleni Maria Stea

fixed the test program (can now get gamma as en argument)

656. By Eleni Maria Stea

removed useless comments and trailing whitespaces

655. By Eleni Maria Stea

minor change in main

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NuxGraphics/GraphicsEngine.cpp'
2--- NuxGraphics/GraphicsEngine.cpp 2012-09-17 09:55:43 +0000
3+++ NuxGraphics/GraphicsEngine.cpp 2012-09-24 06:59:20 +0000
4@@ -220,6 +220,7 @@
5 InitAsm2TextureMod();
6 InitAsm4TextureAdd();
7 InitAsmBlendModes();
8+ InitAsmSRGBShader();
9
10 InitAsmPower();
11 InitAsmAlphaReplicate();
12
13=== modified file 'NuxGraphics/GraphicsEngine.h'
14--- NuxGraphics/GraphicsEngine.h 2012-09-17 09:55:43 +0000
15+++ NuxGraphics/GraphicsEngine.h 2012-09-24 06:59:20 +0000
16@@ -192,6 +192,7 @@
17 Shader Output = ve4(tex.r, tex.g, tex.b, tex.a)
18 */
19 void QRP_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
20+<<<<<<< TREE
21 //! Render a textured quad.
22 /*!
23 Multiply the shader rgb output with the texture alpha.
24@@ -199,6 +200,9 @@
25 */
26 void QRP_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
27 void QRP_TexDesaturate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0, float desaturation_factor);
28+=======
29+ void QRP_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma);
30+>>>>>>> MERGE-SOURCE
31 void QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
32 void QRP_Color(int x, int y, int width, int height, const Color& c0);
33 void QRP_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3);
34@@ -271,7 +275,11 @@
35
36 // ASM
37 void QRP_ASM_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
38+<<<<<<< TREE
39 void QRP_ASM_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
40+=======
41+ void QRP_ASM_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma);
42+>>>>>>> MERGE-SOURCE
43 void QRP_ASM_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
44
45 void QRP_ASM_Color(int x, int y, int width, int height, const Color& c0);
46@@ -391,8 +399,12 @@
47 // GLSL
48
49 void QRP_GLSL_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);
50+<<<<<<< TREE
51 void QRP_GLSL_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);
52 void QRP_GLSL_TexDesaturate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0, float desaturation_factor);
53+=======
54+ void QRP_GLSL_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma);
55+>>>>>>> MERGE-SOURCE
56 void QRP_GLSL_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
57
58 void QRP_GLSL_Color(int x, int y, int width, int height, const Color& c0);
59@@ -844,12 +856,21 @@
60 //! Same as m_AsmTextureModColor for rectangle textures.
61 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTextureRectModColor;
62
63+<<<<<<< TREE
64 void InitAsmTexturePremultiplyShader();
65 //! Render polygons with a texture modulated by a color.
66 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTexturePremultiplyModColor;
67 //! Same as m_AsmTextureModColor for rectangle textures.
68 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTexturePremultiplyRectModColor;
69
70+=======
71+ void InitAsmSRGBShader();
72+ //! Render a texture in linear colour space in an sRGB non-linear space.
73+ ObjectPtr<IOpenGLAsmShaderProgram> m_AsmLineartoSRGB;
74+ //! Render a texture rectangle in linear colour space in an sRGB non-linear space.
75+ ObjectPtr<IOpenGLAsmShaderProgram> m_AsmLineartoSRGBRect;
76+
77+>>>>>>> MERGE-SOURCE
78 void InitAsmPixelateShader();
79 //! Render a pixelated texture over a polygon.
80 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPixelate;
81@@ -928,10 +949,17 @@
82 //! Render polygons with a texture modulated by a color.
83 ObjectPtr<IOpenGLShaderProgram> m_SlTextureModColor;
84
85+<<<<<<< TREE
86 void InitSlTexturePremultiplyShader();
87 //! Render polygons with a premultiplied texture modulated by a color.
88 ObjectPtr<IOpenGLShaderProgram> m_SlTexturePremultiplyModColor;
89
90+=======
91+ void InitSRGBTextureShader();
92+ //! Renders a texture in linear colour space using non-linear sRGB.
93+ ObjectPtr<IOpenGLShaderProgram> m_sRGBTexture;
94+
95+>>>>>>> MERGE-SOURCE
96 void InitSlPixelateShader();
97 //! Render a pixelated texture over a polygon.
98 ObjectPtr<IOpenGLShaderProgram> m_SLPixelate;
99
100=== modified file 'NuxGraphics/RenderingPipe.cpp'
101--- NuxGraphics/RenderingPipe.cpp 2012-09-14 18:26:55 +0000
102+++ NuxGraphics/RenderingPipe.cpp 2012-09-24 06:59:20 +0000
103@@ -368,6 +368,7 @@
104 #endif
105 }
106
107+<<<<<<< TREE
108 void GraphicsEngine::QRP_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform0, const Color &color0)
109 {
110 #ifndef NUX_OPENGLES_20
111@@ -395,6 +396,20 @@
112 #endif
113 }
114
115+=======
116+ void GraphicsEngine::QRP_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma)
117+ {
118+#ifndef NUX_OPENGLES_20
119+ if (UsingGLSLCodePath())
120+ QRP_GLSL_sRGB(x, y, width, height, tex, texxform, colour, gamma);
121+ else
122+ QRP_ASM_sRGB(x, y, width, height, tex, texxform, colour, gamma);
123+#else
124+ QRP_GLSL_sRGB(x, y, width, height, tex, texxform, colour, gamma);
125+#endif
126+ }
127+
128+>>>>>>> MERGE-SOURCE
129 void GraphicsEngine::QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &c0, int pixel_size)
130 {
131 #ifndef NUX_OPENGLES_20
132
133=== modified file 'NuxGraphics/RenderingPipeAsm.cpp'
134--- NuxGraphics/RenderingPipeAsm.cpp 2012-08-17 12:41:21 +0000
135+++ NuxGraphics/RenderingPipeAsm.cpp 2012-09-24 06:59:20 +0000
136@@ -102,7 +102,7 @@
137
138 void GraphicsEngine::InitAsmColorShader()
139 {
140- NString AsmVtx =
141+ NString AsmVtx =
142 "!!ARBvp1.0 \n\
143 ATTRIB iPos = vertex.position; \n\
144 ATTRIB iColor = vertex.attrib[3]; \n\
145@@ -117,7 +117,7 @@
146 MOV oColor, iColor; \n\
147 END";
148
149- NString AsmFrg =
150+ NString AsmFrg =
151 "!!ARBfp1.0 \n\
152 MOV result.color, fragment.color; \n\
153 END";
154@@ -130,7 +130,7 @@
155
156 void GraphicsEngine::InitAsmTextureShader()
157 {
158- NString AsmVtx =
159+ NString AsmVtx =
160 "!!ARBvp1.0 \n\
161 ATTRIB iPos = vertex.position; \n\
162 ATTRIB iColor = vertex.attrib[3]; \n\
163@@ -147,14 +147,14 @@
164 MOV oTexCoord0, vertex.attrib[8]; \n\
165 END";
166
167- NString AsmFrg =
168+ NString AsmFrg =
169 "!!ARBfp1.0 \n\
170 TEMP tex0; \n\
171 TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\
172 MUL result.color, fragment.color, tex0; \n\
173 END";
174
175- NString AsmFrgRect =
176+ NString AsmFrgRect =
177 "!!ARBfp1.0 \n\
178 TEMP tex0; \n\
179 TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\
180@@ -172,9 +172,58 @@
181 m_AsmTextureRectModColor->Link();
182 }
183
184+ void GraphicsEngine::InitAsmSRGBShader()
185+ {
186+ const char* vertex =
187+ "!!ARBvp1.0 \n\
188+ OUTPUT oPos = result.position; \n\
189+ OUTPUT oTexCoord0 = result.texcoord[0]; \n\
190+ # Transform the vertex to clip coordinates. \n\
191+ DP4 oPos.x, state.matrix.mvp.row[0], vertex.position; \n\
192+ DP4 oPos.y, state.matrix.mvp.row[1], vertex.position; \n\
193+ DP4 oPos.z, state.matrix.mvp.row[2], vertex.position; \n\
194+ DP4 oPos.w, state.matrix.mvp.row[3], vertex.position; \n\
195+ MOV oTexCoord0, vertex.attrib[8]; \n\
196+ END";
197+
198+ const char* pixel =
199+ "!!ARBfp1.0 \n\
200+ PARAM gamma = program.local[0]; \n\
201+ TEMP T; \n\
202+ TEMP P; \n\
203+ TEX T.xyz, fragment.texcoord[0], texture[0], 2D; \n\
204+ POW P.x, T.x, gamma.x; \n\
205+ POW P.y, T.y, gamma.x; \n\
206+ POW P.z, T.z, gamma.x; \n\
207+ MOV result.color, P; \n\
208+ END";
209+
210+ const char* rect =
211+ "!!ARBfp1.0 \n\
212+ PARAM gamma = program.local[0]; \n\
213+ TEMP T; \n\
214+ TEMP P; \n\
215+ TEX T.xyz, fragment.texcoord[0], texture[0], 2D; \n\
216+ POW P.x, T.x, gamma.x; \n\
217+ POW P.y, T.y, gamma.x; \n\
218+ POW P.z, T.z, gamma.x; \n\
219+ MOV result.color, P; \n\
220+ END";
221+
222+ m_AsmLineartoSRGB = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
223+ m_AsmLineartoSRGB->LoadVertexShader(vertex);
224+ m_AsmLineartoSRGB->LoadPixelShader(pixel);
225+ m_AsmLineartoSRGB->Link();
226+
227+ m_AsmLineartoSRGBRect = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
228+ m_AsmLineartoSRGBRect->LoadVertexShader(vertex);
229+ m_AsmLineartoSRGBRect->LoadPixelShader(rect);
230+ m_AsmLineartoSRGBRect->Link();
231+ }
232+
233 void GraphicsEngine::InitAsmColorModTexMaskAlpha()
234 {
235- NString AsmVtx =
236+ NString AsmVtx =
237 "!!ARBvp1.0 \n\
238 OUTPUT oPos = result.position; \n\
239 OUTPUT oColor = result.color; \n\
240@@ -188,7 +237,7 @@
241 MOV oTexCoord0, vertex.attrib[8]; \n\
242 END";
243
244- NString AsmFrg =
245+ NString AsmFrg =
246 "!!ARBfp1.0 \n\
247 TEMP tex0; \n\
248 TEMP temp; \n\
249@@ -198,7 +247,7 @@
250 MOV result.color, temp; \n\
251 END";
252
253- NString AsmFrgRect =
254+ NString AsmFrgRect =
255 "!!ARBfp1.0 \n\
256 TEMP tex0; \n\
257 TEMP temp; \n\
258@@ -221,7 +270,7 @@
259
260 void GraphicsEngine::InitAsm2TextureAdd()
261 {
262- NString AsmVtx =
263+ NString AsmVtx =
264 "!!ARBvp1.0 \n\
265 ATTRIB iPos = vertex.position; \n\
266 OUTPUT oPos = result.position; \n\
267@@ -236,7 +285,7 @@
268 MOV oTexCoord1, vertex.attrib[9]; \n\
269 END";
270
271- NString AsmFrg =
272+ NString AsmFrg =
273 "!!ARBfp1.0 \n\
274 PARAM color0 = program.local[0]; \n\
275 PARAM color1 = program.local[1]; \n\
276@@ -250,7 +299,7 @@
277 MOV result.color, temp; \n\
278 END";
279
280- NString AsmFrgRect =
281+ NString AsmFrgRect =
282 "!!ARBfp1.0 \n\
283 PARAM color0 = program.local[0]; \n\
284 PARAM color1 = program.local[1]; \n\
285@@ -277,7 +326,7 @@
286
287 void GraphicsEngine::InitAsm2TextureDepRead()
288 {
289- NString AsmVtx =
290+ NString AsmVtx =
291 "!!ARBvp1.0 \n\
292 ATTRIB iPos = vertex.position; \n\
293 OUTPUT oPos = result.position; \n\
294@@ -292,7 +341,7 @@
295 MOV oTexCoord1, vertex.attrib[9]; \n\
296 END";
297
298- NString AsmFrg =
299+ NString AsmFrg =
300 "!!ARBfp1.0 \n\
301 PARAM color0 = program.local[0]; \n\
302 PARAM color1 = program.local[1]; \n\
303@@ -309,7 +358,7 @@
304 MUL result.color, color1, tex1; \n\
305 END";
306
307- NString AsmFrgRect =
308+ NString AsmFrgRect =
309 "!!ARBfp1.0 \n\
310 PARAM color0 = program.local[0]; \n\
311 PARAM color1 = program.local[1]; \n\
312@@ -336,7 +385,7 @@
313
314 void GraphicsEngine::InitAsm2TextureMod()
315 {
316- NString AsmVtx =
317+ NString AsmVtx =
318 "!!ARBvp1.0 \n\
319 ATTRIB iPos = vertex.position; \n\
320 OUTPUT oPos = result.position; \n\
321@@ -351,7 +400,7 @@
322 MOV oTexCoord1, vertex.attrib[9]; \n\
323 END";
324
325- NString AsmFrg =
326+ NString AsmFrg =
327 "!!ARBfp1.0 \n\
328 PARAM color0 = program.local[0]; \n\
329 PARAM color1 = program.local[1]; \n\
330@@ -366,7 +415,7 @@
331 MUL result.color, temp0, temp1; \n\
332 END";
333
334- NString AsmFrgRect =
335+ NString AsmFrgRect =
336 "!!ARBfp1.0 \n\
337 PARAM color0 = program.local[0]; \n\
338 PARAM color1 = program.local[1]; \n\
339@@ -394,7 +443,7 @@
340
341 void GraphicsEngine::InitAsm4TextureAdd()
342 {
343- NString AsmVtx =
344+ NString AsmVtx =
345 "!!ARBvp1.0 \n\
346 ATTRIB iPos = vertex.position; \n\
347 OUTPUT oPos = result.position; \n\
348@@ -413,7 +462,7 @@
349 MOV oTexCoord3, vertex.attrib[11]; \n\
350 END";
351
352- NString AsmFrg =
353+ NString AsmFrg =
354 "!!ARBfp1.0 \n\
355 PARAM color0 = program.local[0]; \n\
356 PARAM color1 = program.local[1]; \n\
357@@ -435,7 +484,7 @@
358 MOV result.color, temp; \n\
359 END";
360
361- NString AsmFrgRect =
362+ NString AsmFrgRect =
363 "!!ARBfp1.0 \n\
364 PARAM color0 = program.local[0]; \n\
365 PARAM color1 = program.local[1]; \n\
366@@ -470,7 +519,7 @@
367
368 void GraphicsEngine::InitAsmBlendModes()
369 {
370- NString AsmVtx =
371+ NString AsmVtx =
372 "!!ARBvp1.0 \n\
373 OUTPUT oPos = result.position; \n\
374 OUTPUT oTexCoord0 = result.texcoord[0]; \n\
375@@ -484,7 +533,7 @@
376 MOV oTexCoord1, vertex.attrib[9]; \n\
377 END";
378
379- NString AsmPSBNormal =
380+ NString AsmPSBNormal =
381 "!!ARBfp1.0 \n\
382 TEMP tex0; \n\
383 TEMP tex1; \n\
384@@ -518,7 +567,7 @@
385 m_AsmPSBLighten->Link();
386
387 // Darken
388- NString AsmPSBDarken =
389+ NString AsmPSBDarken =
390 "!!ARBfp1.0 \n\
391 TEMP tex0; \n\
392 TEMP tex1; \n\
393@@ -537,7 +586,7 @@
394 m_AsmPSBDarken->Link();
395
396 // Multiply
397- NString AsmPSBMultiply =
398+ NString AsmPSBMultiply =
399 "!!ARBfp1.0 \n\
400 TEMP tex0; \n\
401 TEMP tex1; \n\
402@@ -627,7 +676,7 @@
403
404 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
405 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
406-
407+
408 ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmTextureModColor;
409 if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
410 {
411@@ -677,6 +726,62 @@
412 shader_program->End();
413 }
414
415+ void GraphicsEngine::QRP_ASM_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& color, const float gamma)
416+ {
417+ NUX_RETURN_IF_FALSE(m_AsmLineartoSRGB.IsValid() || m_AsmLineartoSRGBRect.IsValid());
418+
419+ QRP_Compute_Texture_Coord(width, height, tex, texxform);
420+
421+ float fx = x; float fy = y;
422+
423+ float vertexArray[] = {
424+ fx, fy, 0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
425+ fx, fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
426+ fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
427+ fx + width, fy, 0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
428+ };
429+
430+ CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
431+ CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
432+
433+ ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmLineartoSRGB;
434+ if (tex->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
435+ shader_program = m_AsmLineartoSRGBRect;
436+
437+ shader_program->Begin();
438+
439+ SetTexture(GL_TEXTURE0, tex);
440+ CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, gamma, 0.0, 0.0, 0.0));
441+
442+ CHECKGL(glMatrixMode(GL_MODELVIEW));
443+ CHECKGL(glLoadIdentity());
444+ CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
445+ CHECKGL(glMatrixMode(GL_PROJECTION));
446+ CHECKGL(glLoadIdentity());
447+ CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
448+
449+ int vertexLocation = VTXATTRIB_POSITION;
450+ int textureCoord0Location = VTXATTRIB_TEXCOORD0;
451+ int vertexColorLocation = VTXATTRIB_COLOR;
452+
453+ CHECKGL(glEnableVertexAttribArrayARB(vertexLocation));
454+ CHECKGL(glVertexAttribPointerARB((GLuint) vertexLocation, 4, GL_FLOAT, GL_FALSE, 48, vertexArray));
455+
456+ CHECKGL(glEnableVertexAttribArrayARB(textureCoord0Location));
457+ CHECKGL(glVertexAttribPointerARB((GLuint)textureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, vertexArray + 4));
458+
459+ CHECKGL(glEnableVertexAttribArrayARB(vertexColorLocation));
460+ CHECKGL(glVertexAttribPointerARB((GLuint)vertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, vertexArray + 8));
461+
462+ CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
463+
464+ CHECKGL(glDisableVertexAttribArrayARB(vertexLocation));
465+ CHECKGL(glDisableVertexAttribArrayARB(textureCoord0Location));
466+ CHECKGL(glDisableVertexAttribArrayARB(vertexColorLocation));
467+
468+ shader_program->End();
469+ }
470+
471 void GraphicsEngine::QRP_ASM_ColorModTexAlpha(int x, int y, int width, int height,
472 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)
473 {
474@@ -1241,7 +1346,7 @@
475
476 void GraphicsEngine::InitAsmPower()
477 {
478- NString AsmVtx =
479+ NString AsmVtx =
480 "!!ARBvp1.0 \n\
481 ATTRIB iPos = vertex.position; \n\
482 OUTPUT oPos = result.position; \n\
483@@ -1255,7 +1360,7 @@
484 END";
485
486
487- NString AsmFrg =
488+ NString AsmFrg =
489 "!!ARBfp1.0 \n\
490 PARAM color0 = program.local[0]; \n\
491 PARAM exponent = program.local[1]; \n\
492@@ -1269,7 +1374,7 @@
493 MUL result.color, color0, final; \n\
494 END";
495
496- NString AsmFrgRect =
497+ NString AsmFrgRect =
498 "!!ARBfp1.0 \n\
499 PARAM color0 = program.local[0]; \n\
500 PARAM exponent = program.local[1]; \n\
501@@ -1351,7 +1456,7 @@
502
503 void GraphicsEngine::InitAsmAlphaReplicate()
504 {
505- NString AsmVtx =
506+ NString AsmVtx =
507 "!!ARBvp1.0 \n\
508 ATTRIB iPos = vertex.position; \n\
509 OUTPUT oPos = result.position; \n\
510@@ -1365,7 +1470,7 @@
511 END";
512
513
514- NString AsmFrg =
515+ NString AsmFrg =
516 "!!ARBfp1.0 \n\
517 PARAM color0 = program.local[0]; \n\
518 TEMP tex0; \n\
519@@ -1373,7 +1478,7 @@
520 MUL result.color, color0, tex0.aaaa; \n\
521 END";
522
523- NString AsmFrgRect =
524+ NString AsmFrgRect =
525 "!!ARBfp1.0 \n\
526 PARAM color0 = program.local[0]; \n\
527 TEMP tex0; \n\
528@@ -1450,7 +1555,7 @@
529
530 void GraphicsEngine::InitAsmColorMatrixFilter()
531 {
532- NString AsmVtx =
533+ NString AsmVtx =
534 "!!ARBvp1.0 \n\
535 ATTRIB iPos = vertex.position; \n\
536 OUTPUT oPos = result.position; \n\
537@@ -1464,7 +1569,7 @@
538 END";
539
540
541- NString AsmFrg =
542+ NString AsmFrg =
543 "!!ARBfp1.0 \n\
544 PARAM color0 = program.local[0]; \n\
545 PARAM CM0 = program.local[1]; \n\
546@@ -1482,7 +1587,7 @@
547 MUL result.color, color0, final; \n\
548 END";
549
550- NString AsmFrgRect =
551+ NString AsmFrgRect =
552 "!!ARBfp1.0 \n\
553 PARAM color0 = program.local[0]; \n\
554 PARAM CM0 = program.local[1]; \n\
555@@ -1578,7 +1683,7 @@
556
557 void GraphicsEngine::InitAsmSeparableGaussFilter()
558 {
559- NString AsmVtx =
560+ NString AsmVtx =
561 "!!ARBvp1.0 \n\
562 ATTRIB iPos = vertex.position; \n\
563 OUTPUT oPos = result.position; \n\
564@@ -1604,7 +1709,7 @@
565 END";
566
567
568- NString AsmFrg =
569+ NString AsmFrg =
570 "!!ARBfp1.0 \n\
571 TEMP tex0; \n\
572 TEMP final; \n\
573@@ -1627,7 +1732,7 @@
574 END";
575
576
577- NString AsmFrgRect =
578+ NString AsmFrgRect =
579 "!!ARBfp1.0 \n\
580 TEMP tex0; \n\
581 TEMP final; \n\
582@@ -2021,7 +2126,7 @@
583 fx_structure->dst_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
584 fx_structure->temp_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
585 fx_structure->temp_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
586-
587+
588 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
589 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
590
591@@ -2050,7 +2155,7 @@
592 {
593 SetViewport(0, 0, previous_width, previous_height);
594 }
595- }
596+ }
597
598 ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetPower(
599 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color & c0, const Vector4 &exponent)
600@@ -2287,7 +2392,7 @@
601
602 void GraphicsEngine::InitAsmPixelateShader()
603 {
604- NString AsmVtx =
605+ NString AsmVtx =
606 "!!ARBvp1.0 \n\
607 ATTRIB iPos = vertex.position; \n\
608 ATTRIB iColor = vertex.attrib[3]; \n\
609@@ -2304,7 +2409,7 @@
610 MOV oTexCoord0, vertex.attrib[8]; \n\
611 END";
612
613- NString AsmFrg =
614+ NString AsmFrg =
615 "!!ARBfp1.0 \n\
616 TEMP tex0; \n\
617 TEMP tex_coord; \n\
618@@ -2317,7 +2422,7 @@
619 MUL result.color, fragment.color, tex0; \n\
620 END";
621
622- NString AsmFrgRect =
623+ NString AsmFrgRect =
624 "!!ARBfp1.0 \n\
625 TEMP tex0; \n\
626 TEMP tex_coord; \n\
627
628=== modified file 'NuxGraphics/RenderingPipeGLSL.cpp'
629--- NuxGraphics/RenderingPipeGLSL.cpp 2012-09-14 18:26:55 +0000
630+++ NuxGraphics/RenderingPipeGLSL.cpp 2012-09-24 06:59:20 +0000
631@@ -117,6 +117,52 @@
632 m_SlTextureModColor->Link();
633 }
634
635+ void GraphicsEngine::InitSRGBTextureShader()
636+ {
637+ ObjectPtr<IOpenGLVertexShader> vertexShader = _graphics_display.m_DeviceFactory->CreateVertexShader();
638+ ObjectPtr<IOpenGLPixelShader> pixelShader = _graphics_display.m_DeviceFactory->CreatePixelShader();
639+
640+ std::string vertexString =
641+ NUX_VERTEX_SHADER_HEADER
642+ "attribute vec4 vertex; \n\
643+ attribute vec4 textureCoord0; \n\
644+ uniform mat4 viewProjectionMatrix; \n\
645+ uniform float gamma; \n\
646+ varying vec4 varyTexCoord0; \n\
647+ void main() \n\
648+ { \n\
649+ gl_Position = viewProjectionMatrix * vertex; \n\
650+ varyTexCoord0 = textureCoord0; \n\
651+ }";
652+
653+ std::string pixelString =
654+ NUX_FRAGMENT_SHADER_HEADER
655+ "uniform sampler2D textureObject; \n\
656+ uniform float gamma; \n\
657+ varying vec4 varyTexCoord0; \n\
658+ void main() \n\
659+ { \n\
660+ vec2 uv = varyTexCoord0.st; \n\
661+ vec4 tempTex = texture2D(textureObject, uv); \n\
662+ gl_FragColor.rgb = pow(tempTex.rgb, 1 / gamma); \n\
663+ gl_FragColor.a = tempTex.a; \n\
664+ }";
665+
666+ m_sRGBTexture = _graphics_display.m_DeviceFactory->CreateShaderProgram();
667+
668+ vertexShader->SetShaderCode(vertexString.c_str());
669+ pixelShader->SetShaderCode(pixelString.c_str());
670+
671+ m_sRGBTexture->ClearShaderObjects();
672+ m_sRGBTexture->AddShaderObject(vertexShader);
673+ m_sRGBTexture->AddShaderObject(pixelShader);
674+
675+ CHECKGL(glBindAttribLocation(m_sRGBTexture->GetOpenGLID(), 0, "vertex"));
676+ CHECKGL(glBindAttribLocation(m_sRGBTexture->GetOpenGLID(), 1, "textureCoord0"));
677+
678+ m_sRGBTexture->Link();
679+ }
680+
681 void GraphicsEngine::InitSlColorModTexMaskAlpha()
682 {
683 ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
684@@ -973,6 +1019,66 @@
685 ShaderProg->End();
686 }
687
688+ void GraphicsEngine::QRP_GLSL_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma)
689+ {
690+ if (!m_sRGBTexture.IsValid())
691+ InitSRGBTextureShader();
692+
693+ m_quad_tex_stats++;
694+ QRP_Compute_Texture_Coord(width, height, tex, texxform);
695+
696+ float fx = x;
697+ float fy = y;
698+ float vertexBuffer[] =
699+ {
700+ fx, fy, 0.0f, 1.0f, texxform.u0, texxform.v0, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
701+ fx, fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
702+ fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
703+ fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v0, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
704+ };
705+
706+ CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
707+ CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
708+ m_sRGBTexture->Begin();
709+
710+ int vertexLocation = m_sRGBTexture->GetAttributeLocation("vertex");
711+ int textureCoord0Location = m_sRGBTexture->GetAttributeLocation("textureCoord0");
712+ int textureObjectLocation = m_sRGBTexture->GetUniformLocationARB("textureObject");
713+
714+ //Set texture and it's uniform location.
715+ SetTexture(GL_TEXTURE0, tex);
716+ CHECKGL(glUniform1iARB(textureObjectLocation, 0));
717+
718+ GLint viewProjMatLocation = m_sRGBTexture->GetUniformLocationARB("viewProjectionMatrix");
719+ Matrix4 modelViewProjMat = GetOpenGLModelViewProjectionMatrix();
720+ m_sRGBTexture->SetUniformLocMatrix4fv(viewProjMatLocation, 1, false, (GLfloat*) &(modelViewProjMat.m));
721+
722+ //Set our gamma uniform.
723+ m_sRGBTexture->SetUniform1f("gamma", gamma);
724+
725+ if (vertexLocation != -1)
726+ {
727+ CHECKGL(glEnableVertexAttribArrayARB(vertexLocation));
728+ CHECKGL(glVertexAttribPointerARB((GLuint)vertexLocation, 4, GL_FLOAT, GL_FALSE, 48, vertexBuffer));
729+ }
730+
731+ if (textureCoord0Location != -1)
732+ {
733+ CHECKGL(glEnableVertexAttribArrayARB(textureCoord0Location));
734+ CHECKGL(glVertexAttribPointerARB((GLuint)textureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, vertexBuffer + 4));
735+ }
736+
737+ CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
738+
739+ if (vertexLocation != -1)
740+ CHECKGL(glDisableVertexAttribArrayARB(vertexLocation));
741+
742+ if (textureCoord0Location != -1)
743+ CHECKGL(glDisableVertexAttribArrayARB(textureCoord0Location));
744+
745+ m_sRGBTexture->End();
746+ }
747+
748 // Render the texture alpha into RGB and modulated by a color.
749 void GraphicsEngine::QRP_GLSL_ColorModTexAlpha(int x, int y, int width, int height,
750 ObjectPtr< IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &color)
751
752=== modified file 'gputests/Makefile.am'
753--- gputests/Makefile.am 2012-05-25 20:36:09 +0000
754+++ gputests/Makefile.am 2012-09-24 06:59:20 +0000
755@@ -7,7 +7,7 @@
756 # This tells automake that we want to build binaries, but they shouldn't be
757 # installed. For each individual test, add it's binary name here
758
759-noinst_PROGRAMS = texture_power_of_2 framebufferobject quad_2texmod texture_copy_blur texture_blur texture_data
760+noinst_PROGRAMS = texture_power_of_2 gamma_correction framebufferobject quad_2texmod texture_copy_blur texture_blur texture_data
761
762 if !NUX_OPENGLES_20
763 noinst_PROGRAMS += arb_programs_limits
764@@ -19,7 +19,7 @@
765 -I$(srcdir) \
766 -I$(top_srcdir) \
767 -DPREFIX=\""$(prefix)"\" \
768- -DLIBDIR=\""$(libdir)"\" \
769+ -DLIBDIR=\""$(libdir)"\" \
770 -DDATADIR=\""$(datadir)"\" \
771 -DG_LOG_DOMAIN=\"NuxGpuTests\" \
772 $(GCC_FLAGS) \
773@@ -39,6 +39,8 @@
774 # you need a $exe_SOURCES and $exe_LDADD so it builds
775 texture_power_of_2_SOURCES = texture_power_of_2.cpp
776 texture_power_of_2_LDADD = $(ALL_LIBS)
777+gamma_correction_SOURCES = gamma_correction.cpp
778+gamma_correction_LDADD = $(ALL_LIBS)
779 framebufferobject_SOURCES = framebufferobject.cpp
780 framebufferobject_LDADD = $(ALL_LIBS)
781 quad_2texmod_SOURCES = quad_2texmod.cpp
782@@ -55,6 +57,7 @@
783 # distribute source along to the documentation
784 sourcegputestsdir = "$(pkgdatadir)/gputests"
785 sourcegputests_DATA = $(texture_power_of_2_SOURCES) \
786+ $(gamma_correction_SOURCES) \
787 $(framebufferobject_SOURCES) \
788 $(quad_2texmod) \
789 $(texture_copy_blur_SOURCES) \
790
791=== added file 'gputests/gamma_correction.cpp'
792--- gputests/gamma_correction.cpp 1970-01-01 00:00:00 +0000
793+++ gputests/gamma_correction.cpp 2012-09-24 06:59:20 +0000
794@@ -0,0 +1,117 @@
795+#include "NuxCore/NuxCore.h"
796+#include "NuxGraphics/BitmapFormats.h"
797+#include "NuxGraphics/GraphicsDisplay.h"
798+#include "NuxGraphics/GLWindowManager.h"
799+#include "NuxGraphics/GraphicsEngine.h"
800+
801+/*
802+ * Tests:
803+ * - loading texture from the hard drive
804+ * - performing gamma correction
805+ */
806+
807+void correct_gamma(float g)
808+{
809+ nux::GraphicsDisplay* m_GLWindow = gGLWindowManager.CreateGLWindow("Test gamma", 512, 512, nux::WINDOWSTYLE_NORMAL, 0, false);
810+ nux::GraphicsEngine* m_GraphicsContext = m_GLWindow->GetGraphicsEngine();
811+ m_GLWindow->ShowWindow();
812+
813+ const TCHAR* fname = TEXT("./data/img.png");
814+ nux::ObjectPtr<nux::IOpenGLTexture2D> tex;
815+ nux::NBitmapData *bitmap = nux::LoadImageFile(fname);
816+ nux::ImageSurface surface = bitmap->GetSurface(0);
817+ surface.GetFormat();
818+
819+ tex = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture(
820+ surface.GetWidth(),
821+ surface.GetHeight(),
822+ 1,
823+ surface.GetFormat());
824+
825+ nux::SURFACE_LOCKED_RECT lockrect;
826+ tex->LockRect(0, &lockrect, 0);
827+
828+ BYTE *dest = (BYTE *) lockrect.pBits;
829+ const BYTE *src = surface.GetPtrRawData();
830+ int RowByteSize = surface.GetPitch();
831+ int num_row = surface.GetBlockHeight();
832+
833+ for (int Y = 0; Y < num_row; Y++ )
834+ {
835+ // Take Min(RowByteSize, StrideY): the source and the destination may not have the same Pitch but
836+ // they contain the same amount of valid data since they have the same width, height and format.
837+ nux::Memcpy(dest + Y * lockrect.Pitch, &src[Y * RowByteSize], nux::Min (RowByteSize, lockrect.Pitch));
838+ }
839+
840+ tex->UnlockRect(0);
841+
842+ int w, h;
843+ m_GraphicsContext->GetWindowSize(w, h);
844+ m_GraphicsContext->SetViewport(0, 0, w, h);
845+ m_GraphicsContext->SetContext(0, 0, w, h);
846+ m_GraphicsContext->Push2DWindow(w, h);
847+
848+ nux::Event event;
849+ memset(&event, 0, sizeof(nux::Event));
850+
851+ do
852+ {
853+ CHECKGL(glClearColor(0, 0, 0, 1) );
854+ CHECKGL(glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT));
855+
856+ m_GLWindow->GetSystemEvent(&event);
857+
858+ if(event.type == nux::NUX_SIZE_CONFIGURATION)
859+ {
860+ m_GraphicsContext->DisableAllTextureMode(0);
861+ m_GraphicsContext->DisableAllTextureMode(1);
862+ m_GraphicsContext->DisableAllTextureMode(2);
863+ m_GraphicsContext->DisableAllTextureMode(3);
864+ m_GraphicsContext->GetWindowSize(w, h);
865+ m_GraphicsContext->SetViewport(0, 0, w, h);
866+ m_GraphicsContext->SetScissor(0, 0, w, h);
867+ m_GraphicsContext->SetContext(0, 0, w, h);
868+ m_GraphicsContext->Push2DWindow(w, h);
869+ }
870+
871+ int x=10;
872+ int y=10;
873+
874+ m_GraphicsContext->SetTexture(GL_TEXTURE0, tex);
875+
876+ int width = tex->GetWidth();
877+ int height = tex->GetHeight();
878+
879+ nux::TexCoordXForm texxform;
880+ m_GraphicsContext->QRP_ASM_sRGB(x, y, width, height, tex, texxform, nux::color::White, g);
881+
882+ m_GLWindow->SwapBuffer();
883+
884+ } while(event.type != nux::NUX_TERMINATE_APP);
885+
886+ tex.Release();
887+ delete m_GLWindow;
888+}
889+
890+float g;
891+int main(int argc, char **argv)
892+{
893+ if(argc > 1) {
894+ char *endp; float val = strtof(argv[1], &endp);
895+
896+ if(!(endp == argv[1]))
897+ g = val;
898+ else
899+ g = 1.0;
900+ }
901+ else
902+ g = 1.0;
903+
904+ nux::NuxCoreInitialize(0);
905+ nux::NuxGraphicsInitialize();
906+
907+ printf("NuxGraphics Input gamma: %2f Exponent 1/gamma: %2f\n", g, (float)1.0 / g);
908+ correct_gamma(g);
909+
910+ return 0;
911+}
912
913=== modified file 'gputests/quad_2texmod.cpp' (properties changed: +x to -x)

Subscribers

People subscribed via source and target branches