Commit d8afb0f2 by Nicolas Capens Committed by Nicolas Capens

Add the DisplacementMap PowerVR sample.

BUG=14598298 Change-Id: Ie155538dac9395021b5a69b9aa553a8c7e85aa8f Reviewed-on: https://swiftshader-review.googlesource.com/1100Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 7b21f276
......@@ -219,6 +219,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2ChameleonMan", "..\te
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2Tools", "..\tests\third_party\PowerVR\Tools\OGLES2\Build\WindowsVC2010\OGLES2Tools.vcxproj", "{09ABE661-9BC0-4152-A820-1FB0522CAC01}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2DisplacementMap", "..\tests\third_party\PowerVR\Examples\Intermediate\DisplacementMap\OGLES2\Build\WindowsVC2010\OGLES2DisplacementMap.vcxproj", "{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}"
ProjectSection(ProjectDependencies) = postProject
{B5871A7A-968C-42E3-A33B-981E6F448E78} = {B5871A7A-968C-42E3-A33B-981E6F448E78}
{E746FCA9-64C3-433E-85E8-9A5A67AB7ED6} = {E746FCA9-64C3-433E-85E8-9A5A67AB7ED6}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
......@@ -577,6 +583,18 @@ Global
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Release|Win32.Build.0 = Release|Win32
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Release|x64.ActiveCfg = Release|x64
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Release|x64.Build.0 = Release|x64
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Debug|Win32.ActiveCfg = Debug|Win32
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Debug|Win32.Build.0 = Debug|Win32
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Debug|x64.ActiveCfg = Debug|x64
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Debug|x64.Build.0 = Debug|x64
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Profile|Win32.ActiveCfg = Release|Win32
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Profile|Win32.Build.0 = Release|Win32
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Profile|x64.ActiveCfg = Release|x64
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Profile|x64.Build.0 = Release|x64
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Release|Win32.ActiveCfg = Release|Win32
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Release|Win32.Build.0 = Release|Win32
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Release|x64.ActiveCfg = Release|x64
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -610,5 +628,6 @@ Global
{9DAFEE32-19F6-4410-AA09-2B564FB86F62} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{9CF4408B-9B08-481F-95DA-3DF0846DABE4} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{09ABE661-9BC0-4152-A820-1FB0522CAC01} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
EndGlobalSection
EndGlobal
:Title:
DisplacementMap
:ShortDescription:
This training course demonstrates displacement mapping using a texture read from the vertex shader.
:FullDescription:
This training course demonstrates displacement mapping using a texture read from the vertex shader. A tesselated grid of vertices is displaced by differing amounts as dictated by the value read from the texture.
Displacement mapping is an alternative to bump mapping, normal mapping, and parallax mapping, that causes the actual geometric position of points over a textured surface to be displaced, often along the local surface normal, according to the value the texture function evaluates to at each point on the surface. It gives surfaces a great sense of depth and detail, permitting self-occlusion, self-shadowing and silhouettes.
Additional geometry is requried in order for the effect to be achieved and thus performance will be affected.
Controls:
- Esc - Close the application
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733}</ProjectGuid>
<RootNamespace>OGLES2DisplacementMap</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>BUILD_OGLES2;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\..\..\Shell;..\..\..\..\..\..\Shell\API\KEGL;..\..\..\..\..\..\Shell\OS\Windows;..\..\..\..\..\..\Builds\Include;..\..\..\..\..\..\Tools\OGLES2;</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\..\..\..\..\Builds\Windows\x86_32\Lib;..\..\..\..\..\..\Tools\OGLES2\Build\WindowsVC2010\$(IntDir);</AdditionalLibraryDirectories>
<AdditionalDependencies>libEGL.lib;libGLESv2.lib;OGLES2Tools.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>BUILD_OGLES2;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\..\..\Shell;..\..\..\..\..\..\Shell\API\KEGL;..\..\..\..\..\..\Shell\OS\Windows;..\..\..\..\..\..\Builds\Include;..\..\..\..\..\..\Tools\OGLES2;</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>..\..\..\..\..\..\Builds\Windows\x86_64\Lib;..\..\..\..\..\..\Tools\OGLES2\Build\WindowsVC2010\$(IntDir);</AdditionalLibraryDirectories>
<AdditionalDependencies>libEGL.lib;libGLESv2.lib;OGLES2Tools.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>BUILD_OGLES2;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\..\..\Shell;..\..\..\..\..\..\Shell\API\KEGL;..\..\..\..\..\..\Shell\OS\Windows;..\..\..\..\..\..\Builds\Include;..\..\..\..\..\..\Tools\OGLES2;</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\..\..\..\..\Builds\Windows\x86_32\Lib;..\..\..\..\..\..\Tools\OGLES2\Build\WindowsVC2010\$(IntDir);</AdditionalLibraryDirectories>
<AdditionalDependencies>libEGL.lib;libGLESv2.lib;OGLES2Tools.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>BUILD_OGLES2;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\..\..\..\Shell;..\..\..\..\..\..\Shell\API\KEGL;..\..\..\..\..\..\Shell\OS\Windows;..\..\..\..\..\..\Builds\Include;..\..\..\..\..\..\Tools\OGLES2;</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>..\..\..\..\..\..\Builds\Windows\x86_64\Lib;..\..\..\..\..\..\Tools\OGLES2\Build\WindowsVC2010\$(IntDir);</AdditionalLibraryDirectories>
<AdditionalDependencies>libEGL.lib;libGLESv2.lib;OGLES2Tools.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\OGLES2DisplacementMap.cpp" />
<ClCompile Include="..\..\..\..\..\..\Shell\PVRShell.cpp" />
<ClCompile Include="..\..\..\..\..\..\Shell\API\KEGL\PVRShellAPI.cpp" />
<ClCompile Include="..\..\..\..\..\..\Shell\OS\Windows\PVRShellOS.cpp" />
<ClCompile Include="..\..\Content\FragShader.cpp" />
<ClCompile Include="..\..\Content\VertShader.cpp" />
<ClCompile Include="..\..\Content\DisMapScene.cpp" />
<ClCompile Include="..\..\Content\Cow.cpp" />
<ClCompile Include="..\..\Content\DisMap.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\..\Shell\PVRShell.h" />
<ClInclude Include="..\..\..\..\..\..\Shell\PVRShellImpl.h" />
<ClInclude Include="..\..\..\..\..\..\Shell\API\KEGL\PVRShellAPI.h" />
<ClInclude Include="..\..\..\..\..\..\Shell\OS\Windows\PVRShellOS.h" />
<ClInclude Include="..\..\..\..\..\..\Builds\Windows\Resources\resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\..\..\..\..\Builds\Windows\Resources\shared.rc" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\DisMapScene.pod">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Wrapping scene file ..\..\DisMapScene.pod as ..\..\Content\DisMapScene.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMapScene.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\Content\DisMapScene.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Wrapping scene file ..\..\DisMapScene.pod as ..\..\Content\DisMapScene.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMapScene.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\Content\DisMapScene.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Wrapping scene file ..\..\DisMapScene.pod as ..\..\Content\DisMapScene.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMapScene.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\Content\DisMapScene.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Wrapping scene file ..\..\DisMapScene.pod as ..\..\Content\DisMapScene.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMapScene.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\Content\DisMapScene.cpp;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\FragShader.fsh">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Wrapping shader ..\..\FragShader.fsh as ..\..\Content\FragShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\FragShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\Content\FragShader.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Wrapping shader ..\..\FragShader.fsh as ..\..\Content\FragShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\FragShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\Content\FragShader.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Wrapping shader ..\..\FragShader.fsh as ..\..\Content\FragShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\FragShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\Content\FragShader.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Wrapping shader ..\..\FragShader.fsh as ..\..\Content\FragShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\FragShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\Content\FragShader.cpp;%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="..\..\VertShader.vsh">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Wrapping shader ..\..\VertShader.vsh as ..\..\Content\VertShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\VertShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\Content\VertShader.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Wrapping shader ..\..\VertShader.vsh as ..\..\Content\VertShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\VertShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\Content\VertShader.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Wrapping shader ..\..\VertShader.vsh as ..\..\Content\VertShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\VertShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\Content\VertShader.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Wrapping shader ..\..\VertShader.vsh as ..\..\Content\VertShader.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -s -o "..\..\Content\VertShader.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\Content\VertShader.cpp;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\DisMap.pvr">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Wrapping texture ..\..\DisMap.pvr as ..\..\Content\DisMap.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMap.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\Content\DisMap.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Wrapping texture ..\..\DisMap.pvr as ..\..\Content\DisMap.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMap.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\Content\DisMap.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Wrapping texture ..\..\DisMap.pvr as ..\..\Content\DisMap.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMap.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\Content\DisMap.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Wrapping texture ..\..\DisMap.pvr as ..\..\Content\DisMap.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\DisMap.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\Content\DisMap.cpp;%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="..\..\Cow.pvr">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Wrapping texture ..\..\Cow.pvr as ..\..\Content\Cow.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\Cow.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\Content\Cow.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Wrapping texture ..\..\Cow.pvr as ..\..\Content\Cow.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\Cow.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\Content\Cow.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Wrapping texture ..\..\Cow.pvr as ..\..\Content\Cow.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\Cow.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\Content\Cow.cpp;%(Outputs)</Outputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Wrapping texture ..\..\Cow.pvr as ..\..\Content\Cow.cpp</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(ProjectDir)..\..\..\..\..\..\Utilities\Filewrap\Windows_x86_32\Filewrap.exe" -o "..\..\Content\Cow.cpp" "%(FullPath)"</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\Content\Cow.cpp;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\..\Tools\OGLES2\Build\WindowsVC2010\OGLES2Tools.vcxproj">
<Project>{09abe661-9bc0-4152-a820-1fb0522cac01}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Content Files">
<UniqueIdentifier>{900022e4-757a-46fb-bd53-6dfc20b3d893}</UniqueIdentifier>
</Filter>
<Filter Include="Content Files\Scene Files">
<UniqueIdentifier>{2c3d4c8c-5d1a-459a-a05a-a4e4b608a44e}</UniqueIdentifier>
<Extensions>pod</Extensions>
</Filter>
<Filter Include="Content Files\Shaders">
<UniqueIdentifier>{2c3d4c8c-5d1a-459a-a05a-a4e4b608a44e}</UniqueIdentifier>
<Extensions>fsh;psh;glsl;frag;vert</Extensions>
</Filter>
<Filter Include="Content Files\Textures">
<UniqueIdentifier>{2c3d4c8c-5d1a-459a-a05a-a4e4b608a44e}</UniqueIdentifier>
<Extensions>ico;bmp;gif;jpg;jpeg;jpe;tiff;tif;png;pvr</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\..\Shell\PVRShell.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\..\Shell\PVRShellImpl.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\..\Shell\API\KEGL\PVRShellAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\..\Shell\OS\Windows\PVRShellOS.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\..\Builds\Windows\Resources\resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\..\..\..\..\Builds\Windows\Resources\shared.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\OGLES2DisplacementMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\..\Shell\PVRShell.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\..\Shell\API\KEGL\PVRShellAPI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\..\Shell\OS\Windows\PVRShellOS.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\FragShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\VertShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\DisMapScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\Cow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\DisMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\DisMapScene.pod">
<Filter>Content Files\Scene Files</Filter>
</CustomBuild>
<CustomBuild Include="..\..\DisMap.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\Cow.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\FragShader.fsh">
<Filter>Content Files\Shaders</Filter>
</CustomBuild>
<CustomBuild Include="..\..\VertShader.vsh">
<Filter>Content Files\Shaders</Filter>
</CustomBuild>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerEnvironment>PATH=$(SolutionDir)..\lib\$(Configuration)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerEnvironment>PATH=$(SolutionDir)..\lib\$(Configuration)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerEnvironment>PATH=$(SolutionDir)..\lib\$(Configuration)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerEnvironment>PATH=$(SolutionDir)..\lib\$(Configuration)</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
// This file was created by Filewrap 1.1
// Little endian mode
// DO NOT EDIT
#include "../PVRTMemoryFileSystem.h"
// using 32 bit to guarantee alignment.
#ifndef A32BIT
#define A32BIT static const unsigned int
#endif
// ******** Start: FragShader.fsh ********
// File data
static const char _FragShader_fsh[] =
"uniform sampler2D sTexture;\r\n"
"\r\n"
"varying lowp float LightIntensity;\r\n"
"varying mediump vec2 TexCoord;\r\n"
"\r\n"
"void main()\r\n"
"{\r\n"
" gl_FragColor = texture2D(sTexture, TexCoord) * LightIntensity;\r\n"
"}\r\n";
// Register FragShader.fsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_FragShader_fsh("FragShader.fsh", _FragShader_fsh, 195);
// ******** End: FragShader.fsh ********
// This file was created by Filewrap 1.1
// Little endian mode
// DO NOT EDIT
#include "../PVRTMemoryFileSystem.h"
// using 32 bit to guarantee alignment.
#ifndef A32BIT
#define A32BIT static const unsigned int
#endif
// ******** Start: VertShader.vsh ********
// File data
static const char _VertShader_vsh[] =
"attribute highp vec3 inVertex;\r\n"
"attribute mediump vec3 inNormal;\r\n"
"attribute mediump vec2 inTexCoord;\r\n"
"\r\n"
"uniform highp mat4 MVPMatrix;\r\n"
"uniform mediump vec3 LightDirection;\r\n"
"uniform mediump\tfloat DisplacementFactor;\r\n"
"\r\n"
"varying lowp float LightIntensity;\r\n"
"varying mediump vec2 TexCoord;\r\n"
"\r\n"
"uniform sampler2D sDisMap;\r\n"
"\r\n"
"void main()\r\n"
"{\r\n"
"\t/* \r\n"
"\t\tCalculate the displacemnt value by taking the colour value from our texture\r\n"
"\t\tand scale it by out displacement factor.\r\n"
"\t*/\r\n"
"\tmediump float disp = texture2D(sDisMap, inTexCoord).r * DisplacementFactor;\r\n"
"\r\n"
"\t/* \r\n"
"\t\tTransform position by the model-view-projection matrix but first\r\n"
"\t\tmove the untransformed position along the normal by our displacement\r\n"
"\t\tvalue.\r\n"
"\t*/\r\n"
"\tgl_Position = MVPMatrix * vec4(inVertex + (inNormal * disp), 1.0);\r\n"
"\r\n"
"\t// Pass through texcoords\r\n"
"\tTexCoord = inTexCoord;\r\n"
"\t\r\n"
"\t// Simple diffuse lighting in model space\r\n"
"\tLightIntensity = dot(inNormal, -LightDirection);\r\n"
"}";
// Register VertShader.vsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_VertShader_vsh("VertShader.vsh", _VertShader_vsh, 949);
// ******** End: VertShader.vsh ********
uniform sampler2D sTexture;
varying lowp float LightIntensity;
varying mediump vec2 TexCoord;
void main()
{
gl_FragColor = texture2D(sTexture, TexCoord) * LightIntensity;
}
/******************************************************************************
@File OGLES2DisplacementMap.cpp
@Title Displacement Map
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform Independent
@Description Shows how to displace geometry in the vertex shader using a
texture.
******************************************************************************/
#include <string.h>
#include "PVRShell.h"
#include "OGLES2Tools.h"
/******************************************************************************
Defines
******************************************************************************/
// Index to bind the attributes to vertex shaders
#define VERTEX_ARRAY 0
#define NORMAL_ARRAY 1
#define TEXCOORD_ARRAY 2
/******************************************************************************
Consts
******************************************************************************/
// Camera constants. Used for making the projection matrix
const float g_fCameraNear = 4.0f;
const float g_fCameraFar = 2000.0f;
const float g_fDemoFrameRate = 1.0f / 90.0f;
// The camera to use from the pod file
const int g_ui32Camera = 0;
/******************************************************************************
Content file names
******************************************************************************/
// Source and binary shaders
const char c_szFragShaderSrcFile[] = "FragShader.fsh";
const char c_szFragShaderBinFile[] = "FragShader.fsc";
const char c_szVertShaderSrcFile[] = "VertShader.vsh";
const char c_szVertShaderBinFile[] = "VertShader.vsc";
// POD scene files
const char c_szSceneFile[] = "DisMapScene.pod";
const char c_szDisMapFile[] = "DisMap.pvr";
/*!****************************************************************************
Class implementing the PVRShell functions.
******************************************************************************/
class OGLES2DisplacementMap : public PVRShell
{
// Print3D class used to display text
CPVRTPrint3D m_Print3D;
// 3D Model
CPVRTModelPOD m_Scene;
// OpenGL handles for shaders, textures and VBOs
GLuint m_uiVertShader;
GLuint m_uiFragShader;
GLuint* m_puiVbo;
GLuint* m_puiIndexVbo;
GLuint* m_puiTextureIDs;
GLuint m_uiDisMapID;
// Group shader programs and their uniform locations together
struct
{
GLuint uiId;
GLuint uiMVPMatrixLoc;
GLuint uiLightDirLoc;
GLuint uiTexture;
GLuint uiDisMap;
GLuint uiDisplacementFactor;
}
m_ShaderProgram;
// Variables to handle the animation in a time-based manner
unsigned long m_ulTimePrev;
// App variables
PVRTVec4 m_LightDir;
PVRTMat4 m_View, m_Projection;
float m_DisplacementFactor;
bool m_bGrow;
public:
virtual bool InitApplication();
virtual bool InitView();
virtual bool ReleaseView();
virtual bool QuitApplication();
virtual bool RenderScene();
OGLES2DisplacementMap();
bool LoadTextures(CPVRTString* pErrorStr);
bool LoadShaders(CPVRTString* pErrorStr);
bool LoadVbos(CPVRTString* pErrorStr);
void DrawMesh(int i32NodeIndex);
};
/*!****************************************************************************
@Function OGLES2DisplacementMap
@Description Constructor
******************************************************************************/
OGLES2DisplacementMap::OGLES2DisplacementMap() : m_puiVbo(0),
m_puiIndexVbo(0),
m_puiTextureIDs(0),
m_ulTimePrev(0),
m_DisplacementFactor(0),
m_bGrow(false)
{
}
/*!****************************************************************************
@Function LoadTextures
@Return bool true if no error occurred
@Description Loads the textures required for this training course
******************************************************************************/
bool OGLES2DisplacementMap::LoadTextures(CPVRTString* pErrorStr)
{
/*
Load the textures.
For a more detailed explanation, see Texturing and IntroducingPVRTools
*/
/*
Initialises an array to lookup the textures
for each material in the scene.
*/
m_puiTextureIDs = new GLuint[m_Scene.nNumMaterial];
if(!m_puiTextureIDs)
{
*pErrorStr = "ERROR: Insufficient memory.";
return false;
}
for(int i = 0; i < (int) m_Scene.nNumMaterial; ++i)
{
m_puiTextureIDs[i] = 0;
SPODMaterial* pMaterial = &m_Scene.pMaterial[i];
if(pMaterial->nIdxTexDiffuse != -1)
{
/*
Using the tools function PVRTTextureLoadFromPVR load the textures required by the pod file.
Note: This function only loads .pvr files. You can set the textures in 3D Studio Max to .pvr
files using the PVRTexTool plug-in for max. Alternatively, the pod material properties can be
modified in PVRShaman.
*/
CPVRTString sTextureName = m_Scene.pTexture[pMaterial->nIdxTexDiffuse].pszName;
if(PVRTTextureLoadFromPVR(sTextureName.c_str(), &m_puiTextureIDs[i]) != PVR_SUCCESS)
{
*pErrorStr = "ERROR: Failed to load " + sTextureName + ".";
// Check to see if we're trying to load .pvr or not
CPVRTString sFileExtension = PVRTStringGetFileExtension(sTextureName);
if(sFileExtension.toLower() == "pvr")
*pErrorStr += "Note: Can only load pvr files.";
return false;
}
}
}
// Load the texture used for the displacement map
if(PVRTTextureLoadFromPVR(c_szDisMapFile, &m_uiDisMapID) != PVR_SUCCESS)
{
*pErrorStr = "ERROR: Failed to load " + CPVRTString(c_szDisMapFile) + ".";
return false;
}
// Define the wrapping to use for the displacement map
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
return true;
}
/*!****************************************************************************
@Function LoadShaders
@Output pErrorStr A string describing the error on failure
@Return bool true if no error occurred
@Description Loads and compiles the shaders and links the shader programs
required for this training course
******************************************************************************/
bool OGLES2DisplacementMap::LoadShaders(CPVRTString* pErrorStr)
{
/*
Load and compile the shaders from files.
Binary shaders are tried first, source shaders
are used as fallback.
*/
if(PVRTShaderLoadFromFile(
c_szVertShaderBinFile, c_szVertShaderSrcFile, GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_uiVertShader, pErrorStr) != PVR_SUCCESS)
{
return false;
}
if (PVRTShaderLoadFromFile(
c_szFragShaderBinFile, c_szFragShaderSrcFile, GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_uiFragShader, pErrorStr) != PVR_SUCCESS)
{
return false;
}
/*
Set up and link the shader program
*/
const char* aszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };
if(PVRTCreateProgram(
&m_ShaderProgram.uiId, m_uiVertShader, m_uiFragShader, aszAttribs, 3, pErrorStr) != PVR_SUCCESS)
{
PVRShellSet(prefExitMessage, pErrorStr->c_str());
return false;
}
// Store the location of uniforms for later use
m_ShaderProgram.uiMVPMatrixLoc = glGetUniformLocation(m_ShaderProgram.uiId, "MVPMatrix");
m_ShaderProgram.uiLightDirLoc = glGetUniformLocation(m_ShaderProgram.uiId, "LightDirection");
m_ShaderProgram.uiDisplacementFactor = glGetUniformLocation(m_ShaderProgram.uiId, "DisplacementFactor");
m_ShaderProgram.uiTexture = glGetUniformLocation(m_ShaderProgram.uiId, "sTexture");
m_ShaderProgram.uiDisMap = glGetUniformLocation(m_ShaderProgram.uiId, "sDisMap");
return true;
}
/*!****************************************************************************
@Function LoadVbos
@Description Loads the mesh data required for this training course into
vertex buffer objects
******************************************************************************/
bool OGLES2DisplacementMap::LoadVbos(CPVRTString* pErrorStr)
{
if(!m_Scene.pMesh[0].pInterleaved)
{
*pErrorStr = "ERROR: IntroducingPOD requires the pod data to be interleaved. Please re-export with the interleaved option enabled.";
return false;
}
if (!m_puiVbo) m_puiVbo = new GLuint[m_Scene.nNumMesh];
if (!m_puiIndexVbo) m_puiIndexVbo = new GLuint[m_Scene.nNumMesh];
/*
Load vertex data of all meshes in the scene into VBOs
The meshes have been exported with the "Interleave Vectors" option,
so all data is interleaved in the buffer at pMesh->pInterleaved.
Interleaving data improves the memory access pattern and cache efficiency,
thus it can be read faster by the hardware.
*/
glGenBuffers(m_Scene.nNumMesh, m_puiVbo);
for (unsigned int i = 0; i < m_Scene.nNumMesh; ++i)
{
// Load vertex data into buffer object
SPODMesh& Mesh = m_Scene.pMesh[i];
unsigned int uiSize = Mesh.nNumVertex * Mesh.sVertex.nStride;
glBindBuffer(GL_ARRAY_BUFFER, m_puiVbo[i]);
glBufferData(GL_ARRAY_BUFFER, uiSize, Mesh.pInterleaved, GL_STATIC_DRAW);
// Load index data into buffer object if available
m_puiIndexVbo[i] = 0;
if (Mesh.sFaces.pData)
{
glGenBuffers(1, &m_puiIndexVbo[i]);
uiSize = PVRTModelPODCountIndices(Mesh) * sizeof(GLshort);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_puiIndexVbo[i]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, uiSize, Mesh.sFaces.pData, GL_STATIC_DRAW);
}
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
return true;
}
/*!****************************************************************************
@Function InitApplication
@Return bool true if no error occurred
@Description Code in InitApplication() will be called by PVRShell once per
run, before the rendering context is created.
Used to initialize variables that are not dependent on it
(e.g. external modules, loading meshes, etc.)
If the rendering context is lost, InitApplication() will
not be called again.
******************************************************************************/
bool OGLES2DisplacementMap::InitApplication()
{
// Get and set the read path for content files
CPVRTResourceFile::SetReadPath((char*)PVRShellGet(prefReadPath));
// Get and set the load/release functions for loading external files.
// In the majority of cases the PVRShell will return NULL function pointers implying that
// nothing special is required to load external files.
CPVRTResourceFile::SetLoadReleaseFunctions(PVRShellGet(prefLoadFileFunc), PVRShellGet(prefReleaseFileFunc));
// Load the scene
if(m_Scene.ReadFromFile(c_szSceneFile) != PVR_SUCCESS)
{
PVRShellSet(prefExitMessage, "ERROR: Couldn't load the .pod file\n");
return false;
}
// The cameras are stored in the file. We check it contains at least one.
if(m_Scene.nNumCamera == 0)
{
PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a camera. Please add one and re-export.\n");
return false;
}
// We also check that the scene contains at least one light
if(m_Scene.nNumLight == 0)
{
PVRShellSet(prefExitMessage, "ERROR: The scene does not contain a light. Please add one and re-export.\n");
return false;
}
return true;
}
/*!****************************************************************************
@Function QuitApplication
@Return bool true if no error occurred
@Description Code in QuitApplication() will be called by PVRShell once per
run, just before exiting the program.
If the rendering context is lost, QuitApplication() will
not be called.
******************************************************************************/
bool OGLES2DisplacementMap::QuitApplication()
{
// Free the memory allocated for the scene
m_Scene.Destroy();
delete[] m_puiVbo;
delete[] m_puiIndexVbo;
return true;
}
/*!****************************************************************************
@Function InitView
@Return bool true if no error occurred
@Description Code in InitView() will be called by PVRShell upon
initialization or after a change in the rendering context.
Used to initialize variables that are dependent on the rendering
context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLES2DisplacementMap::InitView()
{
CPVRTString ErrorStr;
/*
Initialize VBO data
*/
if(!LoadVbos(&ErrorStr))
{
PVRShellSet(prefExitMessage, ErrorStr.c_str());
return false;
}
/*
Load textures
*/
if(!LoadTextures(&ErrorStr))
{
PVRShellSet(prefExitMessage, ErrorStr.c_str());
return false;
}
/*
Load and compile the shaders & link programs
*/
if(!LoadShaders(&ErrorStr))
{
PVRShellSet(prefExitMessage, ErrorStr.c_str());
return false;
}
/*
Initialize Print3D
*/
bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen);
if(m_Print3D.SetTextures(0,PVRShellGet(prefWidth),PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS)
{
PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D\n");
return false;
}
/*
Set OpenGL ES render states needed for this training course
*/
// Enable backface culling and depth test
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
// Use a nice bright blue as clear colour
glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
//Get the direction of the first light from the scene.
m_LightDir = m_Scene.GetLightDirection(0);
// For direction vectors, w should be 0
m_LightDir.w = 0.0f;
// Set up the view and projection matrices from the camera
PVRTVec3 vFrom, vTo(0.0f), vUp(0.0f, 1.0f, 0.0f);
float fFOV;
// Setup the camera
// Camera nodes are after the mesh and light nodes in the array
int i32CamID = m_Scene.pNode[m_Scene.nNumMeshNode + m_Scene.nNumLight + g_ui32Camera].nIdx;
// Get the camera position, target and field of view (fov)
if(m_Scene.pCamera[i32CamID].nIdxTarget != -1) // Does the camera have a target?
fFOV = m_Scene.GetCameraPos( vFrom, vTo, g_ui32Camera); // vTo is taken from the target node
else
fFOV = m_Scene.GetCamera( vFrom, vTo, vUp, g_ui32Camera); // vTo is calculated from the rotation
// We can build the model view matrix from the camera position, target and an up vector.
// For this we usePVRTMat4LookAtRH()
m_View = PVRTMat4::LookAtRH(vFrom, vTo, vUp);
// Calculate the projection matrix
m_Projection = PVRTMat4::PerspectiveFovRH(fFOV, (float)PVRShellGet(prefWidth)/(float)PVRShellGet(prefHeight), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate);
// Initialize variables used for the animation
m_ulTimePrev = PVRShellGetTime();
return true;
}
/*!****************************************************************************
@Function ReleaseView
@Return bool true if no error occurred
@Description Code in ReleaseView() will be called by PVRShell when the
application quits or before a change in the rendering context.
******************************************************************************/
bool OGLES2DisplacementMap::ReleaseView()
{
// Deletes the textures
glDeleteTextures(m_Scene.nNumMaterial, &m_puiTextureIDs[0]);
glDeleteTextures(1, &m_uiDisMapID);
// Frees the texture lookup array
delete[] m_puiTextureIDs;
m_puiTextureIDs = 0;
// Delete program and shader objects
glDeleteProgram(m_ShaderProgram.uiId);
glDeleteShader(m_uiVertShader);
glDeleteShader(m_uiFragShader);
// Delete buffer objects
glDeleteBuffers(m_Scene.nNumMesh, m_puiVbo);
glDeleteBuffers(m_Scene.nNumMesh, m_puiIndexVbo);
// Release Print3D Textures
m_Print3D.ReleaseTextures();
return true;
}
/*!****************************************************************************
@Function RenderScene
@Return bool true if no error occurred
@Description Main rendering loop function of the program. The shell will
call this function every frame.
eglSwapBuffers() will be performed by PVRShell automatically.
PVRShell will also manage important OS events.
Will also manage relevant OS events. The user has access to
these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLES2DisplacementMap::RenderScene()
{
// Clear the color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Calculates the the time since the last frame
unsigned long ulTime = PVRShellGetTime();
unsigned long ulDeltaTime = ulTime - m_ulTimePrev;
m_ulTimePrev = ulTime;
// Use shader program
glUseProgram(m_ShaderProgram.uiId);
// Enable 2D texturing for the first texture.
glActiveTexture(GL_TEXTURE0);
// Set the sampler2D variable to the first texture unit
glUniform1i(m_ShaderProgram.uiTexture, 0);
// Enable 2D texturing for the second texture.
glActiveTexture(GL_TEXTURE1);
// Set the displacement map variable to the second texture unit
glUniform1i(m_ShaderProgram.uiDisMap, 1);
// Calculate and set the displacement factor
if(m_bGrow)
{
m_DisplacementFactor += (float)ulDeltaTime * g_fDemoFrameRate;
if(m_DisplacementFactor > 25.0f)
{
m_bGrow = false;
m_DisplacementFactor = 25.0f;
}
}
else
{
m_DisplacementFactor -= (float)ulDeltaTime * g_fDemoFrameRate;
if(m_DisplacementFactor < 0.0f)
{
m_bGrow = true;
m_DisplacementFactor = 0.0f;
}
}
glUniform1f(m_ShaderProgram.uiDisplacementFactor, m_DisplacementFactor);
// Bind the displacement map texture
glBindTexture(GL_TEXTURE_2D, m_uiDisMapID);
// Now the displacement map texture is bound set the active texture to texture 0
glActiveTexture(GL_TEXTURE0);
// Draw the scene
// Enable the vertex attribute arrays
glEnableVertexAttribArray(VERTEX_ARRAY);
glEnableVertexAttribArray(NORMAL_ARRAY);
glEnableVertexAttribArray(TEXCOORD_ARRAY);
for(unsigned int i = 0; i < m_Scene.nNumMeshNode; ++i)
{
SPODNode& Node = m_Scene.pNode[i];
// Get the node model matrix
PVRTMat4 mWorld;
mWorld = m_Scene.GetWorldMatrix(Node);
// Pass the model-view-projection matrix (MVP) to the shader to transform the vertices
PVRTMat4 mModelView, mMVP;
mModelView = m_View * mWorld;
mMVP = m_Projection * mModelView;
glUniformMatrix4fv(m_ShaderProgram.uiMVPMatrixLoc, 1, GL_FALSE, mMVP.f);
// Pass the light direction in model space to the shader
PVRTVec4 vLightDir;
vLightDir = mWorld.inverse() * m_LightDir;
PVRTVec3 vLightDirModel = *(PVRTVec3*) vLightDir.ptr();
vLightDirModel.normalize();
glUniform3fv(m_ShaderProgram.uiLightDirLoc, 1, &vLightDirModel.x);
// Load the correct texture for the mesh using our texture lookup table
GLuint uiTex = 0;
if(Node.nIdxMaterial != -1)
uiTex = m_puiTextureIDs[Node.nIdxMaterial];
glBindTexture(GL_TEXTURE_2D, uiTex);
/*
Now that the model-view matrix is set and the materials ready,
call another function to actually draw the mesh.
*/
DrawMesh(i);
}
// Safely disable the vertex attribute arrays
glDisableVertexAttribArray(VERTEX_ARRAY);
glDisableVertexAttribArray(NORMAL_ARRAY);
glDisableVertexAttribArray(TEXCOORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// Display the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools
m_Print3D.DisplayDefaultTitle("DisplacementMapping", "", ePVRTPrint3DSDKLogo);
m_Print3D.Flush();
return true;
}
/*!****************************************************************************
@Function DrawMesh
@Input i32NodeIndex Node index of the mesh to draw
@Description Draws a SPODMesh after the model view matrix has been set and
the material prepared.
******************************************************************************/
void OGLES2DisplacementMap::DrawMesh(int i32NodeIndex)
{
int i32MeshIndex = m_Scene.pNode[i32NodeIndex].nIdx;
SPODMesh* pMesh = &m_Scene.pMesh[i32MeshIndex];
// bind the VBO for the mesh
glBindBuffer(GL_ARRAY_BUFFER, m_puiVbo[i32MeshIndex]);
// bind the index buffer, won't hurt if the handle is 0
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_puiIndexVbo[i32MeshIndex]);
// Set the vertex attribute offsets
glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, pMesh->sVertex.nStride, pMesh->sVertex.pData);
glVertexAttribPointer(NORMAL_ARRAY, 3, GL_FLOAT, GL_FALSE, pMesh->sNormals.nStride, pMesh->sNormals.pData);
glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, pMesh->psUVW[0].nStride, pMesh->psUVW[0].pData);
/*
The geometry can be exported in 4 ways:
- Indexed Triangle list
- Non-Indexed Triangle list
- Indexed Triangle strips
- Non-Indexed Triangle strips
*/
if(pMesh->nNumStrips == 0)
{
if(m_puiIndexVbo[i32MeshIndex])
{
// Indexed Triangle list
glDrawElements(GL_TRIANGLES, pMesh->nNumFaces*3, GL_UNSIGNED_SHORT, 0);
}
else
{
// Non-Indexed Triangle list
glDrawArrays(GL_TRIANGLES, 0, pMesh->nNumFaces*3);
}
}
else
{
int offset = 0;
for(int i = 0; i < (int)pMesh->nNumStrips; ++i)
{
if(m_puiIndexVbo[i32MeshIndex])
{
// Indexed Triangle strips
glDrawElements(GL_TRIANGLE_STRIP, pMesh->pnStripLength[i]+2, GL_UNSIGNED_SHORT, &((GLshort*)0)[offset]);
}
else
{
// Non-Indexed Triangle strips
glDrawArrays(GL_TRIANGLE_STRIP, offset, pMesh->pnStripLength[i]+2);
}
offset += pMesh->pnStripLength[i]+2;
}
}
}
/*!****************************************************************************
@Function NewDemo
@Return PVRShell* The demo supplied by the user
@Description This function must be implemented by the user of the shell.
The user should return its PVRShell object defining the
behaviour of the application.
******************************************************************************/
PVRShell* NewDemo()
{
return new OGLES2DisplacementMap();
}
/******************************************************************************
End of file (OGLES2DisplacementMap.cpp)
******************************************************************************/
attribute highp vec3 inVertex;
attribute mediump vec3 inNormal;
attribute mediump vec2 inTexCoord;
uniform highp mat4 MVPMatrix;
uniform mediump vec3 LightDirection;
uniform mediump float DisplacementFactor;
varying lowp float LightIntensity;
varying mediump vec2 TexCoord;
uniform sampler2D sDisMap;
void main()
{
/*
Calculate the displacemnt value by taking the colour value from our texture
and scale it by out displacement factor.
*/
mediump float disp = texture2D(sDisMap, inTexCoord).r * DisplacementFactor;
/*
Transform position by the model-view-projection matrix but first
move the untransformed position along the normal by our displacement
value.
*/
gl_Position = MVPMatrix * vec4(inVertex + (inNormal * disp), 1.0);
// Pass through texcoords
TexCoord = inTexCoord;
// Simple diffuse lighting in model space
LightIntensity = dot(inNormal, -LightDirection);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment