Explorar el Código

More work on the manuals

BearishSun hace 9 años
padre
commit
2d2282d7b4

+ 82 - 0
Documentation/Manuals/Native/gpuPrograms.md

@@ -0,0 +1,82 @@
+GPU programs									{#gpuPrograms}
+===============
+[TOC]
+
+GPU programs are programmable parts of the GPU pipeline, in other literature often called shaders (Banshee uses the word shader for a higher level concept, see the [material](@ref materials) manual).
+
+GPU programs in Banshee are represented with the @ref BansheeEngine::GpuProgram "GpuProgram" and @ref BansheeEngine::GpuProgramCore "GpuProgramCore" classes. Both of these provide almost equivalent functionality, but the former is for use on the simulation thread, and the latter is for use on the core thread. If you are confused by the dual nature of the objects, read the [core thread](@ref coreThread) manual. 
+
+In this manual we will focus on the simulation thread implementation, and then note the differences in the core thread version at the end.
+
+There are six types of GPU programs: vertex, hull (tesselation control), geometry, domain (tesselation evaluation), fragment (pixel) and compute programs. Each is used for a different purpose but has the same interface. We assume the user is familiar with the GPU pipeline and what the different programs types do. 
+
+Although GPU programs can be used on their own (which we will cover in this manual), they are more commonly used as parts of @ref BansheeEngine::Shader "Shaders". Read the [material](@ref materials) manual for more information.
+
+# Creating GPU programs {#gpuPrograms_a}
+To create a GPU program call @ref BansheeEngine::GpuProgram::create() "GpuProgram::create". This method expects the following parameters:
+ - Source code of the GPU program. This should be in a language supported by the current render API (e.g. HLSL for DirectX, GLSL for OpenGL).
+ - Name of the entry point into the GPU program. This is the name of the function that will be called when the program is ran. Must be "main" for OpenGL.
+ - Language the source code is written in. This can be "hlsl" or "glsl" by default, but more languages can be added by extensions.
+ - @ref BansheeEngine::GpuProgramType "Type" of the GPU program (vertex, fragment, etc.).
+ - @ref BansheeEngine::GpuProgramProfile "Profile" of the GPU program. Determines what functionality does the underyling hardware support. Nowadays it is safe to always set this to profile 5.0 unless creating programs for very old hardware.
+ 
+For example if we wanted to create a HLSL fragment program (HLSL source not shown):
+~~~~~~~~~~~~~{.cpp}
+String hlslSource = "...";
+
+SPtr<GpuProgram> myProgram = GpuProgram::create(hlslSource, "main", "hlsl", GPT_FRAGMENT_PROGRAM, GPP_FS_5_0);
+~~~~~~~~~~~~~ 
+ 
+Once the GPU program has been created it is not guaranteed to be usable. The compilation of the provided source code could have failed, which you can check by calling @ref BansheeEngine::GpuProgram::isCompiled() "GpuProgram::isCompiled", and retrieve the error message by calling @ref BansheeEngine::GpuProgram::getCompileErrorMessage() "GpuProgram::getCompileErrorMessage". Be aware that both of these methods are only valid after the core thread has initialized the object. You can ensure this by calling @ref BansheeEngine::CoreObject::blockUntilCoreInitialized "GpuProgram::blockUntilCoreInitialized" but be aware this will block the calling thread which can result in a significant performance impact.
+
+# GPU program parameters {#gpuPrograms_b}
+Once the GPU program has been compiled you can access information about its parameters (constant variables, or uniforms in DirectX/OpenGL lingo). Use @ref BansheeEngine::GpuProgram::getParamDesc "GpuProgram::getParamDesc" to retrieve a structure containing all GPU parameters, including primitive parameters, textures, samplers, buffers and parameter buffers (constant/uniform buffers in DirectX/OpenGL lingo). You can use this information to manually bind parameters to the GPU program, but normally you do not have to.
+
+Instead @ref BansheeEngine::GpuProgram::createParameters "GpuProgram::createParameters()" will create a @ref BansheeEngine::GpuParams "GpuParams" object which allows you to query information about all parameters, but more importantly it also allows you to set values of those parameters easily.
+
+## GpuParams {#gpuPrograms_b_a}
+@ref BansheeEngine::GpuParams "GpuParams" is a container for all parameters required by a GPU program. It allows you to set primitive/texture/sampler/buffer parameters used by the GPU program, which it stores in an internal buffer. You can then bind it to the pipeline and it will be used by the program.
+
+For example to assign a texture and a 2D vector as input to the program we created earlier:
+~~~~~~~~~~~~~{.cpp}
+GpuParamsPtr params = myProgram->createParameters();
+
+// Retrieve GPU params we can then read/write to
+GpuParamVec2 myVectorParam;
+GpuParamTexture myTextureParam;
+
+params->getParam("myVector", myVectorParam); // Assuming "myVector" is the variable name in the program source code
+params->getTextureParam("myTexture", myTextureParam); // Assuming "myTexture" is the variable name in the program source code
+
+myVectorParam.set(Vector2(1, 2));
+myTextureParam.set(myTexture); // Assuming we created "myTexture" earlier.
+~~~~~~~~~~~~~
+
+As you can see we must first retrieve a handle to the parameter, and then we can use that handle for reading/writing to the parameter. You can store those handles for easier access to the parameters, as looking them up by using the parameter name can be relatively slow.
+
+# Using GPU programs for rendering {#gpuPrograms_c}
+You can bind a GPU program to the pipeline by calling @ref BansheeEngine::RenderAPI::bindGpuProgram "RenderAPI::bindGpuProgram". Any draw calls following this bind will use the bound GPU program. You can unbind a program by calling @ref BansheeEngine::RenderAPI::unbindGpuProgram "RenderAPI::unbindGpuProgram".
+
+You can bind parameters by calling @ref BansheeEngine::RenderAPI::setGpuParams "RenderAPI::setGpuParams" and providing them with the GPU program type and a @ref BansheeEngine::GpuParams "GpuParams" object which you previously populated with parameter values.
+
+Optionally you can also call @ref BansheeEngine::RenderAPI::setConstantBuffers "RenderAPI::setConstantBuffers" using the same parameters, which will only set the primitive parameters (vectors, floats, etc.) but not textures/samplers/buffers. Sometimes this is useful if you want to set textures/samplers/buffers manually.
+
+To learn more about the render API read the [manual](@ref renderAPI).
+
+# Core thread GPU programs {#gpuPrograms_e}
+So far we have only talked about the simulation thread @ref BansheeEngine::GpuProgram "GpuProgram" but have ignored the core thread @ref BansheeEngine::GpuProgramCore "GpuProgramCore". The functionality between the two is mostly the same, with the major difference being that operations performed on the core thread version are immediate. So calls to @ref BansheeEngine::GpuProgramCore::isCompiled() "GpuProgramCore::isCompiled" and @ref BansheeEngine::GpuProgramCore::getCompileErrorMessage() "GpuProgramCore::getCompileErrorMessage" don't require any waiting.
+
+Addtionally the core thread object can provide information about vertex input declaration. Vertex input declaration is only available for vertex shaders, and it defines in what format does the GPU program expect vertices to be in. This can be useful for setting up your meshes in the valid format. Use @ref BansheeEngine::GpuProgramCore::getInputDeclaration "GpuProgramCore::getInputDeclaration" to retrieve the @ref BansheeEngine::VertexDeclarationCore "VertexDeclaration". Check out the [mesh](@ref meshes) manual for more information on how to use vertex declarations.
+
+# OpenGL specifics {#gpuPrograms_f}
+When creating vertex inputs for a GPU program written in GLSL a set of built-in variables are provided:
+ - bs_position - Vertex position
+ - bs_normal - Vertex normal
+ - bs_tangent - Vertex tangent
+ - bs_bitangent - Vertex bitangent
+ - bs_texcoord - Vertex UV
+ - bs_color - Vertex color
+ - bs_blendweights - Blend weights used for skinning
+ - bs_blendindices - Blend indices used for skinning
+ 
+You can append 0-8 to the names to receive more than one element of the same name. For HLSL the standard HLSL semantics are used instead. Actual types of these elements, as well as the data stored by them doesn't need to match the names and it's up to the user to provide whatever data he needs.

+ 1 - 1
Documentation/Manuals/Native/import.md

@@ -2,7 +2,7 @@ Creating custom importers						{#customImporters}
 ===============
 ===============
 [TOC]
 [TOC]
 
 
-Importers process a raw resource in a third-party format (like FBX mesh or a PNG image) into an engine-ready format (e.g. a @ref BansheeEngine::Mesh "Mesh" or a @ref BansheeEngine::Texture "Texture"). Banshee has an extensible importer system so you may easily add your own, either for existing resource types, or for new ones. If you are also interested in creating new resource types check out [this manual](@ref customResources).
+Importers process a raw resource in a third-party format (like FBX mesh or a PNG image) into an engine-ready format (e.g. a @ref BansheeEngine::Mesh "Mesh" or a @ref BansheeEngine::Texture "Texture"). Banshee has an extensible importer system so you may easily add your own, either for existing resource types, or for new ones. If you are also interested in creating new resource types check out [this manual](@ref resources).
 
 
 On the user-facing level resource import works through the @ref BansheeEngine::Importer "Importer" module. You call its @ref BansheeEngine::Importer::import "Importer::import" method which takes a path to the resource you want to import, and the system automatically finds the necessary importer plugin (if one is available) and returns the resource in an engine ready format. Optionally you can also supply the importer with @ref BansheeEngine::ImportOptions "ImportOptions" to control resource import in more detail.
 On the user-facing level resource import works through the @ref BansheeEngine::Importer "Importer" module. You call its @ref BansheeEngine::Importer::import "Importer::import" method which takes a path to the resource you want to import, and the system automatically finds the necessary importer plugin (if one is available) and returns the resource in an engine ready format. Optionally you can also supply the importer with @ref BansheeEngine::ImportOptions "ImportOptions" to control resource import in more detail.
 
 

+ 4 - 1
Documentation/Manuals/Native/manuals.md

@@ -11,8 +11,8 @@ Name                                      | Description
 [Custom GUI elements](@ref customGUI)     | Shows you how to create custom GUI elements, manually render text or modify GUI system in a general way.
 [Custom GUI elements](@ref customGUI)     | Shows you how to create custom GUI elements, manually render text or modify GUI system in a general way.
 [Custom importers](@ref customImporters)  | Shows you how to create importers that handle conversion of third party resources into engine ready formats.
 [Custom importers](@ref customImporters)  | Shows you how to create importers that handle conversion of third party resources into engine ready formats.
 [Custom plugins](@ref customPlugins)      | Shows you how to create custom plugins that can be loaded by Banshee.
 [Custom plugins](@ref customPlugins)      | Shows you how to create custom plugins that can be loaded by Banshee.
-[Custom resources](@ref customResources)  | Shows you how to create brand new resource types.
 [Custom renderer](@ref customRenderer)    | Shows you how to create a custom renderer so you may fully customize the look of your application.
 [Custom renderer](@ref customRenderer)    | Shows you how to create a custom renderer so you may fully customize the look of your application.
+[Resources](@ref resources)  			  | Explains how resources work, including saving, loading and creating brand new resource types.
 [Core thread](@ref coreThread)            | Explains how core (rendering) thread works, how it interacts with simulation thread, what are core objects and how to create your own.
 [Core thread](@ref coreThread)            | Explains how core (rendering) thread works, how it interacts with simulation thread, what are core objects and how to create your own.
 [Game objects](@ref gameObjects)          | Explains what are scene objects and components and how can you use them to create your scene.
 [Game objects](@ref gameObjects)          | Explains what are scene objects and components and how can you use them to create your scene.
 [RTTI](@ref rtti)                         | Shows you how to add run-time type information for your objects.
 [RTTI](@ref rtti)                         | Shows you how to add run-time type information for your objects.
@@ -20,6 +20,9 @@ Name                                      | Description
 [Render API](@ref renderAPI)              | Explains how to use the render API to use the graphics pipeline and draw objects. 
 [Render API](@ref renderAPI)              | Explains how to use the render API to use the graphics pipeline and draw objects. 
 [Textures](@ref textures)                 | Shows you how to create, use and manipulate textures.
 [Textures](@ref textures)                 | Shows you how to create, use and manipulate textures.
 [Meshes](@ref meshes)                     | Shows you how to create, use and manipulate meshes.
 [Meshes](@ref meshes)                     | Shows you how to create, use and manipulate meshes.
+[Render targets](@ref renderTargets)	  | Shows you how to create and use render textures and windows.
+[GPU programs](@ref gpuPrograms)		  | Shows you how to create and use GPU programs.
+[Materials](@ref materials)				  | Shows you how to create and use materials and shaders.
 [Utilities](@ref utilities)               | Provides an overview of a variety of utility systems used throughout Banshee.
 [Utilities](@ref utilities)               | Provides an overview of a variety of utility systems used throughout Banshee.
 [Quick reference](@ref quickref)          | Provides a few bits of commonly required information, that might be hard to remember otherwise.
 [Quick reference](@ref quickref)          | Provides a few bits of commonly required information, that might be hard to remember otherwise.
 [Porting](@ref porting)                   | Information about how to go on about porting Banshee to a different operating system.
 [Porting](@ref porting)                   | Information about how to go on about porting Banshee to a different operating system.

+ 57 - 0
Documentation/Manuals/Native/textures.md

@@ -0,0 +1,57 @@
+Textures									{#textures}
+===============
+[TOC]
+
+Textures in Banshee are represented with the @ref BansheeEngine::Texture "Texture" and @ref BansheeEngine::TextureCore "TextureCore" classes. Both of these provide almost equivalent functionality, but the former is for use on the simulation thread, and the latter is for use on the core thread. If you are confused by the dual nature of the objects, read the [core thread](@ref coreThread) manual. 
+
+We're going to focus on the simulation thread implementation in this manual, and then note the differences in the core thread version at the end.
+
+# Creating a texture {#textures_a}
+To create a texture call @ref BansheeEngine::Texture::create "create" or one if its overloads. At minimum you need to provide a @ref BansheeEngine::TextureType "texture type", dimensions and @ref BansheeEngine::PixelFormat "pixel format". The dimensions range from one to three dimensional depending on the texture type.
+
+Optionally you can also provide the number of mipmaps, number of samples, usage flags and a gamma correction flag:
+ - A texture with mip-maps will contain a set of scaled down versions of itself that are used by the GPU for special filtering. 
+ - A texture with more than one sample can be used only for rendering (see the [render targets](@ref renderTargets) manual), and is useful for antialiasing.
+ - @ref BansheeEngine::TextureUsage "Usage flags" specify how is the texture allowed to be used.
+ - Gamma correction flag specifies if the data in the texture has been gamma corrected. If enabled the GPU will transform the texture data back to linear space when it is accessing it. If the texture is already in linear space, or you do not need it to be in linear space you can leave this off.
+ 
+For example:
+~~~~~~~~~~~~~{.cpp}
+// Creates a 2D texture, 128x128 with an 8-bit RGBA format
+HTexture texture = Texture::create(TEX_TYPE_2D, 128, 128, 0, PF_R8G8B8A8);
+~~~~~~~~~~~~~ 
+ 
+# Accessing properties {#textures_b} 
+You can access all relevant texture properties by calling @ref BansheeEngine::Texture::getProperties() "Texture::getProperties()" which will return an instance of @ref BansheeEngine::TextureProperties "TextureProperties" which contains all the information about the texture, as well as some useful methods (as we'll see in the next section).
+ 
+# Reading/writing {#textures_c}
+To read and write to the texture use the @ref BansheeEngine::Texture::readSubresource "Texture::readSubresource" and @ref BansheeEngine::Texture::writeSubresource "Texture::writeSubresource" methods. These expect an index of a sub-resource to read/write to, and a @ref BansheeEngine::PixelData "PixelData" object.
+
+The sub-resource index is simply a sequential index of the surface you want to access. If the texture has only one surface this will always be zero. But if the texture has multiple mipmaps or multiple faces (like for cube textures or texture arrays) you can use @ref BansheeEngine::TextureProperties::mapToSubresourceIdx "TextureProperties::mapToSubresourceIdx" to convert mip/face combination into an subresource index, and @ref BansheeEngine::TextureProperties::mapFromSubresourceIdx "TextureProperties::mapFromSubresourceIdx" for the other way around.
+
+@ref BansheeEngine::PixelData "PixelData" object is just a container for a set of pixels. You can create one manually or use @ref BansheeEngine::TextureProperties::allocateSubresourceBuffer "TextureProperties::allocateSubresourceBuffer" to create the object of valid size and format for the specified sub-resource index. When reading from the texture the buffer will be filled with pixels from the texture, and when writing you are expected to populate the object.
+
+## PixelData {#textures_c_a}
+You can create @ref BansheeEngine::PixelData "PixelData" manually by calling @ref BansheeEngine::PixelData::create "PixelData::create" and providing it with dimensions and pixel format. When working with textures you must ensure that the dimensions and the format matches the texture sub-resource.
+
+Once created you can use @ref BansheeEngine::PixelData::getColorAt "PixelData::getColorAt", @ref BansheeEngine::PixelData::setColorAt "PixelData::setColorAt", @ref BansheeEngine::PixelData::getColors "PixelData::getColors" and @ref BansheeEngine::PixelData::setColors "PixelData::setColors" to read/write colors from/to its internal buffer.
+
+You can also use @ref BansheeEngine::PixelUtil "PixelUtil" to perform various operations on the pixels. This includes generating mip maps, converting to different pixel formats, compressing, scaling and other.
+
+## Cached CPU data {#textures_c_b}
+When you read from a texture using the @ref BansheeEngine::Texture::readSubresource "Texture::readSubresource" method the read will be performed from the GPU. This is useful if the GPU has in some way modified the texture, but will also incur a potentially large performance penalty because it will introduce a CPU-GPU synchronization point. In a lot of cases you might just want to read pixels from a texture that was imported or created on the CPU in some other way.
+
+For this reason @ref BansheeEngine::Texture::readData "Texture::readData" exists. It will read data quickly with little performance impact. However you must create the texture using the @ref BansheeEngine::TU_CPUCACHED usage. This also means that the texture will keep a copy of its pixels in system memory, so use it sparingly. If the texture is modified from the GPU this method will not reflect such changes.
+
+# Rendering using the texture {#textures_d}
+To use a texture for rendering you can either bind it to the @ref BansheeEngine::RenderAPI::setTexture "RenderAPI::setTexture" directly, or assign it to a @ref BansheeEngine::Material "Material" which will then be used on a @ref BansheeEngine::Renderable "Renderable" or a similar object. To learn more about this check out the [render API](@ref renderAPI) and [material](@ref materials) manuals.
+
+# Saving/loading {#textures_e}
+A texture is a @ref BansheeEngine::Resource "Resource" and can be saved/loaded like any other. See the [resource](@ref resources) manual.
+
+# Core thread textures {#textures_f}
+So far we have only talked about the simulation thread @ref BansheeEngine::Texture "Texture" but have ignored the core thread @ref BansheeEngine::TextureCore "TextureCore". The functionality between the two is mostly the same, with the major difference being that the core thread version doesn't require a @ref BansheeEngine::CoreThreadAccessor "CoreAccessor" for access, and you can instead perform operations on it directly.
+
+You can also use @ref BansheeEngine::TextureCore::lock "TextureCore::lock" and @ref BansheeEngine::TextureCore::unlock "TextureCore::unlock" to get access to the texture buffer, which allows you to only read/write from/to portions of it, instead of always writing to the entire buffer.
+
+And finally @ref BansheeEngine::TextureCore::copy "TextureCore::copy" method can be used for quickly copying a contents of one texture to another texture. This method will also resolve multi-sampled surface in the case the source is multi-sampled but the destination is not.

+ 34 - 34
Source/BansheeCore/Include/BsGpuProgram.h

@@ -15,45 +15,45 @@ namespace BansheeEngine
 	/** Types of programs that may run on GPU. */
 	/** Types of programs that may run on GPU. */
 	enum GpuProgramType
 	enum GpuProgramType
 	{
 	{
-		GPT_VERTEX_PROGRAM,
-		GPT_FRAGMENT_PROGRAM,
-		GPT_GEOMETRY_PROGRAM,
-		GPT_DOMAIN_PROGRAM,
-		GPT_HULL_PROGRAM,
-		GPT_COMPUTE_PROGRAM
+		GPT_VERTEX_PROGRAM, /**< Vertex program. */
+		GPT_FRAGMENT_PROGRAM, /**< Fragment(pixel) program. */
+		GPT_GEOMETRY_PROGRAM, /**< Geometry program. */
+		GPT_DOMAIN_PROGRAM, /**< Domain (tesselation evaluation) program. */
+		GPT_HULL_PROGRAM, /**< Hull (tesselation control) program. */
+		GPT_COMPUTE_PROGRAM /**< Compute program. */
 	};
 	};
 
 
 	/**	GPU program profiles representing supported feature sets. */
 	/**	GPU program profiles representing supported feature sets. */
 	enum GpuProgramProfile
 	enum GpuProgramProfile
 	{
 	{
-		GPP_NONE,
-		GPP_FS_1_1,
-		GPP_FS_1_2,
-		GPP_FS_1_3,
-		GPP_FS_1_4,
-		GPP_FS_2_0,
-		GPP_FS_2_x,
-		GPP_FS_2_a,
-		GPP_FS_2_b,
-		GPP_FS_3_0,
-		GPP_FS_3_x,
-		GPP_FS_4_0,
-		GPP_FS_4_1,
-		GPP_FS_5_0,
-		GPP_VS_1_1,
-		GPP_VS_2_0,
-		GPP_VS_2_x,
-		GPP_VS_2_a,
-		GPP_VS_3_0,
-		GPP_VS_4_0,
-		GPP_VS_4_1,
-		GPP_VS_5_0,
-		GPP_GS_4_0,
-		GPP_GS_4_1,
-		GPP_GS_5_0,
-		GPP_HS_5_0,
-		GPP_DS_5_0,
-		GPP_CS_5_0
+		GPP_NONE, /**< No profile. */
+		GPP_FS_1_1, /**< Fragment program 1.1 profile. */
+		GPP_FS_1_2, /**< Fragment program 1.2 profile. */
+		GPP_FS_1_3, /**< Fragment program 1.3 profile. */
+		GPP_FS_1_4, /**< Fragment program 1.4 profile. */
+		GPP_FS_2_0, /**< Fragment program 2.0 profile. */
+		GPP_FS_2_x, /**< Fragment program 2.x profile. */
+		GPP_FS_2_a, /**< Fragment program 2.a profile. */
+		GPP_FS_2_b, /**< Fragment program 2.b profile. */
+		GPP_FS_3_0, /**< Fragment program 3.0 profile. */
+		GPP_FS_3_x, /**< Fragment program 3.x profile. */
+		GPP_FS_4_0, /**< Fragment program 4.0 profile. */
+		GPP_FS_4_1, /**< Fragment program 4.1 profile. */
+		GPP_FS_5_0, /**< Fragment program 5.0 profile. */
+		GPP_VS_1_1, /**< Vertex program 1.1 profile. */
+		GPP_VS_2_0, /**< Vertex program 2.0 profile. */
+		GPP_VS_2_x, /**< Vertex program 2.x profile. */
+		GPP_VS_2_a, /**< Vertex program 2.a profile. */
+		GPP_VS_3_0, /**< Vertex program 3.0 profile. */
+		GPP_VS_4_0, /**< Vertex program 4.0 profile. */
+		GPP_VS_4_1, /**< Vertex program 4.1 profile. */
+		GPP_VS_5_0, /**< Vertex program 5.0 profile. */
+		GPP_GS_4_0, /**< Geometry program 4.0 profile. */
+		GPP_GS_4_1, /**< Geometry program 4.1 profile. */
+		GPP_GS_5_0, /**< Geometry program 5.0 profile. */
+		GPP_HS_5_0, /**< Hull program 5.0 profile. */
+		GPP_DS_5_0, /**< Domain program 5.0 profile. */
+		GPP_CS_5_0 /**< Compute program 5.0 profile. */
 	};
 	};
 
 
 	/** Data describing a GpuProgram. */
 	/** Data describing a GpuProgram. */

+ 3 - 6
Source/BansheeCore/Include/BsPixelData.h

@@ -160,12 +160,9 @@ namespace BansheeEngine
 	 * A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession 
 	 * A buffer describing a volume (3D), image (2D) or line (1D) of pixels in memory. Pixels are stored as a succession 
 	 * of "depth" slices, each containing "height" rows of "width" pixels.
 	 * of "depth" slices, each containing "height" rows of "width" pixels.
 	 *
 	 *
-	 * As any GpuResourceData this is used primarily for reading and writing from/to a GPU resource, and is normally 
-	 * constructed by the resource itself. However you may still construct it manually and use it for other purposes if 
-	 * needed.
-	 *
-	 * @note	
-	 * You must call allocateInternalBuffer or set the buffer in some other way before reading/writing from this object.
+	 * @note
+	 * If using the constructor instead of create() you must call GpuResourceData::allocateInternalBuffer or set the buffer
+	 * in some other way before reading/writing from this object, as by the default there is no buffer allocated.
 	 *
 	 *
 	 * @see		GpuResourceData
 	 * @see		GpuResourceData
 	 */
 	 */

+ 17 - 0
Source/BansheeCore/Include/BsTexture.h

@@ -425,6 +425,23 @@ namespace BansheeEngine
 		/**	Returns properties that contain information about the texture. */
 		/**	Returns properties that contain information about the texture. */
 		const TextureProperties& getProperties() const { return mProperties; }
 		const TextureProperties& getProperties() const { return mProperties; }
 
 
+		/************************************************************************/
+		/* 								STATICS		                     		*/
+		/************************************************************************/
+
+		/** @copydoc Texture::create(TextureType, UINT32, UINT32, UINT32, int, PixelFormat, int, bool, UINT32) */
+		static SPtr<TextureCore> create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+			int numMips, PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
+
+		/** @copydoc Texture::create(TextureType, UINT32, UINT32, int, PixelFormat, int, bool, UINT32) */
+		static SPtr<TextureCore> create(TextureType texType, UINT32 width, UINT32 height, int numMips,
+			PixelFormat format, int usage = TU_DEFAULT,
+			bool hwGammaCorrection = false, UINT32 multisampleCount = 0);
+
+		/** @copydoc Texture::create(const PixelDataPtr&, int, bool) */
+		static SPtr<TextureCore> create(const PixelDataPtr& pixelData, int usage = TU_DEFAULT, bool hwGammaCorrection = false);
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								TEXTURE VIEW                      		*/
 		/* 								TEXTURE VIEW                      		*/
 		/************************************************************************/
 		/************************************************************************/

+ 1 - 0
Source/BansheeCore/Include/BsTextureManager.h

@@ -124,6 +124,7 @@ namespace BansheeEngine
 
 
 	protected:
 	protected:
 		friend class Texture;
 		friend class Texture;
+		friend class TextureCore;
 		friend class RenderTexture;
 		friend class RenderTexture;
 		friend class MultiRenderTexture;
 		friend class MultiRenderTexture;
 
 

+ 24 - 0
Source/BansheeCore/Source/BsTexture.cpp

@@ -283,6 +283,30 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	/************************************************************************/
+	/* 								STATICS	                      			*/
+	/************************************************************************/
+	SPtr<TextureCore> TextureCore::create(TextureType texType, UINT32 width, UINT32 height, UINT32 depth,
+		int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount)
+	{
+		return TextureCoreManager::instance().createTexture(texType,
+			width, height, depth, numMips, format, usage, hwGammaCorrection, multisampleCount);
+	}
+
+	SPtr<TextureCore> TextureCore::create(TextureType texType, UINT32 width, UINT32 height,
+		int numMips, PixelFormat format, int usage, bool hwGammaCorrection, UINT32 multisampleCount)
+	{
+		return TextureCoreManager::instance().createTexture(texType,
+			width, height, 1, numMips, format, usage, hwGammaCorrection, multisampleCount);
+	}
+
+	SPtr<TextureCore> TextureCore::create(const PixelDataPtr& pixelData, int usage, bool hwGammaCorrection)
+	{
+		return TextureCoreManager::instance().createTextureInternal(pixelData->getDepth() > 1 ? TEX_TYPE_3D : TEX_TYPE_2D, 
+			pixelData->getWidth(), pixelData->getHeight(),
+			pixelData->getDepth(), 0, pixelData->getFormat(), usage, hwGammaCorrection, 0, pixelData);
+	}
+
 	Texture::Texture()
 	Texture::Texture()
 	{
 	{
 
 

+ 18 - 2
Source/RenderBeast/Include/BsPostProcessing.h

@@ -5,6 +5,7 @@
 #include "BsRenderBeastPrerequisites.h"
 #include "BsRenderBeastPrerequisites.h"
 #include "BsRendererMaterial.h"
 #include "BsRendererMaterial.h"
 #include "BsParamBlocks.h"
 #include "BsParamBlocks.h"
+#include "BsRenderTexturePool.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -28,6 +29,16 @@ namespace BansheeEngine
 		float histogramLog2Max = 4.0f;
 		float histogramLog2Max = 4.0f;
 	};
 	};
 
 
+	/** Contains per-camera data used by post process effects. */
+	struct PostProcessInfo
+	{
+		PostProcessSettings settings;
+
+		SPtr<PooledRenderTexture> downsampledSceneTex;
+		SPtr<PooledRenderTexture> histogramTex;
+		SPtr<PooledRenderTexture> eyeAdaptationTex;
+	};
+
 	BS_PARAM_BLOCK_BEGIN(DownsampleParams)
 	BS_PARAM_BLOCK_BEGIN(DownsampleParams)
 		BS_PARAM_BLOCK_ENTRY(Vector2, gInvTexSize)
 		BS_PARAM_BLOCK_ENTRY(Vector2, gInvTexSize)
 	BS_PARAM_BLOCK_END
 	BS_PARAM_BLOCK_END
@@ -42,10 +53,15 @@ namespace BansheeEngine
 
 
 		/** Updates the parameter buffers used by the material. */
 		/** Updates the parameter buffers used by the material. */
 		void setParameters(const SPtr<RenderTextureCore>& target);
 		void setParameters(const SPtr<RenderTextureCore>& target);
+
+		/** Renders the post-process effect on the provided target. */
+		void render(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo);
 	private:
 	private:
 		DownsampleParams mParams;
 		DownsampleParams mParams;
 		MaterialParamVec2Core mInvTexSize;
 		MaterialParamVec2Core mInvTexSize;
 		MaterialParamTextureCore mInputTexture;
 		MaterialParamTextureCore mInputTexture;
+
+		POOLED_RENDER_TEXTURE_DESC mOutputDesc;
 	};
 	};
 
 
 	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramParams)
 	BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramParams)
