Skip to content

Commit

Permalink
(Partial) MSAA implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ssell committed Mar 23, 2017
1 parent dd65899 commit 35e917d
Show file tree
Hide file tree
Showing 25 changed files with 762 additions and 100 deletions.
30 changes: 29 additions & 1 deletion OcularCore/include/Graphics/GraphicsDriver.hpp
Expand Up @@ -94,8 +94,9 @@ namespace Ocular

/**
* Swaps the back and front buffers.
* \param[in] renderTexture If provided, render texture to be resolved into the backbuffer.
*/
virtual void swapBuffers();
virtual void swapBuffers(RenderTexture* renderTexture = nullptr);

/**
* Returns the current RenderState for the GraphicsDriver.
Expand Down Expand Up @@ -276,6 +277,20 @@ namespace Ocular
* a valid buffer, then NULL is returned.
*/
virtual GPUBuffer* createGPUBuffer(GPUBufferDescriptor const& descriptor) const;

//------------------------------------------------------------------------------
// Multisampling
//------------------------------------------------------------------------------

/**
* Returns the maximum supported multisampling count.
*/
virtual uint32_t const& getMaxMultisampling() const;

/**
* Returns the currently set multisampling count.
*/
virtual uint32_t const& getCurrentMultisampling() const;

//------------------------------------------------------------------------------
// Debug Draw Methods
Expand Down Expand Up @@ -326,6 +341,16 @@ namespace Ocular
*/
virtual bool renderBounds(Core::SceneObject* object, Math::BoundsType type);

/**
* Renders from the currently bound VBO.
*
* \note Depending on underlying implementation, no VBO may need to be bound.
*
* \param[in] vertCount Number of vertices to render.
* \param[in] vertStart Index of first vertex to render.
*/
virtual bool render(uint32_t vertCount, uint32_t vertStart);

//------------------------------------------------------------------------------
// Frame Info
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -373,6 +398,9 @@ namespace Ocular

RenderState* m_RenderState;

uint32_t m_MultisamplingMax;
uint32_t m_MultisamplingCurrent;

private:
};
}
Expand Down
99 changes: 99 additions & 0 deletions OcularCore/include/Graphics/Helpers/ScreenSpaceQuad.hpp
@@ -0,0 +1,99 @@
/**
* Copyright 2014-2017 Steven T Sell (ssell@vertexfragment.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once
#ifndef __H__OCULAR_GRAPHICS_HELPERS_SCREEN_SPACE_QUAD__H__
#define __H__OCULAR_GRAPHICS_HELPERS_SCREEN_SPACE_QUAD__H__

#include <string>
#include <memory>

//------------------------------------------------------------------------------------------

/**
* \addtogroup Ocular
* @{
*/
namespace Ocular
{
/**
* \addtogroup Graphics
* @{
*/
namespace Graphics
{
class Material;
class VertexBuffer;
class Texture;

/**
* \class ScreenSpaceQuad
*
* ScreenSpaceQuad is a helper class for easily rendering to a screen-filling quad. This is useful
* for several different tasks including: deferred rendering, render texture resolution, etc.
*
* The ScreenSpaceQuad does not use a shared material and so may be modified independently of any other.
*/
class ScreenSpaceQuad
{
public:

ScreenSpaceQuad();
~ScreenSpaceQuad();

/**
* Builds the default mesh and material.
*/
bool initialize();

/**
* Immediately renders the ScreenSpaceQuad.
*/
void render();

/**
* Sets a texture to be used by the ScreenSpaceQuad.
*
* \note The default material makes use of only a single texture.
*
* \param[in] index
* \param[in] name
* \param[in] texture
*/
void setTexture(uint32_t index, std::string const& name, Texture* texture);

protected:

std::unique_ptr<Material> m_Material;
std::unique_ptr<VertexBuffer> m_VertexBuffer;

private:

ScreenSpaceQuad(ScreenSpaceQuad const& other) = delete;
ScreenSpaceQuad& operator=(ScreenSpaceQuad const& other) = delete;
};
}
/**
* @} End of Doxygen Groups
*/
}
/**
* @} End of Doxygen Groups
*/

//------------------------------------------------------------------------------------------

#endif
2 changes: 1 addition & 1 deletion OcularCore/include/Graphics/Texture/Texture.hpp
Expand Up @@ -78,7 +78,7 @@ namespace Ocular
/**
* Returns a copy of the texture descriptor that defines this texture resource.
*/
TextureDescriptor getDescriptor() const;
TextureDescriptor const& getDescriptor() const;

protected:

Expand Down
20 changes: 11 additions & 9 deletions OcularCore/include/Graphics/Texture/TextureDescriptor.hpp
Expand Up @@ -48,6 +48,7 @@ namespace Ocular
uint32_t height; ///< Height of the texture in pixels
uint32_t mipmaps; ///< Levels of mipmaps to create. 0 creates an entire mipmap chain, 1 has the single texture level-of-detail, etc.
uint32_t pixelSize; ///< Size of each pixel in bytes
uint32_t multisamples; ///< Number of multisamples

TextureType type; ///< The type of texture
TextureFormat format; ///< The format of this texture
Expand All @@ -57,15 +58,16 @@ namespace Ocular
TextureAccess cpuAccess; ///< The level of access requried by the CPU

TextureDescriptor()
: width(800),
height(600),
mipmaps(1),
pixelSize(32),
type(TextureType::Texture2D),
format(TextureFormat::R32G32B32A32Float),
filter(TextureFilterMode::Point),
gpuAccess(TextureAccess::ReadWrite),
cpuAccess(TextureAccess::None)
: width{800},
height{600},
mipmaps{1},
pixelSize{32},
multisamples{1},
type{TextureType::Texture2D},
format{TextureFormat::R32G32B32A32Float},
filter{TextureFilterMode::Point},
gpuAccess{TextureAccess::ReadWrite},
cpuAccess{TextureAccess::None}
{

}
Expand Down
54 changes: 54 additions & 0 deletions OcularCore/include/Math/MathCommon.hpp
Expand Up @@ -24,6 +24,7 @@
#include <cmath>
#include <cstdint>
#include <algorithm>
#include <limits>

//------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -54,6 +55,16 @@ namespace Ocular
// Common Functions
//----------------------------------------------------------------------------------

/**
* Calculates if the specified integer is a power of 2.
* Source: http://www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
*/
template<typename T, typename = std::enable_if_t<std::numeric_limits<T>::is_integer>>
static bool IsPowTwo(T const& t)
{
return (t && !(t & (t - 1)));
}

/**
* Performs a fast floor operation on the provided floating point value.
*
Expand Down Expand Up @@ -330,6 +341,49 @@ namespace Ocular
}
}

/**
* Returns the specified integer rounded up to the nearest power of two.
* Supports 2, 4, 8-byte integers.
*
* Adapted from: http://www.graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
*/
template<typename T, typename = std::enable_if_t<std::numeric_limits<T>::is_integer>>
static T RoundUpPowTwo(T const& t)
{
T result = t;

result--;

result |= (result >> 1);
result |= (result >> 2);
result |= (result >> 4);
result |= (result >> 8);

if(sizeof(T) > 2)
{
result |= (result >> 16);

if(sizeof(T) > 4)
{
result |= (result >> 32);
}
}

result++;

return result;
}

/**
* Returns the specified integer rounded down to the nearest power of two.
* Supports 2, 4, 8-byte integers.
*/
template<typename T, typename = std::enable_if_t<std::numeric_limits<T>::is_integer>>
static T RoundDownPowTwo(T const& t)
{
return (RoundUpPowTwo(t) >> 1);
}

/**
* Counts and returns the number of leading zeros in the provided 32-bit uint32_teger.
*
Expand Down
5 changes: 5 additions & 0 deletions OcularCore/include/Resources/ResourceManager.hpp
Expand Up @@ -121,6 +121,11 @@ namespace Ocular
*/
void initialize();

/**
*
*/
void initializeDefaultResources();

/**
*
*/
Expand Down
2 changes: 2 additions & 0 deletions OcularCore/projects/vs2017/OcularCore.vcxproj
Expand Up @@ -189,6 +189,7 @@
<ClCompile Include="..\..\src\Graphics\DebugGraphics\DebugGraphics.cpp" />
<ClCompile Include="..\..\src\Graphics\FrameStats.cpp" />
<ClCompile Include="..\..\src\Graphics\GraphicsDriver.cpp" />
<ClCompile Include="..\..\src\Graphics\Helpers\ScreenSpaceQuad.cpp" />
<ClCompile Include="..\..\src\Graphics\Material\Material.cpp" />
<ClCompile Include="..\..\src\Graphics\Material\MaterialEmpty.cpp" />
<ClCompile Include="..\..\src\Graphics\Material\MaterialMissing.cpp" />
Expand Down Expand Up @@ -353,6 +354,7 @@
<ClInclude Include="..\..\include\Graphics\DebugGraphics\DebugGraphics.hpp" />
<ClInclude Include="..\..\include\Graphics\FrameStats.hpp" />
<ClInclude Include="..\..\include\Graphics\GraphicsDriver.hpp" />
<ClInclude Include="..\..\include\Graphics\Helpers\ScreenSpaceQuad.hpp" />
<ClInclude Include="..\..\include\Graphics\Material\Material.hpp" />
<ClInclude Include="..\..\include\Graphics\Material\MaterialEmpty.hpp" />
<ClInclude Include="..\..\include\Graphics\Material\MaterialMissing.hpp" />
Expand Down
12 changes: 12 additions & 0 deletions OcularCore/projects/vs2017/OcularCore.vcxproj.filters
Expand Up @@ -295,6 +295,12 @@
<Filter Include="Source Files\Graphics\Shader\Buffer">
<UniqueIdentifier>{87b9c302-d46d-437a-8bd8-c8f3dc225eee}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Graphics\Helpers">
<UniqueIdentifier>{4eadffb2-61f8-433d-b481-1faf569a65de}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Graphics\Helpers">
<UniqueIdentifier>{5b6368c1-9ba6-4f66-82f2-904122bc0156}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\Object.cpp">
Expand Down Expand Up @@ -774,6 +780,9 @@
<ClCompile Include="..\..\src\Graphics\Material\MaterialResourceSaver.cpp">
<Filter>Source Files\Graphics\Material</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Graphics\Helpers\ScreenSpaceQuad.cpp">
<Filter>Source Files\Graphics\Helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\include\Object.hpp">
Expand Down Expand Up @@ -1415,5 +1424,8 @@
<ClInclude Include="..\..\include\Graphics\Material\MaterialResourceSaver.hpp">
<Filter>Header Files\Graphics\Material</Filter>
</ClInclude>
<ClInclude Include="..\..\include\Graphics\Helpers\ScreenSpaceQuad.hpp">
<Filter>Header Files\Graphics\Helpers</Filter>
</ClInclude>
</ItemGroup>
</Project>
25 changes: 23 additions & 2 deletions OcularCore/src/Graphics/GraphicsDriver.cpp
Expand Up @@ -28,7 +28,9 @@ namespace Ocular
//----------------------------------------------------------------------------------

GraphicsDriver::GraphicsDriver()
: m_RenderState(nullptr)
: m_RenderState{nullptr},
m_MultisamplingMax{1},
m_MultisamplingCurrent{1}
{

}
Expand Down Expand Up @@ -66,7 +68,7 @@ namespace Ocular
// Nothing to do without an active graphics API
}

void GraphicsDriver::swapBuffers()
void GraphicsDriver::swapBuffers(RenderTexture* renderTexture)
{
// Nothing to do without an active graphics API
}
Expand Down Expand Up @@ -199,6 +201,20 @@ namespace Ocular
return new GPUBuffer(descriptor);
}

//----------------------------------------------------------------------------------
// Multisampling
//----------------------------------------------------------------------------------

uint32_t const& GraphicsDriver::getMaxMultisampling() const
{
return m_MultisamplingMax;
}

uint32_t const& GraphicsDriver::getCurrentMultisampling() const
{
return m_MultisamplingCurrent;
}

//----------------------------------------------------------------------------------
// Debug Methods
//----------------------------------------------------------------------------------
Expand Down Expand Up @@ -232,6 +248,11 @@ namespace Ocular
return false;
}

bool GraphicsDriver::render(uint32_t const vertCount, uint32_t const vertStart)
{
return false;
}

//----------------------------------------------------------------------------------
// Frame Info
//----------------------------------------------------------------------------------
Expand Down

0 comments on commit 35e917d

Please sign in to comment.