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