@@ -63,7 +79,7 @@ namespace BansheeEngine
 		EyeAdaptHistogramMat();
 		EyeAdaptHistogramMat();
 
 
 		/** Updates the parameter buffers used by the material. */
 		/** Updates the parameter buffers used by the material. */
-		void setParameters(const SPtr<RenderTextureCore>& target, const PostProcessSettings& settings);
+		void setParameters(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo);
 	private:
 	private:
 		EyeAdaptHistogramParams mParams;
 		EyeAdaptHistogramParams mParams;
 		MaterialParamTextureCore mSceneColor;
 		MaterialParamTextureCore mSceneColor;
@@ -84,7 +100,7 @@ namespace BansheeEngine
 	{
 	{
 	public:
 	public:
 		/** Renders post-processing effects for the provided render target. */
 		/** Renders post-processing effects for the provided render target. */
-		static void postProcess(const SPtr<RenderTextureCore>& target, const PostProcessSettings& settings);
+		static void postProcess(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo);
 		
 		
 	private:
 	private:
 	};
 	};

+ 2 - 0
Source/RenderBeast/Include/BsRenderBeast.h

@@ -9,6 +9,7 @@
 #include "BsSamplerOverrides.h"
 #include "BsSamplerOverrides.h"
 #include "BsRendererMaterial.h"
 #include "BsRendererMaterial.h"
 #include "BsLightRendering.h"
 #include "BsLightRendering.h"
+#include "BsPostProcessing.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
@@ -99,6 +100,7 @@ namespace BansheeEngine
 			RenderQueuePtr transparentQueue;
 			RenderQueuePtr transparentQueue;
 
 
 			SPtr<RenderTargets> target;
 			SPtr<RenderTargets> target;
+			PostProcessInfo postProcessInfo;
 		};
 		};
 
 
 		/**	Data used by the renderer for lights. */
 		/**	Data used by the renderer for lights. */

+ 3 - 0
Source/RenderBeast/Include/BsRenderTargets.h

@@ -53,6 +53,9 @@ namespace BansheeEngine
 		/**	Resolves the GBuffer scene color into the output scene color buffer. */
 		/**	Resolves the GBuffer scene color into the output scene color buffer. */
 		void resolve();
 		void resolve();
 
 
+		/** Returns the scene color render target. */
+		SPtr<RenderTextureCore> getSceneColorRT() const { return mSceneColorRT; }
+
 		/**	Returns the first color texture of the gbuffer as a bindable texture. */
 		/**	Returns the first color texture of the gbuffer as a bindable texture. */
 		SPtr<TextureCore> getTextureA() const;
 		SPtr<TextureCore> getTextureA() const;
 
 

+ 0 - 2
Source/RenderBeast/Include/BsRenderTexturePool.h

@@ -121,8 +121,6 @@ namespace BansheeEngine
 	private:
 	private:
 		friend class RenderTexturePool;
 		friend class RenderTexturePool;
 
 
-		POOLED_RENDER_TEXTURE_DESC() { }
-
 		UINT32 width;
 		UINT32 width;
 		UINT32 height;
 		UINT32 height;
 		UINT32 depth;
 		UINT32 depth;

+ 15 - 7
Source/RenderBeast/Source/BsPostProcessing.cpp

@@ -34,12 +34,18 @@ namespace BansheeEngine
 		UINT32 width = std::max(1, Math::ceilToInt(colorProps.getWidth() * 0.5f));
 		UINT32 width = std::max(1, Math::ceilToInt(colorProps.getWidth() * 0.5f));
 		UINT32 height = std::max(1, Math::ceilToInt(colorProps.getHeight() * 0.5f));
 		UINT32 height = std::max(1, Math::ceilToInt(colorProps.getHeight() * 0.5f));
 
 
-		POOLED_RENDER_TEXTURE_DESC outputDesc = POOLED_RENDER_TEXTURE_DESC::create2D(colorProps.getFormat(), width, height, 
-			TU_RENDERTARGET);
-
-		SPtr<PooledRenderTexture> outputRT = RenderTexturePool::instance().get(outputDesc);
+		mOutputDesc = POOLED_RENDER_TEXTURE_DESC::create2D(colorProps.getFormat(), width, height, TU_RENDERTARGET);
+		
 		// TODO - Actually send params to GPU.
 		// TODO - Actually send params to GPU.
