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
=== modified file 'NuxGraphics/GraphicsEngine.cpp'
--- NuxGraphics/GraphicsEngine.cpp 2012-09-17 09:55:43 +0000
+++ NuxGraphics/GraphicsEngine.cpp 2012-09-24 06:59:20 +0000
@@ -220,6 +220,7 @@
220 InitAsm2TextureMod();220 InitAsm2TextureMod();
221 InitAsm4TextureAdd();221 InitAsm4TextureAdd();
222 InitAsmBlendModes();222 InitAsmBlendModes();
223 InitAsmSRGBShader();
223224
224 InitAsmPower();225 InitAsmPower();
225 InitAsmAlphaReplicate();226 InitAsmAlphaReplicate();
226227
=== modified file 'NuxGraphics/GraphicsEngine.h'
--- NuxGraphics/GraphicsEngine.h 2012-09-17 09:55:43 +0000
+++ NuxGraphics/GraphicsEngine.h 2012-09-24 06:59:20 +0000
@@ -192,6 +192,7 @@
192 Shader Output = ve4(tex.r, tex.g, tex.b, tex.a)192 Shader Output = ve4(tex.r, tex.g, tex.b, tex.a)
193 */193 */
194 void QRP_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);194 void QRP_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
195<<<<<<< TREE
195 //! Render a textured quad. 196 //! Render a textured quad.
196 /*!197 /*!
197 Multiply the shader rgb output with the texture alpha.198 Multiply the shader rgb output with the texture alpha.
@@ -199,6 +200,9 @@
199 */200 */
200 void QRP_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);201 void QRP_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
201 void QRP_TexDesaturate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0, float desaturation_factor); 202 void QRP_TexDesaturate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0, float desaturation_factor);
203=======
204 void QRP_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma);
205>>>>>>> MERGE-SOURCE
202 void QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);206 void QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
203 void QRP_Color(int x, int y, int width, int height, const Color& c0);207 void QRP_Color(int x, int y, int width, int height, const Color& c0);
204 void QRP_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3);208 void QRP_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3);
@@ -271,7 +275,11 @@
271275
272 // ASM276 // ASM
273 void QRP_ASM_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);277 void QRP_ASM_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
278<<<<<<< TREE
274 void QRP_ASM_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);279 void QRP_ASM_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
280=======
281 void QRP_ASM_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma);
282>>>>>>> MERGE-SOURCE
275 void QRP_ASM_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);283 void QRP_ASM_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
276284
277 void QRP_ASM_Color(int x, int y, int width, int height, const Color& c0);285 void QRP_ASM_Color(int x, int y, int width, int height, const Color& c0);
@@ -391,8 +399,12 @@
391 // GLSL399 // GLSL
392400
393 void QRP_GLSL_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);401 void QRP_GLSL_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);
402<<<<<<< TREE
394 void QRP_GLSL_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);403 void QRP_GLSL_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);
395 void QRP_GLSL_TexDesaturate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0, float desaturation_factor);404 void QRP_GLSL_TexDesaturate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0, float desaturation_factor);
405=======
406 void QRP_GLSL_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma);
407>>>>>>> MERGE-SOURCE
396 void QRP_GLSL_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);408 void QRP_GLSL_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
397409
398 void QRP_GLSL_Color(int x, int y, int width, int height, const Color& c0);410 void QRP_GLSL_Color(int x, int y, int width, int height, const Color& c0);
@@ -844,12 +856,21 @@
844 //! Same as m_AsmTextureModColor for rectangle textures.856 //! Same as m_AsmTextureModColor for rectangle textures.
845 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTextureRectModColor;857 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTextureRectModColor;
846858
859<<<<<<< TREE
847 void InitAsmTexturePremultiplyShader();860 void InitAsmTexturePremultiplyShader();
848 //! Render polygons with a texture modulated by a color.861 //! Render polygons with a texture modulated by a color.
849 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTexturePremultiplyModColor;862 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTexturePremultiplyModColor;
850 //! Same as m_AsmTextureModColor for rectangle textures.863 //! Same as m_AsmTextureModColor for rectangle textures.
851 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTexturePremultiplyRectModColor;864 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTexturePremultiplyRectModColor;
852865
866=======
867 void InitAsmSRGBShader();
868 //! Render a texture in linear colour space in an sRGB non-linear space.
869 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmLineartoSRGB;
870 //! Render a texture rectangle in linear colour space in an sRGB non-linear space.
871 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmLineartoSRGBRect;
872
873>>>>>>> MERGE-SOURCE
853 void InitAsmPixelateShader();874 void InitAsmPixelateShader();
854 //! Render a pixelated texture over a polygon.875 //! Render a pixelated texture over a polygon.
855 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPixelate;876 ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPixelate;
@@ -928,10 +949,17 @@
928 //! Render polygons with a texture modulated by a color.949 //! Render polygons with a texture modulated by a color.
929 ObjectPtr<IOpenGLShaderProgram> m_SlTextureModColor;950 ObjectPtr<IOpenGLShaderProgram> m_SlTextureModColor;
930951
952<<<<<<< TREE
931 void InitSlTexturePremultiplyShader();953 void InitSlTexturePremultiplyShader();
932 //! Render polygons with a premultiplied texture modulated by a color.954 //! Render polygons with a premultiplied texture modulated by a color.
933 ObjectPtr<IOpenGLShaderProgram> m_SlTexturePremultiplyModColor;955 ObjectPtr<IOpenGLShaderProgram> m_SlTexturePremultiplyModColor;
934956
957=======
958 void InitSRGBTextureShader();
959 //! Renders a texture in linear colour space using non-linear sRGB.
960 ObjectPtr<IOpenGLShaderProgram> m_sRGBTexture;
961
962>>>>>>> MERGE-SOURCE
935 void InitSlPixelateShader();963 void InitSlPixelateShader();
936 //! Render a pixelated texture over a polygon.964 //! Render a pixelated texture over a polygon.
937 ObjectPtr<IOpenGLShaderProgram> m_SLPixelate;965 ObjectPtr<IOpenGLShaderProgram> m_SLPixelate;
938966
=== modified file 'NuxGraphics/RenderingPipe.cpp'
--- NuxGraphics/RenderingPipe.cpp 2012-09-14 18:26:55 +0000
+++ NuxGraphics/RenderingPipe.cpp 2012-09-24 06:59:20 +0000
@@ -368,6 +368,7 @@
368#endif368#endif
369 }369 }
370370
371<<<<<<< TREE
371 void GraphicsEngine::QRP_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform0, const Color &color0)372 void GraphicsEngine::QRP_1TexPremultiply(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform0, const Color &color0)
372 {373 {
373#ifndef NUX_OPENGLES_20374#ifndef NUX_OPENGLES_20
@@ -395,6 +396,20 @@
395#endif396#endif
396 }397 }
397398
399=======
400 void GraphicsEngine::QRP_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma)
401 {
402#ifndef NUX_OPENGLES_20
403 if (UsingGLSLCodePath())
404 QRP_GLSL_sRGB(x, y, width, height, tex, texxform, colour, gamma);
405 else
406 QRP_ASM_sRGB(x, y, width, height, tex, texxform, colour, gamma);
407#else
408 QRP_GLSL_sRGB(x, y, width, height, tex, texxform, colour, gamma);
409#endif
410 }
411
412>>>>>>> MERGE-SOURCE
398 void GraphicsEngine::QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &c0, int pixel_size)413 void GraphicsEngine::QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &c0, int pixel_size)
399 {414 {
400#ifndef NUX_OPENGLES_20415#ifndef NUX_OPENGLES_20
401416
=== modified file 'NuxGraphics/RenderingPipeAsm.cpp'
--- NuxGraphics/RenderingPipeAsm.cpp 2012-08-17 12:41:21 +0000
+++ NuxGraphics/RenderingPipeAsm.cpp 2012-09-24 06:59:20 +0000
@@ -102,7 +102,7 @@
102102
103 void GraphicsEngine::InitAsmColorShader()103 void GraphicsEngine::InitAsmColorShader()
104 {104 {
105 NString AsmVtx = 105 NString AsmVtx =
106 "!!ARBvp1.0 \n\106 "!!ARBvp1.0 \n\
107 ATTRIB iPos = vertex.position; \n\107 ATTRIB iPos = vertex.position; \n\
108 ATTRIB iColor = vertex.attrib[3]; \n\108 ATTRIB iColor = vertex.attrib[3]; \n\
@@ -117,7 +117,7 @@
117 MOV oColor, iColor; \n\117 MOV oColor, iColor; \n\
118 END";118 END";
119119
120 NString AsmFrg = 120 NString AsmFrg =
121 "!!ARBfp1.0 \n\121 "!!ARBfp1.0 \n\
122 MOV result.color, fragment.color; \n\122 MOV result.color, fragment.color; \n\
123 END";123 END";
@@ -130,7 +130,7 @@
130130
131 void GraphicsEngine::InitAsmTextureShader()131 void GraphicsEngine::InitAsmTextureShader()
132 {132 {
133 NString AsmVtx = 133 NString AsmVtx =
134 "!!ARBvp1.0 \n\134 "!!ARBvp1.0 \n\
135 ATTRIB iPos = vertex.position; \n\135 ATTRIB iPos = vertex.position; \n\
136 ATTRIB iColor = vertex.attrib[3]; \n\136 ATTRIB iColor = vertex.attrib[3]; \n\
@@ -147,14 +147,14 @@
147 MOV oTexCoord0, vertex.attrib[8]; \n\147 MOV oTexCoord0, vertex.attrib[8]; \n\
148 END";148 END";
149149
150 NString AsmFrg = 150 NString AsmFrg =
151 "!!ARBfp1.0 \n\151 "!!ARBfp1.0 \n\
152 TEMP tex0; \n\152 TEMP tex0; \n\
153 TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\153 TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\
154 MUL result.color, fragment.color, tex0; \n\154 MUL result.color, fragment.color, tex0; \n\
155 END";155 END";
156156
157 NString AsmFrgRect = 157 NString AsmFrgRect =
158 "!!ARBfp1.0 \n\158 "!!ARBfp1.0 \n\
159 TEMP tex0; \n\159 TEMP tex0; \n\
160 TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\160 TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\
@@ -172,9 +172,58 @@
172 m_AsmTextureRectModColor->Link();172 m_AsmTextureRectModColor->Link();
173 }173 }
174174
175 void GraphicsEngine::InitAsmSRGBShader()
176 {
177 const char* vertex =
178 "!!ARBvp1.0 \n\
179 OUTPUT oPos = result.position; \n\
180 OUTPUT oTexCoord0 = result.texcoord[0]; \n\
181 # Transform the vertex to clip coordinates. \n\
182 DP4 oPos.x, state.matrix.mvp.row[0], vertex.position; \n\
183 DP4 oPos.y, state.matrix.mvp.row[1], vertex.position; \n\
184 DP4 oPos.z, state.matrix.mvp.row[2], vertex.position; \n\
185 DP4 oPos.w, state.matrix.mvp.row[3], vertex.position; \n\
186 MOV oTexCoord0, vertex.attrib[8]; \n\
187 END";
188
189 const char* pixel =
190 "!!ARBfp1.0 \n\
191 PARAM gamma = program.local[0]; \n\
192 TEMP T; \n\
193 TEMP P; \n\
194 TEX T.xyz, fragment.texcoord[0], texture[0], 2D; \n\
195 POW P.x, T.x, gamma.x; \n\
196 POW P.y, T.y, gamma.x; \n\
197 POW P.z, T.z, gamma.x; \n\
198 MOV result.color, P; \n\
199 END";
200
201 const char* rect =
202 "!!ARBfp1.0 \n\
203 PARAM gamma = program.local[0]; \n\
204 TEMP T; \n\
205 TEMP P; \n\
206 TEX T.xyz, fragment.texcoord[0], texture[0], 2D; \n\
207 POW P.x, T.x, gamma.x; \n\
208 POW P.y, T.y, gamma.x; \n\
209 POW P.z, T.z, gamma.x; \n\
210 MOV result.color, P; \n\
211 END";
212
213 m_AsmLineartoSRGB = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
214 m_AsmLineartoSRGB->LoadVertexShader(vertex);
215 m_AsmLineartoSRGB->LoadPixelShader(pixel);
216 m_AsmLineartoSRGB->Link();
217
218 m_AsmLineartoSRGBRect = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
219 m_AsmLineartoSRGBRect->LoadVertexShader(vertex);
220 m_AsmLineartoSRGBRect->LoadPixelShader(rect);
221 m_AsmLineartoSRGBRect->Link();
222 }
223
175 void GraphicsEngine::InitAsmColorModTexMaskAlpha()224 void GraphicsEngine::InitAsmColorModTexMaskAlpha()
176 {225 {
177 NString AsmVtx = 226 NString AsmVtx =
178 "!!ARBvp1.0 \n\227 "!!ARBvp1.0 \n\
179 OUTPUT oPos = result.position; \n\228 OUTPUT oPos = result.position; \n\
180 OUTPUT oColor = result.color; \n\229 OUTPUT oColor = result.color; \n\
@@ -188,7 +237,7 @@
188 MOV oTexCoord0, vertex.attrib[8]; \n\237 MOV oTexCoord0, vertex.attrib[8]; \n\
189 END";238 END";
190239
191 NString AsmFrg = 240 NString AsmFrg =
192 "!!ARBfp1.0 \n\241 "!!ARBfp1.0 \n\
193 TEMP tex0; \n\242 TEMP tex0; \n\
194 TEMP temp; \n\243 TEMP temp; \n\
@@ -198,7 +247,7 @@
198 MOV result.color, temp; \n\247 MOV result.color, temp; \n\
199 END";248 END";
200249
201 NString AsmFrgRect = 250 NString AsmFrgRect =
202 "!!ARBfp1.0 \n\251 "!!ARBfp1.0 \n\
203 TEMP tex0; \n\252 TEMP tex0; \n\
204 TEMP temp; \n\253 TEMP temp; \n\
@@ -221,7 +270,7 @@
221270
222 void GraphicsEngine::InitAsm2TextureAdd()271 void GraphicsEngine::InitAsm2TextureAdd()
223 {272 {
224 NString AsmVtx = 273 NString AsmVtx =
225 "!!ARBvp1.0 \n\274 "!!ARBvp1.0 \n\
226 ATTRIB iPos = vertex.position; \n\275 ATTRIB iPos = vertex.position; \n\
227 OUTPUT oPos = result.position; \n\276 OUTPUT oPos = result.position; \n\
@@ -236,7 +285,7 @@
236 MOV oTexCoord1, vertex.attrib[9]; \n\285 MOV oTexCoord1, vertex.attrib[9]; \n\
237 END";286 END";
238287
239 NString AsmFrg = 288 NString AsmFrg =
240 "!!ARBfp1.0 \n\289 "!!ARBfp1.0 \n\
241 PARAM color0 = program.local[0]; \n\290 PARAM color0 = program.local[0]; \n\
242 PARAM color1 = program.local[1]; \n\291 PARAM color1 = program.local[1]; \n\
@@ -250,7 +299,7 @@
250 MOV result.color, temp; \n\299 MOV result.color, temp; \n\
251 END";300 END";
252301
253 NString AsmFrgRect = 302 NString AsmFrgRect =
254 "!!ARBfp1.0 \n\303 "!!ARBfp1.0 \n\
255 PARAM color0 = program.local[0]; \n\304 PARAM color0 = program.local[0]; \n\
256 PARAM color1 = program.local[1]; \n\305 PARAM color1 = program.local[1]; \n\
@@ -277,7 +326,7 @@
277326
278 void GraphicsEngine::InitAsm2TextureDepRead()327 void GraphicsEngine::InitAsm2TextureDepRead()
279 {328 {
280 NString AsmVtx = 329 NString AsmVtx =
281 "!!ARBvp1.0 \n\330 "!!ARBvp1.0 \n\
282 ATTRIB iPos = vertex.position; \n\331 ATTRIB iPos = vertex.position; \n\
283 OUTPUT oPos = result.position; \n\332 OUTPUT oPos = result.position; \n\
@@ -292,7 +341,7 @@
292 MOV oTexCoord1, vertex.attrib[9]; \n\341 MOV oTexCoord1, vertex.attrib[9]; \n\
293 END";342 END";
294343
295 NString AsmFrg = 344 NString AsmFrg =
296 "!!ARBfp1.0 \n\345 "!!ARBfp1.0 \n\
297 PARAM color0 = program.local[0]; \n\346 PARAM color0 = program.local[0]; \n\
298 PARAM color1 = program.local[1]; \n\347 PARAM color1 = program.local[1]; \n\
@@ -309,7 +358,7 @@
309 MUL result.color, color1, tex1; \n\358 MUL result.color, color1, tex1; \n\
310 END";359 END";
311360
312 NString AsmFrgRect = 361 NString AsmFrgRect =
313 "!!ARBfp1.0 \n\362 "!!ARBfp1.0 \n\
314 PARAM color0 = program.local[0]; \n\363 PARAM color0 = program.local[0]; \n\
315 PARAM color1 = program.local[1]; \n\364 PARAM color1 = program.local[1]; \n\
@@ -336,7 +385,7 @@
336385
337 void GraphicsEngine::InitAsm2TextureMod()386 void GraphicsEngine::InitAsm2TextureMod()
338 {387 {
339 NString AsmVtx = 388 NString AsmVtx =
340 "!!ARBvp1.0 \n\389 "!!ARBvp1.0 \n\
341 ATTRIB iPos = vertex.position; \n\390 ATTRIB iPos = vertex.position; \n\
342 OUTPUT oPos = result.position; \n\391 OUTPUT oPos = result.position; \n\
@@ -351,7 +400,7 @@
351 MOV oTexCoord1, vertex.attrib[9]; \n\400 MOV oTexCoord1, vertex.attrib[9]; \n\
352 END";401 END";
353402
354 NString AsmFrg = 403 NString AsmFrg =
355 "!!ARBfp1.0 \n\404 "!!ARBfp1.0 \n\
356 PARAM color0 = program.local[0]; \n\405 PARAM color0 = program.local[0]; \n\
357 PARAM color1 = program.local[1]; \n\406 PARAM color1 = program.local[1]; \n\
@@ -366,7 +415,7 @@
366 MUL result.color, temp0, temp1; \n\415 MUL result.color, temp0, temp1; \n\
367 END";416 END";
368417
369 NString AsmFrgRect = 418 NString AsmFrgRect =
370 "!!ARBfp1.0 \n\419 "!!ARBfp1.0 \n\
371 PARAM color0 = program.local[0]; \n\420 PARAM color0 = program.local[0]; \n\
372 PARAM color1 = program.local[1]; \n\421 PARAM color1 = program.local[1]; \n\
@@ -394,7 +443,7 @@
394443
395 void GraphicsEngine::InitAsm4TextureAdd()444 void GraphicsEngine::InitAsm4TextureAdd()
396 {445 {
397 NString AsmVtx = 446 NString AsmVtx =
398 "!!ARBvp1.0 \n\447 "!!ARBvp1.0 \n\
399 ATTRIB iPos = vertex.position; \n\448 ATTRIB iPos = vertex.position; \n\
400 OUTPUT oPos = result.position; \n\449 OUTPUT oPos = result.position; \n\
@@ -413,7 +462,7 @@
413 MOV oTexCoord3, vertex.attrib[11]; \n\462 MOV oTexCoord3, vertex.attrib[11]; \n\
414 END";463 END";
415464
416 NString AsmFrg = 465 NString AsmFrg =
417 "!!ARBfp1.0 \n\466 "!!ARBfp1.0 \n\
418 PARAM color0 = program.local[0]; \n\467 PARAM color0 = program.local[0]; \n\
419 PARAM color1 = program.local[1]; \n\468 PARAM color1 = program.local[1]; \n\
@@ -435,7 +484,7 @@
435 MOV result.color, temp; \n\484 MOV result.color, temp; \n\
436 END";485 END";
437486
438 NString AsmFrgRect = 487 NString AsmFrgRect =
439 "!!ARBfp1.0 \n\488 "!!ARBfp1.0 \n\
440 PARAM color0 = program.local[0]; \n\489 PARAM color0 = program.local[0]; \n\
441 PARAM color1 = program.local[1]; \n\490 PARAM color1 = program.local[1]; \n\
@@ -470,7 +519,7 @@
470519
471 void GraphicsEngine::InitAsmBlendModes()520 void GraphicsEngine::InitAsmBlendModes()
472 {521 {
473 NString AsmVtx = 522 NString AsmVtx =
474 "!!ARBvp1.0 \n\523 "!!ARBvp1.0 \n\
475 OUTPUT oPos = result.position; \n\524 OUTPUT oPos = result.position; \n\
476 OUTPUT oTexCoord0 = result.texcoord[0]; \n\525 OUTPUT oTexCoord0 = result.texcoord[0]; \n\
@@ -484,7 +533,7 @@
484 MOV oTexCoord1, vertex.attrib[9]; \n\533 MOV oTexCoord1, vertex.attrib[9]; \n\
485 END";534 END";
486535
487 NString AsmPSBNormal = 536 NString AsmPSBNormal =
488 "!!ARBfp1.0 \n\537 "!!ARBfp1.0 \n\
489 TEMP tex0; \n\538 TEMP tex0; \n\
490 TEMP tex1; \n\539 TEMP tex1; \n\
@@ -518,7 +567,7 @@
518 m_AsmPSBLighten->Link();567 m_AsmPSBLighten->Link();
519568
520 // Darken569 // Darken
521 NString AsmPSBDarken = 570 NString AsmPSBDarken =
522 "!!ARBfp1.0 \n\571 "!!ARBfp1.0 \n\
523 TEMP tex0; \n\572 TEMP tex0; \n\
524 TEMP tex1; \n\573 TEMP tex1; \n\
@@ -537,7 +586,7 @@
537 m_AsmPSBDarken->Link();586 m_AsmPSBDarken->Link();
538587
539 // Multiply588 // Multiply
540 NString AsmPSBMultiply = 589 NString AsmPSBMultiply =
541 "!!ARBfp1.0 \n\590 "!!ARBfp1.0 \n\
542 TEMP tex0; \n\591 TEMP tex0; \n\
543 TEMP tex1; \n\592 TEMP tex1; \n\
@@ -627,7 +676,7 @@
627676
628 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));677 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
629 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));678 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
630 679
631 ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmTextureModColor;680 ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmTextureModColor;
632 if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))681 if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
633 {682 {
@@ -677,6 +726,62 @@
677 shader_program->End();726 shader_program->End();
678 }727 }
679728
729 void GraphicsEngine::QRP_ASM_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& color, const float gamma)
730 {
731 NUX_RETURN_IF_FALSE(m_AsmLineartoSRGB.IsValid() || m_AsmLineartoSRGBRect.IsValid());
732
733 QRP_Compute_Texture_Coord(width, height, tex, texxform);
734
735 float fx = x; float fy = y;
736
737 float vertexArray[] = {
738 fx, fy, 0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
739 fx, fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
740 fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
741 fx + width, fy, 0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
742 };
743
744 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
745 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
746
747 ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmLineartoSRGB;
748 if (tex->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
749 shader_program = m_AsmLineartoSRGBRect;
750
751 shader_program->Begin();
752
753 SetTexture(GL_TEXTURE0, tex);
754 CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, gamma, 0.0, 0.0, 0.0));
755
756 CHECKGL(glMatrixMode(GL_MODELVIEW));
757 CHECKGL(glLoadIdentity());
758 CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
759 CHECKGL(glMatrixMode(GL_PROJECTION));
760 CHECKGL(glLoadIdentity());
761 CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
762
763 int vertexLocation = VTXATTRIB_POSITION;
764 int textureCoord0Location = VTXATTRIB_TEXCOORD0;
765 int vertexColorLocation = VTXATTRIB_COLOR;
766
767 CHECKGL(glEnableVertexAttribArrayARB(vertexLocation));
768 CHECKGL(glVertexAttribPointerARB((GLuint) vertexLocation, 4, GL_FLOAT, GL_FALSE, 48, vertexArray));
769
770 CHECKGL(glEnableVertexAttribArrayARB(textureCoord0Location));
771 CHECKGL(glVertexAttribPointerARB((GLuint)textureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, vertexArray + 4));
772
773 CHECKGL(glEnableVertexAttribArrayARB(vertexColorLocation));
774 CHECKGL(glVertexAttribPointerARB((GLuint)vertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, vertexArray + 8));
775
776 CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
777
778 CHECKGL(glDisableVertexAttribArrayARB(vertexLocation));
779 CHECKGL(glDisableVertexAttribArrayARB(textureCoord0Location));
780 CHECKGL(glDisableVertexAttribArrayARB(vertexColorLocation));
781
782 shader_program->End();
783 }
784
680 void GraphicsEngine::QRP_ASM_ColorModTexAlpha(int x, int y, int width, int height,785 void GraphicsEngine::QRP_ASM_ColorModTexAlpha(int x, int y, int width, int height,
681 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)786 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)
682 {787 {
@@ -1241,7 +1346,7 @@
12411346
1242 void GraphicsEngine::InitAsmPower()1347 void GraphicsEngine::InitAsmPower()
1243 {1348 {
1244 NString AsmVtx = 1349 NString AsmVtx =
1245 "!!ARBvp1.0 \n\1350 "!!ARBvp1.0 \n\
1246 ATTRIB iPos = vertex.position; \n\1351 ATTRIB iPos = vertex.position; \n\
1247 OUTPUT oPos = result.position; \n\1352 OUTPUT oPos = result.position; \n\
@@ -1255,7 +1360,7 @@
1255 END";1360 END";
12561361
12571362
1258 NString AsmFrg = 1363 NString AsmFrg =
1259 "!!ARBfp1.0 \n\1364 "!!ARBfp1.0 \n\
1260 PARAM color0 = program.local[0]; \n\1365 PARAM color0 = program.local[0]; \n\
1261 PARAM exponent = program.local[1]; \n\1366 PARAM exponent = program.local[1]; \n\
@@ -1269,7 +1374,7 @@
1269 MUL result.color, color0, final; \n\1374 MUL result.color, color0, final; \n\
1270 END";1375 END";
12711376
1272 NString AsmFrgRect = 1377 NString AsmFrgRect =
1273 "!!ARBfp1.0 \n\1378 "!!ARBfp1.0 \n\
1274 PARAM color0 = program.local[0]; \n\1379 PARAM color0 = program.local[0]; \n\
1275 PARAM exponent = program.local[1]; \n\1380 PARAM exponent = program.local[1]; \n\
@@ -1351,7 +1456,7 @@
13511456
1352 void GraphicsEngine::InitAsmAlphaReplicate()1457 void GraphicsEngine::InitAsmAlphaReplicate()
1353 {1458 {
1354 NString AsmVtx = 1459 NString AsmVtx =
1355 "!!ARBvp1.0 \n\1460 "!!ARBvp1.0 \n\
1356 ATTRIB iPos = vertex.position; \n\1461 ATTRIB iPos = vertex.position; \n\
1357 OUTPUT oPos = result.position; \n\1462 OUTPUT oPos = result.position; \n\
@@ -1365,7 +1470,7 @@
1365 END";1470 END";
13661471
13671472
1368 NString AsmFrg = 1473 NString AsmFrg =
1369 "!!ARBfp1.0 \n\1474 "!!ARBfp1.0 \n\
1370 PARAM color0 = program.local[0]; \n\1475 PARAM color0 = program.local[0]; \n\
1371 TEMP tex0; \n\1476 TEMP tex0; \n\
@@ -1373,7 +1478,7 @@
1373 MUL result.color, color0, tex0.aaaa; \n\1478 MUL result.color, color0, tex0.aaaa; \n\
1374 END";1479 END";
13751480
1376 NString AsmFrgRect = 1481 NString AsmFrgRect =
1377 "!!ARBfp1.0 \n\1482 "!!ARBfp1.0 \n\
1378 PARAM color0 = program.local[0]; \n\1483 PARAM color0 = program.local[0]; \n\
1379 TEMP tex0; \n\1484 TEMP tex0; \n\
@@ -1450,7 +1555,7 @@
14501555
1451 void GraphicsEngine::InitAsmColorMatrixFilter()1556 void GraphicsEngine::InitAsmColorMatrixFilter()
1452 {1557 {
1453 NString AsmVtx = 1558 NString AsmVtx =
1454 "!!ARBvp1.0 \n\1559 "!!ARBvp1.0 \n\
1455 ATTRIB iPos = vertex.position; \n\1560 ATTRIB iPos = vertex.position; \n\
1456 OUTPUT oPos = result.position; \n\1561 OUTPUT oPos = result.position; \n\
@@ -1464,7 +1569,7 @@
1464 END";1569 END";
14651570
14661571
1467 NString AsmFrg = 1572 NString AsmFrg =
1468 "!!ARBfp1.0 \n\1573 "!!ARBfp1.0 \n\
1469 PARAM color0 = program.local[0]; \n\1574 PARAM color0 = program.local[0]; \n\
1470 PARAM CM0 = program.local[1]; \n\1575 PARAM CM0 = program.local[1]; \n\
@@ -1482,7 +1587,7 @@
1482 MUL result.color, color0, final; \n\1587 MUL result.color, color0, final; \n\
1483 END";1588 END";
14841589
1485 NString AsmFrgRect = 1590 NString AsmFrgRect =
1486 "!!ARBfp1.0 \n\1591 "!!ARBfp1.0 \n\
1487 PARAM color0 = program.local[0]; \n\1592 PARAM color0 = program.local[0]; \n\
1488 PARAM CM0 = program.local[1]; \n\1593 PARAM CM0 = program.local[1]; \n\
@@ -1578,7 +1683,7 @@
15781683
1579 void GraphicsEngine::InitAsmSeparableGaussFilter()1684 void GraphicsEngine::InitAsmSeparableGaussFilter()
1580 {1685 {
1581 NString AsmVtx = 1686 NString AsmVtx =
1582 "!!ARBvp1.0 \n\1687 "!!ARBvp1.0 \n\
1583 ATTRIB iPos = vertex.position; \n\1688 ATTRIB iPos = vertex.position; \n\
1584 OUTPUT oPos = result.position; \n\1689 OUTPUT oPos = result.position; \n\
@@ -1604,7 +1709,7 @@
1604 END";1709 END";
16051710
16061711
1607 NString AsmFrg = 1712 NString AsmFrg =
1608 "!!ARBfp1.0 \n\1713 "!!ARBfp1.0 \n\
1609 TEMP tex0; \n\1714 TEMP tex0; \n\
1610 TEMP final; \n\1715 TEMP final; \n\
@@ -1627,7 +1732,7 @@
1627 END";1732 END";
16281733
16291734
1630 NString AsmFrgRect = 1735 NString AsmFrgRect =
1631 "!!ARBfp1.0 \n\1736 "!!ARBfp1.0 \n\
1632 TEMP tex0; \n\1737 TEMP tex0; \n\
1633 TEMP final; \n\1738 TEMP final; \n\
@@ -2021,7 +2126,7 @@
2021 fx_structure->dst_texture->SetFiltering(GL_NEAREST, GL_NEAREST);2126 fx_structure->dst_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
2022 fx_structure->temp_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);2127 fx_structure->temp_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
2023 fx_structure->temp_texture->SetFiltering(GL_NEAREST, GL_NEAREST);2128 fx_structure->temp_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
2024 2129
2025 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);2130 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
2026 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);2131 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
20272132
@@ -2050,7 +2155,7 @@
2050 {2155 {
2051 SetViewport(0, 0, previous_width, previous_height);2156 SetViewport(0, 0, previous_width, previous_height);
2052 }2157 }
2053 } 2158 }
20542159
2055 ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetPower(2160 ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetPower(
2056 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color & c0, const Vector4 &exponent)2161 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color & c0, const Vector4 &exponent)
@@ -2287,7 +2392,7 @@
22872392
2288 void GraphicsEngine::InitAsmPixelateShader()2393 void GraphicsEngine::InitAsmPixelateShader()
2289 {2394 {
2290 NString AsmVtx = 2395 NString AsmVtx =
2291 "!!ARBvp1.0 \n\2396 "!!ARBvp1.0 \n\
2292 ATTRIB iPos = vertex.position; \n\2397 ATTRIB iPos = vertex.position; \n\
2293 ATTRIB iColor = vertex.attrib[3]; \n\2398 ATTRIB iColor = vertex.attrib[3]; \n\
@@ -2304,7 +2409,7 @@
2304 MOV oTexCoord0, vertex.attrib[8]; \n\2409 MOV oTexCoord0, vertex.attrib[8]; \n\
2305 END";2410 END";
23062411
2307 NString AsmFrg = 2412 NString AsmFrg =
2308 "!!ARBfp1.0 \n\2413 "!!ARBfp1.0 \n\
2309 TEMP tex0; \n\2414 TEMP tex0; \n\
2310 TEMP tex_coord; \n\2415 TEMP tex_coord; \n\
@@ -2317,7 +2422,7 @@
2317 MUL result.color, fragment.color, tex0; \n\2422 MUL result.color, fragment.color, tex0; \n\
2318 END";2423 END";
23192424
2320 NString AsmFrgRect = 2425 NString AsmFrgRect =
2321 "!!ARBfp1.0 \n\2426 "!!ARBfp1.0 \n\
2322 TEMP tex0; \n\2427 TEMP tex0; \n\
2323 TEMP tex_coord; \n\2428 TEMP tex_coord; \n\
23242429
=== modified file 'NuxGraphics/RenderingPipeGLSL.cpp'
--- NuxGraphics/RenderingPipeGLSL.cpp 2012-09-14 18:26:55 +0000
+++ NuxGraphics/RenderingPipeGLSL.cpp 2012-09-24 06:59:20 +0000
@@ -117,6 +117,52 @@
117 m_SlTextureModColor->Link();117 m_SlTextureModColor->Link();
118 }118 }
119119
120 void GraphicsEngine::InitSRGBTextureShader()
121 {
122 ObjectPtr<IOpenGLVertexShader> vertexShader = _graphics_display.m_DeviceFactory->CreateVertexShader();
123 ObjectPtr<IOpenGLPixelShader> pixelShader = _graphics_display.m_DeviceFactory->CreatePixelShader();
124
125 std::string vertexString =
126 NUX_VERTEX_SHADER_HEADER
127 "attribute vec4 vertex; \n\
128 attribute vec4 textureCoord0; \n\
129 uniform mat4 viewProjectionMatrix; \n\
130 uniform float gamma; \n\
131 varying vec4 varyTexCoord0; \n\
132 void main() \n\
133 { \n\
134 gl_Position = viewProjectionMatrix * vertex; \n\
135 varyTexCoord0 = textureCoord0; \n\
136 }";
137
138 std::string pixelString =
139 NUX_FRAGMENT_SHADER_HEADER
140 "uniform sampler2D textureObject; \n\
141 uniform float gamma; \n\
142 varying vec4 varyTexCoord0; \n\
143 void main() \n\
144 { \n\
145 vec2 uv = varyTexCoord0.st; \n\
146 vec4 tempTex = texture2D(textureObject, uv); \n\
147 gl_FragColor.rgb = pow(tempTex.rgb, 1 / gamma); \n\
148 gl_FragColor.a = tempTex.a; \n\
149 }";
150
151 m_sRGBTexture = _graphics_display.m_DeviceFactory->CreateShaderProgram();
152
153 vertexShader->SetShaderCode(vertexString.c_str());
154 pixelShader->SetShaderCode(pixelString.c_str());
155
156 m_sRGBTexture->ClearShaderObjects();
157 m_sRGBTexture->AddShaderObject(vertexShader);
158 m_sRGBTexture->AddShaderObject(pixelShader);
159
160 CHECKGL(glBindAttribLocation(m_sRGBTexture->GetOpenGLID(), 0, "vertex"));
161 CHECKGL(glBindAttribLocation(m_sRGBTexture->GetOpenGLID(), 1, "textureCoord0"));
162
163 m_sRGBTexture->Link();
164 }
165
120 void GraphicsEngine::InitSlColorModTexMaskAlpha()166 void GraphicsEngine::InitSlColorModTexMaskAlpha()
121 {167 {
122 ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();168 ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
@@ -973,6 +1019,66 @@
973 ShaderProg->End();1019 ShaderProg->End();
974 }1020 }
9751021
1022 void GraphicsEngine::QRP_GLSL_sRGB(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> tex, TexCoordXForm& texxform, const Color& colour, const float gamma)
1023 {
1024 if (!m_sRGBTexture.IsValid())
1025 InitSRGBTextureShader();
1026
1027 m_quad_tex_stats++;
1028 QRP_Compute_Texture_Coord(width, height, tex, texxform);
1029
1030 float fx = x;
1031 float fy = y;
1032 float vertexBuffer[] =
1033 {
1034 fx, fy, 0.0f, 1.0f, texxform.u0, texxform.v0, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
1035 fx, fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
1036 fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
1037 fx + width, fy + height, 0.0f, 1.0f, texxform.u1, texxform.v0, 0, 0, colour.red, colour.green, colour.blue, colour.alpha,
1038 };
1039
1040 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
1041 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
1042 m_sRGBTexture->Begin();
1043
1044 int vertexLocation = m_sRGBTexture->GetAttributeLocation("vertex");
1045 int textureCoord0Location = m_sRGBTexture->GetAttributeLocation("textureCoord0");
1046 int textureObjectLocation = m_sRGBTexture->GetUniformLocationARB("textureObject");
1047
1048 //Set texture and it's uniform location.
1049 SetTexture(GL_TEXTURE0, tex);
1050 CHECKGL(glUniform1iARB(textureObjectLocation, 0));
1051
1052 GLint viewProjMatLocation = m_sRGBTexture->GetUniformLocationARB("viewProjectionMatrix");
1053 Matrix4 modelViewProjMat = GetOpenGLModelViewProjectionMatrix();
1054 m_sRGBTexture->SetUniformLocMatrix4fv(viewProjMatLocation, 1, false, (GLfloat*) &(modelViewProjMat.m));
1055
1056 //Set our gamma uniform.
1057 m_sRGBTexture->SetUniform1f("gamma", gamma);
1058
1059 if (vertexLocation != -1)
1060 {
1061 CHECKGL(glEnableVertexAttribArrayARB(vertexLocation));
1062 CHECKGL(glVertexAttribPointerARB((GLuint)vertexLocation, 4, GL_FLOAT, GL_FALSE, 48, vertexBuffer));
1063 }
1064
1065 if (textureCoord0Location != -1)
1066 {
1067 CHECKGL(glEnableVertexAttribArrayARB(textureCoord0Location));
1068 CHECKGL(glVertexAttribPointerARB((GLuint)textureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, vertexBuffer + 4));
1069 }
1070
1071 CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
1072
1073 if (vertexLocation != -1)
1074 CHECKGL(glDisableVertexAttribArrayARB(vertexLocation));
1075
1076 if (textureCoord0Location != -1)
1077 CHECKGL(glDisableVertexAttribArrayARB(textureCoord0Location));
1078
1079 m_sRGBTexture->End();
1080 }
1081
976// Render the texture alpha into RGB and modulated by a color.1082// Render the texture alpha into RGB and modulated by a color.
977 void GraphicsEngine::QRP_GLSL_ColorModTexAlpha(int x, int y, int width, int height,1083 void GraphicsEngine::QRP_GLSL_ColorModTexAlpha(int x, int y, int width, int height,
978 ObjectPtr< IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &color)1084 ObjectPtr< IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &color)
9791085
=== modified file 'gputests/Makefile.am'
--- gputests/Makefile.am 2012-05-25 20:36:09 +0000
+++ gputests/Makefile.am 2012-09-24 06:59:20 +0000
@@ -7,7 +7,7 @@
7# This tells automake that we want to build binaries, but they shouldn't be7# This tells automake that we want to build binaries, but they shouldn't be
8# installed. For each individual test, add it's binary name here8# installed. For each individual test, add it's binary name here
99
10noinst_PROGRAMS = texture_power_of_2 framebufferobject quad_2texmod texture_copy_blur texture_blur texture_data10noinst_PROGRAMS = texture_power_of_2 gamma_correction framebufferobject quad_2texmod texture_copy_blur texture_blur texture_data
1111
12if !NUX_OPENGLES_2012if !NUX_OPENGLES_20
13noinst_PROGRAMS += arb_programs_limits13noinst_PROGRAMS += arb_programs_limits
@@ -19,7 +19,7 @@
19 -I$(srcdir) \19 -I$(srcdir) \
20 -I$(top_srcdir) \20 -I$(top_srcdir) \
21 -DPREFIX=\""$(prefix)"\" \21 -DPREFIX=\""$(prefix)"\" \
22 -DLIBDIR=\""$(libdir)"\" \22 -DLIBDIR=\""$(libdir)"\" \
23 -DDATADIR=\""$(datadir)"\" \23 -DDATADIR=\""$(datadir)"\" \
24 -DG_LOG_DOMAIN=\"NuxGpuTests\" \24 -DG_LOG_DOMAIN=\"NuxGpuTests\" \
25 $(GCC_FLAGS) \25 $(GCC_FLAGS) \
@@ -39,6 +39,8 @@
39# you need a $exe_SOURCES and $exe_LDADD so it builds39# you need a $exe_SOURCES and $exe_LDADD so it builds
40texture_power_of_2_SOURCES = texture_power_of_2.cpp40texture_power_of_2_SOURCES = texture_power_of_2.cpp
41texture_power_of_2_LDADD = $(ALL_LIBS)41texture_power_of_2_LDADD = $(ALL_LIBS)
42gamma_correction_SOURCES = gamma_correction.cpp
43gamma_correction_LDADD = $(ALL_LIBS)
42framebufferobject_SOURCES = framebufferobject.cpp44framebufferobject_SOURCES = framebufferobject.cpp
43framebufferobject_LDADD = $(ALL_LIBS)45framebufferobject_LDADD = $(ALL_LIBS)
44quad_2texmod_SOURCES = quad_2texmod.cpp46quad_2texmod_SOURCES = quad_2texmod.cpp
@@ -55,6 +57,7 @@
55# distribute source along to the documentation57# distribute source along to the documentation
56sourcegputestsdir = "$(pkgdatadir)/gputests"58sourcegputestsdir = "$(pkgdatadir)/gputests"
57sourcegputests_DATA = $(texture_power_of_2_SOURCES) \59sourcegputests_DATA = $(texture_power_of_2_SOURCES) \
60 $(gamma_correction_SOURCES) \
58 $(framebufferobject_SOURCES) \61 $(framebufferobject_SOURCES) \
59 $(quad_2texmod) \62 $(quad_2texmod) \
60 $(texture_copy_blur_SOURCES) \63 $(texture_copy_blur_SOURCES) \
6164
=== added file 'gputests/gamma_correction.cpp'
--- gputests/gamma_correction.cpp 1970-01-01 00:00:00 +0000
+++ gputests/gamma_correction.cpp 2012-09-24 06:59:20 +0000
@@ -0,0 +1,117 @@
1#include "NuxCore/NuxCore.h"
2#include "NuxGraphics/BitmapFormats.h"
3#include "NuxGraphics/GraphicsDisplay.h"
4#include "NuxGraphics/GLWindowManager.h"
5#include "NuxGraphics/GraphicsEngine.h"
6
7/*
8 * Tests:
9 * - loading texture from the hard drive
10 * - performing gamma correction
11 */
12
13void correct_gamma(float g)
14{
15 nux::GraphicsDisplay* m_GLWindow = gGLWindowManager.CreateGLWindow("Test gamma", 512, 512, nux::WINDOWSTYLE_NORMAL, 0, false);
16 nux::GraphicsEngine* m_GraphicsContext = m_GLWindow->GetGraphicsEngine();
17 m_GLWindow->ShowWindow();
18
19 const TCHAR* fname = TEXT("./data/img.png");
20 nux::ObjectPtr<nux::IOpenGLTexture2D> tex;
21 nux::NBitmapData *bitmap = nux::LoadImageFile(fname);
22 nux::ImageSurface surface = bitmap->GetSurface(0);
23 surface.GetFormat();
24
25 tex = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateTexture(
26 surface.GetWidth(),
27 surface.GetHeight(),
28 1,
29 surface.GetFormat());
30
31 nux::SURFACE_LOCKED_RECT lockrect;
32 tex->LockRect(0, &lockrect, 0);
33
34 BYTE *dest = (BYTE *) lockrect.pBits;
35 const BYTE *src = surface.GetPtrRawData();
36 int RowByteSize = surface.GetPitch();
37 int num_row = surface.GetBlockHeight();
38
39 for (int Y = 0; Y < num_row; Y++ )
40 {
41 // Take Min(RowByteSize, StrideY): the source and the destination may not have the same Pitch but
42 // they contain the same amount of valid data since they have the same width, height and format.
43 nux::Memcpy(dest + Y * lockrect.Pitch, &src[Y * RowByteSize], nux::Min (RowByteSize, lockrect.Pitch));
44 }
45
46 tex->UnlockRect(0);
47
48 int w, h;
49 m_GraphicsContext->GetWindowSize(w, h);
50 m_GraphicsContext->SetViewport(0, 0, w, h);
51 m_GraphicsContext->SetContext(0, 0, w, h);
52 m_GraphicsContext->Push2DWindow(w, h);
53
54 nux::Event event;
55 memset(&event, 0, sizeof(nux::Event));
56
57 do
58 {
59 CHECKGL(glClearColor(0, 0, 0, 1) );
60 CHECKGL(glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT));
61
62 m_GLWindow->GetSystemEvent(&event);
63
64 if(event.type == nux::NUX_SIZE_CONFIGURATION)
65 {
66 m_GraphicsContext->DisableAllTextureMode(0);
67 m_GraphicsContext->DisableAllTextureMode(1);
68 m_GraphicsContext->DisableAllTextureMode(2);
69 m_GraphicsContext->DisableAllTextureMode(3);
70 m_GraphicsContext->GetWindowSize(w, h);
71 m_GraphicsContext->SetViewport(0, 0, w, h);
72 m_GraphicsContext->SetScissor(0, 0, w, h);
73 m_GraphicsContext->SetContext(0, 0, w, h);
74 m_GraphicsContext->Push2DWindow(w, h);
75 }
76
77 int x=10;
78 int y=10;
79
80 m_GraphicsContext->SetTexture(GL_TEXTURE0, tex);
81
82 int width = tex->GetWidth();
83 int height = tex->GetHeight();
84
85 nux::TexCoordXForm texxform;
86 m_GraphicsContext->QRP_ASM_sRGB(x, y, width, height, tex, texxform, nux::color::White, g);
87
88 m_GLWindow->SwapBuffer();
89
90 } while(event.type != nux::NUX_TERMINATE_APP);
91
92 tex.Release();
93 delete m_GLWindow;
94}
95
96float g;
97int main(int argc, char **argv)
98{
99 if(argc > 1) {
100 char *endp; float val = strtof(argv[1], &endp);
101
102 if(!(endp == argv[1]))
103 g = val;
104 else
105 g = 1.0;
106 }
107 else
108 g = 1.0;
109
110 nux::NuxCoreInitialize(0);
111 nux::NuxGraphicsInitialize();
112
113 printf("NuxGraphics Input gamma: %2f Exponent 1/gamma: %2f\n", g, (float)1.0 / g);
114 correct_gamma(g);
115
116 return 0;
117}
0118
=== modified file 'gputests/quad_2texmod.cpp' (properties changed: +x to -x)

Subscribers

People subscribed via source and target branches