Coverage Report

Created: 2026-12-01 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreGpuProgramParams.cpp
Line
Count
Source
1
/*
2
  -----------------------------------------------------------------------------
3
  This source file is part of OGRE
4
  (Object-oriented Graphics Rendering Engine)
5
  For the latest info, see http://www.ogre3d.org
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
10
  of this software and associated documentation files (the "Software"), to deal
11
  in the Software without restriction, including without limitation the rights
12
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
  copies of the Software, and to permit persons to whom the Software is
14
  furnished to do so, subject to the following conditions:
15
16
  The above copyright notice and this permission notice shall be included in
17
  all copies or substantial portions of the Software.
18
19
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
  THE SOFTWARE.
26
  -----------------------------------------------------------------------------
27
*/
28
#include "OgreStableHeaders.h"
29
#include "OgreGpuProgramParams.h"
30
#include "OgreGpuProgramManager.h"
31
#include "OgreDualQuaternion.h"
32
33
namespace Ogre
34
{
35
    //---------------------------------------------------------------------
36
    GpuProgramParameters::AutoConstantDefinition GpuProgramParameters::AutoConstantDictionary[] = {
37
        AutoConstantDefinition(ACT_WORLD_MATRIX,                  "world_matrix",                16, ET_REAL, ACDT_NONE),
38
        AutoConstantDefinition(ACT_INVERSE_WORLD_MATRIX,          "inverse_world_matrix",        16, ET_REAL, ACDT_NONE),
39
        AutoConstantDefinition(ACT_TRANSPOSE_WORLD_MATRIX,             "transpose_world_matrix",            16, ET_REAL, ACDT_NONE),
40
        AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_WORLD_MATRIX, "inverse_transpose_world_matrix", 16, ET_REAL, ACDT_NONE),
41
42
        AutoConstantDefinition(ACT_BONE_MATRIX_ARRAY_3x4,        "bone_matrix_array_3x4",      12, ET_REAL, ACDT_NONE),
43
        AutoConstantDefinition(ACT_BONE_MATRIX_ARRAY,            "bone_matrix_array",          16, ET_REAL, ACDT_NONE),
44
        AutoConstantDefinition(ACT_BONE_DUALQUATERNION_ARRAY_2x4, "bone_dualquaternion_array_2x4",      8, ET_REAL, ACDT_NONE),
45
        AutoConstantDefinition(ACT_BONE_SCALE_SHEAR_MATRIX_ARRAY_3x4, "bone_scale_shear_matrix_array_3x4", 12, ET_REAL, ACDT_NONE),
46
        AutoConstantDefinition(ACT_VIEW_MATRIX,                   "view_matrix",                 16, ET_REAL, ACDT_NONE),
47
        AutoConstantDefinition(ACT_INVERSE_VIEW_MATRIX,           "inverse_view_matrix",         16, ET_REAL, ACDT_NONE),
48
        AutoConstantDefinition(ACT_TRANSPOSE_VIEW_MATRIX,              "transpose_view_matrix",             16, ET_REAL, ACDT_NONE),
49
        AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_VIEW_MATRIX,       "inverse_transpose_view_matrix",     16, ET_REAL, ACDT_NONE),
50
51
        AutoConstantDefinition(ACT_PROJECTION_MATRIX,             "projection_matrix",           16, ET_REAL, ACDT_NONE),
52
        AutoConstantDefinition(ACT_INVERSE_PROJECTION_MATRIX,          "inverse_projection_matrix",         16, ET_REAL, ACDT_NONE),
53
        AutoConstantDefinition(ACT_TRANSPOSE_PROJECTION_MATRIX,        "transpose_projection_matrix",       16, ET_REAL, ACDT_NONE),
54
        AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX, "inverse_transpose_projection_matrix", 16, ET_REAL, ACDT_NONE),
55
56
        AutoConstantDefinition(ACT_VIEWPROJ_MATRIX,               "viewproj_matrix",             16, ET_REAL, ACDT_NONE),
57
        AutoConstantDefinition(ACT_INVERSE_VIEWPROJ_MATRIX,       "inverse_viewproj_matrix",     16, ET_REAL, ACDT_NONE),
58
        AutoConstantDefinition(ACT_TRANSPOSE_VIEWPROJ_MATRIX,          "transpose_viewproj_matrix",         16, ET_REAL, ACDT_NONE),
59
        AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX,   "inverse_transpose_viewproj_matrix", 16, ET_REAL, ACDT_NONE),
60
61
        AutoConstantDefinition(ACT_WORLDVIEW_MATRIX,              "worldview_matrix",            16, ET_REAL, ACDT_NONE),
62
        AutoConstantDefinition(ACT_INVERSE_WORLDVIEW_MATRIX,      "inverse_worldview_matrix",    16, ET_REAL, ACDT_NONE),
63
        AutoConstantDefinition(ACT_TRANSPOSE_WORLDVIEW_MATRIX,         "transpose_worldview_matrix",        16, ET_REAL, ACDT_NONE),
64
        AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX, "inverse_transpose_worldview_matrix", 16, ET_REAL, ACDT_NONE),
65
        AutoConstantDefinition(ACT_NORMAL_MATRIX,                  "normal_matrix",     9, ET_REAL, ACDT_NONE),
66
67
        AutoConstantDefinition(ACT_WORLDVIEWPROJ_MATRIX,          "worldviewproj_matrix",        16, ET_REAL, ACDT_NONE),
68
        AutoConstantDefinition(ACT_INVERSE_WORLDVIEWPROJ_MATRIX,       "inverse_worldviewproj_matrix",      16, ET_REAL, ACDT_NONE),
69
        AutoConstantDefinition(ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX,     "transpose_worldviewproj_matrix",    16, ET_REAL, ACDT_NONE),
70
        AutoConstantDefinition(ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX, "inverse_transpose_worldviewproj_matrix", 16, ET_REAL, ACDT_NONE),
71
        AutoConstantDefinition(ACT_WORLDVIEWPROJ_MATRIX_ARRAY,          "worldviewproj_matrix_array",        16, ET_REAL, ACDT_INT),
72
73
        AutoConstantDefinition(ACT_RENDER_TARGET_FLIPPING,          "render_target_flipping",         1, ET_REAL, ACDT_NONE),
74
        AutoConstantDefinition(ACT_VERTEX_WINDING,          "vertex_winding",         1, ET_REAL, ACDT_NONE),
75
76
        AutoConstantDefinition(ACT_FOG_COLOUR,                    "fog_colour",                   4, ET_REAL, ACDT_NONE),
77
        AutoConstantDefinition(ACT_FOG_PARAMS,                    "fog_params",                   4, ET_REAL, ACDT_NONE),
78
79
        AutoConstantDefinition(ACT_SURFACE_AMBIENT_COLOUR,          "surface_ambient_colour",           4, ET_REAL, ACDT_NONE),
80
        AutoConstantDefinition(ACT_SURFACE_DIFFUSE_COLOUR,          "surface_diffuse_colour",           4, ET_REAL, ACDT_NONE),
81
        AutoConstantDefinition(ACT_SURFACE_SPECULAR_COLOUR,         "surface_specular_colour",          4, ET_REAL, ACDT_NONE),
82
        AutoConstantDefinition(ACT_SURFACE_EMISSIVE_COLOUR,         "surface_emissive_colour",          4, ET_REAL, ACDT_NONE),
83
        AutoConstantDefinition(ACT_SURFACE_SHININESS,               "surface_shininess",                1, ET_REAL, ACDT_NONE),
84
        AutoConstantDefinition(ACT_SURFACE_ALPHA_REJECTION_VALUE,   "surface_alpha_rejection_value",    1, ET_REAL, ACDT_NONE),
85
86
        AutoConstantDefinition(ACT_LIGHT_COUNT,                   "light_count",                  1, ET_REAL, ACDT_NONE),
87
88
        AutoConstantDefinition(ACT_AMBIENT_LIGHT_COLOUR,          "ambient_light_colour",         4, ET_REAL, ACDT_NONE),
89
        AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR,          "light_diffuse_colour",         4, ET_REAL, ACDT_INT),
90
        AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR,         "light_specular_colour",        4, ET_REAL, ACDT_INT),
91
        AutoConstantDefinition(ACT_LIGHT_ATTENUATION,             "light_attenuation",            4, ET_REAL, ACDT_INT),
92
        AutoConstantDefinition(ACT_SPOTLIGHT_PARAMS,              "spotlight_params",             4, ET_REAL, ACDT_INT),
93
        AutoConstantDefinition(ACT_LIGHT_POSITION,                "light_position",               4, ET_REAL, ACDT_INT),
94
        AutoConstantDefinition(ACT_LIGHT_POSITION_OBJECT_SPACE,   "light_position_object_space",  4, ET_REAL, ACDT_INT),
95
        AutoConstantDefinition(ACT_LIGHT_POSITION_VIEW_SPACE,          "light_position_view_space",    4, ET_REAL, ACDT_INT),
96
        AutoConstantDefinition(ACT_LIGHT_DIRECTION,               "light_direction",              4, ET_REAL, ACDT_INT),
97
        AutoConstantDefinition(ACT_LIGHT_DIRECTION_OBJECT_SPACE,  "light_direction_object_space", 4, ET_REAL, ACDT_INT),
98
        AutoConstantDefinition(ACT_LIGHT_DIRECTION_VIEW_SPACE,         "light_direction_view_space",   4, ET_REAL, ACDT_INT),
99
        AutoConstantDefinition(ACT_LIGHT_DISTANCE_OBJECT_SPACE,   "light_distance_object_space",  1, ET_REAL, ACDT_INT),
100
        AutoConstantDefinition(ACT_LIGHT_POWER_SCALE,                     "light_power",  1, ET_REAL, ACDT_INT),
101
        AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED, "light_diffuse_colour_power_scaled",         4, ET_REAL, ACDT_INT),
102
        AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED, "light_specular_colour_power_scaled",        4, ET_REAL, ACDT_INT),
103
        AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR_ARRAY,          "light_diffuse_colour_array",         4, ET_REAL, ACDT_INT),
104
        AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR_ARRAY,         "light_specular_colour_array",        4, ET_REAL, ACDT_INT),
105
        AutoConstantDefinition(ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY, "light_diffuse_colour_power_scaled_array",         4, ET_REAL, ACDT_INT),
106
        AutoConstantDefinition(ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY, "light_specular_colour_power_scaled_array",        4, ET_REAL, ACDT_INT),
107
        AutoConstantDefinition(ACT_LIGHT_ATTENUATION_ARRAY,             "light_attenuation_array",            4, ET_REAL, ACDT_INT),
108
        AutoConstantDefinition(ACT_LIGHT_POSITION_ARRAY,                "light_position_array",               4, ET_REAL, ACDT_INT),
109
        AutoConstantDefinition(ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY,   "light_position_object_space_array",  4, ET_REAL, ACDT_INT),
110
        AutoConstantDefinition(ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY,          "light_position_view_space_array",    4, ET_REAL, ACDT_INT),
111
        AutoConstantDefinition(ACT_LIGHT_DIRECTION_ARRAY,               "light_direction_array",              4, ET_REAL, ACDT_INT),
112
        AutoConstantDefinition(ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY,  "light_direction_object_space_array", 4, ET_REAL, ACDT_INT),
113
        AutoConstantDefinition(ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY,         "light_direction_view_space_array",   4, ET_REAL, ACDT_INT),
114
        AutoConstantDefinition(ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY,   "light_distance_object_space_array",  1, ET_REAL, ACDT_INT),
115
        AutoConstantDefinition(ACT_LIGHT_POWER_SCALE_ARRAY,               "light_power_array",  1, ET_REAL, ACDT_INT),
116
        AutoConstantDefinition(ACT_SPOTLIGHT_PARAMS_ARRAY,              "spotlight_params_array",             4, ET_REAL, ACDT_INT),
117
118
        AutoConstantDefinition(ACT_DERIVED_AMBIENT_LIGHT_COLOUR,    "derived_ambient_light_colour",     4, ET_REAL, ACDT_NONE),
119
        AutoConstantDefinition(ACT_DERIVED_SCENE_COLOUR,            "derived_scene_colour",             4, ET_REAL, ACDT_NONE),
120
        AutoConstantDefinition(ACT_DERIVED_LIGHT_DIFFUSE_COLOUR,    "derived_light_diffuse_colour",     4, ET_REAL, ACDT_INT),
121
        AutoConstantDefinition(ACT_DERIVED_LIGHT_SPECULAR_COLOUR,   "derived_light_specular_colour",    4, ET_REAL, ACDT_INT),
122
        AutoConstantDefinition(ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY,  "derived_light_diffuse_colour_array",   4, ET_REAL, ACDT_INT),
123
        AutoConstantDefinition(ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY, "derived_light_specular_colour_array",  4, ET_REAL, ACDT_INT),
124
125
        AutoConstantDefinition(ACT_LIGHT_NUMBER,                                          "light_number",  1, ET_REAL, ACDT_INT),
126
        AutoConstantDefinition(ACT_LIGHT_CASTS_SHADOWS,                           "light_casts_shadows",  1, ET_REAL, ACDT_INT),
127
        AutoConstantDefinition(ACT_LIGHT_CASTS_SHADOWS_ARRAY,     "light_casts_shadows_array",  1, ET_REAL, ACDT_INT),
128
129
        AutoConstantDefinition(ACT_SHADOW_EXTRUSION_DISTANCE,     "shadow_extrusion_distance",    1, ET_REAL, ACDT_INT),
130
        AutoConstantDefinition(ACT_CAMERA_POSITION,               "camera_position",              3, ET_REAL, ACDT_NONE),
131
        AutoConstantDefinition(ACT_CAMERA_POSITION_OBJECT_SPACE,  "camera_position_object_space", 3, ET_REAL, ACDT_NONE),
132
        AutoConstantDefinition(ACT_CAMERA_RELATIVE_POSITION,      "camera_relative_position",     3, ET_REAL, ACDT_NONE),
133
        AutoConstantDefinition(ACT_TEXTURE_VIEWPROJ_MATRIX,       "texture_viewproj_matrix",     16, ET_REAL, ACDT_INT),
134
        AutoConstantDefinition(ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY, "texture_viewproj_matrix_array", 16, ET_REAL, ACDT_INT),
135
        AutoConstantDefinition(ACT_TEXTURE_WORLDVIEWPROJ_MATRIX,  "texture_worldviewproj_matrix",16, ET_REAL, ACDT_INT),
136
        AutoConstantDefinition(ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY, "texture_worldviewproj_matrix_array",16, ET_REAL, ACDT_INT),
137
        AutoConstantDefinition(ACT_SPOTLIGHT_VIEWPROJ_MATRIX,       "spotlight_viewproj_matrix",     16, ET_REAL, ACDT_INT),
138
        AutoConstantDefinition(ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY, "spotlight_viewproj_matrix_array", 16, ET_REAL, ACDT_INT),
139
        AutoConstantDefinition(ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX,  "spotlight_worldviewproj_matrix",16, ET_REAL, ACDT_INT),
140
        AutoConstantDefinition(ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX_ARRAY,  "spotlight_worldviewproj_matrix_array",16, ET_REAL, ACDT_INT),
141
        AutoConstantDefinition(ACT_CUSTOM,                        "custom",                       4, ET_REAL, ACDT_INT),  // *** needs to be tested
142
        AutoConstantDefinition(ACT_TIME,                               "time",                               1, ET_REAL, ACDT_REAL),
143
        AutoConstantDefinition(ACT_TIME_0_X,                      "time_0_x",                     1, ET_REAL, ACDT_REAL),
144
        AutoConstantDefinition(ACT_COSTIME_0_X,                   "costime_0_x",                  1, ET_REAL, ACDT_REAL),
145
        AutoConstantDefinition(ACT_SINTIME_0_X,                   "sintime_0_x",                  1, ET_REAL, ACDT_REAL),
146
        AutoConstantDefinition(ACT_TANTIME_0_X,                   "tantime_0_x",                  1, ET_REAL, ACDT_REAL),
147
        AutoConstantDefinition(ACT_TIME_0_X_PACKED,               "time_0_x_packed",              4, ET_REAL, ACDT_REAL),
148
        AutoConstantDefinition(ACT_TIME_0_1,                      "time_0_1",                     1, ET_REAL, ACDT_REAL),
149
        AutoConstantDefinition(ACT_COSTIME_0_1,                   "costime_0_1",                  1, ET_REAL, ACDT_REAL),
150
        AutoConstantDefinition(ACT_SINTIME_0_1,                   "sintime_0_1",                  1, ET_REAL, ACDT_REAL),
151
        AutoConstantDefinition(ACT_TANTIME_0_1,                   "tantime_0_1",                  1, ET_REAL, ACDT_REAL),
152
        AutoConstantDefinition(ACT_TIME_0_1_PACKED,               "time_0_1_packed",              4, ET_REAL, ACDT_REAL),
153
        AutoConstantDefinition(ACT_TIME_0_2PI,                    "time_0_2pi",                   1, ET_REAL, ACDT_REAL),
154
        AutoConstantDefinition(ACT_COSTIME_0_2PI,                 "costime_0_2pi",                1, ET_REAL, ACDT_REAL),
155
        AutoConstantDefinition(ACT_SINTIME_0_2PI,                 "sintime_0_2pi",                1, ET_REAL, ACDT_REAL),
156
        AutoConstantDefinition(ACT_TANTIME_0_2PI,                 "tantime_0_2pi",                1, ET_REAL, ACDT_REAL),
157
        AutoConstantDefinition(ACT_TIME_0_2PI_PACKED,             "time_0_2pi_packed",            4, ET_REAL, ACDT_REAL),
158
        AutoConstantDefinition(ACT_FRAME_TIME,                    "frame_time",                   1, ET_REAL, ACDT_REAL),
159
        AutoConstantDefinition(ACT_FPS,                           "fps",                          1, ET_REAL, ACDT_NONE),
160
        AutoConstantDefinition(ACT_VIEWPORT_WIDTH,                "viewport_width",               1, ET_REAL, ACDT_NONE),
161
        AutoConstantDefinition(ACT_VIEWPORT_HEIGHT,               "viewport_height",              1, ET_REAL, ACDT_NONE),
162
        AutoConstantDefinition(ACT_INVERSE_VIEWPORT_WIDTH,        "inverse_viewport_width",       1, ET_REAL, ACDT_NONE),
163
        AutoConstantDefinition(ACT_INVERSE_VIEWPORT_HEIGHT,       "inverse_viewport_height",      1, ET_REAL, ACDT_NONE),
164
        AutoConstantDefinition(ACT_VIEWPORT_SIZE,                 "viewport_size",                4, ET_REAL, ACDT_NONE),
165
        AutoConstantDefinition(ACT_VIEW_DIRECTION,                "view_direction",               3, ET_REAL, ACDT_NONE),
166
        AutoConstantDefinition(ACT_VIEW_SIDE_VECTOR,              "view_side_vector",             3, ET_REAL, ACDT_NONE),
167
        AutoConstantDefinition(ACT_VIEW_UP_VECTOR,                "view_up_vector",               3, ET_REAL, ACDT_NONE),
168
        AutoConstantDefinition(ACT_FOV,                           "fov",                          1, ET_REAL, ACDT_NONE),
169
        AutoConstantDefinition(ACT_NEAR_CLIP_DISTANCE,            "near_clip_distance",           1, ET_REAL, ACDT_NONE),
170
        AutoConstantDefinition(ACT_FAR_CLIP_DISTANCE,             "far_clip_distance",            1, ET_REAL, ACDT_NONE),
171
        AutoConstantDefinition(ACT_PASS_NUMBER,                        "pass_number",                        1, ET_REAL, ACDT_NONE),
172
        AutoConstantDefinition(ACT_PASS_ITERATION_NUMBER,              "pass_iteration_number",              1, ET_REAL, ACDT_NONE),
173
        AutoConstantDefinition(ACT_ANIMATION_PARAMETRIC,               "animation_parametric",               4, ET_REAL, ACDT_INT),
174
        AutoConstantDefinition(ACT_TEXEL_OFFSETS,               "texel_offsets",                                  4, ET_REAL, ACDT_NONE),
175
        AutoConstantDefinition(ACT_SCENE_DEPTH_RANGE,           "scene_depth_range",                      4, ET_REAL, ACDT_NONE),
176
        AutoConstantDefinition(ACT_SHADOW_SCENE_DEPTH_RANGE,    "shadow_scene_depth_range",               4, ET_REAL, ACDT_INT),
177
        AutoConstantDefinition(ACT_SHADOW_SCENE_DEPTH_RANGE_ARRAY,    "shadow_scene_depth_range_array",           4, ET_REAL, ACDT_INT),
178
        AutoConstantDefinition(ACT_SHADOW_COLOUR,                               "shadow_colour",                                  4, ET_REAL, ACDT_NONE),
179
        AutoConstantDefinition(ACT_TEXTURE_SIZE,                "texture_size",                   4, ET_REAL, ACDT_INT),
180
        AutoConstantDefinition(ACT_INVERSE_TEXTURE_SIZE,        "inverse_texture_size",           4, ET_REAL, ACDT_INT),
181
        AutoConstantDefinition(ACT_PACKED_TEXTURE_SIZE,         "packed_texture_size",            4, ET_REAL, ACDT_INT),
182
        AutoConstantDefinition(ACT_TEXTURE_MATRIX,  "texture_matrix", 16, ET_REAL, ACDT_INT),
183
        AutoConstantDefinition(ACT_LOD_CAMERA_POSITION,               "lod_camera_position",              3, ET_REAL, ACDT_NONE),
184
        AutoConstantDefinition(ACT_LOD_CAMERA_POSITION_OBJECT_SPACE,  "lod_camera_position_object_space", 3, ET_REAL, ACDT_NONE),
185
        AutoConstantDefinition(ACT_LIGHT_CUSTOM,        "light_custom", 4, ET_REAL, ACDT_INT),
186
        AutoConstantDefinition(ACT_POINT_PARAMS,                    "point_params",                   4, ET_REAL, ACDT_NONE),
187
        AutoConstantDefinition(ACT_MATERIAL_LOD_INDEX,       "material_lod_index",             1, ET_INT, ACDT_NONE),
188
        AutoConstantDefinition(ACT_FROXEL_TILE_PARAMS,   "froxel_tile_params",   4, ET_REAL, ACDT_NONE),
189
        AutoConstantDefinition(ACT_FROXEL_DEPTH_PARAMS, "froxel_depth_params", 4, ET_REAL, ACDT_NONE),
190
        AutoConstantDefinition(ACT_FROXEL_GRID, "froxel_grid", 4096, ET_INT, ACDT_NONE),
191
        AutoConstantDefinition(ACT_FROXEL_RECORDS, "froxel_records", 4096, ET_INT, ACDT_NONE),
192
193
        // NOTE: new auto constants must be added before this line, as the following are merely aliases
194
        // to allow legacy world_ names in scripts
195
        AutoConstantDefinition(ACT_BONE_MATRIX_ARRAY_3x4,        "world_matrix_array_3x4",      12, ET_REAL, ACDT_NONE),
196
        AutoConstantDefinition(ACT_BONE_MATRIX_ARRAY,            "world_matrix_array",          16, ET_REAL, ACDT_NONE),
197
        AutoConstantDefinition(ACT_BONE_DUALQUATERNION_ARRAY_2x4, "world_dualquaternion_array_2x4",      8, ET_REAL, ACDT_NONE),
198
        AutoConstantDefinition(ACT_BONE_SCALE_SHEAR_MATRIX_ARRAY_3x4, "world_scale_shear_matrix_array_3x4", 12, ET_REAL, ACDT_NONE),
199
    };
200
201
0
    GpuNamedConstants::GpuNamedConstants() : bufferSize(0), registerCount(0) {}
202
0
    GpuNamedConstants::~GpuNamedConstants() {}
203
204
0
    GpuLogicalBufferStruct::GpuLogicalBufferStruct() : bufferSize(0) {}
205
0
    GpuLogicalBufferStruct::~GpuLogicalBufferStruct() {}
206
207
    //---------------------------------------------------------------------
208
    //  GpuNamedConstants methods
209
    //---------------------------------------------------------------------
210
    void GpuNamedConstants::save(const String& filename) const
211
0
    {
212
0
        GpuNamedConstantsSerializer ser;
213
0
        ser.exportNamedConstants(this, filename);
214
0
    }
215
    //---------------------------------------------------------------------
216
    void GpuNamedConstants::load(DataStreamPtr& stream)
217
0
    {
218
0
        GpuNamedConstantsSerializer ser;
219
0
        ser.importNamedConstants(stream, this);
220
0
    }
221
    //-----------------------------------------------------------------------------
222
    size_t GpuNamedConstants::calculateSize(void) const
223
0
    {
224
0
        size_t memSize = sizeof(*this);
225
        // Tally up constant defs
226
0
        memSize += sizeof(GpuConstantDefinition) * map.size();
227
228
0
        return memSize;
229
0
    }
230
    //---------------------------------------------------------------------
231
    //  GpuNamedConstantsSerializer methods
232
    //---------------------------------------------------------------------
233
    GpuNamedConstantsSerializer::GpuNamedConstantsSerializer()
234
0
    {
235
0
        mVersion = "[v1.0]";
236
0
    }
237
    //---------------------------------------------------------------------
238
    GpuNamedConstantsSerializer::~GpuNamedConstantsSerializer()
239
0
    {
240
241
0
    }
242
    //---------------------------------------------------------------------
243
    void GpuNamedConstantsSerializer::exportNamedConstants(
244
        const GpuNamedConstants* pConsts, const String& filename, Endian endianMode)
245
0
    {
246
0
        DataStreamPtr stream = _openFileStream(filename, std::ios::binary | std::ios::out);
247
0
        exportNamedConstants(pConsts, stream, endianMode);
248
249
0
        stream->close();
250
0
    }
251
    //---------------------------------------------------------------------
252
    void GpuNamedConstantsSerializer::exportNamedConstants(
253
        const GpuNamedConstants* pConsts, DataStreamPtr stream, Endian endianMode)
254
0
    {
255
        // Decide on endian mode
256
0
        determineEndianness(endianMode);
257
258
0
        mStream =stream;
259
0
        if (!stream->isWriteable())
260
0
        {
261
0
            OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE,
262
0
                        "Unable to write to stream " + stream->getName(),
263
0
                        "GpuNamedConstantsSerializer::exportNamedConstants");
264
0
        }
265
266
0
        writeFileHeader();
267
268
0
        writeInts(((const uint32*)&pConsts->bufferSize), 1);
269
0
        writeInts(((const uint32*)&pConsts->bufferSize), 1);
270
0
        writeInts(((const uint32*)&pConsts->bufferSize), 1);
271
272
        // simple export of all the named constants, no chunks
273
        // name, physical index
274
0
        for (const auto& i : pConsts->map)
275
0
        {
276
0
            const String& name = i.first;
277
0
            const GpuConstantDefinition& def = i.second;
278
279
0
            writeString(name);
280
0
            writeInts(((const uint32*)&def.physicalIndex), 1);
281
0
            writeInts(((const uint32*)&def.logicalIndex), 1);
282
0
            uint32 constType = static_cast<uint32>(def.constType);
283
0
            writeInts(&constType, 1);
284
0
            writeInts(((const uint32*)&def.elementSize), 1);
285
0
            writeInts(((const uint32*)&def.arraySize), 1);
286
0
        }
287
288
0
    }
289
    //---------------------------------------------------------------------
290
    void GpuNamedConstantsSerializer::importNamedConstants(
291
        DataStreamPtr& stream, GpuNamedConstants* pDest)
292
0
    {
293
        // Determine endianness (must be the first thing we do!)
294
0
        determineEndianness(stream);
295
296
        // Check header
297
0
        readFileHeader(stream);
298
299
        // simple file structure, no chunks
300
0
        pDest->map.clear();
301
302
0
        readInts(stream, ((uint32*)&pDest->bufferSize), 1);
303
0
        readInts(stream, ((uint32*)&pDest->bufferSize), 1);
304
0
        readInts(stream, ((uint32*)&pDest->bufferSize), 1);
305
306
0
        while (!stream->eof())
307
0
        {
308
0
            GpuConstantDefinition def;
309
0
            String name = readString(stream);
310
            // Hmm, deal with trailing information
311
0
            if (name.empty())
312
0
                continue;
313
0
            readInts(stream, ((uint32*)&def.physicalIndex), 1);
314
0
            readInts(stream, ((uint32*)&def.logicalIndex), 1);
315
0
            uint constType;
316
0
            readInts(stream, &constType, 1);
317
0
            def.constType = static_cast<GpuConstantType>(constType);
318
0
            readInts(stream, ((uint32*)&def.elementSize), 1);
319
0
            readInts(stream, ((uint32*)&def.arraySize), 1);
320
321
0
            pDest->map[name] = def;
322
0
        }
323
0
    }
324
325
    //-----------------------------------------------------------------------------
326
    //      GpuSharedParameters Methods
327
    //-----------------------------------------------------------------------------
328
    GpuSharedParameters::GpuSharedParameters(const String& name)
329
0
        : mName(name), mVersion(0), mOffset(0), mDirty(false), mUseLinearColours(false)
330
0
    {
331
0
    }
332
    //-----------------------------------------------------------------------------
333
    size_t GpuSharedParameters::calculateSize(void) const
334
0
    {
335
0
        size_t memSize = sizeof(*this);
336
337
0
        memSize += mConstants.size();
338
0
        memSize += mName.size() * sizeof(char);
339
340
0
        return memSize;
341
0
    }
342
    //---------------------------------------------------------------------
343
    void GpuSharedParameters::addConstantDefinition(const String& name, GpuConstantType constType, uint32 arraySize)
344
0
    {
345
0
        if (mNamedConstants.map.find(name) != mNamedConstants.map.end())
346
0
        {
347
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
348
0
                        "Constant entry with name '" + name + "' already exists. ",
349
0
                        "GpuSharedParameters::addConstantDefinition");
350
0
        }
351
0
        GpuConstantDefinition def;
352
0
        def.arraySize = arraySize;
353
0
        def.constType = constType;
354
355
    // here, we do not consider padding, but rather alignment
356
0
        def.elementSize = GpuConstantDefinition::getElementSize(constType, false);
357
358
    // we try to adhere to GLSL std140 packing rules
359
    // handle alignment requirements
360
0
        size_t align_size = std::min<size_t>(def.elementSize == 3 ? 4 : def.elementSize, 4); // vec3 is 16 byte aligned, which is max
361
0
        align_size *= 4; // bytes
362
363
0
        size_t nextAlignedOffset = ((mOffset + align_size - 1) / align_size) * align_size;
364
365
        // abuse logical index to store offset
366
0
        if (mOffset + align_size > nextAlignedOffset)
367
0
        {
368
0
            def.logicalIndex = nextAlignedOffset;
369
0
        }
370
0
        else
371
0
        {
372
0
            def.logicalIndex = mOffset;
373
0
        }
374
375
0
        mOffset = def.logicalIndex + (def.constType == GCT_MATRIX_4X3 ? 16 : def.elementSize) * 4; // mat4x3 have a size of 64 bytes
376
377
0
        def.variability = (uint16)GPV_GLOBAL;
378
379
0
        if (def.isFloat())
380
0
        {
381
0
            def.physicalIndex = mConstants.size();
382
0
            mConstants.resize(mConstants.size() + def.arraySize * def.elementSize*4);
383
0
        }
384
0
        else if (def.isDouble())
385
0
        {
386
0
            def.physicalIndex = mConstants.size();
387
0
            mConstants.resize(mConstants.size() + def.arraySize * def.elementSize*8);
388
0
        }
389
0
        else if (def.isInt() || def.isUnsignedInt() || def.isBool())
390
0
        {
391
0
            def.physicalIndex = mConstants.size();
392
0
            mConstants.resize(mConstants.size() + def.arraySize * def.elementSize*4);
393
0
        }
394
0
        else 
395
0
        {
396
            //FIXME Is this the right exception type?
397
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
398
0
                        "Constant entry with name '" + name + "' is not a known type.",
399
0
                        "GpuSharedParameters::addConstantDefinition");
400
0
        }
401
402
0
        mNamedConstants.map[name] = def;
403
404
0
        ++mVersion;
405
0
    }
406
    void GpuSharedParameters::setAutoConstant(const String& name, GpuProgramParameters::AutoConstantType acType)
407
0
    {
408
0
        auto& def = mNamedConstants.map[name];
409
0
        mAutoConstants.push_back({def.physicalIndex, acType, def.arraySize, def.elementSize});
410
        // no version increment, as this is not a change to the buffer layout
411
0
    }
412
    void GpuSharedParameters::_updateAutoParam(AutoConstantEntry& entry, const char* data, uint32 size)
413
0
    {
414
0
        auto hash = FastHash(data, size);
415
0
        if (hash != entry.hash)
416
0
        {
417
0
            if(mUseLinearColours && entry.acType == GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY)
418
0
            {
419
0
                auto colours = reinterpret_cast<const ColourValue*>(data);
420
0
                for (size_t i = 0; i < entry.arraySize; ++i)
421
0
                {
422
0
                    memcpy(&mConstants[entry.physicalIndex + i * sizeof(ColourValue)], colours[i].gammaToLinear().ptr(),
423
0
                           sizeof(ColourValue));
424
0
                }
425
0
            }
426
0
            else
427
0
            {
428
0
                memcpy(&mConstants[entry.physicalIndex], data, size);
429
0
            }
430
0
            entry.hash = hash;
431
0
            _markDirty();
432
0
        }
433
0
    }
434
    void GpuSharedParameters::_updateAutoParams(const AutoParamDataSource* source)
435
0
    {
436
0
        for(auto& ac : mAutoConstants)
437
0
        {
438
0
            const char* data = nullptr;
439
0
            uint32 size = 0;
440
0
            switch (ac.acType)
441
0
            {
442
0
            case GpuProgramParameters::ACT_FROXEL_GRID:
443
0
            {
444
0
                const auto& froxelGrid = source->getFroxelGrid();
445
0
                size = std::min(froxelGrid.size(), ac.arraySize * ac.elementCount) * sizeof(uint32);
446
0
                data = (const char*)froxelGrid.data();
447
0
            }
448
0
            break;
449
0
            case GpuProgramParameters::ACT_FROXEL_RECORDS:
450
0
            {
451
0
                const auto& froxelRecords = source->getFroxelRecords();
452
0
                size = std::min(froxelRecords.size(), ac.arraySize * ac.elementCount) * sizeof(uint32);
453
0
                data = (const char*)froxelRecords.data();
454
0
            }
455
0
            break;
456
0
            case GpuProgramParameters::ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY:
457
0
                data = (const char*)source->getLightPositionViewSpaceArray(ac.arraySize);
458
0
                size = ac.arraySize * ac.elementCount * sizeof(float);
459
0
                break;
460
0
            case GpuProgramParameters::ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY:
461
0
                data = (const char*)source->getLightDirectionViewSpaceArray(ac.arraySize);
462
0
                size = ac.arraySize * ac.elementCount * sizeof(float);
463
0
                break;
464
0
            case GpuProgramParameters::ACT_LIGHT_ATTENUATION_ARRAY:
465
0
                data = (const char*)source->getLightAttenuationArray(ac.arraySize);
466
0
                size = ac.arraySize * ac.elementCount * sizeof(float);
467
0
                break;
468
0
            case GpuProgramParameters::ACT_SPOTLIGHT_PARAMS_ARRAY:
469
0
                data = (const char*)source->getSpotlightParamsArray(ac.arraySize);
470
0
                size = ac.arraySize * ac.elementCount * sizeof(float);
471
0
                break;
472
0
            case GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY:
473
0
                data = (const char*)source->getLightDiffuseColourPowerScaledArray(ac.arraySize);
474
0
                size = ac.arraySize * ac.elementCount * sizeof(float);
475
0
                break;
476
0
            default:
477
0
                continue;
478
0
                break;
479
0
            }
480
481
0
            _updateAutoParam(ac, data, size);
482
0
        }
483
0
    }
484
    //---------------------------------------------------------------------
485
    void GpuSharedParameters::removeConstantDefinition(const String& name)
486
0
    {
487
0
        GpuConstantDefinitionMap::iterator i = mNamedConstants.map.find(name);
488
0
        if (i != mNamedConstants.map.end())
489
0
        {
490
0
            GpuConstantDefinition& def = i->second;
491
0
            size_t numElems = def.elementSize * def.arraySize;
492
493
0
            for (auto& j : mNamedConstants.map)
494
0
            {
495
0
                GpuConstantDefinition& otherDef = j.second;
496
                // comes after in the buffer
497
0
                if (otherDef.physicalIndex > def.physicalIndex)
498
0
                {
499
                    // adjust index
500
0
                    otherDef.logicalIndex -= numElems;
501
0
                    otherDef.physicalIndex -= numElems;
502
0
                }
503
0
            }
504
505
            // remove and reduce buffer
506
0
            if (def.isFloat() || def.isInt() || def.isUnsignedInt() || def.isBool())
507
0
            {
508
0
                mNamedConstants.bufferSize -= numElems;
509
510
0
                ConstantList::iterator beg = mConstants.begin();
511
0
                std::advance(beg, def.physicalIndex);
512
0
                ConstantList::iterator en = beg;
513
0
                std::advance(en, numElems*4);
514
0
                mConstants.erase(beg, en);
515
0
            }
516
0
            else {
517
                //TODO exception handling
518
0
            }
519
520
0
            ++mVersion;
521
0
        }
522
523
0
    }
524
525
    void GpuSharedParameters::_upload() const
526
0
    {
527
0
        OgreAssert(mHardwareBuffer, "not backed by a HardwareBuffer");
528
529
0
        if (!mDirty)
530
0
            return;
531
532
0
        mHardwareBuffer->writeData(0, mConstants.size(), mConstants.data());
533
0
    }
534
    void GpuSharedParameters::download()
535
0
    {
536
0
        OgreAssert(mHardwareBuffer, "not backed by a HardwareBuffer");
537
0
        mHardwareBuffer->readData(0, mConstants.size(), mConstants.data());
538
0
    }
539
    //---------------------------------------------------------------------
540
    void GpuSharedParameters::removeAllConstantDefinitions()
541
0
    {
542
0
    mOffset = 0;
543
0
        mNamedConstants.map.clear();
544
0
        mNamedConstants.bufferSize = 0;
545
0
        mConstants.clear();
546
0
        mAutoConstants.clear();
547
0
    }
548
    //---------------------------------------------------------------------
549
    GpuConstantDefinitionIterator GpuSharedParameters::getConstantDefinitionIterator(void) const
550
0
    {
551
0
        return GpuConstantDefinitionIterator(mNamedConstants.map.begin(), mNamedConstants.map.end());
552
0
    }
553
    //---------------------------------------------------------------------
554
    const GpuConstantDefinition& GpuSharedParameters::getConstantDefinition(const String& name) const
555
0
    {
556
0
        GpuConstantDefinitionMap::const_iterator i = mNamedConstants.map.find(name);
557
0
        if (i == mNamedConstants.map.end())
558
0
        {
559
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
560
0
                        "Constant entry with name '" + name + "' does not exist. ",
561
0
                        "GpuSharedParameters::getConstantDefinition");
562
0
        }
563
0
        return i->second;
564
0
    }
565
    //---------------------------------------------------------------------
566
    const GpuNamedConstants& GpuSharedParameters::getConstantDefinitions() const
567
0
    {
568
0
        return mNamedConstants;
569
0
    }
570
    std::vector<std::pair<String, GpuConstantDefinition>> GpuSharedParameters::getConstantDefinitionsSorted() const
571
0
    {
572
0
        std::vector<std::pair<String, GpuConstantDefinition>> ordered(mNamedConstants.map.begin(),
573
0
                                                                      mNamedConstants.map.end());
574
0
        std::sort(ordered.begin(), ordered.end(),
575
0
                  [](const auto& a, const auto& b) { return a.second.physicalIndex < b.second.physicalIndex; });
576
577
0
        return ordered;
578
0
    }
579
    //---------------------------------------------------------------------
580
    void GpuSharedParameters::setNamedConstant(const String& name, const Matrix4& m)
581
0
    {
582
0
        _setNamedConstant(name, m[0], 16);
583
0
    }
584
    //---------------------------------------------------------------------
585
    void GpuSharedParameters::setNamedConstant(const String& name, const Matrix4* m, uint32 numEntries)
586
0
    {
587
0
        _setNamedConstant(name, m[0][0], 16 * numEntries);
588
0
    }
589
    //---------------------------------------------------------------------
590
    void GpuSharedParameters::setNamedConstant(const String& name, const ColourValue& colour)
591
0
    {
592
0
        _setNamedConstant(name, mUseLinearColours ? colour.gammaToLinear().ptr() : colour.ptr(), 4);
593
0
    }
594
    //---------------------------------------------------------------------
595
    template <typename T> void GpuSharedParameters::_setNamedConstant(const String& name, const T* val, uint32 count)
596
0
    {
597
0
        GpuConstantDefinitionMap::const_iterator i = mNamedConstants.map.find(name);
598
0
        if (i == mNamedConstants.map.end())
599
0
            return; // ignore
600
601
0
        const GpuConstantDefinition& def = i->second;
602
0
        memcpy(&mConstants[def.physicalIndex], val, sizeof(float) * std::min(count, def.elementSize * def.arraySize));
603
0
        _markDirty();
604
0
    }
Unexecuted instantiation: void Ogre::GpuSharedParameters::_setNamedConstant<float>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, float const*, unsigned int)
Unexecuted instantiation: void Ogre::GpuSharedParameters::_setNamedConstant<double>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double const*, unsigned int)
Unexecuted instantiation: void Ogre::GpuSharedParameters::_setNamedConstant<int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int const*, unsigned int)
Unexecuted instantiation: void Ogre::GpuSharedParameters::_setNamedConstant<unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int const*, unsigned int)
605
    void GpuSharedParameters::setNamedConstant(const String& name, const float* val, uint32 count)
606
0
    {
607
0
        _setNamedConstant(name, val, count);
608
0
    }
609
    //---------------------------------------------------------------------
610
    void GpuSharedParameters::setNamedConstant(const String& name, const double* val, uint32 count)
611
0
    {
612
0
        _setNamedConstant(name, val, count);
613
0
    }
614
    //---------------------------------------------------------------------
615
    void GpuSharedParameters::setNamedConstant(const String& name, const int* val, uint32 count)
616
0
    {
617
0
        _setNamedConstant(name, val, count);
618
0
    }
619
    //---------------------------------------------------------------------
620
    void GpuSharedParameters::setNamedConstant(const String& name, const uint* val, uint32 count)
621
0
    {
622
0
        _setNamedConstant(name, val, count);
623
0
    }
624
    //---------------------------------------------------------------------
625
    void GpuSharedParameters::_markClean()
626
0
    {
627
0
        mDirty = false;
628
0
    }
629
    //---------------------------------------------------------------------
630
    void GpuSharedParameters::_markDirty()
631
0
    {
632
0
        mDirty = true;
633
0
    }
634
    
635
636
    //-----------------------------------------------------------------------------
637
    //      GpuSharedParametersUsage Methods
638
    //-----------------------------------------------------------------------------
639
    GpuSharedParametersUsage::GpuSharedParametersUsage(GpuSharedParametersPtr sharedParams,
640
                                                       GpuProgramParameters* params)
641
0
        : mSharedParams(sharedParams)
642
0
        , mParams(params)
643
0
    {
644
0
        initCopyData();
645
0
    }
646
    //---------------------------------------------------------------------
647
    void GpuSharedParametersUsage::initCopyData()
648
0
    {
649
650
0
        mCopyDataList.clear();
651
652
0
        const GpuConstantDefinitionMap& sharedmap = mSharedParams->getConstantDefinitions().map;
653
0
        for (const auto& i : sharedmap)
654
0
        {
655
0
            const String& pName = i.first;
656
0
            const GpuConstantDefinition& shareddef = i.second;
657
658
0
            const GpuConstantDefinition* instdef = mParams->_findNamedConstantDefinition(pName, false);
659
0
            if (instdef)
660
0
            {
661
                // Check that the definitions are the same
662
0
                if (instdef->constType == shareddef.constType &&
663
0
                    instdef->arraySize <= shareddef.arraySize)
664
0
                {
665
0
                    CopyDataEntry e;
666
0
                    e.srcDefinition = &shareddef;
667
0
                    e.dstDefinition = instdef;
668
0
                    mCopyDataList.push_back(e);
669
0
                }
670
0
                else
671
0
                    LogManager::getSingleton().logWarning("cannot copy shared parameter '" + pName +
672
0
                                                          "' - type or variability mismatch");
673
0
            }
674
0
        }
675
676
0
        mCopyDataVersion = mSharedParams->getVersion();
677
0
    }
678
    //---------------------------------------------------------------------
679
    void GpuSharedParametersUsage::_copySharedParamsToTargetParams() const
680
0
    {
681
        // check copy data version
682
0
        if (mCopyDataVersion != mSharedParams->getVersion())
683
0
            const_cast<GpuSharedParametersUsage*>(this)->initCopyData();
684
685
        // force const call to get*Pointer
686
0
        const GpuSharedParameters* sharedParams = mSharedParams.get();
687
688
0
        for (const CopyDataEntry& e : mCopyDataList)
689
0
        {
690
            // dst type cannot be double, so src will never be double either
691
0
            if (mParams->getTransposeMatrices() && (e.dstDefinition->constType == GCT_MATRIX_4X4))
692
0
            {
693
0
                const float* pSrc = sharedParams->getFloatPointer(e.srcDefinition->physicalIndex);
694
0
                float* pDst = mParams->getFloatPointer(e.dstDefinition->physicalIndex);
695
696
                // for each matrix that needs to be transposed and copied,
697
0
                for (size_t iMat = 0; iMat < e.dstDefinition->arraySize; ++iMat)
698
0
                {
699
0
                    for (int row = 0; row < 4; ++row)
700
0
                        for (int col = 0; col < 4; ++col)
701
0
                            pDst[row * 4 + col] = pSrc[col * 4 + row];
702
0
                    pSrc += 16;
703
0
                    pDst += 16;
704
0
                }
705
0
            }
706
0
            else
707
0
            {
708
0
                OgreAssertDbg(!e.dstDefinition->isSampler() && !e.dstDefinition->isDouble() &&
709
0
                                  !e.dstDefinition->isSpecialization(),
710
0
                              "expected 4 byte type");
711
0
                const int* pSrc = sharedParams->getIntPointer(e.srcDefinition->physicalIndex);
712
0
                int* pDst = mParams->getIntPointer(e.dstDefinition->physicalIndex);
713
714
0
                if (e.dstDefinition->elementSize == e.srcDefinition->elementSize)
715
0
                {
716
                    // simple copy
717
0
                    memcpy(pDst, pSrc, sizeof(int) * e.dstDefinition->elementSize * e.dstDefinition->arraySize);
718
0
                }
719
0
                else
720
0
                {
721
                    // element wise copy
722
0
                    for (uint32 l = 0; l < e.dstDefinition->arraySize; ++l)
723
0
                    {
724
0
                        memcpy(pDst, pSrc, sizeof(int) * e.dstDefinition->elementSize);
725
0
                        pSrc += e.srcDefinition->elementSize;
726
0
                        pDst += e.dstDefinition->elementSize;
727
0
                    }
728
0
                }
729
0
            }
730
0
        }
731
0
    }
732
733
0
    const String& GpuSharedParametersUsage::getName() const { return mSharedParams->getName(); }
734
735
736
    //-----------------------------------------------------------------------------
737
    //      GpuProgramParameters Methods
738
    //-----------------------------------------------------------------------------
739
    GpuProgramParameters::GpuProgramParameters() :
740
0
        mCombinedVariability(GPV_GLOBAL)
741
0
        , mTransposeMatrices(false)
742
0
        , mIgnoreMissingParams(false)
743
0
        , mActivePassIterationIndex(std::numeric_limits<size_t>::max())
744
0
        , mUseLinearColours(false)
745
0
    {
746
0
        static_assert((sizeof(AutoConstantDictionary) / sizeof(AutoConstantDefinition) - 5) == ACT_FROXEL_RECORDS,
747
0
                      "AutoConstantDictionary out of sync");
748
0
    }
749
0
    GpuProgramParameters::~GpuProgramParameters() {}
750
751
    //-----------------------------------------------------------------------------
752
753
    GpuProgramParameters::GpuProgramParameters(const GpuProgramParameters& oth)
754
0
    {
755
0
        *this = oth;
756
0
    }
757
758
    //-----------------------------------------------------------------------------
759
    GpuProgramParameters& GpuProgramParameters::operator=(const GpuProgramParameters& oth)
760
0
    {
761
        // let compiler perform shallow copies of structures
762
        // AutoConstantEntry, RealConstantEntry, IntConstantEntry
763
0
        mConstants = oth.mConstants;
764
0
        mRegisters = oth.mRegisters;
765
0
        mAutoConstants = oth.mAutoConstants;
766
0
        mLogicalToPhysical = oth.mLogicalToPhysical;
767
0
        mNamedConstants = oth.mNamedConstants;
768
0
        copySharedParamSetUsage(oth.mSharedParamSets);
769
770
0
        mCombinedVariability = oth.mCombinedVariability;
771
0
        mTransposeMatrices = oth.mTransposeMatrices;
772
0
        mIgnoreMissingParams  = oth.mIgnoreMissingParams;
773
0
        mActivePassIterationIndex = oth.mActivePassIterationIndex;
774
0
        mUseLinearColours = oth.mUseLinearColours;
775
776
0
        return *this;
777
0
    }
778
    //---------------------------------------------------------------------
779
    void GpuProgramParameters::copySharedParamSetUsage(const GpuSharedParamUsageList& srcList)
780
0
    {
781
0
        mSharedParamSets.clear();
782
0
        for (const auto& i : srcList)
783
0
        {
784
0
            mSharedParamSets.push_back(GpuSharedParametersUsage(i.getSharedParams(), this));
785
0
        }
786
787
0
    }
788
    //-----------------------------------------------------------------------------
789
    size_t GpuProgramParameters::calculateSize(void) const
790
0
    {
791
0
        size_t memSize = sizeof(*this);
792
793
0
        memSize += mConstants.size();
794
0
        memSize += mRegisters.size()*4;
795
796
0
        for (const auto& ac : mAutoConstants)
797
0
        {
798
0
            memSize += sizeof(ac);
799
0
        }
800
801
0
        return memSize;
802
0
    }
803
    //---------------------------------------------------------------------
804
    void GpuProgramParameters::_setNamedConstants(
805
        const GpuNamedConstantsPtr& namedConstants)
806
0
    {
807
0
        mNamedConstants = namedConstants;
808
809
        // Determine any extension to local buffers
810
811
        // Size and reset buffer (fill with zero to make comparison later ok)
812
0
        if (namedConstants->bufferSize*4 > mConstants.size())
813
0
        {
814
0
            mConstants.insert(mConstants.end(), namedConstants->bufferSize * 4 - mConstants.size(), 0);
815
0
        }
816
817
0
        if(namedConstants->registerCount > mRegisters.size())
818
0
            mRegisters.insert(mRegisters.end(), namedConstants->registerCount - mRegisters.size(), 0);
819
0
    }
820
    //---------------------------------------------------------------------
821
    void GpuProgramParameters::_setLogicalIndexes(const GpuLogicalBufferStructPtr& indexMap)
822
0
    {
823
0
        mLogicalToPhysical = indexMap;
824
825
        // resize the internal buffers
826
        // Note that these will only contain something after the first parameter
827
        // set has set some parameters
828
829
        // Size and reset buffer (fill with zero to make comparison later ok)
830
0
        if (indexMap && indexMap->bufferSize*4 > mConstants.size())
831
0
        {
832
0
            mConstants.insert(mConstants.end(), indexMap->bufferSize * 4 - mConstants.size(), 0);
833
0
        }
834
0
    }
835
    //---------------------------------------------------------------------()
836
    void GpuProgramParameters::setConstant(size_t index, const Vector4& vec)
837
0
    {
838
0
        setConstant(index, vec.ptr(), 1);
839
0
    }
840
    //-----------------------------------------------------------------------------
841
    void GpuProgramParameters::setConstant(size_t index, Real val)
842
0
    {
843
0
        setConstant(index, Vector4(val, 0.0f, 0.0f, 0.0f));
844
0
    }
845
    //-----------------------------------------------------------------------------
846
    void GpuProgramParameters::setConstant(size_t index, const Vector3& vec)
847
0
    {
848
0
        setConstant(index, Vector4(vec.x, vec.y, vec.z, 1.0f));
849
0
    }
850
    //-----------------------------------------------------------------------------
851
    void GpuProgramParameters::setConstant(size_t index, const Vector2& vec)
852
0
    {
853
0
        setConstant(index, Vector4(vec.x, vec.y, 1.0f, 1.0f));
854
0
    }
855
    //-----------------------------------------------------------------------------
856
    void GpuProgramParameters::setConstant(size_t index, const Matrix4& m)
857
0
    {
858
        // set as 4x 4-element floats
859
0
        if (mTransposeMatrices)
860
0
        {
861
0
            Matrix4 t = m.transpose();
862
0
            GpuProgramParameters::setConstant(index, t[0], 4);
863
0
        }
864
0
        else
865
0
        {
866
0
            GpuProgramParameters::setConstant(index, m[0], 4);
867
0
        }
868
869
0
    }
870
    //-----------------------------------------------------------------------------
871
    void GpuProgramParameters::setConstant(size_t index, const Matrix4* pMatrix,
872
                                           size_t numEntries)
873
0
    {
874
0
        if (mTransposeMatrices)
875
0
        {
876
0
            for (size_t i = 0; i < numEntries; ++i)
877
0
            {
878
0
                Matrix4 t = pMatrix[i].transpose();
879
0
                GpuProgramParameters::setConstant(index, t[0], 4);
880
0
                index += 4;
881
0
            }
882
0
        }
883
0
        else
884
0
        {
885
0
            GpuProgramParameters::setConstant(index, pMatrix[0][0], 4 * numEntries);
886
0
        }
887
888
0
    }
889
    //-----------------------------------------------------------------------------
890
    void GpuProgramParameters::setConstant(size_t index, const ColourValue& colour)
891
0
    {
892
0
        setConstant(index, colour.ptr(), 1);
893
0
    }
894
    //-----------------------------------------------------------------------------