-		// TODO - keep reference to output RT, Release output RT, actually render to it
+	}
+
+	void DownsampleMat::render(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo)
+	{
+		ppInfo.downsampledSceneTex = RenderTexturePool::instance().get(mOutputDesc);
+
+		// TODO - Render
+
+		RenderTexturePool::instance().release(ppInfo.downsampledSceneTex);
 	}
 	}
 
 
 	EyeAdaptHistogramMat::EyeAdaptHistogramMat()
 	EyeAdaptHistogramMat::EyeAdaptHistogramMat()
@@ -58,10 +64,12 @@ namespace BansheeEngine
 		defines.set("LOOP_COUNT_Y", LOOP_COUNT_Y);
 		defines.set("LOOP_COUNT_Y", LOOP_COUNT_Y);
 	}
 	}
 
 
-	void EyeAdaptHistogramMat::setParameters(const SPtr<RenderTextureCore>& target, const PostProcessSettings& settings)
+	void EyeAdaptHistogramMat::setParameters(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo)
 	{
 	{
 		mSceneColor.set(target->getBindableColorTexture());
 		mSceneColor.set(target->getBindableColorTexture());
 
 
+		const PostProcessSettings& settings = ppInfo.settings;
+
 		float diff = settings.histogramLog2Max - settings.histogramLog2Min;
 		float diff = settings.histogramLog2Max - settings.histogramLog2Min;
 		float scale = 1.0f / diff;
 		float scale = 1.0f / diff;
 		float offset = -settings.histogramLog2Min * scale;
 		float offset = -settings.histogramLog2Min * scale;
@@ -84,7 +92,7 @@ namespace BansheeEngine
 		// TODO - Output
 		// TODO - Output
 	}
 	}
 
 
