Compositor: Change uniform enum names to avoid name clashing on Windows

This commit is contained in:
Fernando García Liñán 2021-07-28 15:18:21 +02:00
parent db8b66203d
commit 7f4fb15636
3 changed files with 44 additions and 42 deletions

View File

@ -147,7 +147,8 @@ Compositor::Compositor(osg::View *view,
new osg::Uniform("fg_SunDirectionWorld", osg::Vec3f()), new osg::Uniform("fg_SunDirectionWorld", osg::Vec3f()),
} }
{ {
_uniforms[SUN_DIRECTION_WORLD]->setUpdateCallback(new SunDirectionWorldCallback); _uniforms[SG_UNIFORM_SUN_DIRECTION_WORLD]->setUpdateCallback(
new SunDirectionWorldCallback);
} }
Compositor::~Compositor() Compositor::~Compositor()
@ -179,58 +180,58 @@ Compositor::update(const osg::Matrix &view_matrix,
proj_matrix.getFrustum(left, right, bottom, top, zNear, zFar); proj_matrix.getFrustum(left, right, bottom, top, zNear, zFar);
osg::Matrixf prev_view_matrix, prev_view_matrix_inv; osg::Matrixf prev_view_matrix, prev_view_matrix_inv;
_uniforms[VIEW_MATRIX]->get(prev_view_matrix); _uniforms[SG_UNIFORM_VIEW_MATRIX]->get(prev_view_matrix);
_uniforms[VIEW_MATRIX_INV]->get(prev_view_matrix_inv); _uniforms[SG_UNIFORM_VIEW_MATRIX_INV]->get(prev_view_matrix_inv);
osg::Matrixf prev_proj_matrix, prev_proj_matrix_inv; osg::Matrixf prev_proj_matrix, prev_proj_matrix_inv;
_uniforms[PROJECTION_MATRIX]->get(prev_proj_matrix); _uniforms[SG_UNIFORM_PROJECTION_MATRIX]->get(prev_proj_matrix);
_uniforms[PROJECTION_MATRIX_INV]->get(prev_proj_matrix_inv); _uniforms[SG_UNIFORM_PROJECTION_MATRIX_INV]->get(prev_proj_matrix_inv);
_uniforms[PREV_VIEW_MATRIX]->set(prev_view_matrix); _uniforms[SG_UNIFORM_PREV_VIEW_MATRIX]->set(prev_view_matrix);
_uniforms[PREV_VIEW_MATRIX_INV]->set(prev_view_matrix_inv); _uniforms[SG_UNIFORM_PREV_VIEW_MATRIX_INV]->set(prev_view_matrix_inv);
_uniforms[PREV_PROJECTION_MATRIX]->set(prev_proj_matrix); _uniforms[SG_UNIFORM_PREV_PROJECTION_MATRIX]->set(prev_proj_matrix);
_uniforms[PREV_PROJECTION_MATRIX_INV]->set(prev_proj_matrix_inv); _uniforms[SG_UNIFORM_PREV_PROJECTION_MATRIX_INV]->set(prev_proj_matrix_inv);
osg::Vec3f sun_dir_world; osg::Vec3f sun_dir_world;
_uniforms[SUN_DIRECTION_WORLD]->get(sun_dir_world); _uniforms[SG_UNIFORM_SUN_DIRECTION_WORLD]->get(sun_dir_world);
osg::Vec4f sun_dir_view = osg::Vec4f( osg::Vec4f sun_dir_view = osg::Vec4f(
sun_dir_world.x(), sun_dir_world.y(), sun_dir_world.z(), 0.0f) * view_matrix; sun_dir_world.x(), sun_dir_world.y(), sun_dir_world.z(), 0.0f) * view_matrix;
for (int i = 0; i < TOTAL_BUILTIN_UNIFORMS; ++i) { for (int i = 0; i < SG_TOTAL_BUILTIN_UNIFORMS; ++i) {
osg::ref_ptr<osg::Uniform> u = _uniforms[i]; osg::ref_ptr<osg::Uniform> u = _uniforms[i];
switch (i) { switch (i) {
case VIEWPORT_SIZE: case SG_UNIFORM_VIEWPORT_SIZE:
u->set(osg::Vec2f(_viewport->width(), _viewport->height())); u->set(osg::Vec2f(_viewport->width(), _viewport->height()));
break; break;
case VIEW_MATRIX: case SG_UNIFORM_VIEW_MATRIX:
u->set(view_matrix); u->set(view_matrix);
break; break;
case VIEW_MATRIX_INV: case SG_UNIFORM_VIEW_MATRIX_INV:
u->set(view_inverse); u->set(view_inverse);
break; break;
case PROJECTION_MATRIX: case SG_UNIFORM_PROJECTION_MATRIX:
u->set(proj_matrix); u->set(proj_matrix);
break; break;
case PROJECTION_MATRIX_INV: case SG_UNIFORM_PROJECTION_MATRIX_INV:
u->set(osg::Matrix::inverse(proj_matrix)); u->set(osg::Matrix::inverse(proj_matrix));
break; break;
case CAMERA_POSITION_CART: case SG_UNIFORM_CAMERA_POSITION_CART:
u->set(osg::Vec3f(camera_pos.x(), camera_pos.y(), camera_pos.z())); u->set(osg::Vec3f(camera_pos.x(), camera_pos.y(), camera_pos.z()));
break; break;
case CAMERA_POSITION_GEOD: case SG_UNIFORM_CAMERA_POSITION_GEOD:
u->set(osg::Vec3f(camera_pos_geod.getLongitudeRad(), u->set(osg::Vec3f(camera_pos_geod.getLongitudeRad(),
camera_pos_geod.getLatitudeRad(), camera_pos_geod.getLatitudeRad(),
camera_pos_geod.getElevationM())); camera_pos_geod.getElevationM()));
break; break;
case NEAR_FAR: case SG_UNIFORM_NEAR_FAR:
u->set(osg::Vec2f(zNear, zFar)); u->set(osg::Vec2f(zNear, zFar));
break; break;
case PLANES: case SG_UNIFORM_PLANES:
u->set(osg::Vec3f(-zFar, -zFar * zNear, zFar - zNear)); u->set(osg::Vec3f(-zFar, -zFar * zNear, zFar - zNear));
break; break;
case SUN_DIRECTION: case SG_UNIFORM_SUN_DIRECTION:
u->set(osg::Vec3f(sun_dir_view.x(), sun_dir_view.y(), sun_dir_view.z())); u->set(osg::Vec3f(sun_dir_view.x(), sun_dir_view.y(), sun_dir_view.z()));
break; break;
case FCOEF: case SG_UNIFORM_FCOEF:
if (zFar != 0.0) if (zFar != 0.0)
u->set(2.0f / log2(float(zFar) + 1.0f)); u->set(2.0f / log2(float(zFar) + 1.0f));
break; break;

View File

@ -46,23 +46,23 @@ namespace compositor {
class Compositor { class Compositor {
public: public:
enum BuiltinUniform { enum BuiltinUniform {
VIEWPORT_SIZE = 0, SG_UNIFORM_VIEWPORT_SIZE = 0,
VIEW_MATRIX, SG_UNIFORM_VIEW_MATRIX,
VIEW_MATRIX_INV, SG_UNIFORM_VIEW_MATRIX_INV,
PROJECTION_MATRIX, SG_UNIFORM_PROJECTION_MATRIX,
PROJECTION_MATRIX_INV, SG_UNIFORM_PROJECTION_MATRIX_INV,
PREV_VIEW_MATRIX, SG_UNIFORM_PREV_VIEW_MATRIX,
PREV_VIEW_MATRIX_INV, SG_UNIFORM_PREV_VIEW_MATRIX_INV,
PREV_PROJECTION_MATRIX, SG_UNIFORM_PREV_PROJECTION_MATRIX,
PREV_PROJECTION_MATRIX_INV, SG_UNIFORM_PREV_PROJECTION_MATRIX_INV,
CAMERA_POSITION_CART, SG_UNIFORM_CAMERA_POSITION_CART,
CAMERA_POSITION_GEOD, SG_UNIFORM_CAMERA_POSITION_GEOD,
NEAR_FAR, SG_UNIFORM_NEAR_FAR,
PLANES, SG_UNIFORM_PLANES,
FCOEF, SG_UNIFORM_FCOEF,
SUN_DIRECTION, SG_UNIFORM_SUN_DIRECTION,
SUN_DIRECTION_WORLD, SG_UNIFORM_SUN_DIRECTION_WORLD,
TOTAL_BUILTIN_UNIFORMS SG_TOTAL_BUILTIN_UNIFORMS
}; };
Compositor(osg::View *view, Compositor(osg::View *view,
@ -112,7 +112,7 @@ public:
typedef std::array< typedef std::array<
osg::ref_ptr<osg::Uniform>, osg::ref_ptr<osg::Uniform>,
TOTAL_BUILTIN_UNIFORMS> BuiltinUniforms; SG_TOTAL_BUILTIN_UNIFORMS> BuiltinUniforms;
const BuiltinUniforms &getUniforms() const { return _uniforms; } const BuiltinUniforms &getUniforms() const { return _uniforms; }
void addBuffer(const std::string &name, Buffer *buffer); void addBuffer(const std::string &name, Buffer *buffer);

View File

@ -743,8 +743,9 @@ public:
osg::StateSet *ss = camera->getOrCreateStateSet(); osg::StateSet *ss = camera->getOrCreateStateSet();
auto &uniforms = compositor->getUniforms(); auto &uniforms = compositor->getUniforms();
ss->addUniform(uniforms[Compositor::FCOEF]); ss->addUniform(uniforms[Compositor::SG_UNIFORM_FCOEF]);
ss->addUniform(uniforms[Compositor::SUN_DIRECTION]); ss->addUniform(uniforms[Compositor::SG_UNIFORM_SUN_DIRECTION]);
ss->addUniform(uniforms[Compositor::SG_UNIFORM_SUN_DIRECTION_WORLD]);
osg::ref_ptr<osg::Uniform> clustered_shading_enabled = osg::ref_ptr<osg::Uniform> clustered_shading_enabled =
new osg::Uniform("fg_ClusteredEnabled", clustered ? true : false); new osg::Uniform("fg_ClusteredEnabled", clustered ? true : false);