895
    void GpuProgramParameters::setConstant(size_t index, const float *val, size_t count)
896
0
    {
897
        // Raw buffer size is 4x count
898
0
        size_t rawCount = count * 4;
899
        // get physical index
900
0
        assert(mLogicalToPhysical && "GpuProgram hasn't set up the logical -> physical map!");
901
902
0
        size_t physicalIndex = _getConstantPhysicalIndex(index, rawCount, GPV_GLOBAL, BCT_FLOAT);
903
904
        // Copy
905
0
        _writeRawConstants(physicalIndex, val, rawCount);
906
907
0
    }
908
    //-----------------------------------------------------------------------------
909
    void GpuProgramParameters::setConstant(size_t index, const double *val, size_t count)
910
0
    {
911
        // Raw buffer size is 4x count
912
0
        size_t rawCount = count * 4;
913
        // get physical index
914
0
        assert(mLogicalToPhysical && "GpuProgram hasn't set up the logical -> physical map!");
915
916
0
        size_t physicalIndex = _getConstantPhysicalIndex(index, rawCount, GPV_GLOBAL, BCT_DOUBLE);
917
        // Copy
918
0
        _writeRawConstants(physicalIndex, val, rawCount);
919
0
    }
920
    //-----------------------------------------------------------------------------
921
    void GpuProgramParameters::setConstant(size_t index, const int *val, size_t count)
922
0
    {
923
        // Raw buffer size is 4x count
924
0
        size_t rawCount = count * 4;
925
        // get physical index
926
0
        assert(mLogicalToPhysical && "GpuProgram hasn't set up the logical -> physical map!");
927
928
0
        size_t physicalIndex = _getConstantPhysicalIndex(index, rawCount, GPV_GLOBAL, BCT_INT);
929
        // Copy
930
0
        _writeRawConstants(physicalIndex, val, rawCount);
931
0
    }
932
    //-----------------------------------------------------------------------------
933
    void GpuProgramParameters::setConstant(size_t index, const uint *val, size_t count)
934
0
    {
935
        // Raw buffer size is 4x count
936
0
        size_t rawCount = count * 4;
937
        // get physical index
938
0
        assert(mLogicalToPhysical && "GpuProgram hasn't set up the logical -> physical map!");
939
940
0
        size_t physicalIndex = _getConstantPhysicalIndex(index, rawCount, GPV_GLOBAL, BCT_INT);
941
        // Copy
942
0
        _writeRawConstants(physicalIndex, val, rawCount);
943
0
    }
944
    //-----------------------------------------------------------------------------
945
    void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const Matrix4& m, size_t elementCount)
946
0
    {
947
948
        // remember, raw content access uses raw float count rather than float4
949
0
        if (mTransposeMatrices)
950
0
        {
951
0
            Matrix4 t = m.transpose();
952
0
            _writeRawConstants(physicalIndex, t[0], elementCount > 16 ? 16 : elementCount);
953
0
        }
954
0
        else
955
0
        {
956
0
            _writeRawConstants(physicalIndex, m[0], elementCount > 16 ? 16 : elementCount);
957
0
        }
958
959
0
    }
960
    //-----------------------------------------------------------------------------
961
    void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const Matrix3& m, size_t elementCount)
962
0
    {
963
964
        // remember, raw content access uses raw float count rather than float4
965
0
        if (mTransposeMatrices)
966
0
        {
967
0
            Matrix3 t = m.transpose();
968
0
            _writeRawConstants(physicalIndex, t[0], elementCount > 9 ? 9 : elementCount);
969
0
        }
970
0
        else
971
0
        {
972
0
            _writeRawConstants(physicalIndex, m[0], elementCount > 9 ? 9 : elementCount);
973
0
        }
974
975
0
    }
976
    //-----------------------------------------------------------------------------
977
    void GpuProgramParameters::_writeRawConstant(size_t physicalIndex, const TransformBaseReal* pMatrix, size_t numEntries)
978
0
    {
979
        // remember, raw content access uses raw float count rather than float4
980
0
        if (mTransposeMatrices)
981
0
        {
982
0
            for (size_t i = 0; i < numEntries; ++i)
983
0
            {
984
0
                Matrix4 t = pMatrix[i].transpose();
985
0
                _writeRawConstants(physicalIndex, t[0], 16);
986
0
                physicalIndex += 16*sizeof(Real);
987
0
            }
988
0
        }
989
0
        else
990
0
        {
991
0
            _writeRawConstants(physicalIndex, pMatrix[0][0], 16 * numEntries);
992
0
        }
993
994
995
0
    }
996
    //-----------------------------------------------------------------------------
997
    void GpuProgramParameters::_writeRawConstant(size_t physicalIndex,
998
                                                 const ColourValue& colour, size_t count)
999
0
    {
1000
0
        if(mUseLinearColours)
1001
0
            return _writeRawConstants(physicalIndex, colour.gammaToLinear().ptr(), std::min(count, (size_t)4));
1002
1003
        // write either the number requested (for packed types) or up to 4
1004
0
        _writeRawConstants(physicalIndex, colour.ptr(), std::min(count, (size_t)4));
1005
0
    }
1006
    //-----------------------------------------------------------------------------
1007
    void GpuProgramParameters::_writeRawConstants(size_t physicalIndex, const double* val, size_t count)
1008
0
    {
1009
0
        assert(physicalIndex + sizeof(float) * count <= mConstants.size());
1010
0
        for (size_t i = 0; i < count; ++i)
1011
0
        {
1012
0
            float tmp = val[i];
1013
0
            memcpy(&mConstants[physicalIndex + i * sizeof(float)], &tmp, sizeof(float));
1014
0
        }
1015
0
    }
1016
    void GpuProgramParameters::_writeRegisters(size_t index, const int* val, size_t count)
1017
0
    {
1018
0
        assert(index + count <= mRegisters.size());
1019
0
        memcpy(&mRegisters[index], val, sizeof(int) * count);
1020
0
    }
1021
    //-----------------------------------------------------------------------------
1022
    void GpuProgramParameters::_readRawConstants(size_t physicalIndex, size_t count, float* dest)
1023
0
    {
1024
0
        assert(physicalIndex + count <= mConstants.size());
1025
0
        memcpy(dest, &mConstants[physicalIndex], sizeof(float) * count);
1026
0
    }
1027
    //-----------------------------------------------------------------------------
1028
    void GpuProgramParameters::_readRawConstants(size_t physicalIndex, size_t count, int* dest)
1029
0
    {
1030
0
        assert(physicalIndex + count <= mConstants.size());
1031
0
        memcpy(dest, &mConstants[physicalIndex], sizeof(int) * count);
1032
0
    }
1033
    //---------------------------------------------------------------------
1034
    uint16 GpuProgramParameters::deriveVariability(GpuProgramParameters::AutoConstantType act)
1035
0
    {
1036
0
        switch(act)
1037
0
        {
1038
0
        case ACT_VIEW_MATRIX:
1039
0
        case ACT_INVERSE_VIEW_MATRIX:
1040
0
        case ACT_TRANSPOSE_VIEW_MATRIX:
1041
0
        case ACT_INVERSE_TRANSPOSE_VIEW_MATRIX:
1042
0
        case ACT_PROJECTION_MATRIX:
1043
0
        case ACT_INVERSE_PROJECTION_MATRIX:
1044
0
        case ACT_TRANSPOSE_PROJECTION_MATRIX:
1045
0
        case ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX:
1046
0
        case ACT_VIEWPROJ_MATRIX:
1047
0
        case ACT_INVERSE_VIEWPROJ_MATRIX:
1048
0
        case ACT_TRANSPOSE_VIEWPROJ_MATRIX:
1049
0
        case ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX:
1050
0
        case ACT_RENDER_TARGET_FLIPPING:
1051
0
        case ACT_VERTEX_WINDING:
1052
0
        case ACT_AMBIENT_LIGHT_COLOUR:
1053
0
        case ACT_DERIVED_AMBIENT_LIGHT_COLOUR:
1054
0
        case ACT_DERIVED_SCENE_COLOUR:
1055
0
        case ACT_FOG_COLOUR:
1056
0
        case ACT_FOG_PARAMS:
1057
0
        case ACT_SURFACE_AMBIENT_COLOUR:
1058
0
        case ACT_SURFACE_DIFFUSE_COLOUR:
1059
0
        case ACT_SURFACE_SPECULAR_COLOUR:
1060
0
        case ACT_SURFACE_EMISSIVE_COLOUR:
1061
0
        case ACT_SURFACE_SHININESS:
1062
0
        case ACT_SURFACE_ALPHA_REJECTION_VALUE:
1063
0
        case ACT_CAMERA_POSITION:
1064
0
        case ACT_CAMERA_RELATIVE_POSITION:
1065
0
        case ACT_TIME:
1066
0
        case ACT_TIME_0_X:
1067
0
        case ACT_COSTIME_0_X:
1068
0
        case ACT_SINTIME_0_X:
1069
0
        case ACT_TANTIME_0_X:
1070
0
        case ACT_TIME_0_X_PACKED:
1071
0
        case ACT_TIME_0_1:
1072
0
        case ACT_COSTIME_0_1:
1073
0
        case ACT_SINTIME_0_1:
1074
0
        case ACT_TANTIME_0_1:
1075
0
        case ACT_TIME_0_1_PACKED:
1076
0
        case ACT_TIME_0_2PI:
1077
0
        case ACT_COSTIME_0_2PI:
1078
0
        case ACT_SINTIME_0_2PI:
1079
0
        case ACT_TANTIME_0_2PI:
1080
0
        case ACT_TIME_0_2PI_PACKED:
1081
0
        case ACT_FRAME_TIME:
1082
0
        case ACT_FPS:
1083
0
        case ACT_VIEWPORT_WIDTH:
1084
0
        case ACT_VIEWPORT_HEIGHT:
1085
0
        case ACT_INVERSE_VIEWPORT_WIDTH:
1086
0
        case ACT_INVERSE_VIEWPORT_HEIGHT:
1087
0
        case ACT_VIEWPORT_SIZE:
1088
0
        case ACT_TEXEL_OFFSETS:
1089
0
        case ACT_TEXTURE_SIZE:
1090
0
        case ACT_INVERSE_TEXTURE_SIZE:
1091
0
        case ACT_PACKED_TEXTURE_SIZE:
1092
0
        case ACT_SCENE_DEPTH_RANGE:
1093
0
        case ACT_VIEW_DIRECTION:
1094
0
        case ACT_VIEW_SIDE_VECTOR:
1095
0
        case ACT_VIEW_UP_VECTOR:
1096
0
        case ACT_FOV:
1097
0
        case ACT_NEAR_CLIP_DISTANCE:
1098
0
        case ACT_FAR_CLIP_DISTANCE:
1099
0
        case ACT_PASS_NUMBER:
1100
0
        case ACT_TEXTURE_MATRIX:
1101
0
        case ACT_LOD_CAMERA_POSITION:
1102
0
        case ACT_FROXEL_TILE_PARAMS:
1103
0
        case ACT_FROXEL_DEPTH_PARAMS:
1104
1105
0
            return (uint16)GPV_GLOBAL;
1106
1107
0
        case ACT_WORLD_MATRIX:
1108
0
        case ACT_INVERSE_WORLD_MATRIX:
1109
0
        case ACT_TRANSPOSE_WORLD_MATRIX:
1110
0
        case ACT_INVERSE_TRANSPOSE_WORLD_MATRIX:
1111
0
        case ACT_WORLD_MATRIX_ARRAY_3x4:
1112
0
        case ACT_WORLD_MATRIX_ARRAY:
1113
0
        case ACT_WORLD_DUALQUATERNION_ARRAY_2x4:
1114
0
        case ACT_WORLD_SCALE_SHEAR_MATRIX_ARRAY_3x4:
1115
0
        case ACT_WORLDVIEW_MATRIX:
1116
0
        case ACT_INVERSE_WORLDVIEW_MATRIX:
1117
0
        case ACT_TRANSPOSE_WORLDVIEW_MATRIX:
1118
0
        case ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX:
1119
0
        case ACT_NORMAL_MATRIX:
1120
0
        case ACT_WORLDVIEWPROJ_MATRIX:
1121
0
        case ACT_WORLDVIEWPROJ_MATRIX_ARRAY:
1122
0
        case ACT_INVERSE_WORLDVIEWPROJ_MATRIX:
1123
0
        case ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX:
1124
0
        case ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX:
1125
0
        case ACT_CAMERA_POSITION_OBJECT_SPACE:
1126
0
        case ACT_LOD_CAMERA_POSITION_OBJECT_SPACE:
1127
0
        case ACT_CUSTOM:
1128
0
        case ACT_ANIMATION_PARAMETRIC:
1129
1130
0
            return (uint16)GPV_PER_OBJECT;
1131
1132
0
        case ACT_LIGHT_POSITION_OBJECT_SPACE:
1133
0
        case ACT_LIGHT_DIRECTION_OBJECT_SPACE:
1134
0
        case ACT_LIGHT_DISTANCE_OBJECT_SPACE:
1135
0
        case ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY:
1136
0
        case ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY:
1137
0
        case ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY:
1138
0
        case ACT_TEXTURE_WORLDVIEWPROJ_MATRIX:
1139
0
        case ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY:
1140
0
        case ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX:
1141
0
        case ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX_ARRAY:
1142
0
        case ACT_SHADOW_EXTRUSION_DISTANCE:
1143
1144
            // These depend on BOTH lights and objects
1145
0
            return ((uint16)GPV_PER_OBJECT) | ((uint16)GPV_LIGHTS);
1146
1147
0
        case ACT_LIGHT_COUNT:
1148
0
        case ACT_LIGHT_DIFFUSE_COLOUR:
1149
0
        case ACT_LIGHT_SPECULAR_COLOUR:
1150
0
        case ACT_LIGHT_POSITION:
1151
0
        case ACT_LIGHT_DIRECTION:
1152
0
        case ACT_LIGHT_POSITION_VIEW_SPACE:
1153
0
        case ACT_LIGHT_DIRECTION_VIEW_SPACE:
1154
0
        case ACT_SHADOW_SCENE_DEPTH_RANGE:
1155
0
        case ACT_SHADOW_SCENE_DEPTH_RANGE_ARRAY:
1156
0
        case ACT_SHADOW_COLOUR:
1157
0
        case ACT_LIGHT_POWER_SCALE:
1158
0
        case ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED:
1159
0
        case ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED:
1160
0
        case ACT_LIGHT_NUMBER:
1161
0
        case ACT_LIGHT_CASTS_SHADOWS:
1162
0
        case ACT_LIGHT_CASTS_SHADOWS_ARRAY:
1163
0
        case ACT_LIGHT_ATTENUATION:
1164
0
        case ACT_SPOTLIGHT_PARAMS:
1165
0
        case ACT_LIGHT_DIFFUSE_COLOUR_ARRAY:
1166
0
        case ACT_LIGHT_SPECULAR_COLOUR_ARRAY:
1167
0
        case ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY:
1168
0
        case ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY:
1169
0
        case ACT_LIGHT_POSITION_ARRAY:
1170
0
        case ACT_LIGHT_DIRECTION_ARRAY:
1171
0
        case ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY:
1172
0
        case ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY:
1173
0
        case ACT_LIGHT_POWER_SCALE_ARRAY:
1174
0
        case ACT_LIGHT_ATTENUATION_ARRAY:
1175
0
        case ACT_SPOTLIGHT_PARAMS_ARRAY:
1176
0
        case ACT_TEXTURE_VIEWPROJ_MATRIX:
1177
0
        case ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY:
1178
0
        case ACT_SPOTLIGHT_VIEWPROJ_MATRIX:
1179
0
        case ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY:
1180
0
        case ACT_LIGHT_CUSTOM:
1181
1182
0
            return (uint16)GPV_LIGHTS;
1183
1184
0
        case ACT_DERIVED_LIGHT_DIFFUSE_COLOUR:
1185
0
        case ACT_DERIVED_LIGHT_SPECULAR_COLOUR:
1186
0
        case ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY:
1187
0
        case ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY:
1188
1189
0
            return ((uint16)GPV_GLOBAL | (uint16)GPV_LIGHTS);
1190
1191
0
        case ACT_PASS_ITERATION_NUMBER:
1192
1193
0
            return (uint16)GPV_PASS_ITERATION_NUMBER;
1194
1195
0
        default:
1196
0
            return (uint16)GPV_GLOBAL;
1197
0
        };
1198
1199
0
    }
1200
    //---------------------------------------------------------------------
1201
    GpuLogicalIndexUse* GpuProgramParameters::getConstantLogicalIndexUse(
1202
        size_t logicalIndex, size_t requestedSize, uint16 variability, BaseConstantType type)
