Coverage Report

Created: 2025-11-11 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreUnifiedHighLevelGpuProgram.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 "OgreUnifiedHighLevelGpuProgram.h"
30
#include "OgreGpuProgramManager.h"
31
32
namespace Ogre
33
{
34
    //-----------------------------------------------------------------------
35
    /// Command object for setting delegate (can set more than once)
36
    class CmdDelegate : public ParamCommand
37
    {
38
    public:
39
        String doGet(const void* target) const override;
40
        void doSet(void* target, const String& val) override;
41
    };
42
    static CmdDelegate msCmdDelegate;
43
    static const String sLanguage = "unified";
44
45
    //-----------------------------------------------------------------------
46
    //-----------------------------------------------------------------------
47
    UnifiedHighLevelGpuProgram::UnifiedHighLevelGpuProgram(
48
        ResourceManager* creator, const String& name, ResourceHandle handle,
49
        const String& group, bool isManual, ManualResourceLoader* loader)
50
0
        :GpuProgram(creator, name, handle, group, isManual, loader)
51
0
    {
52
0
        if (createParamDictionary("UnifiedHighLevelGpuProgram"))
53
0
        {
54
0
            setupBaseParamDictionary();
55
56
0
            ParamDictionary* dict = getParamDictionary();
57
58
0
            dict->addParameter(ParameterDef("delegate",
59
0
                "Additional delegate programs containing implementations.",
60
0
                PT_STRING),&msCmdDelegate);
61
0
        }
62
63
0
    }
64
    //-----------------------------------------------------------------------
65
    UnifiedHighLevelGpuProgram::~UnifiedHighLevelGpuProgram()
66
0
    {
67
68
0
    }
69
    //-----------------------------------------------------------------------
70
    void UnifiedHighLevelGpuProgram::chooseDelegate() const
71
0
    {
72
0
        OGRE_LOCK_AUTO_MUTEX;
73
74
0
        mChosenDelegate.reset();
75
76
0
        for (const String& dn : mDelegateNames)
77
0
        {
78
0
            GpuProgramPtr deleg = GpuProgramManager::getSingleton().getByName(dn, mGroup);
79
80
            //recheck with auto resource group
81
0
            if (!deleg)
82
0
                deleg = GpuProgramManager::getSingleton().getByName(dn, RGN_AUTODETECT);
83
84
            // Silently ignore missing links
85
0
            if(!deleg || (!deleg->isSupported() && !deleg->hasCompileError()))
86
0
                continue;
87
88
0
            if (deleg->getType() != getType())
89
0
            {
90
0
                LogManager::getSingleton().logError("unified program '" + getName() +
91
0
                                                    "' delegating to program with different type '" + dn + "'");
92
0
                continue;
93
0
            }
94
95
0
            mChosenDelegate = deleg;
96
0
            break;
97
0
        }
98
0
    }
99
    //-----------------------------------------------------------------------
100
    const GpuProgramPtr& UnifiedHighLevelGpuProgram::_getDelegate() const
101
0
    {
102
0
        if (!mChosenDelegate)
103
0
        {
104
0
            chooseDelegate();
105
0
        }
106
0
        return mChosenDelegate;
107
0
    }
108
    //-----------------------------------------------------------------------
109
    void UnifiedHighLevelGpuProgram::addDelegateProgram(const String& name)
110
0
    {
111
0
            OGRE_LOCK_AUTO_MUTEX;
112
113
0
        mDelegateNames.push_back(name);
114
115
        // reset chosen delegate
116
0
        mChosenDelegate.reset();
117
118
0
    }
119
    //-----------------------------------------------------------------------
120
    void UnifiedHighLevelGpuProgram::clearDelegatePrograms()
121
0
    {
122
0
            OGRE_LOCK_AUTO_MUTEX;
123
124
0
        mDelegateNames.clear();
125
0
        mChosenDelegate.reset();
126
127
0
    }
128
    //-----------------------------------------------------------------------------
129
    size_t UnifiedHighLevelGpuProgram::calculateSize(void) const
130
0
    {
131
0
        size_t memSize = 0;
132
133
0
        memSize += GpuProgram::calculateSize();
134
135
        // Delegate Names
136
0
        for (const auto& n : mDelegateNames)
137
0
            memSize += n.size() * sizeof(char);
138
139
0
        return memSize;
140
0
    }
141
    //-----------------------------------------------------------------------
142
    const String& UnifiedHighLevelGpuProgram::getLanguage(void) const
143
0
    {
144
0
        return sLanguage;
145
0
    }
146
    //-----------------------------------------------------------------------
147
    GpuProgramParametersSharedPtr UnifiedHighLevelGpuProgram::createParameters(void)
148
0
    {
149
0
        if (isSupported())
150
0
        {
151
0
            return _getDelegate()->createParameters();
152
0
        }
153
0
        else
154
0
        {
155
            // return a default set
156
0
            GpuProgramParametersSharedPtr params = GpuProgramManager::getSingleton().createParameters();
157
            // avoid any errors on parameter names that don't exist
158
0
            params->setIgnoreMissingParams(true);
159
0
            return params;
160
0
        }
161
0
    }
162
    //-----------------------------------------------------------------------
163
    GpuProgram* UnifiedHighLevelGpuProgram::_getBindingDelegate(void)
164
0
    {
165
0
        if (_getDelegate())
166
0
            return _getDelegate()->_getBindingDelegate();
167
0
        else
168
0
            return 0;
169
0
    }
170
    //-----------------------------------------------------------------------
171
    bool UnifiedHighLevelGpuProgram::isSupported(void) const
172
0
    {
173
        // Supported if one of the delegates is
174
0
        return _getDelegate() && _getDelegate()->isSupported();
175
0
    }
176
    //-----------------------------------------------------------------------
177
    bool UnifiedHighLevelGpuProgram::isSkeletalAnimationIncluded(void) const
178
0
    {
179
0
        if (_getDelegate())
180
0
            return _getDelegate()->isSkeletalAnimationIncluded();
181
0
        else
182
0
            return false;
183
0
    }
184
    //-----------------------------------------------------------------------
185
    bool UnifiedHighLevelGpuProgram::isMorphAnimationIncluded(void) const
186
0
    {
187
0
        if (_getDelegate())
188
0
            return _getDelegate()->isMorphAnimationIncluded();
189
0
        else
190
0
            return false;
191
0
    }
192
    //-----------------------------------------------------------------------
193
    bool UnifiedHighLevelGpuProgram::isPoseAnimationIncluded(void) const
194
0
    {
195
0
        if (_getDelegate())
196
0
            return _getDelegate()->isPoseAnimationIncluded();
197
0
        else
198
0
            return false;
199
0
    }
200
    //-----------------------------------------------------------------------
201
    ushort UnifiedHighLevelGpuProgram::getNumberOfPosesIncluded(void) const
202
0
    {
203
0
        if (_getDelegate())
204
0
            return _getDelegate()->getNumberOfPosesIncluded();
205
0
        else
206
0
            return 0;
207
0
    }
208
    //-----------------------------------------------------------------------
209
    bool UnifiedHighLevelGpuProgram::isVertexTextureFetchRequired(void) const
210
0
    {
211
0
        if (_getDelegate())
212
0
            return _getDelegate()->isVertexTextureFetchRequired();
213
0
        else
214
0
            return false;
215
0
    }
216
    //-----------------------------------------------------------------------
217
    const GpuProgramParametersPtr& UnifiedHighLevelGpuProgram::getDefaultParameters(void)
218
0
    {
219
0
        if (_getDelegate())
220
0
            return _getDelegate()->getDefaultParameters();
221
222
0
        static GpuProgramParametersSharedPtr nullPtr;
223
0
        return nullPtr;
224
0
    }
225
    //-----------------------------------------------------------------------
226
    bool UnifiedHighLevelGpuProgram::hasDefaultParameters(void) const
227
0
    {
228
0
        if (_getDelegate())
229
0
            return _getDelegate()->hasDefaultParameters();
230
0
        else
231
0
            return false;
232
0
    }
233
    //-----------------------------------------------------------------------
234
    bool UnifiedHighLevelGpuProgram::getPassSurfaceAndLightStates(void) const
235
0
    {
236
0
        if (_getDelegate())
237
0
            return _getDelegate()->getPassSurfaceAndLightStates();
238
0
        else
239
0
            return GpuProgram::getPassSurfaceAndLightStates();
240
0
    }
241
    //---------------------------------------------------------------------
242
    bool UnifiedHighLevelGpuProgram::getPassFogStates(void) const
243
0
    {
244
0
        if (_getDelegate())
245
0
            return _getDelegate()->getPassFogStates();
246
0
        else
247
0
            return GpuProgram::getPassFogStates();
248
0
    }
249
    //---------------------------------------------------------------------
250
    bool UnifiedHighLevelGpuProgram::getPassTransformStates(void) const
251
0
    {
252
0
        if (_getDelegate())
253
0
            return _getDelegate()->getPassTransformStates();
254
0
        else
255
0
            return GpuProgram::getPassTransformStates();
256
257
0
    }
258
    //-----------------------------------------------------------------------
259
    bool UnifiedHighLevelGpuProgram::hasCompileError(void) const
260
0
    {
261
0
        if (!_getDelegate())
262
0
        {
263
0
            return false;
264
0
        }
265
0
        else
266
0
        {
267
0
            return _getDelegate()->hasCompileError();
268
0
        }
269
0
    }
270
    //-----------------------------------------------------------------------
271
    void UnifiedHighLevelGpuProgram::resetCompileError(void)
272
0
    {
273
0
        if (_getDelegate())
274
0
            _getDelegate()->resetCompileError();
275
0
    }
276
    //-----------------------------------------------------------------------
277
    void UnifiedHighLevelGpuProgram::load(bool backgroundThread)
278
0
    {
279
0
        if (_getDelegate())
280
0
            _getDelegate()->load(backgroundThread);
281
0
    }
282
    //-----------------------------------------------------------------------
283
    void UnifiedHighLevelGpuProgram::reload(LoadingFlags flags)
284
0
    {
285
0
        if (_getDelegate())
286
0
            _getDelegate()->reload(flags);
287
0
    }
288
    //-----------------------------------------------------------------------
289
    bool UnifiedHighLevelGpuProgram::isReloadable(void) const
290
0
    {
291
0
        if (_getDelegate())
292
0
            return _getDelegate()->isReloadable();
293
0
        else
294
0
            return true;
295
0
    }
296
    //-----------------------------------------------------------------------
297
    void UnifiedHighLevelGpuProgram::unload(void)
298
0
    {
299
0
        if (_getDelegate())
300
0
            _getDelegate()->unload();
301
0
    }
302
    //-----------------------------------------------------------------------
303
    bool UnifiedHighLevelGpuProgram::isLoaded(void) const
304
0
    {
305
0
        if (_getDelegate())
306
0
            return _getDelegate()->isLoaded();
307
0
        else
308
0
            return false;
309
0
    }
310
    //-----------------------------------------------------------------------
311
    bool UnifiedHighLevelGpuProgram::isLoading() const
312
0
    {
313
0
        if (_getDelegate())
314
0
            return _getDelegate()->isLoading();
315
0
        else
316
0
            return false;
317
0
    }
318
    //-----------------------------------------------------------------------
319
    Resource::LoadingState UnifiedHighLevelGpuProgram::getLoadingState() const
320
0
    {
321
0
        if (_getDelegate())
322
0
            return _getDelegate()->getLoadingState();
323
0
        else
324
0
            return Resource::LOADSTATE_UNLOADED;
325
0
    }
326
    //-----------------------------------------------------------------------
327
    size_t UnifiedHighLevelGpuProgram::getSize(void) const
328
0
    {
329
0
        if (_getDelegate())
330
0
            return _getDelegate()->getSize();
331
0
        else
332
0
            return 0;
333
0
    }
334
    //-----------------------------------------------------------------------
335
    void UnifiedHighLevelGpuProgram::touch(void)
336
0
    {
337
0
        if (_getDelegate())
338
0
            _getDelegate()->touch();
339
0
    }
340
    //-----------------------------------------------------------------------
341
    bool UnifiedHighLevelGpuProgram::isBackgroundLoaded(void) const
342
0
    {
343
0
        if (_getDelegate())
344
0
            return _getDelegate()->isBackgroundLoaded();
345
0
        else
346
0
            return false;
347
0
    }
348
    //-----------------------------------------------------------------------
349
    void UnifiedHighLevelGpuProgram::setBackgroundLoaded(bool bl)
350
0
    {
351
0
        if (_getDelegate())
352
0
            _getDelegate()->setBackgroundLoaded(bl);
353
0
    }
354
    //-----------------------------------------------------------------------
355
    void UnifiedHighLevelGpuProgram::escalateLoading()
356
0
    {
357
0
        if (_getDelegate())
358
0
            _getDelegate()->escalateLoading();
359
0
    }
360
    //-----------------------------------------------------------------------
361
    void UnifiedHighLevelGpuProgram::addListener(Resource::Listener* lis)
362
0
    {
363
0
        if (_getDelegate())
364
0
            _getDelegate()->addListener(lis);
365
0
    }
366
    //-----------------------------------------------------------------------
367
    void UnifiedHighLevelGpuProgram::removeListener(Resource::Listener* lis)
368
0
    {
369
0
        if (_getDelegate())
370
0
            _getDelegate()->removeListener(lis);
371
0
    }
372
    //-----------------------------------------------------------------------
373
    void UnifiedHighLevelGpuProgram::createLowLevelImpl(void)
374
0
    {
375
0
        OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
376
0
            "This method should never get called!",
377
0
            "UnifiedHighLevelGpuProgram::createLowLevelImpl");
378
0
    }
