summaryrefslogtreecommitdiff
path: root/indra/newview/lldensityctrl.cpp
blob: 298a309e7cad9881e423efcb97437ce56fc69685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/**
* @file lldensityctrl.cpp
* @brief Control for specifying density over a height range for sky settings.
*
* $LicenseInfo:firstyear=2011&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2011, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
* $/LicenseInfo$
*/

#include "llviewerprecompiledheaders.h"

#include "lldensityctrl.h"

#include "llslider.h"
#include "llsliderctrl.h"
#include "llsettingssky.h"

static LLDefaultChildRegistry::Register<LLDensityCtrl> register_density_control("densityctrl");

const std::string LLDensityCtrl::DENSITY_RAYLEIGH("density_rayleigh");
const std::string LLDensityCtrl::DENSITY_MIE("density_mie");
const std::string LLDensityCtrl::DENSITY_ABSORPTION("density_absorption");

namespace
{   
    const std::string   FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL("level_exponential");
    const std::string   FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL_SCALE("exponential_scale");
    const std::string   FIELD_SKY_DENSITY_PROFILE_LINEAR("level_linear");
    const std::string   FIELD_SKY_DENSITY_PROFILE_CONSTANT("level_constant");
    const std::string   FIELD_SKY_DENSITY_MAX_ALTITUDE("max_altitude");
    const std::string   FIELD_SKY_DENSITY_ANISO_FACTOR("aniso_factor");
    const std::string   FIELD_SKY_DENSITY_ANISO_FACTOR_LABEL("aniso_factor_label");
}

const std::string& LLDensityCtrl::NameForDensityProfileType(DensityProfileType t)
{
    switch (t)
    {
        case Rayleigh:   return DENSITY_RAYLEIGH;
        case Mie:        return DENSITY_MIE;
        case Absorption: return DENSITY_ABSORPTION;
        default:
            break;
    }

    llassert(false);
    return DENSITY_RAYLEIGH;
}

LLDensityCtrl::Params::Params()
: image_density_feedback("image_density_feedback")
, lbl_exponential("label_exponential")
, lbl_exponential_scale("label_exponential_scale")
, lbl_linear("label_linear")
, lbl_constant("label_constant")
, lbl_max_altitude("label_max_altitude")
, lbl_aniso_factor("label_aniso_factor")
, profile_type(LLDensityCtrl::Rayleigh)
{
}

LLDensityCtrl::LLDensityCtrl(const Params& params)
: mProfileType(params.profile_type)
, mImgDensityFeedback(params.image_density_feedback)
{

}

LLSD LLDensityCtrl::getProfileConfig()
{
    LLSD config;
    switch (mProfileType)
    {
        case Rayleigh:   return mSkySettings->getRayleighConfigs();
        case Mie:        return mSkySettings->getMieConfigs();
        case Absorption: return mSkySettings->getAbsorptionConfigs();
        default:
            break;
    }
    llassert(false);
    return config;
}

BOOL LLDensityCtrl::postBuild()
{
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onExponentialChanged(); });
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL_SCALE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onExponentialScaleFactorChanged(); });
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_LINEAR)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onLinearChanged(); });
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_CONSTANT)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onConstantChanged(); });
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_MAX_ALTITUDE)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onMaxAltitudeChanged(); });
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_ANISO_FACTOR)->setCommitCallback([this](LLUICtrl *, const LLSD &) { onAnisoFactorChanged(); });

    if (mProfileType != Mie)
    {
        getChild<LLUICtrl>(FIELD_SKY_DENSITY_ANISO_FACTOR_LABEL)->setValue(false);
        getChild<LLUICtrl>(FIELD_SKY_DENSITY_ANISO_FACTOR)->setVisible(false);
    }

    return TRUE;
}

void LLDensityCtrl::setEnabled(BOOL enabled)
{
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL)->setEnabled(enabled);
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL_SCALE)->setEnabled(enabled);
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_LINEAR)->setEnabled(enabled);
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_PROFILE_CONSTANT)->setEnabled(enabled);
    getChild<LLUICtrl>(FIELD_SKY_DENSITY_MAX_ALTITUDE)->setEnabled(enabled);

    if (mProfileType == Mie)
    {
        getChild<LLUICtrl>(FIELD_SKY_DENSITY_ANISO_FACTOR)->setEnabled(enabled);
    }
}

void LLDensityCtrl::refresh()
{
    if (!mSkySettings)
    {
        setAllChildrenEnabled(FALSE);
        setEnabled(FALSE);
        return;
    }

    setEnabled(TRUE);
    setAllChildrenEnabled(TRUE);

    LLSD config = getProfileConfig();

    getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL)->setValue(config[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_TERM]);
    getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL_SCALE)->setValue(config[LLSettingsSky::SETTING_DENSITY_PROFILE_EXP_SCALE_FACTOR]);
    getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_LINEAR)->setValue(config[LLSettingsSky::SETTING_DENSITY_PROFILE_LINEAR_TERM]);
    getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_CONSTANT)->setValue(config[LLSettingsSky::SETTING_DENSITY_PROFILE_CONSTANT_TERM]);
    getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_MAX_ALTITUDE)->setValue(config[LLSettingsSky::SETTING_DENSITY_PROFILE_WIDTH]);

    if (mProfileType == Mie)
    {        
        getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_ANISO_FACTOR)->setValue(config[LLSettingsSky::SETTING_MIE_ANISOTROPY_FACTOR]);
    }
}

void LLDensityCtrl::updateProfile()
{
    F32 exponential_term  = getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL)->getValueF32();
    F32 exponential_scale = getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_EXPONENTIAL_SCALE)->getValueF32();
    F32 linear_term       = getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_LINEAR)->getValueF32();
    F32 constant_term     = getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_PROFILE_CONSTANT)->getValueF32();
    F32 max_alt           = getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_MAX_ALTITUDE)->getValueF32();
    F32 aniso_factor      = 0.0f;

    if (mProfileType == Mie)
    {
        aniso_factor = getChild<LLSliderCtrl>(FIELD_SKY_DENSITY_ANISO_FACTOR)->getValueF32();
    }

    LLSD profile = LLSettingsSky::createSingleLayerDensityProfile(max_alt, exponential_term, exponential_scale, linear_term, constant_term, aniso_factor);

    switch (mProfileType)
    {
        case Rayleigh: mSkySettings->setRayleighConfigs(profile); break;
        case Mie: mSkySettings->setMieConfigs(profile); break;
        case Absorption: mSkySettings->setAbsorptionConfigs(profile); break;
        default:
            break;
    }
}

void LLDensityCtrl::onExponentialChanged()
{
    updateProfile();
    updatePreview();
}

void LLDensityCtrl::onExponentialScaleFactorChanged()
{
    updateProfile();
    updatePreview();
}

void LLDensityCtrl::onLinearChanged()
{
    updateProfile();
    updatePreview();
}

void LLDensityCtrl::onConstantChanged()
{
    updateProfile();
    updatePreview();
}

void LLDensityCtrl::onMaxAltitudeChanged()
{
    updateProfile();
    updatePreview();
}

void LLDensityCtrl::onAnisoFactorChanged()
{
    updateProfile();
}

void LLDensityCtrl::updatePreview()
{
    // AdvancedAtmospherics TODO
    // Generate image according to current density profile
}