1203
0
    {
1204
0
        OgreAssert(type != BCT_SAMPLER, "");
1205
0
        if (!mLogicalToPhysical || int(logicalIndex) == -1)
1206
0
            return NULL;
1207
1208
0
        GpuLogicalIndexUse* indexUse = 0;
1209
0
        OGRE_LOCK_MUTEX(mLogicalToPhysical->mutex);
1210
1211
0
        auto logi = mLogicalToPhysical->map.find(logicalIndex);
1212
0
        if (logi == mLogicalToPhysical->map.end())
1213
0
        {
1214
0
            if (requestedSize)
1215
0
            {
1216
0
                size_t physicalIndex = mConstants.size();
1217
1218
                // Expand at buffer end
1219
0
                mConstants.insert(mConstants.end(), requestedSize*4, 0);
1220
1221
                // Record extended size for future GPU params re-using this information
1222
0
                mLogicalToPhysical->bufferSize = mConstants.size()/4;
1223
1224
                // low-level programs will not know about mapping ahead of time, so
1225
                // populate it. Other params objects will be able to just use this
1226
                // accepted mapping since the constant structure will be the same
1227
1228
                // Set up a mapping for all items in the count
1229
0
                size_t currPhys = physicalIndex;
1230
0
                size_t count = std::max<size_t>(requestedSize / 4, 1);
1231
1232
0
                for (size_t logicalNum = 0; logicalNum < count; ++logicalNum)
1233
0
                {
1234
0
                    GpuLogicalIndexUseMap::iterator it =
1235
0
                            mLogicalToPhysical->map.emplace(
1236
0
                                logicalIndex + logicalNum,
1237
0
                                GpuLogicalIndexUse(currPhys, requestedSize, variability, type)).first;
1238
0
                    currPhys += 4;
1239
1240
0
                    if (logicalNum == 0)
1241
0
                        indexUse = &(it->second);
1242
0
                }
1243
0
            }
1244
0
            else
1245
0
            {
1246
                // no match & ignore
1247
0
                return 0;
1248
0
            }
1249
1250
0
        }
1251
0
        else
1252
0
        {
1253
0
            indexUse = &(logi->second);
1254
            // check size
1255
0
            if (indexUse->currentSize < requestedSize)
1256
0
            {
1257
0
                size_t physicalIndex = indexUse->physicalIndex;
1258
                // init buffer entry wasn't big enough; could be a mistake on the part
1259
                // of the original use, or perhaps a variable length we can't predict
1260
                // until first actual runtime use e.g. world matrix array
1261
0
                size_t insertCount = requestedSize - indexUse->currentSize;
1262
0
                auto insertPos = mConstants.begin();
1263
0
                std::advance(insertPos, physicalIndex);
1264
0
                mConstants.insert(insertPos, insertCount*4, 0);
1265
1266
                // shift all physical positions after this one
1267
0
                for (auto& p : mLogicalToPhysical->map)
1268
0
                {
1269
0
                    if (p.second.physicalIndex > physicalIndex)
1270
0
                        p.second.physicalIndex += insertCount*4;
1271
0
                }
1272
0
                mLogicalToPhysical->bufferSize += insertCount;
1273
0
                for (auto& ac : mAutoConstants)
1274
0
                {
1275
0
                    auto def = getAutoConstantDefinition(ac.paramType);
1276
0
                    if (ac.physicalIndex > physicalIndex && def)
1277
0
                    {
1278
0
                        ac.physicalIndex += insertCount*4;
1279
0
                    }
1280
0
                }
1281
0
                if (mNamedConstants)
1282
0
                {
1283
0
                    for (auto& p : mNamedConstants->map)
1284
0
                    {
1285
0
                        if (p.second.physicalIndex > physicalIndex)
1286
0
                            p.second.physicalIndex += insertCount * 4;
1287
0
                    }
1288
0
                    mNamedConstants->bufferSize += insertCount;
1289
0
                }
1290
1291
0
                indexUse->currentSize += insertCount;
1292
0
            }
1293
0
        }
1294
1295
0
        if (indexUse && requestedSize)
1296
0
            indexUse->variability = variability;
1297
1298
0
        return indexUse;
1299
0
    }
1300
    //-----------------------------------------------------------------------------
1301
    size_t GpuProgramParameters::_getConstantPhysicalIndex(
1302
        size_t logicalIndex, size_t requestedSize, uint16 variability, BaseConstantType type)
1303
0
    {
1304
0
        GpuLogicalIndexUse* indexUse = getConstantLogicalIndexUse(logicalIndex, requestedSize, variability, type);
1305
0
        return indexUse ? indexUse->physicalIndex : 0;
1306
0
    }
1307
    //-----------------------------------------------------------------------------
1308
    size_t GpuProgramParameters::getLogicalIndexForPhysicalIndex(size_t physicalIndex)
1309
0
    {
1310
        // perhaps build a reverse map of this sometime (shared in GpuProgram)
1311
0
        for (const auto& p : mLogicalToPhysical->map)
1312
0
        {
1313
0
            if (p.second.physicalIndex == physicalIndex)
1314
0
                return p.first;
1315
0
        }
1316
0
        return std::numeric_limits<size_t>::max();
1317
0
    }
1318
    //-----------------------------------------------------------------------------
1319
    GpuConstantDefinitionIterator GpuProgramParameters::getConstantDefinitionIterator(void) const
1320
0
    {
1321
0
        if (!mNamedConstants)
1322
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
1323
0
                        "Named constants have not been initialised, perhaps a compile error");
1324
1325
0
        return GpuConstantDefinitionIterator(mNamedConstants->map.begin(),
1326
0
                                             mNamedConstants->map.end());
1327
1328
0
    }
1329
    //-----------------------------------------------------------------------------
1330
    const GpuNamedConstants& GpuProgramParameters::getConstantDefinitions() const
1331
0
    {
1332
0
        if (!mNamedConstants)
1333
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
1334
0
                        "Named constants have not been initialised, perhaps a compile error");
1335
1336
0
        return *mNamedConstants;
1337
0
    }
1338
    //-----------------------------------------------------------------------------
1339
    const GpuConstantDefinition& GpuProgramParameters::getConstantDefinition(const String& name) const
1340
0
    {
1341
0
        if (!mNamedConstants)
1342
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
1343
0
                        "Named constants have not been initialised, perhaps a compile error",
1344
0
                        "GpuProgramParameters::getConstantDefinitionIterator");
1345
1346
1347
        // locate, and throw exception if not found
1348
0
        const GpuConstantDefinition* def = _findNamedConstantDefinition(name, true);
1349
1350
0
        return *def;
1351
1352
0
    }
1353
    //-----------------------------------------------------------------------------
1354
    const GpuConstantDefinition*
1355
    GpuProgramParameters::_findNamedConstantDefinition(const String& name,
1356
                                                       bool throwExceptionIfNotFound) const
1357
0
    {
1358
0
        if (!mNamedConstants)
1359
0
        {
1360
0
            if (throwExceptionIfNotFound)
1361
0
                OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
1362
0
                            "Named constants have not been initialised, perhaps a compile error");
1363
0
            return 0;
1364
0
        }
1365
1366
        // strip array extension
1367
0
        size_t arrStart = name.back() == ']' ? name.find('[') : String::npos;
1368
0
        auto i = mNamedConstants->map.find(arrStart == String::npos ? name : name.substr(0, arrStart));
1369
0
        if (i == mNamedConstants->map.end() || (i->second.arraySize == 1 && arrStart != String::npos))
1370
0
        {
1371
0
            if (throwExceptionIfNotFound)
1372
0
      {
1373
0
        String knownNames;
1374
#if OGRE_DEBUG_MODE
1375
        // make it easy to catch typo and/or unused shader parameter elimination made by some drivers
1376
        knownNames = "Known names are: ";
1377
        for (i = mNamedConstants->map.begin(); i != mNamedConstants->map.end(); ++i)
1378
          knownNames.append(i->first).append(" ");
1379
#endif
1380
0
                OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
1381
0
        "Parameter called " + name + " does not exist. " + knownNames,
1382
0
                            "GpuProgramParameters::_findNamedConstantDefinition");
1383
0
      }
1384
0
            return 0;
1385
0
        }
1386
0
        else
1387
0
        {
1388
0
            return &(i->second);
1389
0
        }
1390
0
    }
1391
    //-----------------------------------------------------------------------------
1392
    void GpuProgramParameters::setAutoConstant(size_t index, AutoConstantType acType, uint32 extraInfo)
1393
0
    {
1394
        // Get auto constant definition for sizing
1395
0
        const AutoConstantDefinition* autoDef = getAutoConstantDefinition(acType);
1396
1397
0
        if(!autoDef)
1398
0
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "No constant definition found for type " +
1399
0
                        StringConverter::toString(acType),
1400
0
                        "GpuProgramParameters::setAutoConstant");
1401
1402
        // round up to nearest multiple of 4
1403
0
        size_t sz = autoDef->elementCount;
1404
0
        if (sz % 4 > 0)
1405
0
        {
1406
0
            sz += 4 - (sz % 4);
1407
0
        }
1408
1409
0
        GpuLogicalIndexUse* indexUse = getConstantLogicalIndexUse(index, sz, deriveVariability(acType), BCT_FLOAT);
1410
1411
0
        if(indexUse)
1412
0
            _setRawAutoConstant(indexUse->physicalIndex, acType, extraInfo, indexUse->variability, sz);
1413
0
    }
1414
    //-----------------------------------------------------------------------------
1415
    void GpuProgramParameters::_setRawAutoConstant(size_t physicalIndex,
1416
                                                   AutoConstantType acType, uint32 extraInfo, uint16 variability, uint8 elementSize)
1417
0
    {
1418
        // update existing index if it exists
1419
0
        bool found = false;
1420
0
        for (auto& ac : mAutoConstants)
1421
0
        {
1422
0
            if (ac.physicalIndex == physicalIndex)
1423
0
            {
1424
0
                ac.paramType = acType;
1425
0
                ac.data = extraInfo;
1426
0
                ac.elementCount = elementSize;
1427
0
                ac.variability = variability;
1428
0
                found = true;
1429
0
                break;
1430
0
            }
1431
0
        }
1432
0
        if (!found)
1433
0
            mAutoConstants.push_back(AutoConstantEntry(acType, physicalIndex, extraInfo, variability, elementSize));
1434
1435
0
        mCombinedVariability |= variability;
1436
1437
1438
0
    }
1439
    //-----------------------------------------------------------------------------
1440
    void GpuProgramParameters::_setRawAutoConstantReal(size_t physicalIndex,
1441
                                                       AutoConstantType acType, float rData, uint16 variability, uint8 elementSize)
1442
0
    {
1443
        // update existing index if it exists
1444
0
        bool found = false;
1445
0
        for (auto& ac : mAutoConstants)
1446
0
        {
1447
0
            if (ac.physicalIndex == physicalIndex)
1448
0
            {
1449
0
                ac.paramType = acType;
1450
0
                ac.fData = rData;
1451
0
                ac.elementCount = elementSize;
1452
0
                ac.variability = variability;
1453
0
                found = true;
1454
0
                break;
1455
0
            }
1456
0
        }
1457
0
        if (!found)
1458
0
            mAutoConstants.push_back(AutoConstantEntry(acType, physicalIndex, rData, variability, elementSize));
1459
1460
0
        mCombinedVariability |= variability;
1461
0
    }
1462
    //-----------------------------------------------------------------------------
1463
    void GpuProgramParameters::clearAutoConstant(size_t index)
1464
0
    {
1465
0
        GpuLogicalIndexUse* indexUse = getConstantLogicalIndexUse(index, 0, GPV_GLOBAL, BCT_FLOAT);
1466
1467
0
        if (indexUse)
1468
0
        {
1469
            // do not clear variability, indexUse is shared across all instances
1470
1471
0
            size_t physicalIndex = indexUse->physicalIndex;
1472
            // update existing index if it exists
1473
0
            for (AutoConstantList::iterator i = mAutoConstants.begin();
1474
0
                 i != mAutoConstants.end(); ++i)
1475
0
            {
1476
0
                if (i->physicalIndex == physicalIndex)
1477
0
                {
1478
0
                    mAutoConstants.erase(i);
1479
0
                    break;
1480
0
                }
1481
0
            }
1482
0
        }
1483
0
    }
1484
    //-----------------------------------------------------------------------------
1485
    void GpuProgramParameters::clearNamedAutoConstant(const String& name)
1486
0
    {
1487
0
        const GpuConstantDefinition* def = _findNamedConstantDefinition(name);
1488
0
        if (def)
1489
0
        {
1490
            // do not clear variability, def is shared across all instances
1491
1492
            // Autos are always floating point
1493
0
            if (def->isFloat()) {
1494
0
                for (AutoConstantList::iterator i = mAutoConstants.begin();
1495
0
                     i != mAutoConstants.end(); ++i)
1496
0
                {
1497
0
                    if (i->physicalIndex == def->physicalIndex)
1498
0
                    {
1499
0
                        mAutoConstants.erase(i);
1500
0
                        break;
1501
0
                    }
1502
0
                }
1503
0
            }
1504
0
        }
1505
0
    }
1506
    //-----------------------------------------------------------------------------
1507
    void GpuProgramParameters::clearAutoConstants(void)
1508
0
    {
1509
0
        mAutoConstants.clear();
1510
0
        mCombinedVariability = GPV_GLOBAL;
1511
0
    }
1512
    //-----------------------------------------------------------------------------
1513
    void GpuProgramParameters::setAutoConstantReal(size_t index, AutoConstantType acType, float rData)
1514
0
    {
1515
        // Get auto constant definition for sizing
1516
0
        const AutoConstantDefinition* autoDef = getAutoConstantDefinition(acType);
1517
1518
0
        if(!autoDef)
1519
0
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "No constant definition found for type " +
1520
0
                        StringConverter::toString(acType),
1521
0
                        "GpuProgramParameters::setAutoConstantReal");
1522
1523
        // round up to nearest multiple of 4
1524
0
        size_t sz = autoDef->elementCount;
1525
0
        if (sz % 4 > 0)
1526
0
        {
1527
0
            sz += 4 - (sz % 4);
1528
0
        }
1529
1530
0
        GpuLogicalIndexUse* indexUse = getConstantLogicalIndexUse(index, sz, deriveVariability(acType), BCT_FLOAT);
1531
1532
0
        _setRawAutoConstantReal(indexUse->physicalIndex, acType, rData, indexUse->variability, sz);
1533
0
    }
1534
    //-----------------------------------------------------------------------------
1535
1536
    //-----------------------------------------------------------------------------
1537
    void GpuProgramParameters::_updateAutoParams(const AutoParamDataSource* source, uint16 mask)
1538
0
    {
1539
0
        for (const auto& usage : mSharedParamSets)
1540
0
        {
1541
0
            usage.getSharedParams()->_updateAutoParams(source);
1542
0
        }
1543
1544
        // abort early if no autos
1545
0
        if (!hasAutoConstants()) return;
1546
        // abort early if variability doesn't match any param
1547
0
        if (!(mask & mCombinedVariability))
1548
0
            return;
1549
1550
0
        size_t index;
1551
0
        size_t numMatrices;
1552
0
        const Affine3* pMatrix;
1553
0
        size_t m;
1554
0
        Vector3 vec3;
1555
0
        Vector4 vec4;
1556
0
        Matrix3 m3;
1557
0
        Matrix4 scaleM;
1558
0
        DualQuaternion dQuat;
1559
1560
0
        mActivePassIterationIndex = std::numeric_limits<size_t>::max();
1561
1562
        // Autoconstant index is not a physical index
1563
0
        for (const auto& ac : mAutoConstants)
1564
0
        {
1565
            // Only update needed slots
1566
0
            if (ac.variability & mask)
1567
0
            {
1568
1569
0
                switch(ac.paramType)
1570
0
                {
1571
0
                case ACT_VIEW_MATRIX:
1572
0
                    _writeRawConstant(ac.physicalIndex, source->getViewMatrix(),ac.elementCount);
1573
0
                    break;
1574
0
                case ACT_INVERSE_VIEW_MATRIX:
1575
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseViewMatrix(),ac.elementCount);
1576
0
                    break;
1577
0
                case ACT_TRANSPOSE_VIEW_MATRIX:
1578
0
                    _writeRawConstant(ac.physicalIndex, source->getTransposeViewMatrix(),ac.elementCount);
1579
0
                    break;
1580
0
                case ACT_INVERSE_TRANSPOSE_VIEW_MATRIX:
1581
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTransposeViewMatrix(),ac.elementCount);
1582
0
                    break;
1583
1584
0
                case ACT_PROJECTION_MATRIX:
1585
0
                    _writeRawConstant(ac.physicalIndex, source->getProjectionMatrix(),ac.elementCount);
1586
0
                    break;
1587
0
                case ACT_INVERSE_PROJECTION_MATRIX:
1588
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseProjectionMatrix(),ac.elementCount);
1589
0
                    break;
1590
0
                case ACT_TRANSPOSE_PROJECTION_MATRIX:
1591
0
                    _writeRawConstant(ac.physicalIndex, source->getTransposeProjectionMatrix(),ac.elementCount);
1592
0
                    break;
1593
0
                case ACT_INVERSE_TRANSPOSE_PROJECTION_MATRIX:
1594
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTransposeProjectionMatrix(),ac.elementCount);
1595
0
                    break;
1596
1597
0
                case ACT_VIEWPROJ_MATRIX:
1598
0
                    _writeRawConstant(ac.physicalIndex, source->getViewProjectionMatrix(),ac.elementCount);
1599
0
                    break;
1600
0
                case ACT_INVERSE_VIEWPROJ_MATRIX:
1601
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseViewProjMatrix(),ac.elementCount);
1602
0
                    break;
1603
0
                case ACT_TRANSPOSE_VIEWPROJ_MATRIX:
1604
0
                    _writeRawConstant(ac.physicalIndex, source->getTransposeViewProjMatrix(),ac.elementCount);
1605
0
                    break;
1606
0
                case ACT_INVERSE_TRANSPOSE_VIEWPROJ_MATRIX:
1607
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTransposeViewProjMatrix(),ac.elementCount);
1608
0
                    break;
1609
0
                case ACT_RENDER_TARGET_FLIPPING:
1610
0
                    _writeRawConstant(ac.physicalIndex, source->getCurrentRenderTarget()->requiresTextureFlipping() ? -1.f : +1.f);
1611
0
                    break;
1612
0
                case ACT_VERTEX_WINDING:
1613
0
                    {
1614
0
                        RenderSystem* rsys = Root::getSingleton().getRenderSystem();
1615
0
                        _writeRawConstant(ac.physicalIndex, rsys->getInvertVertexWinding() ? -1.f : +1.f);
1616
0
                    }
1617
0
                    break;
1618
1619
                    // NB ambient light still here because it's not related to a specific light
1620
0
                case ACT_AMBIENT_LIGHT_COLOUR:
1621
0
                    _writeRawConstant(ac.physicalIndex, source->getAmbientLightColour(),
1622
0
                                      ac.elementCount);
1623
0
                    break;
1624
0
                case ACT_DERIVED_AMBIENT_LIGHT_COLOUR:
1625
0
                    _writeRawConstant(ac.physicalIndex, source->getDerivedAmbientLightColour(),
1626
0
                                      ac.elementCount);
1627
0
                    break;
1628
0
                case ACT_DERIVED_SCENE_COLOUR:
1629
0
                    _writeRawConstant(ac.physicalIndex, source->getDerivedSceneColour(),
1630
0
                                      ac.elementCount);
1631
0
                    break;
1632
1633
0
                case ACT_FOG_COLOUR:
1634
0
                    _writeRawConstant(ac.physicalIndex, source->getFogColour(), ac.elementCount);
1635
0
                    break;
