| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- //
- // Copyright (c) 2008-2017 the Urho3D project.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "../Container/Ptr.h"
- #include "../Container/RefCounted.h"
- #include "../Graphics/GraphicsDefs.h"
- #include "../Math/Color.h"
- #include "../Math/Vector4.h"
- namespace Atomic
- {
- class XMLElement;
- class XMLFile;
- // ATOMIC BEGIN
- class ScriptRenderPathCommand;
- // ATOMIC END
- /// Rendering path command types.
- enum RenderCommandType
- {
- CMD_NONE = 0,
- CMD_CLEAR,
- CMD_SCENEPASS,
- CMD_QUAD,
- CMD_FORWARDLIGHTS,
- CMD_LIGHTVOLUMES,
- CMD_RENDERUI,
- CMD_SENDEVENT
- };
- /// Rendering path sorting modes.
- enum RenderCommandSortMode
- {
- SORT_FRONTTOBACK = 0,
- SORT_BACKTOFRONT
- };
- /// Rendertarget size mode.
- enum RenderTargetSizeMode
- {
- SIZE_ABSOLUTE = 0,
- SIZE_VIEWPORTDIVISOR,
- SIZE_VIEWPORTMULTIPLIER
- };
- /// Rendertarget definition.
- struct ATOMIC_API RenderTargetInfo
- {
- /// Construct.
- RenderTargetInfo() :
- size_(Vector2::ZERO),
- sizeMode_(SIZE_ABSOLUTE),
- multiSample_(1),
- autoResolve_(true),
- enabled_(true),
- cubemap_(false),
- filtered_(false),
- sRGB_(false),
- persistent_(false)
- {
- }
- /// Read from an XML element.
- void Load(const XMLElement& element);
- /// Name.
- String name_;
- /// Tag name.
- String tag_;
- /// Texture format.
- unsigned format_;
- /// Absolute size or multiplier.
- Vector2 size_;
- /// Size mode.
- RenderTargetSizeMode sizeMode_;
- /// Multisampling level (1 = no multisampling).
- int multiSample_;
- /// Multisampling autoresolve flag.
- bool autoResolve_;
- /// Enabled flag.
- bool enabled_;
- /// Cube map flag.
- bool cubemap_;
- /// Filtering flag.
- bool filtered_;
- /// sRGB sampling/writing mode flag.
- bool sRGB_;
- /// Should be persistent and not shared/reused between other buffers of same size.
- bool persistent_;
- };
- /// Rendering path command.
- struct ATOMIC_API RenderPathCommand
- {
- /// Construct.
- RenderPathCommand() :
- clearFlags_(0),
- blendMode_(BLEND_REPLACE),
- enabled_(true),
- useFogColor_(false),
- markToStencil_(false),
- useLitBase_(true),
- vertexLights_(false)
- {
- }
- /// Read from an XML element.
- void Load(const XMLElement& element);
- /// Set a texture resource name. Can also refer to a rendertarget defined in the rendering path.
- void SetTextureName(TextureUnit unit, const String& name);
- /// Set a shader parameter.
- void SetShaderParameter(const String& name, const Variant& value);
- /// Remove a shader parameter.
- void RemoveShaderParameter(const String& name);
- /// Set number of output rendertargets.
- void SetNumOutputs(unsigned num);
- /// Set output rendertarget name and face index for cube maps.
- void SetOutput(unsigned index, const String& name, CubeMapFace face = FACE_POSITIVE_X);
- /// Set output rendertarget name.
- void SetOutputName(unsigned index, const String& name);
- /// Set output rendertarget face index for cube maps.
- void SetOutputFace(unsigned index, CubeMapFace face);
- /// Set depth-stencil output name. When empty, will assign a depth-stencil buffer automatically.
- void SetDepthStencilName(const String& name);
- /// Return texture resource name.
- const String& GetTextureName(TextureUnit unit) const;
- /// Return shader parameter.
- const Variant& GetShaderParameter(const String& name) const;
- /// Return number of output rendertargets.
- unsigned GetNumOutputs() const { return outputs_.Size(); }
- /// Return output rendertarget name.
- const String& GetOutputName(unsigned index) const;
- /// Return output rendertarget face index.
- CubeMapFace GetOutputFace(unsigned index) const;
- /// Return depth-stencil output name.
- const String& GetDepthStencilName() const { return depthStencilName_; }
- /// Tag name.
- String tag_;
- /// Command type.
- RenderCommandType type_;
- /// Sorting mode.
- RenderCommandSortMode sortMode_;
- /// Scene pass name.
- String pass_;
- /// Scene pass index. Filled by View.
- unsigned passIndex_;
- /// Command/pass metadata.
- String metadata_;
- /// Vertex shader name.
- String vertexShaderName_;
- /// Pixel shader name.
- String pixelShaderName_;
- /// Vertex shader defines.
- String vertexShaderDefines_;
- /// Pixel shader defines.
- String pixelShaderDefines_;
- /// Textures.
- String textureNames_[MAX_TEXTURE_UNITS];
- /// %Shader parameters.
- HashMap<StringHash, Variant> shaderParameters_;
- /// Output rendertarget names and faces.
- Vector<Pair<String, CubeMapFace> > outputs_;
- /// Depth-stencil output name.
- String depthStencilName_;
- /// Clear flags. Affects clear command only.
- unsigned clearFlags_;
- /// Clear color. Affects clear command only.
- Color clearColor_;
- /// Clear depth. Affects clear command only.
- float clearDepth_;
- /// Clear stencil value. Affects clear command only.
- unsigned clearStencil_;
- /// Blend mode. Affects quad command only.
- BlendMode blendMode_;
- /// Enabled flag.
- bool enabled_;
- /// Use fog color for clearing.
- bool useFogColor_;
- /// Mark to stencil flag.
- bool markToStencil_;
- /// Use lit base pass optimization for forward per-pixel lights.
- bool useLitBase_;
- /// Vertex lights flag.
- bool vertexLights_;
- /// Event name.
- String eventName_;
- };
- /// Rendering path definition. A sequence of commands (e.g. clear screen, draw objects with specific pass) that yields the scene rendering result.
- class ATOMIC_API RenderPath : public RefCounted
- {
- ATOMIC_REFCOUNTED(RenderPath)
- public:
- /// Construct.
- RenderPath();
- /// Destruct.
- ~RenderPath();
- /// Clone the rendering path.
- SharedPtr<RenderPath> Clone();
- /// Clear existing data and load from an XML file. Return true if successful.
- bool Load(XMLFile* file);
- /// Append data from an XML file. Return true if successful.
- bool Append(XMLFile* file);
- /// Enable/disable commands and rendertargets by tag.
- void SetEnabled(const String& tag, bool active);
- /// Toggle enabled state of commands and rendertargets by tag.
- void ToggleEnabled(const String& tag);
- /// Assign rendertarget at index.
- void SetRenderTarget(unsigned index, const RenderTargetInfo& info);
- /// Add a rendertarget.
- void AddRenderTarget(const RenderTargetInfo& info);
- /// Remove a rendertarget by index.
- void RemoveRenderTarget(unsigned index);
- /// Remove a rendertarget by name.
- void RemoveRenderTarget(const String& name);
- /// Remove rendertargets by tag name.
- void RemoveRenderTargets(const String& tag);
- /// Assign command at index.
- void SetCommand(unsigned index, const RenderPathCommand& command);
- /// Add a command to the end of the list.
- void AddCommand(const RenderPathCommand& command);
- /// Insert a command at a position.
- void InsertCommand(unsigned index, const RenderPathCommand& command);
- /// Remove a command by index.
- void RemoveCommand(unsigned index);
- /// Remove commands by tag name.
- void RemoveCommands(const String& tag);
- /// Set a shader parameter in all commands that define it.
- void SetShaderParameter(const String& name, const Variant& value);
- /// Return number of rendertargets.
- unsigned GetNumRenderTargets() const { return renderTargets_.Size(); }
- /// Return number of commands.
- unsigned GetNumCommands() const { return commands_.Size(); }
- /// Return command at index, or null if does not exist.
- RenderPathCommand* GetCommand(unsigned index) { return index < commands_.Size() ? &commands_[index] : (RenderPathCommand*)0; }
- /// Return a shader parameter (first appearance in any command.)
- const Variant& GetShaderParameter(const String& name) const;
- /// Rendertargets.
- Vector<RenderTargetInfo> renderTargets_;
- /// Rendering commands.
- Vector<RenderPathCommand> commands_;
- // ATOMIC BEGIN
- /// Gets the render command at specified index, note SetCommand must be called to update the RenderPath with any changes
- bool GetCommand(unsigned index, ScriptRenderPathCommand* dst);
- /// Sets the render command at specified index
- bool SetCommand(unsigned index, ScriptRenderPathCommand* src);
- // ATOMIC END
- };
- }
|