Coverage Report

Created: 2025-09-04 07:15

/src/ogre/OgreMain/include/OgreHighLevelGpuProgram.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef __HighLevelGpuProgram_H__
29
#define __HighLevelGpuProgram_H__
30
31
#include "OgrePrerequisites.h"
32
#include "OgreGpuProgram.h"
33
#include "OgreHeaderPrefix.h"
34
35
namespace Ogre {
36
37
    /** \addtogroup Core
38
    *  @{
39
    */
40
    /** \addtogroup Resources
41
    *  @{
42
    */
43
    /** Abstract base class representing a high-level program (a vertex or
44
        fragment program).
45
46
        High-level programs are vertex and fragment programs written in a high-level
47
        language such as Cg or HLSL, and as such do not require you to write assembler code
48
        like GpuProgram does. However, the high-level program does eventually 
49
        get converted (compiled) into assembler and then eventually microcode which is
50
        what runs on the GPU. As well as the convenience, some high-level languages like Cg allow
51
        you to write a program which will operate under both Direct3D and OpenGL, something
52
        which you cannot do with just GpuProgram (which requires you to write 2 programs and
53
        use each in a Technique to provide cross-API compatibility). Ogre will be creating
54
        a GpuProgram for you based on the high-level program, which is compiled specifically 
55
        for the API being used at the time, but this process is transparent.
56
    @par
57
        You cannot create high-level programs direct - use HighLevelGpuProgramManager instead.
58
        Plugins can register new implementations of HighLevelGpuProgramFactory in order to add
59
        support for new languages without requiring changes to the core Ogre API. To allow 
60
        custom parameters to be set, this class extends StringInterface - the application
61
        can query on the available custom parameters and get/set them without having to 
62
        link specifically with it.
63
    */
64
    class _OgreExport HighLevelGpuProgram : public GpuProgram
65
    {
66
    protected:
67
        /// Whether the high-level program (and it's parameter defs) is loaded
68
        bool mHighLevelLoaded;
69
        /// Have we built the name->index parameter map yet?
70
        bool mConstantDefsBuilt;
71
        /// The underlying assembler program
72
        GpuProgramPtr mAssemblerProgram;
73
        /// Preprocessor options
74
        String mPreprocessorDefines;
75
        /// Entry point for this program
76
        String mEntryPoint;
77
78
        /// in-situ parsing of defines
79
        static std::vector<std::pair<const char*, const char*>> parseDefines(String& defines);
80
81
        String appendBuiltinDefines(String defines);
82
83
        /// Internal load high-level portion if not loaded
84
        virtual void loadHighLevel(void);
85
        /// Internal unload high-level portion if loaded
86
        virtual void unloadHighLevel(void);
87
        /** Internal method for creating an appropriate low-level program from this
88
        high-level program, must be implemented by subclasses. */
89
        virtual void createLowLevelImpl(void) = 0;
90
        /// Internal unload implementation, must be implemented by subclasses
91
        virtual void unloadHighLevelImpl(void) = 0;
92
        /// Populate the passed parameters with name->index map
93
        void populateParameterNames(const GpuProgramParametersSharedPtr& params);
94
        /** Build the constant definition map, must be overridden.
95
        @note The implementation must fill in the (inherited) mConstantDefs field at a minimum, 
96
            and if the program requires that parameters are bound using logical 
97
            parameter indexes then the mLogicalToPhysical and mIntLogicalToPhysical
98
            maps must also be populated.
99
        */
100
        virtual void buildConstantDefinitions() = 0;
101
102
        /** @copydoc Resource::loadImpl */
103
        void loadImpl() override;
104
        /** @copydoc Resource::unloadImpl */
105
        void unloadImpl() override;
106
107
        void setupBaseParamDictionary() override;
108
    public:
109
        /** Constructor, should be used only by factory classes. */
110
        HighLevelGpuProgram(ResourceManager* creator, const String& name, ResourceHandle handle,
111
            const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
112
        ~HighLevelGpuProgram();
113
114
115
        /** Creates a new parameters object compatible with this program definition. 
116
117
            Unlike low-level assembly programs, parameters objects are specific to the
118
            program and therefore must be created from it rather than by the 
119
            HighLevelGpuProgramManager. This method creates a new instance of a parameters
120
            object containing the definition of the parameters this program understands.
121
        */
122
        GpuProgramParametersSharedPtr createParameters(void) override;
123
        /** @copydoc GpuProgram::_getBindingDelegate */
124
0
        GpuProgram* _getBindingDelegate(void) override { return mAssemblerProgram.get(); }
125
126
        /** Get the full list of GpuConstantDefinition instances.
127
        @note
128
        Only available if this parameters object has named parameters.
129
        */
130
        const GpuNamedConstants& getConstantDefinitions() override;
131
132
        size_t calculateSize(void) const override;
133
134
        /** Sets the preprocessor defines used to compile the program. */
135
0
        void setPreprocessorDefines(const String& defines) { mPreprocessorDefines = defines; }
136
        /** Gets the preprocessor defines used to compile the program. */
137
0
        const String& getPreprocessorDefines(void) const { return mPreprocessorDefines; }
138
139
        /** Sets the entry point for this program i.e, the first method called. */
140
0
        void setEntryPoint(const String& entryPoint) { mEntryPoint = entryPoint; }
141
        /** Gets the entry point defined for this program. */
142
0
        const String& getEntryPoint(void) const { return mEntryPoint; }
143
144
        /// Scan the source for \#include and replace with contents from OGRE resources
145
        static String _resolveIncludes(const String& source, Resource* resourceBeingLoaded, const String& fileName, bool supportsFilename = false);
146
    };
147
    /** @} */
148
    /** @} */
149
150
}
151
152
#include "OgreHeaderSuffix.h"
153
154
#endif