1636
0
                case ACT_FOG_PARAMS:
1637
0
                    _writeRawConstant(ac.physicalIndex, source->getFogParams(), ac.elementCount);
1638
0
                    break;
1639
0
                case ACT_POINT_PARAMS:
1640
0
                    _writeRawConstant(ac.physicalIndex, source->getPointParams(), ac.elementCount);
1641
0
                    break;
1642
0
                case ACT_SURFACE_AMBIENT_COLOUR:
1643
0
                    _writeRawConstant(ac.physicalIndex, source->getSurfaceAmbientColour(),
1644
0
                                      ac.elementCount);
1645
0
                    break;
1646
0
                case ACT_SURFACE_DIFFUSE_COLOUR:
1647
0
                    _writeRawConstant(ac.physicalIndex, source->getSurfaceDiffuseColour(),
1648
0
                                      ac.elementCount);
1649
0
                    break;
1650
0
                case ACT_SURFACE_SPECULAR_COLOUR:
1651
                    // we also pass metal-roughness here, so avoid any gamma correction
1652
0
                    _writeRawConstants(ac.physicalIndex, source->getSurfaceSpecularColour().ptr(),
1653
0
                                      ac.elementCount);
1654
0
                    break;
1655
0
                case ACT_SURFACE_EMISSIVE_COLOUR:
1656
0
                    _writeRawConstant(ac.physicalIndex, source->getSurfaceEmissiveColour(),
1657
0
                                      ac.elementCount);
1658
0
                    break;
1659
0
                case ACT_SURFACE_SHININESS:
1660
0
                    _writeRawConstant(ac.physicalIndex, source->getSurfaceShininess());
1661
0
                    break;
1662
0
                case ACT_SURFACE_ALPHA_REJECTION_VALUE:
1663
0
                    _writeRawConstant(ac.physicalIndex, source->getSurfaceAlphaRejectionValue());
1664
0
                    break;
1665
1666
0
                case ACT_CAMERA_POSITION:
1667
0
                    _writeRawConstant(ac.physicalIndex, source->getCameraPosition(), ac.elementCount);
1668
0
                    break;
1669
0
                case ACT_CAMERA_RELATIVE_POSITION:
1670
0
                    _writeRawConstant (ac.physicalIndex, source->getCameraRelativePosition(), ac.elementCount);
1671
0
                    break;
1672
0
                case ACT_TIME:
1673
0
                    _writeRawConstant(ac.physicalIndex, source->getTime() * ac.fData);
1674
0
                    break;
1675
0
                case ACT_TIME_0_X:
1676
0
                    _writeRawConstant(ac.physicalIndex, source->getTime_0_X(ac.fData));
1677
0
                    break;
1678
0
                case ACT_COSTIME_0_X:
1679
0
                    _writeRawConstant(ac.physicalIndex, source->getCosTime_0_X(ac.fData));
1680
0
                    break;
1681
0
                case ACT_SINTIME_0_X:
1682
0
                    _writeRawConstant(ac.physicalIndex, source->getSinTime_0_X(ac.fData));
1683
0
                    break;
1684
0
                case ACT_TANTIME_0_X:
1685
0
                    _writeRawConstant(ac.physicalIndex, source->getTanTime_0_X(ac.fData));
1686
0
                    break;
1687
0
                case ACT_TIME_0_X_PACKED:
1688
0
                    _writeRawConstant(ac.physicalIndex, source->getTime_0_X_packed(ac.fData), ac.elementCount);
1689
0
                    break;
1690
0
                case ACT_TIME_0_1:
1691
0
                    _writeRawConstant(ac.physicalIndex, source->getTime_0_1(ac.fData));
1692
0
                    break;
1693
0
                case ACT_COSTIME_0_1:
1694
0
                    _writeRawConstant(ac.physicalIndex, source->getCosTime_0_1(ac.fData));
1695
0
                    break;
1696
0
                case ACT_SINTIME_0_1:
1697
0
                    _writeRawConstant(ac.physicalIndex, source->getSinTime_0_1(ac.fData));
1698
0
                    break;
1699
0
                case ACT_TANTIME_0_1:
1700
0
                    _writeRawConstant(ac.physicalIndex, source->getTanTime_0_1(ac.fData));
1701
0
                    break;
1702
0
                case ACT_TIME_0_1_PACKED:
1703
0
                    _writeRawConstant(ac.physicalIndex, source->getTime_0_1_packed(ac.fData), ac.elementCount);
1704
0
                    break;
1705
0
                case ACT_TIME_0_2PI:
1706
0
                    _writeRawConstant(ac.physicalIndex, source->getTime_0_2Pi(ac.fData));
1707
0
                    break;
1708
0
                case ACT_COSTIME_0_2PI:
1709
0
                    _writeRawConstant(ac.physicalIndex, source->getCosTime_0_2Pi(ac.fData));
1710
0
                    break;
1711
0
                case ACT_SINTIME_0_2PI:
1712
0
                    _writeRawConstant(ac.physicalIndex, source->getSinTime_0_2Pi(ac.fData));
1713
0
                    break;
1714
0
                case ACT_TANTIME_0_2PI:
1715
0
                    _writeRawConstant(ac.physicalIndex, source->getTanTime_0_2Pi(ac.fData));
1716
0
                    break;
1717
0
                case ACT_TIME_0_2PI_PACKED:
1718
0
                    _writeRawConstant(ac.physicalIndex, source->getTime_0_2Pi_packed(ac.fData), ac.elementCount);
1719
0
                    break;
1720
0
                case ACT_FRAME_TIME:
1721
0
                    _writeRawConstant(ac.physicalIndex, source->getFrameTime() * ac.fData);
1722
0
                    break;
1723
0
                case ACT_FPS:
1724
0
                    _writeRawConstant(ac.physicalIndex, source->getFPS());
1725
0
                    break;
1726
0
                case ACT_VIEWPORT_WIDTH:
1727
0
                    _writeRawConstant(ac.physicalIndex, source->getViewportWidth());
1728
0
                    break;
1729
0
                case ACT_VIEWPORT_HEIGHT:
1730
0
                    _writeRawConstant(ac.physicalIndex, source->getViewportHeight());
1731
0
                    break;
1732
0
                case ACT_INVERSE_VIEWPORT_WIDTH:
1733
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseViewportWidth());
1734
0
                    break;
1735
0
                case ACT_INVERSE_VIEWPORT_HEIGHT:
1736
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseViewportHeight());
1737
0
                    break;
1738
0
                case ACT_VIEWPORT_SIZE:
1739
0
                    _writeRawConstant(ac.physicalIndex, Vector4f(
1740
0
                        source->getViewportWidth(),
1741
0
                        source->getViewportHeight(),
1742
0
                        source->getInverseViewportWidth(),
1743
0
                        source->getInverseViewportHeight()), ac.elementCount);
1744
0
                    break;
1745
0
                case ACT_TEXEL_OFFSETS:
1746
0
                    {
1747
0
                        RenderSystem* rsys = Root::getSingleton().getRenderSystem();
1748
0
                        _writeRawConstant(ac.physicalIndex, Vector4f(
1749
0
                            rsys->getHorizontalTexelOffset(),
1750
0
                            rsys->getVerticalTexelOffset(),
1751
0
                            rsys->getHorizontalTexelOffset() * source->getInverseViewportWidth(),
1752
0
                            rsys->getVerticalTexelOffset() * source->getInverseViewportHeight()),
1753
0
                                          ac.elementCount);
1754
0
                    }
1755
0
                    break;
1756
0
                case ACT_TEXTURE_SIZE:
1757
0
                    _writeRawConstant(ac.physicalIndex, source->getTextureSize(ac.data), ac.elementCount);
1758
0
                    break;
1759
0
                case ACT_INVERSE_TEXTURE_SIZE:
1760
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTextureSize(ac.data), ac.elementCount);
1761
0
                    break;
1762
0
                case ACT_PACKED_TEXTURE_SIZE:
1763
0
                    _writeRawConstant(ac.physicalIndex, source->getPackedTextureSize(ac.data), ac.elementCount);
1764
0
                    break;
1765
0
                case ACT_SCENE_DEPTH_RANGE:
1766
0
                    _writeRawConstant(ac.physicalIndex, source->getSceneDepthRange(), ac.elementCount);
1767
0
                    break;
1768
0
                case ACT_VIEW_DIRECTION:
1769
0
                    _writeRawConstant(ac.physicalIndex, source->getViewDirection());
1770
0
                    break;
1771
0
                case ACT_VIEW_SIDE_VECTOR:
1772
0
                    _writeRawConstant(ac.physicalIndex, source->getViewSideVector());
1773
0
                    break;
1774
0
                case ACT_VIEW_UP_VECTOR:
1775
0
                    _writeRawConstant(ac.physicalIndex, source->getViewUpVector());
1776
0
                    break;
1777
0
                case ACT_FOV:
1778
0
                    _writeRawConstant(ac.physicalIndex, source->getFOV());
1779
0
                    break;
1780
0
                case ACT_NEAR_CLIP_DISTANCE:
1781
0
                    _writeRawConstant(ac.physicalIndex, source->getNearClipDistance());
1782
0
                    break;
1783
0
                case ACT_FAR_CLIP_DISTANCE:
1784
0
                    _writeRawConstant(ac.physicalIndex, source->getFarClipDistance());
1785
0
                    break;
1786
0
                case ACT_PASS_NUMBER:
1787
0
                    _writeRawConstant(ac.physicalIndex, (float)source->getPassNumber());
1788
0
                    break;
1789
0
                case ACT_PASS_ITERATION_NUMBER:
1790
                    // this is actually just an initial set-up, it's bound separately, so still global
1791
0
                    _writeRawConstant(ac.physicalIndex, 0.0f);
1792
0
                    mActivePassIterationIndex = ac.physicalIndex;
1793
0
                    break;
1794
0
                case ACT_TEXTURE_MATRIX:
1795
0
                    _writeRawConstant(ac.physicalIndex, source->getTextureTransformMatrix(ac.data),ac.elementCount);
1796
0
                    break;
1797
0
                case ACT_LOD_CAMERA_POSITION:
1798
0
                    _writeRawConstant(ac.physicalIndex, source->getLodCameraPosition(), ac.elementCount);
1799
0
                    break;
1800
0
                case ACT_MATERIAL_LOD_INDEX:
1801
0
                    _writeRawConstant(ac.physicalIndex, (float)source->getMaterialLodIndex());
1802
0
                    break;
1803
0
                case ACT_TEXTURE_WORLDVIEWPROJ_MATRIX:
1804
                    // can also be updated in lights
1805
0
                    _writeRawConstant(ac.physicalIndex, source->getTextureWorldViewProjMatrix(ac.data),ac.elementCount);
1806
0
                    break;
1807
0
                case ACT_TEXTURE_WORLDVIEWPROJ_MATRIX_ARRAY:
1808
0
                    for (size_t l = 0; l < ac.data; ++l)
1809
0
                    {
1810
                        // can also be updated in lights
1811
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Matrix4),
1812
0
                                          source->getTextureWorldViewProjMatrix(l),ac.elementCount);
1813
0
                    }
1814
0
                    break;
1815
0
                case ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX:
1816
0
                    _writeRawConstant(ac.physicalIndex, source->getSpotlightWorldViewProjMatrix(ac.data),ac.elementCount);
1817
0
                    break;
1818
0
                case ACT_SPOTLIGHT_WORLDVIEWPROJ_MATRIX_ARRAY:
1819
0
                    for (size_t l = 0; l < ac.data; ++l)
1820
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Matrix4), source->getSpotlightWorldViewProjMatrix(l), ac.elementCount);
1821
0
                    break;
1822
0
                case ACT_LIGHT_POSITION_OBJECT_SPACE:
1823
0
                    _writeRawConstant(ac.physicalIndex,
1824
0
                                      source->getInverseWorldMatrix() *
1825
0
                                          source->getLightAs4DVector(ac.data),
1826
0
                                      ac.elementCount);
1827
0
                    break;
1828
0
                case ACT_LIGHT_DIRECTION_OBJECT_SPACE:
1829
                    // We need the inverse of the inverse transpose
1830
0
                    m3 = source->getTransposeWorldMatrix().linear();
1831
0
                    vec3 = m3 * source->getLightDirection(ac.data);
1832
0
                    vec3.normalise();
1833
                    // Set as 4D vector for compatibility
1834
0
                    _writeRawConstant(ac.physicalIndex, Vector4f(vec3.x, vec3.y, vec3.z, 0.0f), ac.elementCount);
1835
0
                    break;
1836
0
                case ACT_LIGHT_DISTANCE_OBJECT_SPACE:
1837
0
                    vec3 = source->getInverseWorldMatrix() * source->getLightPosition(ac.data);
1838
0
                    _writeRawConstant(ac.physicalIndex, vec3.length());
1839
0
                    break;
1840
0
                case ACT_LIGHT_POSITION_OBJECT_SPACE_ARRAY:
1841
0
                    for (size_t l = 0; l < ac.data; ++l)
1842
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Vector4f),
1843
0
                                          source->getInverseWorldMatrix() *
1844
0
                                              source->getLightAs4DVector(l),
1845
0
                                          ac.elementCount);
1846
0
                    break;
1847
1848
0
                case ACT_LIGHT_DIRECTION_OBJECT_SPACE_ARRAY:
1849
                    // We need the inverse of the inverse transpose
1850
0
                    m3 = source->getTransposeWorldMatrix().linear();
1851
0
                    for (size_t l = 0; l < ac.data; ++l)
1852
0
                    {
1853
0
                        vec3 = m3 * source->getLightDirection(l);
1854
0
                        vec3.normalise();
1855
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Vector4f),
1856
0
                                          Vector4f(vec3.x, vec3.y, vec3.z, 0.0f), ac.elementCount);
1857
0
                    }
1858
0
                    break;
1859
1860
0
                case ACT_LIGHT_DISTANCE_OBJECT_SPACE_ARRAY:
1861
0
                    for (size_t l = 0; l < ac.data; ++l)
1862
0
                    {
1863
0
                        vec3 = source->getInverseWorldMatrix() * source->getLightPosition(l);
1864
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Real), vec3.length());
1865
0
                    }
1866
0
                    break;
1867
1868
0
                case ACT_WORLD_MATRIX:
1869
0
                    _writeRawConstant(ac.physicalIndex, source->getWorldMatrix(),ac.elementCount);
1870
0
                    break;
1871
0
                case ACT_INVERSE_WORLD_MATRIX:
1872
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseWorldMatrix(),ac.elementCount);
1873
0
                    break;
1874
0
                case ACT_TRANSPOSE_WORLD_MATRIX:
1875
0
                    _writeRawConstant(ac.physicalIndex, source->getTransposeWorldMatrix(),ac.elementCount);
1876
0
                    break;
1877
0
                case ACT_INVERSE_TRANSPOSE_WORLD_MATRIX:
1878
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTransposeWorldMatrix(),ac.elementCount);
1879
0
                    break;
1880
1881
0
                case ACT_BONE_MATRIX_ARRAY_3x4:
1882
                    // Loop over matrices
1883
0
                    pMatrix = source->getBoneMatrixArray();
1884
0
                    numMatrices = source->getBoneMatrixCount();
1885
0
                    index = ac.physicalIndex;
1886
0
                    for (m = 0; m < numMatrices; ++m)
1887
0
                    {
1888
0
                        _writeRawConstants(index, (*pMatrix)[0], 12);
1889
0
                        index += 12*sizeof(Real);
1890
0
                        ++pMatrix;
1891
0
                    }
1892
0
                    break;
1893
0
                case ACT_BONE_MATRIX_ARRAY:
1894
0
                    _writeRawConstant(ac.physicalIndex, source->getBoneMatrixArray(),
1895
0
                                      source->getBoneMatrixCount());
1896
0
                    break;
1897
0
                case ACT_BONE_DUALQUATERNION_ARRAY_2x4:
1898
                    // Loop over matrices
1899
0
                    pMatrix = source->getBoneMatrixArray();
1900
0
                    numMatrices = source->getBoneMatrixCount();
1901
0
                    index = ac.physicalIndex;
1902
0
                    for (m = 0; m < numMatrices; ++m)
1903
0
                    {
1904
0
                        dQuat.fromTransformationMatrix(*pMatrix);
1905
0
                        _writeRawConstants(index, dQuat.ptr(), 8);
1906
0
                        index += sizeof(DualQuaternion);
1907
0
                        ++pMatrix;
1908
0
                    }
1909
0
                    break;
1910
0
                case ACT_BONE_SCALE_SHEAR_MATRIX_ARRAY_3x4:
1911
                    // Loop over matrices
1912
0
                    pMatrix = source->getBoneMatrixArray();
1913
0
                    numMatrices = source->getBoneMatrixCount();
1914
0
                    index = ac.physicalIndex;
1915
1916
0
                    scaleM = Matrix4::IDENTITY;
1917
1918
0
                    for (m = 0; m < numMatrices; ++m)
1919
0
                    {
1920
                        //Based on Matrix4::decompostion, but we don't need the rotation or position components
1921
                        //but do need the scaling and shearing. Shearing isn't available from Matrix4::decomposition
1922
0
                        m3 = pMatrix->linear();
1923
1924
0
                        Matrix3 matQ;
1925
0
                        Vector3 scale;
1926
1927
                        //vecU is the scaling component with vecU[0] = u01, vecU[1] = u02, vecU[2] = u12
1928
                        //vecU[0] is shearing (x,y), vecU[1] is shearing (x,z), and vecU[2] is shearing (y,z)
1929
                        //The first component represents the coordinate that is being sheared,
1930
                        //while the second component represents the coordinate which performs the shearing.
1931
0
                        Vector3 vecU;
1932
0
                        m3.QDUDecomposition( matQ, scale, vecU );
1933
1934
0
                        scaleM[0][0] = scale.x;
1935
0
                        scaleM[1][1] = scale.y;
1936
0
                        scaleM[2][2] = scale.z;
1937
1938
0
                        scaleM[0][1] = vecU[0];
1939
0
                        scaleM[0][2] = vecU[1];
1940
0
                        scaleM[1][2] = vecU[2];
1941
1942
0
                        _writeRawConstants(index, scaleM[0], 12);
1943
0
                        index += 12*sizeof(Real);
1944
0
                        ++pMatrix;
1945
0
                    }
1946
0
                    break;
1947
0
                case ACT_WORLDVIEW_MATRIX:
1948
0
                    _writeRawConstant(ac.physicalIndex, source->getWorldViewMatrix(),ac.elementCount);
1949
0
                    break;
1950
0
                case ACT_INVERSE_WORLDVIEW_MATRIX:
1951
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseWorldViewMatrix(),ac.elementCount);
1952
0
                    break;
1953
0
                case ACT_TRANSPOSE_WORLDVIEW_MATRIX:
1954
0
                    _writeRawConstant(ac.physicalIndex, source->getTransposeWorldViewMatrix(),ac.elementCount);
1955
0
                    break;
1956
0
                case ACT_NORMAL_MATRIX:
1957
0
                    if(ac.elementCount == 9) // check if shader supports packed data
1958
0
                    {
1959
0
                        _writeRawConstant(ac.physicalIndex, source->getInverseTransposeWorldViewMatrix().linear(),ac.elementCount);
1960
0
                        break;
1961
0
                    }
1962
0
                    OGRE_FALLTHROUGH; // fallthrough to padded 4x4 matrix
1963
0
                case ACT_INVERSE_TRANSPOSE_WORLDVIEW_MATRIX:
1964
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTransposeWorldViewMatrix(),ac.elementCount);
1965
0
                    break;
1966
1967
0
                case ACT_WORLDVIEWPROJ_MATRIX:
1968
0
                    _writeRawConstant(ac.physicalIndex, source->getWorldViewProjMatrix(),ac.elementCount);
1969
0
                    break;
1970
0
                case ACT_INVERSE_WORLDVIEWPROJ_MATRIX:
1971
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseWorldViewProjMatrix(),ac.elementCount);
1972
0
                    break;
1973
0
                case ACT_TRANSPOSE_WORLDVIEWPROJ_MATRIX:
1974
0
                    _writeRawConstant(ac.physicalIndex, source->getTransposeWorldViewProjMatrix(),ac.elementCount);
1975
0
                    break;
1976
0
                case ACT_INVERSE_TRANSPOSE_WORLDVIEWPROJ_MATRIX:
1977
0
                    _writeRawConstant(ac.physicalIndex, source->getInverseTransposeWorldViewProjMatrix(),ac.elementCount);
1978
0
                    break;
1979
0
                case ACT_WORLDVIEWPROJ_MATRIX_ARRAY:
1980
0
                    for (size_t l = 0; l < ac.data; ++l)
1981
0
                    {
1982
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Matrix4),
1983
0
                                          source->getWorldViewProjMatrix(l),ac.elementCount);
1984
0
                    }
1985
0
                    break;
1986
0
                case ACT_CAMERA_POSITION_OBJECT_SPACE:
1987
0
                    _writeRawConstant(ac.physicalIndex, source->getCameraPositionObjectSpace(), ac.elementCount);
1988
0
                    break;
1989
0
                case ACT_LOD_CAMERA_POSITION_OBJECT_SPACE:
1990
0
                    _writeRawConstant(ac.physicalIndex, source->getLodCameraPositionObjectSpace(), ac.elementCount);
1991
0
                    break;
1992
1993
0
                case ACT_CUSTOM:
1994
0
                case ACT_ANIMATION_PARAMETRIC:
1995
0
                    source->getCurrentRenderable()->_updateCustomGpuParameter(ac, this);
1996
0
                    break;
1997
0
                case ACT_LIGHT_CUSTOM:
1998
0
                    source->updateLightCustomGpuParameter(ac, this);
1999
0
                    break;
2000
0
                case ACT_LIGHT_COUNT:
2001
0
                    _writeRawConstant(ac.physicalIndex, source->getLightCount());
2002
0
                    break;
2003
0
                case ACT_LIGHT_DIFFUSE_COLOUR:
2004
0
                    _writeRawConstant(ac.physicalIndex, source->getLightDiffuseColour(ac.data), ac.elementCount);
2005
0
                    break;
2006
0
                case ACT_LIGHT_SPECULAR_COLOUR:
2007
0
                    _writeRawConstant(ac.physicalIndex, source->getLightSpecularColour(ac.data), ac.elementCount);
2008
0
                    break;
2009
0
                case ACT_LIGHT_POSITION:
2010
                    // Get as 4D vector, works for directional lights too
2011
                    // Use element count in case uniform slot is smaller
2012
0
                    _writeRawConstant(ac.physicalIndex,
2013
0
                                      source->getLightAs4DVector(ac.data), ac.elementCount);
2014
0
                    break;
2015
0
                case ACT_LIGHT_DIRECTION:
2016
0
                    vec3 = source->getLightDirection(ac.data);
2017
                    // Set as 4D vector for compatibility
2018
                    // Use element count in case uniform slot is smaller
2019
0
                    _writeRawConstant(ac.physicalIndex, Vector4f(vec3.x, vec3.y, vec3.z, 1.0f), ac.elementCount);
2020
0
                    break;
2021
0
                case ACT_LIGHT_POSITION_VIEW_SPACE:
2022
0
                    _writeRawConstant(ac.physicalIndex,
2023
0
                                      source->getViewMatrix() * source->getLightAs4DVector(ac.data), ac.elementCount);
2024
0
                    break;
2025
0
                case ACT_LIGHT_DIRECTION_VIEW_SPACE:
2026
0
                    m3 = source->getInverseTransposeViewMatrix().linear();
2027
                    // inverse transpose in case of scaling
2028
0
                    vec3 = m3 * source->getLightDirection(ac.data);
2029
0
                    vec3.normalise();
2030
                    // Set as 4D vector for compatibility
2031
0
                    _writeRawConstant(ac.physicalIndex, Vector4f(vec3.x, vec3.y, vec3.z, 0.0f),ac.elementCount);
2032
0
                    break;
2033
0
                case ACT_SHADOW_EXTRUSION_DISTANCE:
2034
                    // extrusion is in object-space, so we have to rescale by the inverse
2035
                    // of the world scaling to deal with scaled objects
2036
0
                    m3 = source->getWorldMatrix().linear();
2037
0
                    _writeRawConstant(ac.physicalIndex, source->getShadowExtrusionDistance() /
2038
0
                                      Math::Sqrt(std::max(std::max(m3.GetColumn(0).squaredLength(), m3.GetColumn(1).squaredLength()), m3.GetColumn(2).squaredLength())));
2039
0
                    break;
2040
0
                case ACT_SHADOW_SCENE_DEPTH_RANGE:
2041
0
                    _writeRawConstant(ac.physicalIndex, source->getShadowSceneDepthRange(ac.data));
2042
0
                    break;
2043
0
                case ACT_SHADOW_SCENE_DEPTH_RANGE_ARRAY:
2044
0
                    for (size_t l = 0; l < ac.data; ++l)
2045
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Vector4f), source->getShadowSceneDepthRange(l), ac.elementCount);
2046
0
                    break;
2047
0
                case ACT_SHADOW_COLOUR:
2048
0
                    _writeRawConstant(ac.physicalIndex, source->getShadowColour(), ac.elementCount);
2049
0
                    break;
2050
0
                case ACT_LIGHT_POWER_SCALE:
2051
0
                    _writeRawConstant(ac.physicalIndex, source->getLightPowerScale(ac.data));
2052
0
                    break;
2053
0
                case ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED:
2054
0
                    _writeRawConstant(ac.physicalIndex, source->getLightDiffuseColourWithPower(ac.data), ac.elementCount);
2055
0
                    break;
2056
0
                case ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED:
2057
0
                    _writeRawConstant(ac.physicalIndex, source->getLightSpecularColourWithPower(ac.data), ac.elementCount);
2058
0
                    break;
2059
0
                case ACT_LIGHT_NUMBER:
2060
0
                    _writeRawConstant(ac.physicalIndex, source->getLightNumber(ac.data));
2061
0
                    break;
2062
0
                case ACT_LIGHT_CASTS_SHADOWS:
2063
0
                    _writeRawConstant(ac.physicalIndex, source->getLightCastsShadows(ac.data));
2064
0
                    break;
2065
0
                case ACT_LIGHT_CASTS_SHADOWS_ARRAY:
2066
0
                    for (size_t l = 0; l < ac.data; ++l)
2067
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(float), source->getLightCastsShadows(l));
2068
0
                    break;
2069
0
                case ACT_LIGHT_ATTENUATION:
2070
0
                    _writeRawConstant(ac.physicalIndex, source->getLightAttenuation(ac.data), ac.elementCount);
2071
0
                    break;
2072
0
                case ACT_SPOTLIGHT_PARAMS:
2073
0
                    _writeRawConstant(ac.physicalIndex, source->getSpotlightParams(ac.data), ac.elementCount);
2074
0
                    break;
2075
0
                case ACT_LIGHT_DIFFUSE_COLOUR_ARRAY:
2076
0
                    for (size_t l = 0; l < ac.data; ++l)
2077
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(ColourValue),
2078
0
                                          source->getLightDiffuseColour(l), ac.elementCount);
2079
0
                    break;
2080
2081
0
                case ACT_LIGHT_SPECULAR_COLOUR_ARRAY:
2082
0
                    for (size_t l = 0; l < ac.data; ++l)
2083
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(ColourValue),
2084
0
                                          source->getLightSpecularColour(l), ac.elementCount);
2085
0
                    break;
2086
0
                case ACT_LIGHT_DIFFUSE_COLOUR_POWER_SCALED_ARRAY:
2087
0
                    _writeRawConstants(ac.physicalIndex, source->getLightDiffuseColourPowerScaledArray(ac.data),
2088
0
                                       ac.data);
2089
0
                    break;
2090
2091
0
                case ACT_LIGHT_SPECULAR_COLOUR_POWER_SCALED_ARRAY:
2092
0
                    for (size_t l = 0; l < ac.data; ++l)
2093
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(ColourValue),
2094
0
                                          source->getLightSpecularColourWithPower(l), ac.elementCount);
2095
0
                    break;
2096
2097
0
                case ACT_LIGHT_POSITION_ARRAY:
2098
                    // Get as 4D vector, works for directional lights too
2099
0
                    for (size_t l = 0; l < ac.data; ++l)
2100
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Vector4f),
2101
0
                                          source->getLightAs4DVector(l), ac.elementCount);
2102
0
                    break;
2103
2104
0
                case ACT_LIGHT_DIRECTION_ARRAY:
2105
0
                    for (size_t l = 0; l < ac.data; ++l)
2106
0
                    {
2107
0
                        vec3 = source->getLightDirection(l);
2108
                        // Set as 4D vector for compatibility
2109
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Vector4f),
2110
0
                                          Vector4f(vec3.x, vec3.y, vec3.z, 0.0f), ac.elementCount);
2111
0
                    }
2112
0
                    break;
2113
2114
0
                case ACT_LIGHT_POSITION_VIEW_SPACE_ARRAY:
2115
0
                    _writeRawConstants(ac.physicalIndex, source->getLightPositionViewSpaceArray(ac.data), ac.data);
2116
0
                    break;
2117
2118
0
                case ACT_LIGHT_DIRECTION_VIEW_SPACE_ARRAY:
2119
0
                    _writeRawConstants(ac.physicalIndex, source->getLightDirectionViewSpaceArray(ac.data), ac.data);
2120
0
                    break;
2121
2122
0
                case ACT_LIGHT_POWER_SCALE_ARRAY:
2123
0
                    for (size_t l = 0; l < ac.data; ++l)
2124
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Real),
2125
0
                                          source->getLightPowerScale(l));
2126
0
                    break;
2127
2128
0
                case ACT_LIGHT_ATTENUATION_ARRAY:
2129
0
                    _writeRawConstants(ac.physicalIndex, source->getLightAttenuationArray(ac.data), ac.data);
2130
0
                    break;
2131
0
                case ACT_SPOTLIGHT_PARAMS_ARRAY:
2132
0
                    _writeRawConstants(ac.physicalIndex, source->getSpotlightParamsArray(ac.data), ac.data);
2133
0
                    break;
2134
0
                case ACT_DERIVED_LIGHT_DIFFUSE_COLOUR:
2135
0
                    _writeRawConstant(ac.physicalIndex,
2136
0
                                      source->getLightDiffuseColourWithPower(ac.data) * source->getSurfaceDiffuseColour(),
2137
0
                                      ac.elementCount);
2138
0
                    break;
2139
0
                case ACT_DERIVED_LIGHT_SPECULAR_COLOUR:
2140
0
                    _writeRawConstant(ac.physicalIndex,
2141
0
                                      source->getLightSpecularColourWithPower(ac.data) * source->getSurfaceSpecularColour(),
2142
0
                                      ac.elementCount);
2143
0
                    break;
2144
0
                case ACT_DERIVED_LIGHT_DIFFUSE_COLOUR_ARRAY:
2145
0
                    for (size_t l = 0; l < ac.data; ++l)
2146
0
                    {
2147
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(ColourValue),
2148
0
                                          source->getLightDiffuseColourWithPower(l) * source->getSurfaceDiffuseColour(),
2149
0
                                          ac.elementCount);
2150
0
                    }
2151
0
                    break;
2152
0
                case ACT_DERIVED_LIGHT_SPECULAR_COLOUR_ARRAY:
2153
0
                    for (size_t l = 0; l < ac.data; ++l)
2154
0
                    {
2155
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(ColourValue),
2156
0
                                          source->getLightSpecularColourWithPower(l) * source->getSurfaceSpecularColour(),
2157
0
                                          ac.elementCount);
2158
0
                    }
2159
0
                    break;
2160
0
                case ACT_TEXTURE_VIEWPROJ_MATRIX:
2161
                    // can also be updated in lights
2162
0
                    _writeRawConstant(ac.physicalIndex, source->getTextureViewProjMatrix(ac.data),ac.elementCount);
2163
0
                    break;
2164
0
                case ACT_TEXTURE_VIEWPROJ_MATRIX_ARRAY:
2165
0
                    for (size_t l = 0; l < ac.data; ++l)
2166
0
                    {
2167
                        // can also be updated in lights
2168
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Matrix4),
2169
0
                                          source->getTextureViewProjMatrix(l),ac.elementCount);
2170
0
                    }
2171
0
                    break;
2172
0
                case ACT_SPOTLIGHT_VIEWPROJ_MATRIX:
2173
0
                    _writeRawConstant(ac.physicalIndex, source->getSpotlightViewProjMatrix(ac.data),ac.elementCount);
2174
0
                    break;
2175
0
                case ACT_SPOTLIGHT_VIEWPROJ_MATRIX_ARRAY:
2176
0
                    for (size_t l = 0; l < ac.data; ++l)
2177
0
                    {
2178
                        // can also be updated in lights
2179
0
                        _writeRawConstant(ac.physicalIndex + l*sizeof(Matrix4),
2180
0
                                          source->getSpotlightViewProjMatrix(l),ac.elementCount);
2181
0
                    }
2182
0
                    break;
2183
0
                case ACT_FROXEL_TILE_PARAMS:
2184
0
                    _writeRawConstant(ac.physicalIndex, source->getFroxelTileParams(), ac.elementCount);
2185
0
                    break;
2186
0
                case ACT_FROXEL_DEPTH_PARAMS:
2187
0
                    _writeRawConstant(ac.physicalIndex, source->getFroxelDepthParams(), ac.elementCount);
2188
0
                    break;
2189
0
                default:
2190
0
                    break;
2191
0
                };
2192
0
            }
2193
0
        }
2194
2195
0
    }
2196
    //---------------------------------------------------------------------------
2197
    static size_t withArrayOffset(const GpuConstantDefinition* def, const String& name)
2198
0
    {
2199
0
        uint32 offset = 0;
2200
0
        if(name.back() == ']')
2201
0
        {
2202
0
            size_t start = name.find('[');
2203
0
            offset = StringConverter::parseInt(name.substr(start + 1, name.size() - start - 2));
2204
0
            offset = std::min(offset, def->arraySize - 1);
2205
0
            size_t type_sz = def->isDouble() ? 8 : ( def->isSampler() ? 1 : 4);
2206
0
            offset *= type_sz;
2207
0
        }
2208
2209
0
        return def->physicalIndex + offset * def->elementSize;
2210
0
    }
2211
2212
    void GpuProgramParameters::setNamedConstant(const String& name, float val)
2213
0
    {
2214
        // look up, and throw an exception if we're not ignoring missing
2215
0
        const GpuConstantDefinition* def =
2216
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2217
0
        if (!def)
2218
0
            return;
2219
0
        OgreAssert(def->isFloat(), "Constant type mismatch");
2220
0
        _writeRawConstant(withArrayOffset(def, name), val);
2221
0
    }
2222
    //---------------------------------------------------------------------------
2223
    void GpuProgramParameters::setNamedConstant(const String& name, int val)
2224
0
    {
2225
        // look up, and throw an exception if we're not ignoring missing
2226
0
        const GpuConstantDefinition* def = _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2227
2228
0
        if(!def)
2229
0
            return;
2230
2231
0
        if(def->isSampler())
2232
0
        {
2233
0
            _writeRegisters(withArrayOffset(def, name), &val, 1);
2234
0
            return;
2235
0
        }
2236
2237
0
        OgreAssert(def->isInt(), "Constant type mismatch");
2238
0
        _writeRawConstant(withArrayOffset(def, name), val);
2239
0
    }
2240
    //---------------------------------------------------------------------------
2241
    void GpuProgramParameters::setNamedConstant(const String& name, uint val)
2242
0
    {
2243
        // look up, and throw an exception if we're not ignoring missing
2244
0
        const GpuConstantDefinition* def =
2245
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2246
0
        if (!def)
2247
0
            return;
2248
2249
0
        OgreAssert(def->isUnsignedInt(), "Constant type mismatch");
2250
0
        _writeRawConstant(withArrayOffset(def, name), val);
2251
0
    }
2252
    //---------------------------------------------------------------------------
2253
    void GpuProgramParameters::setNamedConstant(const String& name, const Vector4& vec)
2254
0
    {
2255
        // look up, and throw an exception if we're not ignoring missing
2256
0
        const GpuConstantDefinition* def =
2257
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2258
0
        if (def)
2259
0
            _writeRawConstant(withArrayOffset(def, name), vec, def->elementSize);
2260
0
    }
2261
    //---------------------------------------------------------------------------