379
    //-----------------------------------------------------------------------
380
    void UnifiedHighLevelGpuProgram::unloadHighLevelImpl(void)
381
0
    {
382
0
        OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
383
0
            "This method should never get called!",
384
0
            "UnifiedHighLevelGpuProgram::unloadHighLevelImpl");
385
0
    }
386
    //-----------------------------------------------------------------------
387
    void UnifiedHighLevelGpuProgram::loadFromSource(void)
388
0
    {
389
0
        OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
390
0
            "This method should never get called!",
391
0
            "UnifiedHighLevelGpuProgram::loadFromSource");
392
0
    }
393
    //-----------------------------------------------------------------------
394
    //-----------------------------------------------------------------------
395
    String CmdDelegate::doGet(const void* target) const
396
0
    {
397
        // Can't do this (not one delegate), shouldn't matter
398
0
        return BLANKSTRING;
399
0
    }
400
    //-----------------------------------------------------------------------
401
    void CmdDelegate::doSet(void* target, const String& val)
402
0
    {
403
0
        static_cast<UnifiedHighLevelGpuProgram*>(target)->addDelegateProgram(val);
404
0
    }
405
    //-----------------------------------------------------------------------
406
    //-----------------------------------------------------------------------
407
    UnifiedHighLevelGpuProgramFactory::UnifiedHighLevelGpuProgramFactory()
408
1
    {
409
1
    }
410
    //-----------------------------------------------------------------------
411
    UnifiedHighLevelGpuProgramFactory::~UnifiedHighLevelGpuProgramFactory()
412
1
    {
413
1
    }
414
    //-----------------------------------------------------------------------
415
    const String& UnifiedHighLevelGpuProgramFactory::getLanguage(void) const
416
1
    {
417
1
        return sLanguage;
418
1
    }
419
    //-----------------------------------------------------------------------
420
    GpuProgram* UnifiedHighLevelGpuProgramFactory::create(ResourceManager* creator,
421
        const String& name, ResourceHandle handle,
422
        const String& group, bool isManual, ManualResourceLoader* loader)
423
0
    {
424
        return OGRE_NEW UnifiedHighLevelGpuProgram(creator, name, handle, group, isManual, loader);
425
0
    }
426
}
427