-	void PostProcessing::postProcess(const SPtr<RenderTextureCore>& target, const PostProcessSettings& settings)
+	void PostProcessing::postProcess(const SPtr<RenderTextureCore>& target, PostProcessInfo& ppInfo)
 	{
 	{
 		RenderAPICore& rapi = RenderAPICore::instance();
 		RenderAPICore& rapi = RenderAPICore::instance();
 
 

+ 6 - 0
Source/RenderBeast/Source/BsRenderBeast.cpp

@@ -725,10 +725,16 @@ namespace BansheeEngine
 
 
 		if (hasGBuffer)
 		if (hasGBuffer)
 		{
 		{
+			PostProcessing::postProcess(camData.target->getSceneColorRT(), camData.postProcessInfo);
+
 			// TODO - Instead of doing a separate resolve here I could potentially perform a resolve directly in some
 			// TODO - Instead of doing a separate resolve here I could potentially perform a resolve directly in some
 			// post-processing pass (e.g. tone mapping). Right now it is just an unnecessary blit.
 			// post-processing pass (e.g. tone mapping). Right now it is just an unnecessary blit.
 			camData.target->resolve();
 			camData.target->resolve();
 		}
 		}
+		else
+		{
+			// TODO - Post process without gbuffer
+		}
 
 
 		// Render overlay post-scene callbacks
 		// Render overlay post-scene callbacks
 		if (iterCameraCallbacks != mRenderCallbacks.end())
 		if (iterCameraCallbacks != mRenderCallbacks.end())