2262
    void GpuProgramParameters::setNamedConstant(const String& name, const Vector3& vec)
2263
0
    {
2264
        // look up, and throw an exception if we're not ignoring missing
2265
0
        const GpuConstantDefinition* def =
2266
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2267
0
        if (def)
2268
0
            _writeRawConstant(withArrayOffset(def, name), vec);
2269
0
    }
2270
    //---------------------------------------------------------------------------
2271
    void GpuProgramParameters::setNamedConstant(const String& name, const Vector2& vec)
2272
0
    {
2273
        // look up, and throw an exception if we're not ignoring missing
2274
0
        const GpuConstantDefinition* def =
2275
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2276
0
        if (def)
2277
0
            _writeRawConstant(withArrayOffset(def, name), vec);
2278
0
    }
2279
    //---------------------------------------------------------------------------
2280
    void GpuProgramParameters::setNamedConstant(const String& name, const Matrix4& m)
2281
0
    {
2282
        // look up, and throw an exception if we're not ignoring missing
2283
0
        const GpuConstantDefinition* def =
2284
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2285
0
        if (def)
2286
0
            _writeRawConstant(withArrayOffset(def, name), m, def->elementSize);
2287
0
    }
2288
    //---------------------------------------------------------------------------
2289
    void GpuProgramParameters::setNamedConstant(const String& name, const Matrix4* m,
2290
                                                size_t numEntries)
2291
0
    {
2292
        // look up, and throw an exception if we're not ignoring missing
2293
0
        const GpuConstantDefinition* def =
2294
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2295
0
        if (def)
2296
0
            _writeRawConstant(withArrayOffset(def, name), m, numEntries);
2297
0
    }
2298
    //---------------------------------------------------------------------------
2299
    void GpuProgramParameters::setNamedConstant(const String& name, const ColourValue& colour)
2300
0
    {
2301
        // look up, and throw an exception if we're not ignoring missing
2302
0
        const GpuConstantDefinition* def =
2303
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2304
0
        if (def)
2305
0
            _writeRawConstant(withArrayOffset(def, name), colour, def->elementSize);
2306
0
    }
2307
    //---------------------------------------------------------------------------
2308
    template <typename T> void GpuProgramParameters::_setNamedConstant(const String& name, const T* val, size_t count)
2309
0
    {
2310
        // look up, and throw an exception if we're not ignoring missing
2311
0
        const GpuConstantDefinition* def = _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2312
2313
0
        if (!def)
2314
0
            return;
2315
2316
0
        if (count > def->arraySize * def->elementSize)
2317
0
        {
2318
            // The shader compiler may trim the array if the trailing elements
2319
            // are unused or their usage can be optimized away. Therefore,
2320
            // a count exceeding the array size not not an error.
2321
0
            count = def->arraySize * def->elementSize;
2322
0
        }
2323
2324
0
        _writeRawConstants(withArrayOffset(def, name), val, count);
2325
0
    }
Unexecuted instantiation: void Ogre::GpuProgramParameters::_setNamedConstant<float>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, float const*, unsigned long)
Unexecuted instantiation: void Ogre::GpuProgramParameters::_setNamedConstant<double>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, double const*, unsigned long)
Unexecuted instantiation: void Ogre::GpuProgramParameters::_setNamedConstant<unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned int const*, unsigned long)
2326
    void GpuProgramParameters::setNamedConstant(const String& name, const float* val, size_t count, size_t multiple)
2327
0
    {
2328
0
        _setNamedConstant(name, val, count * multiple);
2329
0
    }
2330
    //---------------------------------------------------------------------------
2331
    void GpuProgramParameters::setNamedConstant(const String& name, const double* val, size_t count, size_t multiple)
2332
0
    {
2333
0
        _setNamedConstant(name, val, count * multiple);
2334
0
    }
2335
    //---------------------------------------------------------------------------
2336
    void GpuProgramParameters::setNamedConstant(const String& name,
2337
                                                const int *val, size_t count, size_t multiple)
2338
0
    {
2339
0
        size_t rawCount = count * multiple;
2340
        // look up, and throw an exception if we're not ignoring missing
2341
0
        const GpuConstantDefinition* def = _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2342
2343
0
        if(!def)
2344
0
            return;
2345
2346
0
        if (rawCount > def->arraySize * def->elementSize)
2347
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
2348
0
                        StringUtil::format("Too many values for parameter %s: %zu > %d", name.c_str(), count,
2349
0
                                           def->arraySize * def->elementSize));
2350
2351
0
        if (def->isSampler())
2352
0
            _writeRegisters(withArrayOffset(def, name), val, rawCount);
2353
0
        else
2354
0
            _writeRawConstants(withArrayOffset(def, name), val, rawCount);
2355
0
    }
2356
    //---------------------------------------------------------------------------
2357
    void GpuProgramParameters::setNamedConstant(const String& name, const uint* val, size_t count, size_t multiple)
2358
0
    {
2359
0
        _setNamedConstant(name, val, count * multiple);
2360
0
    }
2361
    //---------------------------------------------------------------------------
2362
    void GpuProgramParameters::setNamedAutoConstant(const String& name,
2363
                                                    AutoConstantType acType, uint32 extraInfo)
2364
0
    {
2365
        // look up, and throw an exception if we're not ignoring missing
2366
0
        const GpuConstantDefinition* def =
2367
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2368
0
        if (def)
2369
0
        {
2370
0
            OgreAssert(def->isFloat(), "incompatible parameter type in shader");
2371
0
            def->variability = deriveVariability(acType);
2372
            // make sure we also set variability on the logical index map
2373
0
            getConstantLogicalIndexUse(def->logicalIndex, def->elementSize * def->arraySize, def->variability, BCT_FLOAT);
2374
0
            _setRawAutoConstant(withArrayOffset(def, name), acType, extraInfo, def->variability, def->elementSize);
2375
0
        }
2376
2377
0
    }
2378
    //---------------------------------------------------------------------------
2379
    void GpuProgramParameters::setNamedAutoConstantReal(const String& name,
2380
                                                        AutoConstantType acType, Real rData)
2381
0
    {
2382
        // look up, and throw an exception if we're not ignoring missing
2383
0
        const GpuConstantDefinition* def =
2384
0
            _findNamedConstantDefinition(name, !mIgnoreMissingParams);
2385
0
        if (def)
2386
0
        {
2387
0
            OgreAssert(def->isFloat(), "incompatible parameter type in shader");
2388
0
            def->variability = deriveVariability(acType);
2389
            // make sure we also set variability on the logical index map
2390
0
            getConstantLogicalIndexUse(def->logicalIndex, def->elementSize * def->arraySize, def->variability, BCT_FLOAT);
2391
0
            _setRawAutoConstantReal(withArrayOffset(def, name), acType, rData, def->variability, def->elementSize);
2392
0
        }
2393
0
    }
2394
    //---------------------------------------------------------------------------
2395
    GpuProgramParameters::AutoConstantEntry* GpuProgramParameters::getAutoConstantEntry(const size_t index)
2396
0
    {
2397
0
        if (index < mAutoConstants.size())
2398
0
        {
2399
0
            return &(mAutoConstants[index]);
2400
0
        }
2401
0
        else
2402
0
        {
2403
0
            return NULL;
2404
0
        }
2405
0
    }
2406
    //---------------------------------------------------------------------------
2407
    const GpuProgramParameters::AutoConstantEntry*
2408
    GpuProgramParameters::findFloatAutoConstantEntry(size_t logicalIndex)
2409
0
    {
2410
0
        if (!mLogicalToPhysical)
2411
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
2412
0
                        "This is not a low-level parameter parameter object",
2413
0
                        "GpuProgramParameters::findFloatAutoConstantEntry");
2414
2415
0
        return _findRawAutoConstantEntryFloat(
2416
0
            _getConstantPhysicalIndex(logicalIndex, 0, GPV_GLOBAL, BCT_FLOAT));
2417
2418
0
    }
2419
    //---------------------------------------------------------------------------
2420
    const GpuProgramParameters::AutoConstantEntry*
2421
    GpuProgramParameters::findAutoConstantEntry(const String& paramName) const
2422
0
    {
2423
0
        if (!mNamedConstants)
2424
0
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
2425
0
                        "This params object is not based on a program with named parameters.",
2426
0
                        "GpuProgramParameters::findAutoConstantEntry");
2427
2428
0
        const GpuConstantDefinition& def = getConstantDefinition(paramName);
2429
0
        if(def.isSampler())
2430
0
            return NULL;
2431
0
        return _findRawAutoConstantEntryFloat(def.physicalIndex);
2432
0
    }
2433
    //---------------------------------------------------------------------------
2434
    const GpuProgramParameters::AutoConstantEntry*
2435
    GpuProgramParameters::_findRawAutoConstantEntryFloat(size_t physicalIndex) const
2436
0
    {
2437
0
        for(const auto& ac : mAutoConstants)
2438
0
        {
2439
            // should check that auto is float and not int so that physicalIndex
2440
            // doesn't have any ambiguity
2441
            // However, all autos are float I think so no need
2442
0
            if (ac.physicalIndex == physicalIndex)
2443
0
                return &ac;
2444
0
        }
2445
2446
0
        return 0;
2447
2448
0
    }
2449
    //---------------------------------------------------------------------------
2450
    void GpuProgramParameters::copyConstantsFrom(const GpuProgramParameters& source)
2451
0
    {
2452
        // Pull buffers & auto constant list over directly
2453
0
        mConstants = source.getConstantList();
2454
0
        mRegisters = source.mRegisters;
2455
0
        mAutoConstants = source.getAutoConstantList();
2456
0
        mCombinedVariability = source.mCombinedVariability;
2457
0
        mUseLinearColours = source.mUseLinearColours;
2458
0
        copySharedParamSetUsage(source.mSharedParamSets);
2459
0
    }
2460
    //---------------------------------------------------------------------
2461
    void GpuProgramParameters::copyMatchingNamedConstantsFrom(const GpuProgramParameters& source)
2462
0
    {
2463
0
        if (mNamedConstants && source.mNamedConstants)
2464
0
        {
2465
0
            std::map<size_t, String> srcToDestNamedMap;
2466
0
            for (auto& m : source.mNamedConstants->map)
2467
0
            {
2468
0
                const String& paramName = m.first;
2469
0
                const GpuConstantDefinition& olddef = m.second;
2470
0
                const GpuConstantDefinition* newdef = _findNamedConstantDefinition(paramName, false);
2471
0
                if (newdef)
2472
0
                {
2473
                    // Copy data across, based on smallest common definition size
2474
0
                    size_t srcsz = olddef.elementSize * olddef.arraySize;
2475
0
                    size_t destsz = newdef->elementSize * newdef->arraySize;
2476
0
                    size_t sz = std::min(srcsz, destsz);
2477
0
                    if (newdef->isFloat() || newdef->isInt() || newdef->isUnsignedInt() || newdef->isBool())
2478
0
                    {
2479
0
                        OgreAssert(mConstants.size() >= (newdef->physicalIndex + sz * 4), "Invalid physical index or size");
2480
0
                        memcpy(getFloatPointer(newdef->physicalIndex),
2481
0
                               source.getFloatPointer(olddef.physicalIndex),
2482
0
                               sz * 4);
2483
0
                    }
2484
0
                    else if (newdef->isDouble())
2485
0
                    {
2486
2487
0
                        memcpy(getDoublePointer(newdef->physicalIndex),
2488
0
                               source.getDoublePointer(olddef.physicalIndex),
2489
0
                               sz * sizeof(double));
2490
0
                    }
2491
0
                    else if (newdef->isSampler())
2492
0
                    {
2493
0
                        *getRegPointer(newdef->physicalIndex) = *source.getRegPointer(olddef.physicalIndex);
2494
0
                    }
2495
0
                    else
2496
0
                    {
2497
                        //TODO exception handling
2498
0
                    }
2499
                    // we'll use this map to resolve autos later
2500
                    // ignore the [0] aliases
2501
0
                    if (!StringUtil::endsWith(paramName, "[0]") && source.findAutoConstantEntry(paramName))
2502
0
                        srcToDestNamedMap[olddef.physicalIndex] = paramName;
2503
0
                }
2504
0
            }
2505
2506
0
            for (const auto& autoEntry : source.mAutoConstants)
2507
0
            {
2508
                // find dest physical index
2509
0
                std::map<size_t, String>::iterator mi = srcToDestNamedMap.find(autoEntry.physicalIndex);
2510
0
                if (mi != srcToDestNamedMap.end())
2511
0
                {
2512
0
                    if (getAutoConstantDefinition(autoEntry.paramType)->dataType == ACDT_REAL)
2513
0
                    {
2514
0
                        setNamedAutoConstantReal(mi->second, autoEntry.paramType, autoEntry.fData);
2515
0
                    }
2516
0
                    else
2517
0
                    {
2518
0
                        setNamedAutoConstant(mi->second, autoEntry.paramType, autoEntry.data);
2519
0
                    }
2520
0
                }
2521
2522
0
            }
2523
2524
            // Copy shared param sets
2525
0
            for (const auto& usage : source.mSharedParamSets)
2526
0
            {
2527
0
                if (!isUsingSharedParameters(usage.getName()))
2528
0
                {
2529
0
                    addSharedParameters(usage.getSharedParams());
2530
0
                }
2531
0
            }
2532
0
        }
2533
0
    }
2534
    //-----------------------------------------------------------------------
2535
    const GpuProgramParameters::AutoConstantDefinition*
2536
    GpuProgramParameters::getAutoConstantDefinition(const String& name)
2537
0
    {
2538
        // find a constant definition that matches name by iterating through the
2539
        // constant definition array
2540
0
        bool nameFound = false;
2541
0
        size_t i = 0;
2542
0
        const size_t numDefs = getNumAutoConstantDefinitions();
2543
0
        while (!nameFound && (i < numDefs))
2544
0
        {
2545
0
            if (name == AutoConstantDictionary[i].name)
2546
0
                nameFound = true;
2547
0
            else
2548
0
                ++i;
2549
0
        }
2550
2551
0
        if (nameFound)
2552
0
            return &AutoConstantDictionary[i];
2553
0
        else
2554
0
            return 0;
2555
0
    }
2556
2557
    //-----------------------------------------------------------------------
2558
    const GpuProgramParameters::AutoConstantDefinition*
2559
    GpuProgramParameters::getAutoConstantDefinition(AutoConstantType idx)
2560
0
    {
2561
        // verify index is equal to acType
2562
        // if they are not equal then the dictionary was not setup properly
2563
0
        assert(idx == AutoConstantDictionary[idx].acType);
2564
0
        return &AutoConstantDictionary[idx];
2565
0
    }
2566
    //-----------------------------------------------------------------------
2567
    size_t GpuProgramParameters::getNumAutoConstantDefinitions(void)
2568
0
    {
2569
0
        return sizeof(AutoConstantDictionary)/sizeof(AutoConstantDefinition);
2570
0
    }
2571
2572
    //-----------------------------------------------------------------------
2573
    void GpuProgramParameters::incPassIterationNumber(void)
2574
0
    {
2575
0
        if (mActivePassIterationIndex != std::numeric_limits<size_t>::max())
2576
0
        {
2577
            // This is a physical index
2578
0
            *getFloatPointer(mActivePassIterationIndex) += 1;
2579
0
        }
2580
0
    }
2581
    //---------------------------------------------------------------------
2582
    void GpuProgramParameters::addSharedParameters(GpuSharedParametersPtr sharedParams)
2583
0
    {
2584
0
        if (!isUsingSharedParameters(sharedParams->getName()))
2585
0
        {
2586
0
            mSharedParamSets.push_back(GpuSharedParametersUsage(sharedParams, this));
2587
0
        }
2588
0
    }
2589
    //---------------------------------------------------------------------
2590
    void GpuProgramParameters::addSharedParameters(const String& sharedParamsName)
2591
0
    {
2592
0
        addSharedParameters(GpuProgramManager::getSingleton().getSharedParameters(sharedParamsName));
2593
0
    }
2594
    //---------------------------------------------------------------------
2595
    bool GpuProgramParameters::isUsingSharedParameters(const String& sharedParamsName) const
2596
0
    {
2597
0
        for (const auto& mSharedParamSet : mSharedParamSets)
2598
0
        {
2599
0
            if (mSharedParamSet.getName() == sharedParamsName)
2600
0
                return true;
2601
0
        }
2602
0
        return false;
2603
0
    }
2604
    //---------------------------------------------------------------------
2605
    void GpuProgramParameters::removeSharedParameters(const String& sharedParamsName)
2606
0
    {
2607
0
        for (GpuSharedParamUsageList::iterator i = mSharedParamSets.begin();
2608
0
             i != mSharedParamSets.end(); ++i)
2609
0
        {
2610
0
            if (i->getName() == sharedParamsName)
2611
0
            {
2612
0
                mSharedParamSets.erase(i);
2613
0
                break;
2614
0
            }
2615
0
        }
2616
0
    }
2617
    //---------------------------------------------------------------------
2618
    void GpuProgramParameters::removeAllSharedParameters()
2619
0
    {
2620
0
        mSharedParamSets.clear();
2621
0
    }
2622
    //---------------------------------------------------------------------
2623
    const GpuProgramParameters::GpuSharedParamUsageList&
2624
    GpuProgramParameters::getSharedParameters() const
2625
0
    {
2626
0
        return mSharedParamSets;
2627
0
    }
2628
    //---------------------------------------------------------------------
2629
    void GpuProgramParameters::_copySharedParams()
2630
0
    {
2631
0
        for (auto& usage : mSharedParamSets)
2632
0
        {
2633
0
            usage._copySharedParamsToTargetParams();
2634
0
        }
2635
0
    }
2636
2637
    void GpuProgramParameters::_updateSharedParams()
2638
0
    {
2639
0
        for (auto& usage : mSharedParamSets)
2640
0
        {
2641
0
            const GpuSharedParametersPtr& sharedParams = usage.getSharedParams();
2642
0
            if(sharedParams->_getHardwareBuffer())
2643
0
            {
2644
0
                sharedParams->_upload();
2645
0
                sharedParams->_markClean();
2646
0
                continue;
2647
0
            }
2648
2649
0
            usage._copySharedParamsToTargetParams();
2650
0
        }
2651
0
    }
2652
}