Skip to content

Commit

Permalink
Added mip/format texture options
Browse files Browse the repository at this point in the history
Updates docs a bit
  • Loading branch information
BearishSun committed Jul 4, 2014
1 parent 6ed941b commit e918178
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 456 deletions.
3 changes: 3 additions & 0 deletions BansheeCore/BansheeCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@
<ClInclude Include="Include\BsGpuProgIncludeImporter.h" />
<ClInclude Include="Include\BsShaderProxy.h" />
<ClInclude Include="Include\BsSubMesh.h" />
<ClInclude Include="Include\BsTextureImportOptions.h" />
<ClInclude Include="Include\BsTextureImportOptionsRTTI.h" />
<ClInclude Include="Include\BsTextureView.h" />
<ClInclude Include="Include\BsTextData.h" />
<ClInclude Include="Include\BsTimerQuery.h" />
Expand Down Expand Up @@ -468,6 +470,7 @@
<ClCompile Include="Source\BsQueryManager.cpp" />
<ClCompile Include="Source\BsRenderer.cpp" />
<ClCompile Include="Source\BsResourceManifest.cpp" />
<ClCompile Include="Source\BsTextureImportOptions.cpp" />
<ClCompile Include="Source\BsTextureView.cpp" />
<ClCompile Include="Source\BsTextData.cpp" />
<ClCompile Include="Source\BsTimerQuery.cpp" />
Expand Down
9 changes: 9 additions & 0 deletions BansheeCore/BansheeCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,12 @@
<ClInclude Include="Include\BsShaderProxy.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="Include\BsTextureImportOptions.h">
<Filter>Header Files\Importer</Filter>
</ClInclude>
<ClInclude Include="Include\BsTextureImportOptionsRTTI.h">
<Filter>Header Files\RTTI</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\BsCoreApplication.cpp">
Expand Down Expand Up @@ -809,5 +815,8 @@
<ClCompile Include="Source\BsCameraProxy.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="Source\BsTextureImportOptions.cpp">
<Filter>Source Files\Importer</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion BansheeCore/Include/BsCorePrerequisites.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ namespace BansheeEngine
TID_GameObjectHandleBase = 1066,
TID_ResourceManifest = 1067,
TID_ResourceManifestEntry = 1068,
TID_EmulatedParamBlock = 1069
TID_EmulatedParamBlock = 1069,
TID_TextureImportOptions = 1070
};
}

Expand Down
2 changes: 1 addition & 1 deletion BansheeCore/Include/BsMultiRenderTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace BansheeEngine
void throwIfBuffersDontMatch() const;

// TODO - Not implemented
virtual void copyToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO);
virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO);

protected:
Vector<TextureViewPtr> mColorSurfaces;
Expand Down
21 changes: 3 additions & 18 deletions BansheeCore/Include/BsPixelUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@

namespace BansheeEngine
{
/**
* @brief Available compression formats.
*/
enum class CompressedFormat
{
BC1, /**< PF_BC1 */
BC1a, /**< PF_BC1a */
BC2, /**< PF_BC2 */
BC3, /**< PF_BC3 */
BC4, /**< PF_BC4 */
BC5, /**< PF_BC5 */
BC6H, /**< PF_BC6H */
BC7 /**< PF_BC7 */
};

/**
* @brief Available types of texture compression quality.
*/
Expand Down Expand Up @@ -66,7 +51,7 @@ namespace BansheeEngine
*/
struct CompressionOptions
{
CompressedFormat format = CompressedFormat::BC1;
PixelFormat format = PF_BC1;
AlphaMode alphaMode = AlphaMode::None;
bool isNormalMap = false;
bool isSRGB = false;
Expand Down Expand Up @@ -248,7 +233,7 @@ namespace BansheeEngine
* @brief Converts pixels from one format to another. Provided pixel data objects
* must have previously allocated buffers of adequate size and their sizes must match.
*/
static void bulkPixelConversion(const PixelData& src, const PixelData& dst);
static void bulkPixelConversion(const PixelData& src, PixelData& dst);

/**
* @brief Compresses the provided data using the specified compression options.
Expand All @@ -268,7 +253,7 @@ namespace BansheeEngine
* Provided pixel data objects must have previously allocated buffers of adequate size. You may
* also provided a filtering method to use when scaling.
*/
static void scale(const PixelData& src, const PixelData& dst, Filter filter = FILTER_LINEAR);
static void scale(const PixelData& src, PixelData& dst, Filter filter = FILTER_LINEAR);

/**
* @brief Applies gamma correction to the pixels in the provided buffer.
Expand Down
2 changes: 1 addition & 1 deletion BansheeCore/Include/BsRenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace BansheeEngine
*
* @note Core thread only.
*/
virtual void copyToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO) = 0;
virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO) = 0;

/**
* @brief Does the texture need to be vertically flipped because of different screen space coordinate systems.
Expand Down
2 changes: 1 addition & 1 deletion BansheeCore/Include/BsRenderTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace BansheeEngine
/**
* @copydoc RenderTarget::copyToMemory
*/
virtual void copyToMemory(const PixelData &dst, FrameBuffer buffer = FB_AUTO);
virtual void copyToMemory(PixelData &dst, FrameBuffer buffer = FB_AUTO);

protected:
TextureViewPtr mColorSurface;
Expand Down
2 changes: 1 addition & 1 deletion BansheeCore/Source/BsMultiRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace BansheeEngine
}
}

void MultiRenderTexture::copyToMemory(const PixelData &dst, FrameBuffer buffer)
void MultiRenderTexture::copyToMemory(PixelData &dst, FrameBuffer buffer)
{
throw std::exception("The method or operation is not implemented.");
}
Expand Down
74 changes: 34 additions & 40 deletions BansheeCore/Source/BsPixelUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,21 +868,21 @@ namespace BansheeEngine
UINT8* bufferEnd;
};

nvtt::Format toNVTTFormat(CompressedFormat format)
nvtt::Format toNVTTFormat(PixelFormat format)
{
switch (format)
{
case CompressedFormat::BC1:
case PF_BC1:
return nvtt::Format_BC1;
case CompressedFormat::BC1a:
case PF_BC1a:
return nvtt::Format_BC1a;
case CompressedFormat::BC2:
case PF_BC2:
return nvtt::Format_BC2;
case CompressedFormat::BC3:
case PF_BC3:
return nvtt::Format_BC3;
case CompressedFormat::BC4:
case PF_BC4:
return nvtt::Format_BC4;
case CompressedFormat::BC5:
case PF_BC5:
return nvtt::Format_BC5;
}

Expand Down Expand Up @@ -940,33 +940,6 @@ namespace BansheeEngine
return nvtt::WrapMode_Mirror;
}


PixelFormat toPixelFormat(CompressedFormat format)
{
switch (format)
{
case CompressedFormat::BC1:
return PF_BC1;
case CompressedFormat::BC1a:
return PF_BC1a;
case CompressedFormat::BC2:
return PF_BC2;
case CompressedFormat::BC3:
return PF_BC3;
case CompressedFormat::BC4:
return PF_BC4;
case CompressedFormat::BC5:
return PF_BC5;
case CompressedFormat::BC6H:
return PF_BC6H;
case CompressedFormat::BC7:
return PF_BC7;
}

// Unknown format
return PF_BC3;
}

UINT32 PixelUtil::getNumElemBytes(PixelFormat format)
{
return getDescriptionFor(format).elemBytes;
Expand Down Expand Up @@ -1353,14 +1326,14 @@ namespace BansheeEngine
}
}

void PixelUtil::bulkPixelConversion(const PixelData &src, const PixelData &dst)
void PixelUtil::bulkPixelConversion(const PixelData &src, PixelData &dst)
{
assert(src.getWidth() == dst.getWidth() &&
src.getHeight() == dst.getHeight() &&
src.getDepth() == dst.getDepth());

// Check for compressed formats, we don't support decompression, compression or recoding
if(PixelUtil::isCompressed(src.getFormat()) || PixelUtil::isCompressed(dst.getFormat()))
// Check for compressed formats, we don't support decompression
if(PixelUtil::isCompressed(src.getFormat()))
{
if(src.getFormat() == dst.getFormat())
{
Expand All @@ -1373,6 +1346,24 @@ namespace BansheeEngine
}
}

// Check for compression
if (PixelUtil::isCompressed(dst.getFormat()))
{
if (src.getFormat() == dst.getFormat())
{
memcpy(dst.getData(), src.getData(), src.getConsecutiveSize());
return;
}
else
{
CompressionOptions co;
co.format = dst.getFormat();
dst = *compress(src, co);

return;
}
}

// The easy case
if(src.getFormat() == dst.getFormat())
{
Expand Down Expand Up @@ -1478,7 +1469,7 @@ namespace BansheeEngine
}
}

void PixelUtil::scale(const PixelData& src, const PixelData& scaled, Filter filter)
void PixelUtil::scale(const PixelData& src, PixelData& scaled, Filter filter)
{
assert(PixelUtil::isAccessible(src.getFormat()));
assert(PixelUtil::isAccessible(scaled.getFormat()));
Expand Down Expand Up @@ -1624,14 +1615,17 @@ namespace BansheeEngine

PixelDataPtr PixelUtil::compress(const PixelData& src, const CompressionOptions& options)
{
if (!isCompressed(options.format))
BS_EXCEPT(InvalidParametersException, "Wanted format is not a compressed format.");

// Note: NVTT site has implementations for these two formats for when I decide to add them
if (options.format == CompressedFormat::BC6H || options.format == CompressedFormat::BC7)
if (options.format == PF_BC6H || options.format == PF_BC7)
BS_EXCEPT(InvalidParametersException, "Specified formats are not yet supported.");

if (src.getDepth() != 1)
BS_EXCEPT(InvalidParametersException, "3D textures are not supported.");

PixelFormat pf = toPixelFormat(options.format);
PixelFormat pf = options.format;

// TODO - Get rid of this limitation? Maybe it works without it with no additional changes.
if (!isValidExtent(src.getWidth(), src.getHeight(), 1, pf))
Expand Down
2 changes: 1 addition & 1 deletion BansheeCore/Source/BsRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace BansheeEngine
}
}

void RenderTexture::copyToMemory( const PixelData &dst, FrameBuffer buffer /*= FB_AUTO */ )
void RenderTexture::copyToMemory(PixelData &dst, FrameBuffer buffer)
{
throw std::exception("The method or operation is not implemented.");
}
Expand Down
2 changes: 1 addition & 1 deletion BansheeD3D11RenderSystem/Include/BsD3D11RenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace BansheeEngine
/**
* @copydoc RenderWindow::copyContentsToMemory
*/
void copyToMemory(const PixelData &dst, FrameBuffer buffer);
void copyToMemory(PixelData &dst, FrameBuffer buffer);

/**
* @copydoc RenderWindow::swapBuffers
Expand Down
2 changes: 1 addition & 1 deletion BansheeD3D11RenderSystem/Source/BsD3D11RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ namespace BansheeEngine
RenderWindow::getCustomAttribute(name, pData);
}

void D3D11RenderWindow::copyToMemory(const PixelData &dst, FrameBuffer buffer)
void D3D11RenderWindow::copyToMemory(PixelData &dst, FrameBuffer buffer)
{
THROW_IF_NOT_CORE_THREAD;

Expand Down
2 changes: 1 addition & 1 deletion BansheeD3D9RenderSystem/Include/BsD3D9Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace BansheeEngine
/**
* @brief Copies contents of the back or depth/stencil buffer in to the provided object.
*/
void copyContentsToMemory(const D3D9RenderWindow* window, const PixelData &dst, RenderTarget::FrameBuffer buffer);
void copyContentsToMemory(const D3D9RenderWindow* window, PixelData &dst, RenderTarget::FrameBuffer buffer);

/**
* @brief Resets bound pipeline states/streams to null.
Expand Down
2 changes: 1 addition & 1 deletion BansheeD3D9RenderSystem/Include/BsD3D9RenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace BansheeEngine
/**
* @copydoc RenderWindow::copyContentsToMemory
*/
void copyToMemory(const PixelData &dst, FrameBuffer buffer);
void copyToMemory(PixelData &dst, FrameBuffer buffer);

/**
* @copydoc RenderWindow::requiresTextureFlipping
Expand Down
2 changes: 1 addition & 1 deletion BansheeD3D9RenderSystem/Source/BsD3D9Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ namespace BansheeEngine
}

void D3D9Device::copyContentsToMemory(const D3D9RenderWindow* renderWindow,
const PixelData &dst, RenderTarget::FrameBuffer buffer)
PixelData &dst, RenderTarget::FrameBuffer buffer)
{
RenderWindowToResorucesIterator it = getRenderWindowIterator(renderWindow);
RenderWindowResources* resources = it->second;
Expand Down
2 changes: 1 addition & 1 deletion BansheeD3D9RenderSystem/Source/BsD3D9RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ namespace BansheeEngine
return Vector2I(pos.x, pos.y);
}

void D3D9RenderWindow::copyToMemory(const PixelData &dst, FrameBuffer buffer)
void D3D9RenderWindow::copyToMemory(PixelData &dst, FrameBuffer buffer)
{
THROW_IF_NOT_CORE_THREAD;

Expand Down
10 changes: 7 additions & 3 deletions BansheeEngine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Notes", "_Notes", "{1D081E5A-615A-4C06-B2DF-0D8D9390DE02}"
ProjectSection(SolutionItems) = preProject
CSharpWrap.txt = CSharpWrap.txt
Dependencies.txt = Dependencies.txt
DrawHelper.txt = DrawHelper.txt
EditorWindowDock.txt = EditorWindowDock.txt
GameGUI.txt = GameGUI.txt
GameObjectSerialization.txt = GameObjectSerialization.txt
Inspector.txt = Inspector.txt
MonoIntegrationGuide.txt = MonoIntegrationGuide.txt
Notes.txt = Notes.txt
Opts.txt = Opts.txt
Polish.txt = Polish.txt
Expand All @@ -21,7 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Notes", "_Notes", "{1D081E
SpriteTexture.txt = SpriteTexture.txt
TODO.txt = TODO.txt
TODODoc.txt = TODODoc.txt
TransformUpdatesAndRenderer.txt = TransformUpdatesAndRenderer.txt
TreeView.txt = TreeView.txt
UndoRedo.txt = UndoRedo.txt
EndProjectSection
Expand Down Expand Up @@ -180,6 +177,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeD3D11RenderSystem",
{CC7F9445-71C9-4559-9976-FF0A64DCB582} = {CC7F9445-71C9-4559-9976-FF0A64DCB582}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Guides", "Guides", "{4259680D-8A9B-4C17-B75B-CA29482AB299}"
ProjectSection(SolutionItems) = preProject
Dependencies.txt = Dependencies.txt
MonoIntegrationGuide.txt = MonoIntegrationGuide.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -627,6 +630,7 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4259680D-8A9B-4C17-B75B-CA29482AB299} = {1D081E5A-615A-4C06-B2DF-0D8D9390DE02}
{4F05EF0A-B8DE-424B-8848-6ECEE9D99912} = {32E4E2B7-1B4D-4B06-AD87-57CEE00BC247}
{41CC18CE-139E-45A5-A9AA-336CBA2E1521} = {32E4E2B7-1B4D-4B06-AD87-57CEE00BC247}
{08975177-4A13-4EE7-BB21-3BB92FB3F3CC} = {32E4E2B7-1B4D-4B06-AD87-57CEE00BC247}
Expand Down
2 changes: 0 additions & 2 deletions BansheeFreeImgImporter/BansheeFreeImgImporter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
<ItemGroup>
<ClInclude Include="Include\BsFreeImgImporter.h" />
<ClInclude Include="Include\BsFreeImgPrerequisites.h" />
<ClInclude Include="Include\BsTextureData.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Source\BsFreeImgImporter.cpp" />
<ClCompile Include="Source\BsFreeImgPlugin.cpp" />
<ClCompile Include="Source\BsTextureData.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{122B7A22-0C62-4B35-B661-EBF3F394EA79}</ProjectGuid>
Expand Down
Loading

0 comments on commit e918178

Please sign in to comment.