Bug in Ogre GLSL preprocessor

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
atorkhov
Gnoblar
Posts: 24
Joined: Sat Sep 13, 2008 5:29 pm
Location: Moscow, Russia

Bug in Ogre GLSL preprocessor

Post by atorkhov » Wed Dec 31, 2008 10:17 am

Seems there is a bug in ogre GLSL preprocessor.

Consider the following code:

Code: Select all

#define DEF 1

#ifndef DEF
#define DEF 0
#endif
Preprocessor in ogre will have DEF=0.
I think, this happens as it runs contents of #if through parse cycle disabling output later, but this has side-effect of calling second #define and redefining DEF, giving wrong results.
To prevent this, HandleDefine could check either output enabled or not before adding new macro.
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19265
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 2
Contact:

Re: Bug in Ogre GLSL preprocessor

Post by sinbad » Sat Jan 03, 2009 7:16 pm

Ok, but this is a somewhat contrived example. Where would this occur in a real situation?
0 x

atorkhov
Gnoblar
Posts: 24
Joined: Sat Sep 13, 2008 5:29 pm
Location: Moscow, Russia

Re: Bug in Ogre GLSL preprocessor

Post by atorkhov » Sat Jan 03, 2009 7:49 pm

I wanted to provide simplest possible example, but here is situation I get into.

I want to write big shader that handles different cases like normal mapping on or off.
I'm defining fragment_programs with different preprocessor_defines without NORMAL_MAPPING or with NORMAL_MAPPING=1. I was setting "defaults" like

Code: Select all

#ifndef NORMAL_MAPPING
#define NORMAL_MAPPING 0
#endif
So, in this case NORMAL_MAPPING was always 0. And default could be 1, so it's not always possible to eliminate such code.

Also I want to make define that depends on it.

Code: Select all

#if NORMAL_MAPPING
#define ATTENUATION_I lightDir[i].w
#else
#define ATTENUATION_I attenuation[i]
#endif
Only second was always defined in such case.

I was expecting that such simple constructions would work as they should.
0 x

Post Reply