Commit 7b21f276 by Nicolas Capens Committed by Nicolas Capens

Add the ChameleonMan PowerVR sample.

BUG=14598298 Change-Id: Id6dcaebe793cf3d3a10af571348f461023d2a9d2 Reviewed-on: https://swiftshader-review.googlesource.com/1090Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 6f1f1567
......@@ -211,6 +211,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2HelloAPI", "..\tests\
{E746FCA9-64C3-433E-85E8-9A5A67AB7ED6} = {E746FCA9-64C3-433E-85E8-9A5A67AB7ED6}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2ChameleonMan", "..\tests\third_party\PowerVR\Examples\Advanced\ChameleonMan\OGLES2\Build\WindowsVC2010\OGLES2ChameleonMan.vcxproj", "{9CF4408B-9B08-481F-95DA-3DF0846DABE4}"
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
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2Tools", "..\tests\third_party\PowerVR\Tools\OGLES2\Build\WindowsVC2010\OGLES2Tools.vcxproj", "{09ABE661-9BC0-4152-A820-1FB0522CAC01}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
......@@ -545,6 +553,30 @@ Global
{9DAFEE32-19F6-4410-AA09-2B564FB86F62}.Release|Win32.Build.0 = Release|Win32
{9DAFEE32-19F6-4410-AA09-2B564FB86F62}.Release|x64.ActiveCfg = Release|x64
{9DAFEE32-19F6-4410-AA09-2B564FB86F62}.Release|x64.Build.0 = Release|x64
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Debug|Win32.ActiveCfg = Debug|Win32
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Debug|Win32.Build.0 = Debug|Win32
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Debug|x64.ActiveCfg = Debug|x64
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Debug|x64.Build.0 = Debug|x64
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Profile|Win32.ActiveCfg = Release|Win32
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Profile|Win32.Build.0 = Release|Win32
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Profile|x64.ActiveCfg = Release|x64
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Profile|x64.Build.0 = Release|x64
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Release|Win32.ActiveCfg = Release|Win32
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Release|Win32.Build.0 = Release|Win32
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Release|x64.ActiveCfg = Release|x64
{9CF4408B-9B08-481F-95DA-3DF0846DABE4}.Release|x64.Build.0 = Release|x64
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Debug|Win32.ActiveCfg = Debug|Win32
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Debug|Win32.Build.0 = Debug|Win32
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Debug|x64.ActiveCfg = Debug|x64
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Debug|x64.Build.0 = Debug|x64
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Profile|Win32.ActiveCfg = Release|Win32
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Profile|Win32.Build.0 = Release|Win32
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Profile|x64.ActiveCfg = Release|x64
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Profile|x64.Build.0 = Release|x64
{09ABE661-9BC0-4152-A820-1FB0522CAC01}.Release|Win32.ActiveCfg = Release|Win32
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -576,5 +608,7 @@ Global
{5B3A6DB8-1E7E-40D7-92B9-DA8AAE619FAD} = {D33114D7-E582-4D61-B27D-FAB0297C43FF}
{92940255-AB4B-42FB-A2C4-0FAB19C3C48A} = {D33114D7-E582-4D61-B27D-FAB0297C43FF}
{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}
EndGlobalSection
EndGlobal
:Title:
ChameleonMan
:ShortDescription:
This demo shows a matrix skinned character in combination with bump mapping.
:FullDescription:
The ChameleonMan demo shows a Matrix Skinned Character in combination with bump mapping.
Matrix Skinning is the act of animating a vertex over time given a set (palette) of matrices and a known set of blend weights assigned to those matrices. The ChameleonMan model has 19 bones and an animation cycle of 16 frames.
For each frame the Matrix Palette is recomputed based on time. For example to render the model at time point 5.25 the application would linearly blend between the matrices stored for frame 5 and 6 using weights of 0.75 and 0.25 respectively.
Per vertex, up to 3 matrices, from the palette, along with 3 weights are used by the vertex shader to update the vertex position to obtain the current animation frame position.
Two lighting modes are available:
- per vertex lighting
- bump mapped lighting
Controls:
- 1 - Toggle lighting modes
- Esc - Close the application
<?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="..\..\OGLES2ChameleonMan.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\skyline.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\Wall_diffuse_baked.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\Tang_space_BodyMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\Tang_space_LegsMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\Tang_space_BeltMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\FinalChameleonManLegs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\FinalChameleonManHeadBody.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\lamp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\ChameleonBelt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\SkinnedVertShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\SkinnedFragShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\DefaultVertShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\DefaultFragShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\Content\ChameleonScene.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\ChameleonScene.pod">
<Filter>Content Files\Scene Files</Filter>
</CustomBuild>
<CustomBuild Include="..\..\skyline.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\Wall_diffuse_baked.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\FinalChameleonManLegs.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\Tang_space_LegsMap.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\Tang_space_BodyMap.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\lamp.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\ChameleonBelt.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\FinalChameleonManHeadBody.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\Tang_space_BeltMap.pvr">
<Filter>Content Files\Textures</Filter>
</CustomBuild>
<CustomBuild Include="..\..\SkinnedVertShader.vsh">
<Filter>Content Files\Shaders</Filter>
</CustomBuild>
<CustomBuild Include="..\..\SkinnedFragShader.fsh">
<Filter>Content Files\Shaders</Filter>
</CustomBuild>
<CustomBuild Include="..\..\DefaultVertShader.vsh">
<Filter>Content Files\Shaders</Filter>
</CustomBuild>
<CustomBuild Include="..\..\DefaultFragShader.fsh">
<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 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: ChameleonBelt.pvr ********
// File data
A32BIT _ChameleonBelt_pvr[] = {
0x3525650,0x0,0x3,0x0,0x0,0x0,0x20,0x20,0x1,0x1,0x1,0x6,0xf,0x3525650,0x3,0x3,0xeb000200,0x60020201,0x3e6a4e2,0x60035703,0xffe281e2,0x60101010,0x10e281e2,0x61545554,0x3e280e2,0x80030303,0x3e682e2,0x60030303,0x54e682e2,0x60949094,0x94e280e2,0x60949594,0xffe280e2,0x80000000,0xe682e2,0x60a95545,0xffe280e2,0x60000000,0x10e682e2,0x60aa5555,0xaae280e2,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0x3e680de,0x80030303,0x3e682e2,0x60030303,0x94e682e2,0x60949094,0x94e280e2,0x60949594,0x3e280e2,0x80030303,0x3e682e2,0x60ff0203,0x54e282e2,0x60545094,0x50e280e2,0x60ff0000,
0xaae682e2,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x605555a9,0x15e280e2,0x60ff0000,0x55e682e2,0x61005555,0xe280e2,0x80ff0000,0xffe682e2,0x80000000,0xe682e2,0x60aa5545,0xffe280e2,0x60000000,0x10e682e2,0x60aa5555,0xaae280e2,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xffe680de,0x80000000,0xe682e2,0x60595505,0xeae280e2,0x60808040,0x80e6a4e2,0x60c1c1c0,0x55e682e2,0x61555555,0x15e280e2,0x61151515,0xc1e280e2,0x60c0c1c1,0xc0e682e2,0x80c0c0c0,0xaae682e2,0x60aa9aaa,0xaae280e2,0x40aaaaaa,0xaae680de,0x40aaaaaa,0xaae680de,0x40aaaaaa,0x55e680de,0x61545555,0x10e280e2,0x60ff0000,0x55e682e2,0x61005555,0xe280e2,0x80ff0000,
0x15e682e2,0x61555555,0x15e280e2,0x61151515,0xc0e280e2,0x60c0c1c0,0xc0e682e2,0x80c0c0c0,0x56e682e2,0x60555559,0x10e280e2,0x60ff0000,0xc0e682e2,0x60c0c1c0,0xc0e682e2,0x60ea8080,0xabe6a4e2,0x80020202,0x2e682e2,0x60030202,0xfee282e2,0x60001000,0xe281e2,0x81545450,0x3e260e2,0x81030303,0x3e281e2,0x61010101,0x60e682e2,0x60505480,0xe280e2,0x81000000,0xffe281e2,0x81000000,0xe281e2,0x60595211,0xaae280e2,0x60000000,0xe282e2,0x81000000,0x56e281e2,0x60555595,0x55e680e2,0x60000000,0x1e261e2,0x61051d0d,0xe260e2,0x80000000,0x77e682e2,0x8131d711,0x1e260e2,0x61010101,0x55e281e2,0x61000000,0xe281e2,0x61000000,0x56e682e2,0x60555555,0x56e280e2,0x60450145,0x56e281e2,0x60450145,0x56e281e2,0x60555555,
0xaae280e2,0x609a569a,0xaae280e2,0x60baeeba,0xaae260e2,0x60baeeba,0xaae260e2,0x609a569a,0xaae280e2,0x40aaaaaa,0xaae280e2,0x40aaaaaa,0xaae280e2,0x40aaaaaa,0xaae280e2,0x40aaaaaa,0xe280e2,
};
// Register ChameleonBelt.pvr in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_ChameleonBelt_pvr("ChameleonBelt.pvr", _ChameleonBelt_pvr, 835);
// ******** End: ChameleonBelt.pvr ********
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: DefaultFragShader.fsh ********
// File data
static const char _DefaultFragShader_fsh[] =
"uniform sampler2D sTexture;\n"
"\n"
"varying mediump vec2 TexCoord;\n"
"\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(sTexture, TexCoord);\n"
"}\n";
// Register DefaultFragShader.fsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_DefaultFragShader_fsh("DefaultFragShader.fsh", _DefaultFragShader_fsh, 128);
// ******** End: DefaultFragShader.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: DefaultVertShader.vsh ********
// File data
static const char _DefaultVertShader_vsh[] =
"attribute highp vec3 inVertex;\n"
"attribute mediump vec2 inTexCoord;\n"
"\n"
"uniform highp mat4 MVPMatrix;\n"
"uniform float\tfUOffset;\n"
"\n"
"varying mediump vec2 TexCoord;\n"
"\n"
"void main()\n"
"{\n"
"\tgl_Position = MVPMatrix * vec4(inVertex, 1.0);\n"
"\n"
"\t// Pass through texcoords\n"
"\tTexCoord = inTexCoord;\n"
"\tTexCoord.x += fUOffset;\n"
"}\n"
" ";
// Register DefaultVertShader.vsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_DefaultVertShader_vsh("DefaultVertShader.vsh", _DefaultVertShader_vsh, 301);
// ******** End: DefaultVertShader.vsh ********
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: SkinnedFragShader.fsh ********
// File data
static const char _SkinnedFragShader_fsh[] =
"uniform sampler2D sTexture;\n"
"uniform sampler2D sNormalMap;\n"
"uniform bool bUseDot3;\n"
"\n"
"varying mediump vec2 TexCoord;\n"
"varying mediump vec3 Light;\n"
"\n"
"void main()\n"
"{\n"
"\tif(bUseDot3)\n"
"\t{\n"
"\t\t/*\n"
"\t\t\tNote:\n"
"\t\t\tIn the normal map red = y, green = x, blue = z which is why when we get the normal\n"
"\t\t\tfrom the texture we use the swizzle .grb so the colours are mapped to the correct\n"
"\t\t\tco-ordinate variable.\n"
"\t\t*/\n"
"\n"
"\t\tmediump vec3 fNormal = texture2D(sNormalMap, TexCoord).grb;\n"
"\t\tmediump float fNDotL = dot((fNormal - 0.5) * 2.0, Light);\n"
"\t\t\n"
"\t\tgl_FragColor = texture2D(sTexture, TexCoord) * fNDotL;\n"
" }\n"
" else\n"
"\t\tgl_FragColor = texture2D(sTexture, TexCoord) * Light.x;\n"
"}\n";
// Register SkinnedFragShader.fsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_SkinnedFragShader_fsh("SkinnedFragShader.fsh", _SkinnedFragShader_fsh, 646);
// ******** End: SkinnedFragShader.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: SkinnedVertShader.vsh ********
// File data
static const char _SkinnedVertShader_vsh[] =
"/*\n"
"\tIf the current vertex is affected by bones then the vertex position and\n"
"\tnormal will be transformed by the bone matrices. Each vertex wil have up \n"
"\tto 4 bone indices (inBoneIndex) and bone weights (inBoneWeights).\n"
"\t\n"
"\tThe indices are used to index into the array of bone matrices \n"
"\t(BoneMatrixArray) to get the required bone matrix for transformation. The \n"
"\tamount of influence a particular bone has on a vertex is determined by the\n"
"\tweights which should always total 1. So if a vertex is affected by 2 bones \n"
"\tthe vertex position in world space is given by the following equation:\n"
"\n"
"\tposition = (BoneMatrixArray[Index0] * inVertex) * Weight0 + \n"
"\t (BoneMatrixArray[Index1] * inVertex) * Weight1\n"
"\n"
"\tThe same proceedure is applied to the normals but the translation part of \n"
"\tthe transformation is ignored.\n"
"\n"
"\tAfter this the position is multiplied by the view and projection matrices \n"
"\tonly as the bone matrices already contain the model transform for this \n"
"\tparticular mesh. The two-step transformation is required because lighting \n"
"\twill not work properly in clip space.\n"
"*/\n"
"\n"
"attribute highp vec3 inVertex;\n"
"attribute mediump vec3 inNormal;\n"
"attribute mediump vec3 inTangent;\n"
"attribute mediump vec3 inBiNormal;\n"
"attribute mediump vec2 inTexCoord;\n"
"attribute mediump vec4 inBoneIndex;\n"
"attribute mediump vec4 inBoneWeights;\n"
"\n"
"uniform highp mat4 ViewProjMatrix;\n"
"uniform mediump vec3 LightPos;\n"
"uniform mediump\tint\t BoneCount;\n"
"uniform highp mat4 BoneMatrixArray[8];\n"
"uniform highp mat3 BoneMatrixArrayIT[8];\n"
"uniform bool\tbUseDot3;\n"
"\n"
"varying mediump vec3 Light;\n"
"varying mediump vec2 TexCoord;\n"
"\n"
"void main()\n"
"{\n"
"\tif(BoneCount > 0)\n"
"\t{\n"
"\t\t// On PowerVR SGX it is possible to index the components of a vector\n"
"\t\t// with the [] operator. However this can cause trouble with PC\n"
"\t\t// emulation on some hardware so we \"rotate\" the vectors instead.\n"
"\t\tmediump ivec4 boneIndex = ivec4(inBoneIndex);\n"
"\t\tmediump vec4 boneWeights = inBoneWeights;\n"
"\t\n"
"\t\thighp mat4 boneMatrix = BoneMatrixArray[boneIndex.x];\n"
"\t\tmediump mat3 normalMatrix = BoneMatrixArrayIT[boneIndex.x];\n"
"\t\n"
"\t\thighp vec4 position = boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;\n"
"\t\tmediump vec3 worldNormal = normalMatrix * inNormal * boneWeights.x;\n"
"\t\t\n"
"\t\tmediump vec3 worldTangent;\n"
"\t\tmediump vec3 worldBiNormal;\n"
"\t\t\n"
"\t\tif(bUseDot3)\n"
"\t\t{\n"
"\t\t\tworldTangent = normalMatrix * inTangent * boneWeights.x;\n"
"\t\t\tworldBiNormal = normalMatrix * inBiNormal * boneWeights.x;\n"
"\t\t}\n"
"\t\n"
"\t\tfor (lowp int i = 1; i < 3; ++i)\n"
"\t\t{\n"
"\t\t\tif(i < BoneCount)\n"
"\t\t\t{\n"
"\t\t\t\t// \"rotate\" the vector components\n"
"\t\t\t\tboneIndex = boneIndex.yzwx;\n"
"\t\t\t\tboneWeights = boneWeights.yzwx;\n"
"\t\t\t\n"
"\t\t\t\tboneMatrix = BoneMatrixArray[boneIndex.x];\n"
"\t\t\t\tnormalMatrix = BoneMatrixArrayIT[boneIndex.x];\n"
"\n"
"\t\t\t\tposition += boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;\n"
"\t\t\t\tworldNormal += normalMatrix * inNormal * boneWeights.x;\n"
"\t\t\t\t\n"
"\t\t\t\tif(bUseDot3)\n"
"\t\t\t\t{\n"
"\t\t\t\t\tworldTangent += normalMatrix * inTangent * boneWeights.x;\n"
"\t\t\t\t\tworldBiNormal += normalMatrix * inBiNormal * boneWeights.x;\n"
"\t\t\t\t}\n"
"\t\t\t}\n"
"\t\t}\t\t\n"
"\t\tgl_Position = ViewProjMatrix * position;\n"
"\t\t\n"
"\t\t// lighting\n"
"\t\tmediump vec3 TmpLightDir = normalize(LightPos - position.xyz);\n"
"\t\t\n"
"\t\tif(bUseDot3)\n"
"\t\t{\n"
"\t\t\tLight.x = dot(normalize(worldTangent), TmpLightDir);\n"
"\t\t\tLight.y = dot(normalize(worldBiNormal), TmpLightDir);\n"
"\t\t\tLight.z = dot(normalize(worldNormal), TmpLightDir);\n"
"\t\t}\n"
"\t\telse\n"
"\t\t{\n"
"\t\t\tLight.x = dot(normalize(worldNormal), TmpLightDir);\n"
"\t\t}\n"
"\t}\n"
"\n"
"\t\n"
"\t// Pass through texcoords\n"
"\tTexCoord = inTexCoord;\n"
"}\n"
" ";
// Register SkinnedVertShader.vsh in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_SkinnedVertShader_vsh("SkinnedVertShader.vsh", _SkinnedVertShader_vsh, 3431);
// ******** End: SkinnedVertShader.vsh ********
// 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: Tang_space_BeltMap.pvr ********
// File data
A32BIT _Tang_space_BeltMap_pvr[] = {
0x3525650,0x0,0x3,0x0,0x0,0x0,0x20,0x20,0x1,0x1,0x1,0x1,0xf,0x3525650,0x3,0x3,0x16000200,0x1ce730b8,0x8ec61ebe,0x1cce3c77,0x47c1dfba,0x3e1b6754,0x46d1fdb6,0x1efcaec1,0x73c9ffb6,0xbee7994a,0x61c25ebd,0xde622bed,0xefbe5fc5,0x9c3999af,0x75be5fbd,0x3fddfc43,0x61c5feb6,0xde8071de,0x54c25dc1,0x1e5aaa42,0xf8ce1eb6,0xfce988a7,0xa8be3fc9,0xbcefa025,0xb6ba5fc9,0xde50a571,0x5bc27ebd,0xfe9f826a,0x89c63ebd,0xfe0bb81f,0xf3c21fbd,0xfc6f5e56,0x7aca1fb1,0xde955ad8,0x65ba3fcd,0xdc6b2757,0x3dc23fbd,0xdebbf24e,0x42c21fbd,0xbe849434,0xcbc27fc1,0xfc506636,0x58be7fc1,0xbe964f65,0x11c65eb9,0xde89406d,0x75be5fc1,0xbeac2466,
0xd1ba9ec9,0x3c4a6b90,0x10ce1fb6,0xdf174df5,0xe3c63ebd,0x3e6b1d08,0x5bc19ebe,0x3e06ef7e,0xb9c5ddbe,0x9c7fbbc7,0x7dc25ebd,0xfe0d8a75,0x1be1fc9,0x1e41261e,0x93ca1fba,0x9e8f6b1c,0x4dc25db9,0x7c4ff7e6,0x1abe3fc5,0x1cd9cf3d,0x85c1ffc2,0x5e73a90c,0x77c61fba,0x1f5f4441,0xa0cdfeb6,0xdcf08bd5,0xc7c67eb9,0x1e6a3999,0x7bca1eb6,0x9eccfae1,0xc7be1fc9,0xde1f6abd,0xebc61db5,0x9c3e25bf,0x47be3fc5,0x7e255ced,0x68cddeb6,0xfe1720ca,0xb9c67fbd,0xfec20792,0x77c23eb9,0xbe994ef8,0x81c23ebd,0x3edc462d,0x6ace1fb6,0xdcedabe1,0x76c61fb1,0xbc55c6c4,0x57c21fb9,0xfea26a85,0x25ce3db9,0x3ee367aa,0x3fc5ffb6,0xbece88d4,0xf3be3fc1,0xdc3e74b4,0xdfc21fb9,0x1ec0fa7b,0xf3c5ffb6,0xdc126a65,0xbfc27fc1,0xfee800be,0x77c61db5,0xbe4e2595,
0xb3c63fbd,0xdea5494a,0x5db67ec1,0xde5bda6c,0xadbe3fc5,0x9ce3b6a2,0x75c23fbd,0xbc5897a8,0x8ac25ebd,0x1e61555e,0x6bcdfeb2,0xbafaccfa,0x7eb9ffc5,0xde84f22f,0x10c61ebd,0x5e1cabeb,0xcdfeae,
};
// Register Tang_space_BeltMap.pvr in memory file system at application startup time
static CPVRTMemoryFileSystem RegisterFile_Tang_space_BeltMap_pvr("Tang_space_BeltMap.pvr", _Tang_space_BeltMap_pvr, 579);
// ******** End: Tang_space_BeltMap.pvr ********
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 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.
uniform sampler2D sTexture;
varying mediump vec2 TexCoord;
void main()
{
gl_FragColor = texture2D(sTexture, TexCoord);
}
attribute highp vec3 inVertex;
attribute mediump vec2 inTexCoord;
uniform highp mat4 MVPMatrix;
uniform float fUOffset;
varying mediump vec2 TexCoord;
void main()
{
gl_Position = MVPMatrix * vec4(inVertex, 1.0);
// Pass through texcoords
TexCoord = inTexCoord;
TexCoord.x += fUOffset;
}
\ No newline at end of file
uniform sampler2D sTexture;
uniform sampler2D sNormalMap;
uniform bool bUseDot3;
varying mediump vec2 TexCoord;
varying mediump vec3 Light;
void main()
{
if(bUseDot3)
{
/*
Note:
In the normal map red = y, green = x, blue = z which is why when we get the normal
from the texture we use the swizzle .grb so the colours are mapped to the correct
co-ordinate variable.
*/
mediump vec3 fNormal = texture2D(sNormalMap, TexCoord).grb;
mediump float fNDotL = dot((fNormal - 0.5) * 2.0, Light);
gl_FragColor = texture2D(sTexture, TexCoord) * fNDotL;
}
else
gl_FragColor = texture2D(sTexture, TexCoord) * Light.x;
}
/*
If the current vertex is affected by bones then the vertex position and
normal will be transformed by the bone matrices. Each vertex wil have up
to 4 bone indices (inBoneIndex) and bone weights (inBoneWeights).
The indices are used to index into the array of bone matrices
(BoneMatrixArray) to get the required bone matrix for transformation. The
amount of influence a particular bone has on a vertex is determined by the
weights which should always total 1. So if a vertex is affected by 2 bones
the vertex position in world space is given by the following equation:
position = (BoneMatrixArray[Index0] * inVertex) * Weight0 +
(BoneMatrixArray[Index1] * inVertex) * Weight1
The same proceedure is applied to the normals but the translation part of
the transformation is ignored.
After this the position is multiplied by the view and projection matrices
only as the bone matrices already contain the model transform for this
particular mesh. The two-step transformation is required because lighting
will not work properly in clip space.
*/
attribute highp vec3 inVertex;
attribute mediump vec3 inNormal;
attribute mediump vec3 inTangent;
attribute mediump vec3 inBiNormal;
attribute mediump vec2 inTexCoord;
attribute mediump vec4 inBoneIndex;
attribute mediump vec4 inBoneWeights;
uniform highp mat4 ViewProjMatrix;
uniform mediump vec3 LightPos;
uniform mediump int BoneCount;
uniform highp mat4 BoneMatrixArray[8];
uniform highp mat3 BoneMatrixArrayIT[8];
uniform bool bUseDot3;
varying mediump vec3 Light;
varying mediump vec2 TexCoord;
void main()
{
if(BoneCount > 0)
{
// On PowerVR SGX it is possible to index the components of a vector
// with the [] operator. However this can cause trouble with PC
// emulation on some hardware so we "rotate" the vectors instead.
mediump ivec4 boneIndex = ivec4(inBoneIndex);
mediump vec4 boneWeights = inBoneWeights;
highp mat4 boneMatrix = BoneMatrixArray[boneIndex.x];
mediump mat3 normalMatrix = BoneMatrixArrayIT[boneIndex.x];
highp vec4 position = boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;
mediump vec3 worldNormal = normalMatrix * inNormal * boneWeights.x;
mediump vec3 worldTangent;
mediump vec3 worldBiNormal;
if(bUseDot3)
{
worldTangent = normalMatrix * inTangent * boneWeights.x;
worldBiNormal = normalMatrix * inBiNormal * boneWeights.x;
}
for (lowp int i = 1; i < 3; ++i)
{
if(i < BoneCount)
{
// "rotate" the vector components
boneIndex = boneIndex.yzwx;
boneWeights = boneWeights.yzwx;
boneMatrix = BoneMatrixArray[boneIndex.x];
normalMatrix = BoneMatrixArrayIT[boneIndex.x];
position += boneMatrix * vec4(inVertex, 1.0) * boneWeights.x;
worldNormal += normalMatrix * inNormal * boneWeights.x;
if(bUseDot3)
{
worldTangent += normalMatrix * inTangent * boneWeights.x;
worldBiNormal += normalMatrix * inBiNormal * boneWeights.x;
}
}
}
gl_Position = ViewProjMatrix * position;
// lighting
mediump vec3 TmpLightDir = normalize(LightPos - position.xyz);
if(bUseDot3)
{
Light.x = dot(normalize(worldTangent), TmpLightDir);
Light.y = dot(normalize(worldBiNormal), TmpLightDir);
Light.z = dot(normalize(worldNormal), TmpLightDir);
}
else
{
Light.x = dot(normalize(worldNormal), TmpLightDir);
}
}
// Pass through texcoords
TexCoord = inTexCoord;
}
\ No newline at end of file
/*!****************************************************************************
@file KEGL/PVRShellAPI.h
@ingroup API_KEGL
@copyright Copyright (c) Imagination Technologies Limited.
@brief 3D API context management for KEGL.
@details Makes programming for 3D APIs easier by wrapping surface
initialization, Texture allocation and other functions for use by a demo.
******************************************************************************/
#ifndef __PVRSHELLAPI_H_
#define __PVRSHELLAPI_H_
/****************************************************************************
** 3D API header files
****************************************************************************/
#if defined(BUILD_OGLES2)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#elif defined(BUILD_OGLES3)
#include <GLES3/gl3.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#elif defined(BUILD_OGL)
#define SUPPORT_OPENGL
#if defined(_WIN32)
#include <windows.h>
#endif
#include <GL/gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#else
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES/glplatform.h>
#endif
/*!***************************************************************************
@addtogroup API_KEGL
@brief KEGL API
@{
****************************************************************************/
/*!***************************************************************************
@class PVRShellInitAPI
@brief Initialisation interface with specific API.
****************************************************************************/
class PVRShellInitAPI
{
public:
EGLDisplay m_EGLDisplay;
EGLSurface m_EGLWindow;
EGLContext m_EGLContext;
EGLConfig m_EGLConfig;
EGLint m_MajorVersion, m_MinorVersion;
bool m_bPowerManagementSupported;
EGLint m_iRequestedConfig;
EGLint m_iConfig;
EGLNativeDisplayType m_NDT;
EGLNativePixmapType m_NPT;
EGLNativeWindowType m_NWT;
public:
PVRShellInitAPI() : m_bPowerManagementSupported(false), m_iRequestedConfig(0), m_iConfig(0) {}
EGLConfig SelectEGLConfiguration(const PVRShellData * const pData);
const char *StringFrom_eglGetError() const;
#if defined(BUILD_OGLES) || defined(BUILD_OGLES2)
protected:
typedef void (GL_APIENTRY * PFNGLDISCARDFRAMEBUFFEREXT)(GLenum target, GLsizei numAttachments, const GLenum *attachments);
PFNGLDISCARDFRAMEBUFFEREXT glDiscardFramebufferEXT;
#endif
};
/*! @} */
#endif // __PVRSHELLAPI_H_
/*****************************************************************************
End of file (PVRShellAPI.h)
*****************************************************************************/
/*!****************************************************************************
@file Windows/PVRShellOS.h
@ingroup OS_Windows
@copyright Copyright (c) Imagination Technologies Limited.
@brief Initialization for the shell for the Windows OS.
@details Makes programming for 3D APIs easier by wrapping surface
initialization, Texture allocation and other functions for use by a demo.
******************************************************************************/
#ifndef _PVRSHELLOS_
#define _PVRSHELLOS_
#include <windows.h>
// The following defines are for Windows PC platforms only
#if defined(_WIN32)
// Enable the following 2 lines for memory leak checking - also see WinMain()
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif
#define PVRSHELL_DIR_SYM '\\'
#define vsnprintf _vsnprintf
/*!
@addtogroup OS_Windows
@brief Windows OS
@details The following table illustrates how key codes are mapped in Windows:
<table>
<tr><th> Key code </th><th> KeyPressed (PVRShell) </th></tr>
<tr><td> ESCAPE </td><td> PVRShellKeyNameQUIT </td></tr>
<tr><td> UP </td><td> m_eKeyMapUP </td></tr>
<tr><td> DOWN </td><td> m_eKeyMapDOWN </td></tr>
<tr><td> LEFT </td><td> m_eKeyMapLEFT </td></tr>
<tr><td> RIGHT </td><td> m_eKeyMapRIGHT </td></tr>
<tr><td> SPACE </td><td> PVRShellKeyNameSELECT </td></tr>
<tr><td> '1' </td><td> PVRShellKeyNameACTION1 </td></tr>
<tr><td> '2' </td><td> PVRShellKeyNameACTION2 </td></tr>
<tr><td> F11 </td><td> PVRShellKeyNameScreenshot </td></tr>
</table>
@{
*/
/*!***************************************************************************
@class PVRShellInitOS
@brief Interface with specific Operating System.
*****************************************************************************/
class PVRShellInitOS
{
public:
HDC m_hDC;
HWND m_hWnd;
// Pixmap support: variables for the pixmap
HBITMAP m_hBmPixmap, m_hBmPixmapOld;
HDC m_hDcPixmap;
HACCEL m_hAccelTable;
HINSTANCE m_hInstance;
int m_nCmdShow;
bool m_bHaveFocus;
unsigned int m_u32ButtonState;
public:
ATOM MyRegisterClass();
};
/*! @} */
#endif /* _PVRSHELLOS_ */
/*****************************************************************************
End of file (PVRShellOS.h)
*****************************************************************************/
<?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>{bbb4df65-4bc5-4e29-8633-ab3d26acb43b}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{5da3e075-728f-4749-9ea5-d5d0800089da}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</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</Extensions>
</Filter>
<Filter Include="Shader Files">
<UniqueIdentifier>{9e03f4db-475e-4f8e-97f0-2157fdba92a1}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\PVRTBackground.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTDecompress.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTError.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTFixedPoint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\PVRTgles2Ext.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTMatrixF.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTMatrixX.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTMisc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTModelPOD.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTPFXParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\PVRTPFXParserAPI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTPrint3D.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\PVRTPrint3DAPI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTQuaternionF.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTQuaternionX.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTResourceFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\PVRTShader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTShadowVol.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTString.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTTexture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\PVRTTextureAPI.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTTrans.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTTriStrip.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTVector.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTVertex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTUnicode.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\PVRTStringHash.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\PVRTPFXSemantics.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\OGLES2Tools.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTArray.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTBackground.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTBackgroundShaders.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTBoneBatch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTContext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTDecompress.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTError.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTFixedPoint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTgles2Ext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTGlobal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTHash.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTMatrix.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTMemoryFileSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTMisc.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTModelPOD.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTPFXParser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTPFXParserAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTPrint3D.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTPrint3Ddat.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTPrint3DShaders.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTQuaternion.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTResourceFile.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTShader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTShadowVol.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTString.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTTexture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTTextureAPI.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTTrans.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTTriStrip.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTVector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTVertex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTUnicode.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\PVRTStringHash.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\PVRTPFXSemantics.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
/*!****************************************************************************
@file OGLES2/OGLES2Tools.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief Header file of OGLES2Tools.lib.
******************************************************************************/
#ifndef _OGLES2TOOLS_H_
#define _OGLES2TOOLS_H_
/*!
@addtogroup API_OGLES2
@brief Tools for the OpenGL ES 2.0 API.
*/
#ifndef BUILD_OGLES2
#define BUILD_OGLES2
#endif
#include "PVRTContext.h"
#include "../PVRTGlobal.h"
#include "../PVRTArray.h"
#include "../PVRTHash.h"
#include "../PVRTVector.h"
#include "../PVRTString.h"
#include "../PVRTStringHash.h"
#include "../PVRTFixedPoint.h"
#include "../PVRTMatrix.h"
#include "../PVRTQuaternion.h"
#include "../PVRTTrans.h"
#include "../PVRTVertex.h"
#include "../PVRTMap.h"
#include "../PVRTMisc.h"
#include "../PVRTBackground.h"
#include "PVRTgles2Ext.h"
#include "../PVRTPrint3D.h"
#include "../PVRTBoneBatch.h"
#include "../PVRTModelPOD.h"
#include "../PVRTTexture.h"
#include "PVRTTextureAPI.h"
#include "../PVRTTriStrip.h"
#include "PVRTShader.h"
#include "../PVRTPFXParser.h"
#include "PVRTPFXParserAPI.h"
#include "PVRTPFXSemantics.h"
#include "../PVRTShadowVol.h"
#include "../PVRTResourceFile.h"
#include "../PVRTError.h"
#endif /* _OGLES2TOOLS_H_ */
/*****************************************************************************
End of file (OGLES2Tools.h)
*****************************************************************************/
/******************************************************************************
@File OGLES2/PVRTBackground.cpp
@Title OGLES2/PVRTBackground
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform ANSI compatible
@Description Function to draw a background texture.
******************************************************************************/
#include "PVRTShader.h"
#include "PVRTBackground.h"
// The header that contains the shaders
#include "PVRTBackgroundShaders.h"
// Index to bind the attributes to vertex shaders
const int VERTEX_ARRAY = 0;
const int TEXCOORD_ARRAY = 1;
/****************************************************************************
** Structures
****************************************************************************/
// The struct to include various API variables
struct SPVRTBackgroundAPI
{
GLuint m_ui32VertexShader;
GLuint m_ui32FragShader;
GLuint m_ui32ProgramObject;
GLuint m_ui32VertexBufferObject;
};
/****************************************************************************
** Class: CPVRTBackground
****************************************************************************/
/*****************************************************************************
@Function Background
@Description Init some values.
*****************************************************************************/
CPVRTBackground::CPVRTBackground(void)
{
m_bInit = false;
m_pAPI = 0;
}
/*****************************************************************************
@Function ~Background
@Description Calls Destroy()
*****************************************************************************/
CPVRTBackground::~CPVRTBackground(void)
{
delete m_pAPI;
m_pAPI = 0;
}
/*!***************************************************************************
@Function Destroy
@Description Destroys the background and releases API specific resources
*****************************************************************************/
void CPVRTBackground::Destroy()
{
if(m_bInit)
{
// Delete shaders
glDeleteProgram(m_pAPI->m_ui32ProgramObject);
glDeleteShader(m_pAPI->m_ui32VertexShader);
glDeleteShader(m_pAPI->m_ui32FragShader);
// Delete buffer objects
glDeleteBuffers(1, &m_pAPI->m_ui32VertexBufferObject);
m_bInit = false;
}
delete m_pAPI;
m_pAPI = 0;
}
/*!***************************************************************************
@Function Init
@Input pContext A pointer to a PVRTContext
@Input bRotate true to rotate texture 90 degrees.
@Input pszError An option string for returning errors
@Return PVR_SUCCESS on success
@Description Initialises the background
*****************************************************************************/
EPVRTError CPVRTBackground::Init(const SPVRTContext * const pContext, bool bRotate, CPVRTString *pszError)
{
PVRT_UNREFERENCED_PARAMETER(pContext);
Destroy();
m_pAPI = new SPVRTBackgroundAPI;
if(!m_pAPI)
{
if(pszError)
*pszError = "Error: Insufficient memory to allocate SCPVRTBackgroundAPI.";
return PVR_FAIL;
}
m_pAPI->m_ui32VertexShader = 0;
m_pAPI->m_ui32FragShader = 0;
m_pAPI->m_ui32ProgramObject = 0;
m_pAPI->m_ui32VertexBufferObject = 0;
bool bResult;
CPVRTString sTmpErrStr;
// The shader loading code doesn't expect a null pointer for the error string
if(!pszError)
pszError = &sTmpErrStr;
/* Compiles the shaders. For a more detailed explanation, see IntroducingPVRTools */
#if defined(GL_SGX_BINARY_IMG)
// Try binary shaders first
bResult = (PVRTShaderLoadBinaryFromMemory(_BackgroundFragShader_fsc, _BackgroundFragShader_fsc_size,
GL_FRAGMENT_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_ui32FragShader, pszError) == PVR_SUCCESS)
&& (PVRTShaderLoadBinaryFromMemory(_BackgroundVertShader_vsc, _BackgroundVertShader_vsc_size,
GL_VERTEX_SHADER, GL_SGX_BINARY_IMG, &m_pAPI->m_ui32VertexShader, pszError) == PVR_SUCCESS);
if(!bResult)
#endif
{
// if binary shaders don't work, try source shaders
bResult = (PVRTShaderLoadSourceFromMemory(_BackgroundFragShader_fsh, GL_FRAGMENT_SHADER, &m_pAPI->m_ui32FragShader, pszError) == PVR_SUCCESS) &&
(PVRTShaderLoadSourceFromMemory(_BackgroundVertShader_vsh, GL_VERTEX_SHADER, &m_pAPI->m_ui32VertexShader, pszError) == PVR_SUCCESS);
}
_ASSERT(bResult);
if(!bResult)
return PVR_FAIL;
// Reset the error string
if(pszError)
*pszError = "";
// Create the shader program
m_pAPI->m_ui32ProgramObject = glCreateProgram();
// Attach the fragment and vertex shaders to it
glAttachShader(m_pAPI->m_ui32ProgramObject, m_pAPI->m_ui32FragShader);
glAttachShader(m_pAPI->m_ui32ProgramObject, m_pAPI->m_ui32VertexShader);
// Bind the custom vertex attribute "myVertex" to location VERTEX_ARRAY
glBindAttribLocation(m_pAPI->m_ui32ProgramObject, VERTEX_ARRAY, "myVertex");
// Bind the custom vertex attribute "myUV" to location TEXCOORD_ARRAY
glBindAttribLocation(m_pAPI->m_ui32ProgramObject, TEXCOORD_ARRAY, "myUV");
// Link the program
glLinkProgram(m_pAPI->m_ui32ProgramObject);
GLint Linked;
glGetProgramiv(m_pAPI->m_ui32ProgramObject, GL_LINK_STATUS, &Linked);
if (!Linked)
{
int i32InfoLogLength, i32CharsWritten;
glGetProgramiv(m_pAPI->m_ui32ProgramObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
char* pszInfoLog = new char[i32InfoLogLength];
glGetProgramInfoLog(m_pAPI->m_ui32ProgramObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
*pszError = CPVRTString("Failed to link: ") + pszInfoLog + "\n";
delete [] pszInfoLog;
bResult = false;
}
_ASSERT(bResult);
if(!bResult)
return PVR_FAIL;
// Use the loaded shader program
glUseProgram(m_pAPI->m_ui32ProgramObject);
// Set the sampler2D variable to the first texture unit
glUniform1i(glGetUniformLocation(m_pAPI->m_ui32ProgramObject, "sampler2d"), 0);
// Create the vertex buffer object
GLfloat *pVertexData = 0;
// The vertex data for non-rotated
GLfloat afVertexData[16] = { -1, -1, 1, -1, -1, 1, 1, 1,
0, 0, 1, 0, 0, 1, 1, 1};
// The vertex data for rotated
GLfloat afVertexDataRotated[16] = {-1, 1, -1, -1, 1, 1, 1, -1,
1, 1, 0, 1, 1, 0, 0, 0};
if(!bRotate)
pVertexData = &afVertexData[0];
else
pVertexData = &afVertexDataRotated[0];
glGenBuffers(1, &m_pAPI->m_ui32VertexBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, m_pAPI->m_ui32VertexBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, pVertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
m_bInit = true;
return PVR_SUCCESS;
}
/*!***************************************************************************
@Function Draw
@Input ui32Texture Texture to use
@Return PVR_SUCCESS on success
@Description Draws a texture on a quad covering the whole screen.
*****************************************************************************/
EPVRTError CPVRTBackground::Draw(const GLuint ui32Texture)
{
if(!m_bInit)
return PVR_FAIL;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, ui32Texture);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
// Use the loaded shader program
glUseProgram(m_pAPI->m_ui32ProgramObject);
// Set vertex data
glBindBuffer(GL_ARRAY_BUFFER, m_pAPI->m_ui32VertexBufferObject);
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer(VERTEX_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, (const void*) 0);
// Set texture coordinates
glEnableVertexAttribArray(TEXCOORD_ARRAY);
glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, 0, (const void*) (8 * sizeof(float)));
// Render geometry
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glDisableVertexAttribArray(VERTEX_ARRAY);
glDisableVertexAttribArray(TEXCOORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glUseProgram(0);
return PVR_SUCCESS;
}
/*****************************************************************************
End of file (CPVRTBackground.cpp)
*****************************************************************************/
/*!****************************************************************************
@file OGLES2/PVRTBackgroundShaders.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief The shaders used by PVRTBackground. Created by Filewrap 1.0. DO
NOT EDIT.
******************************************************************************/
// This file was created by Filewrap 1.0
// DO NOT EDIT
// using 32 bit to guarantee alignment. Adds endianness dependency.
#ifndef A32BIT
#define A32BIT PVRTuint32
#endif
// ******** Start: BackgroundFragShader.fsh ********
// File data
static const char _BackgroundFragShader_fsh[] =
"uniform sampler2D sampler2d;\r\n"
"\r\n"
"varying mediump vec2\tvarCoord;\r\n"
"\r\n"
"void main()\r\n"
"{\r\n"
"\tgl_FragColor = texture2D(sampler2d, varCoord);\r\n"
"}\r\n";
// ******** End: BackgroundFragShader.fsh ********
// ******** Start: BackgroundVertShader.vsh ********
// File data
static const char _BackgroundVertShader_vsh[] =
"attribute mediump vec2\tmyVertex;\r\n"
"attribute mediump vec2\tmyUV;\r\n"
"\r\n"
"varying mediump vec2\tvarCoord;\r\n"
"\r\n"
"void main()\r\n"
"{\r\n"
"\tgl_Position = vec4(myVertex, 1, 1);\r\n"
"\tvarCoord = myUV;\r\n"
"}\r\n";
// ******** End: BackgroundVertShader.vsh ********
// This file was created by Filewrap 1.0
// DO NOT EDIT
// using 32 bit to guarantee alignment. Adds endianness dependency.
#ifndef A32BIT
#define A32BIT PVRTuint32
#endif
// ******** Start: BackgroundFragShader.fsc ********
// File data
A32BIT _BackgroundFragShader_fsc[] = {
0x10fab438,0xe9233faf,0x35050100,0x901,0xf121629f,0x0,0x0,0x1d020000,
0x1000000,0x4000200,0x0,0x8000000,0x2,0x0,0x20000,0x0,
0x0,0xdc000000,0x55535020,0x17,0xd0,0x1,0x0,0x48,
0x0,0x3,0x6d,0x1,0x0,0x0,0xffffffff,0x0,
0x770009,0xffff,0x1,0x0,0x1,0x0,0x0,0x0,
0x0,0xfffc0000,0x3,0x10004,0x0,0x110000,0xffffffff,0x0,
0x56780000,0x0,0x10000,0x0,0x4,0x50011,0x10000,0x80010000,
0x80018001,0x8001,0x0,0x120000,0xf0000,0x60a000f,0x30003,0x30003,
0x0,0x0,0x40004,0x40004,0x10000,0x30002,0x1,0x20001,
0x6,0xdc000000,0x55535020,0x17,0xd0,0x1,0x0,0x148,
0x0,0x3,0x6d,0x1,0x0,0x0,0xffffffff,0x0,
0x770009,0xffff,0x10001,0x0,0x1,0x0,0x0,0x0,
0x0,0xfffc0000,0x1,0x10004,0x0,0x110000,0xffffffff,0x0,
0x56780000,0x0,0x10000,0x0,0x4,0x50011,0x10000,0x80010000,
0x80018001,0x8001,0x0,0x120000,0xf0000,0x60a000f,0x10001,0x10001,
0x0,0x0,0x40004,0x40004,0x10000,0x30002,0x10001,0x20001,
0x6,0x2000000,0x706d6173,0x3272656c,0x64,0x318,0x2000001,0x10000,
0x76000001,0x6f437261,0x64726f,0x5030000,0x10000,0x100,0x30002,0x0,
};
static int _BackgroundFragShader_fsc_size = 573;
// ******** End: BackgroundFragShader.fsc ********
// ******** Start: BackgroundVertShader.vsc ********
// File data
A32BIT _BackgroundVertShader_vsc[] = {
0x10fab438,0x69857ca,0x35050100,0x901,0xf121629f,0x0,0x0,0x93010000,
0x0,0x4000200,0x0,0x9000000,0x2,0x0,0x20000,0x0,
0x0,0xe0000000,0x55535020,0x17,0xd4,0x1,0x0,0xc,
0x0,0x3,0x6d,0x1,0x0,0x0,0xffffffff,0x0,
0x76000a,0xffff,0x6,0x0,0x0,0x0,0x0,0x0,
0x0,0xfffc0000,0x0,0x0,0x0,0x110000,0xffffffff,0x0,
0x56780006,0x330000,0x40000,0x110000,0x2,0x6,0x80018001,0x80018001,
0x0,0x0,0x0,0x0,0x0,0xa0000000,0x28811001,0xa0200080,
0x28811001,0x60601a00,0x28831001,0xa0800200,0x28a11001,0x60000700,0x28831002,0x5040018e,
0x811005,0x6,0x800,0x0,0x0,0x803f0000,0x3f0000,0x3f0000,
0x0,0x0,0x4000000,0x505f6c67,0x7469736f,0x6e6f69,0x5050100,0x10000,
0x100,0xf0004,0x56796d00,0x65747265,0x78,0x403,0x1000001,0x40000,
0x76000003,0x6f437261,0x64726f,0x5030000,0x10000,0x100,0x30002,0x55796d00,
0x56,0x403,0x1000001,0x40400,0x3,
};
static int _BackgroundVertShader_vsc_size = 435;
// ******** End: BackgroundVertShader.vsc ********
/*!****************************************************************************
@file OGLES2/PVRTContext.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief Context specific stuff - i.e. 3D API-related.
******************************************************************************/
#ifndef _PVRTCONTEXT_H_
#define _PVRTCONTEXT_H_
/*!
@addtogroup API_OGLES2
@{
*/
#include <stdio.h>
#if defined(BUILD_OGLES2)
#if defined(__APPLE__)
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE==1
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
#else //OSX
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extimg.h>
#endif
#else
#if defined(__PALMPDK__)
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#if !defined(EGL_NOT_PRESENT)
#include <EGL/egl.h>
#endif
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#endif
#include <GLES2/gl2extimg.h>
#endif
#elif defined(BUILD_OGLES3)
#include <EGL/egl.h>
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extimg.h>
#endif
/****************************************************************************
** Macros
****************************************************************************/
#define PVRTRGBA(r, g, b, a) ((GLuint) (((a) << 24) | ((b) << 16) | ((g) << 8) | (r)))
/****************************************************************************
** Defines
****************************************************************************/
/****************************************************************************
** Enumerations
****************************************************************************/
/****************************************************************************
** Structures
****************************************************************************/
/*!**************************************************************************
@struct SPVRTContext
@brief A structure for storing API specific variables
****************************************************************************/
struct SPVRTContext
{
int reserved; // No context info for OGLES2.
};
/****************************************************************************
** Functions
****************************************************************************/
/*! @} */
#endif /* _PVRTCONTEXT_H_ */
/*****************************************************************************
End of file (PVRTContext.h)
*****************************************************************************/
/******************************************************************************
@File OGLES2/PVRTPFXSemantics.cpp
@Title PFX Semantics
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform All
@Description A list of supported PFX semantics.
******************************************************************************/
/*****************************************************************************
** Includes
******************************************************************************/
#include "PVRTGlobal.h"
#include "PVRTContext.h"
#include "PVRTArray.h"
#include "PVRTString.h"
#include "PVRTStringHash.h"
#include "PVRTPFXParser.h"
#include "PVRTPFXParserAPI.h"
#include "PVRTPFXSemantics.h"
/*!***************************************************************************
** Default Shaman semantics
*****************************************************************************/
const SPVRTPFXUniformSemantic c_psSemanticsInfo[] =
{
{ "POSITION", ePVRTPFX_UsPOSITION },
{ "NORMAL", ePVRTPFX_UsNORMAL },
{ "TANGENT", ePVRTPFX_UsTANGENT },
{ "BINORMAL", ePVRTPFX_UsBINORMAL },
{ "UV", ePVRTPFX_UsUV },
{ "VERTEXCOLOR", ePVRTPFX_UsVERTEXCOLOR },
{ "BONEINDEX", ePVRTPFX_UsBONEINDEX },
{ "BONEWEIGHT", ePVRTPFX_UsBONEWEIGHT },
{ "WORLD", ePVRTPFX_UsWORLD },
{ "WORLDI", ePVRTPFX_UsWORLDI },
{ "WORLDIT", ePVRTPFX_UsWORLDIT },
{ "VIEW", ePVRTPFX_UsVIEW },
{ "VIEWI", ePVRTPFX_UsVIEWI },
{ "VIEWIT", ePVRTPFX_UsVIEWIT },
{ "PROJECTION", ePVRTPFX_UsPROJECTION },
{ "PROJECTIONI", ePVRTPFX_UsPROJECTIONI },
{ "PROJECTIONIT", ePVRTPFX_UsPROJECTIONIT },
{ "WORLDVIEW", ePVRTPFX_UsWORLDVIEW },
{ "WORLDVIEWI", ePVRTPFX_UsWORLDVIEWI },
{ "WORLDVIEWIT", ePVRTPFX_UsWORLDVIEWIT },
{ "WORLDVIEWPROJECTION", ePVRTPFX_UsWORLDVIEWPROJECTION },
{ "WORLDVIEWPROJECTIONI", ePVRTPFX_UsWORLDVIEWPROJECTIONI },
{ "WORLDVIEWPROJECTIONIT", ePVRTPFX_UsWORLDVIEWPROJECTIONIT },
{ "UNPACKMATRIX", ePVRTPFX_UsUNPACKMATRIX },
{ "VIEWPROJECTION", ePVRTPFX_UsVIEWPROJECTION },
{ "VIEWPROJECTIONI", ePVRTPFX_UsVIEWPROJECTIONI },
{ "VIEWPROJECTIONIT", ePVRTPFX_UsVIEWPROJECTIONIT },
{ "OBJECT", ePVRTPFX_UsOBJECT, },
{ "OBJECTI", ePVRTPFX_UsOBJECTI, },
{ "OBJECTIT", ePVRTPFX_UsOBJECTIT, },
{ "MATERIALOPACITY", ePVRTPFX_UsMATERIALOPACITY },
{ "MATERIALSHININESS", ePVRTPFX_UsMATERIALSHININESS },
{ "MATERIALCOLORAMBIENT", ePVRTPFX_UsMATERIALCOLORAMBIENT },
{ "MATERIALCOLORDIFFUSE", ePVRTPFX_UsMATERIALCOLORDIFFUSE },
{ "MATERIALCOLORSPECULAR", ePVRTPFX_UsMATERIALCOLORSPECULAR },
{ "BONECOUNT", ePVRTPFX_UsBONECOUNT },
{ "BONEMATRIXARRAY", ePVRTPFX_UsBONEMATRIXARRAY },
{ "BONEMATRIXARRAYIT", ePVRTPFX_UsBONEMATRIXARRAYIT },
{ "LIGHTCOLOR", ePVRTPFX_UsLIGHTCOLOR },
{ "LIGHTPOSMODEL", ePVRTPFX_UsLIGHTPOSMODEL },
{ "LIGHTPOSWORLD", ePVRTPFX_UsLIGHTPOSWORLD },
{ "LIGHTPOSEYE", ePVRTPFX_UsLIGHTPOSEYE },
{ "LIGHTDIRMODEL", ePVRTPFX_UsLIGHTDIRMODEL },
{ "LIGHTDIRWORLD", ePVRTPFX_UsLIGHTDIRWORLD },
{ "LIGHTDIREYE", ePVRTPFX_UsLIGHTDIREYE },
{ "LIGHTATTENUATION", ePVRTPFX_UsLIGHTATTENUATION },
{ "LIGHTFALLOFF", ePVRTPFX_UsLIGHTFALLOFF },
{ "EYEPOSMODEL", ePVRTPFX_UsEYEPOSMODEL },
{ "EYEPOSWORLD", ePVRTPFX_UsEYEPOSWORLD },
{ "TEXTURE", ePVRTPFX_UsTEXTURE },
{ "ANIMATION", ePVRTPFX_UsANIMATION },
{ "VIEWPORTPIXELSIZE", ePVRTPFX_UsVIEWPORTPIXELSIZE },
{ "VIEWPORTCLIPPING", ePVRTPFX_UsVIEWPORTCLIPPING },
{ "TIME", ePVRTPFX_UsTIME },
{ "TIMECOS", ePVRTPFX_UsTIMECOS },
{ "TIMESIN", ePVRTPFX_UsTIMESIN },
{ "TIMETAN", ePVRTPFX_UsTIMETAN, },
{ "TIME2PI", ePVRTPFX_UsTIME2PI, },
{ "TIME2PICOS", ePVRTPFX_UsTIME2PICOS, },
{ "TIME2PISIN", ePVRTPFX_UsTIME2PISIN, },
{ "TIME2PITAN", ePVRTPFX_UsTIME2PITAN, },
{ "RANDOM", ePVRTPFX_UsRANDOM, },
};
PVRTCOMPILEASSERT(c_psSemanticsInfo, sizeof(c_psSemanticsInfo) / sizeof(c_psSemanticsInfo[0]) == ePVRTPFX_NumSemantics);
const SPVRTPFXUniformSemantic* PVRTPFXSemanticsGetSemanticList()
{
return c_psSemanticsInfo;
}
/*****************************************************************************
End of file (PVRTPFXSemantics.cpp)
*****************************************************************************/
/*!****************************************************************************
@file OGLES2/PVRTPFXSemantics.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief A list of supported PFX semantics.
******************************************************************************/
#ifndef PVRTPFXSEMANTICS_H
#define PVRTPFXSEMANTICS_H
/*!
@addtogroup API_OGLES2
@{
*/
struct SPVRTPFXUniformSemantic;
/****************************************************************************
** Semantic Enumerations
****************************************************************************/
/*!**************************************************************************
@enum EPVRTPFXUniformSemantic
@brief The default Shaman semantics.
***************************************************************************/
enum EPVRTPFXUniformSemantic
{
ePVRTPFX_UsPOSITION, /*!< POSITION */
ePVRTPFX_UsNORMAL, /*!< NORMAL */
ePVRTPFX_UsTANGENT, /*!< TANGENT */
ePVRTPFX_UsBINORMAL, /*!< BINORMAL */
ePVRTPFX_UsUV, /*!< UV */
ePVRTPFX_UsVERTEXCOLOR, /*!< VERTEXCOLOR */
ePVRTPFX_UsBONEINDEX, /*!< BONEINDEX */
ePVRTPFX_UsBONEWEIGHT, /*!< BONEWEIGHT */
ePVRTPFX_UsWORLD, /*!< WORLD */
ePVRTPFX_UsWORLDI, /*!< WORLDI */
ePVRTPFX_UsWORLDIT, /*!< WORLDIT */
ePVRTPFX_UsVIEW, /*!< VIEW */
ePVRTPFX_UsVIEWI, /*!< VIEWI */
ePVRTPFX_UsVIEWIT, /*!< VIEWIT */
ePVRTPFX_UsPROJECTION, /*!< PROJECTION */
ePVRTPFX_UsPROJECTIONI, /*!< PROJECTIONI */
ePVRTPFX_UsPROJECTIONIT, /*!< PROJECTIONIT */
ePVRTPFX_UsWORLDVIEW, /*!< WORLDVIEW */
ePVRTPFX_UsWORLDVIEWI, /*!< WORLDVIEWI */
ePVRTPFX_UsWORLDVIEWIT, /*!< WORLDVIEWIT */
ePVRTPFX_UsWORLDVIEWPROJECTION, /*!< WORLDVIEWPROJECTION */
ePVRTPFX_UsWORLDVIEWPROJECTIONI, /*!< WORLDVIEWPROJECTIONI */
ePVRTPFX_UsWORLDVIEWPROJECTIONIT, /*!< WORLDVIEWPROJECTIONIT */
ePVRTPFX_UsVIEWPROJECTION, /*!< VIEWPROJECTION */
ePVRTPFX_UsVIEWPROJECTIONI, /*!< VIEWPROJECTIONI */
ePVRTPFX_UsVIEWPROJECTIONIT, /*!< VIEWPROJECTIONIT */
ePVRTPFX_UsOBJECT, /*!< OBJECT */
ePVRTPFX_UsOBJECTI, /*!< OBJECTI */
ePVRTPFX_UsOBJECTIT, /*!< OBJECTIT */
ePVRTPFX_UsUNPACKMATRIX, /*!< UNPACKMATRIX */
ePVRTPFX_UsBONECOUNT, /*!< BONECOUNT */
ePVRTPFX_UsBONEMATRIXARRAY, /*!< BONEMATRIXARRAY */
ePVRTPFX_UsBONEMATRIXARRAYIT, /*!< BONEMATRIXARRAYIT */
ePVRTPFX_UsMATERIALOPACITY, /*!< MATERIALOPACITY */
ePVRTPFX_UsMATERIALSHININESS, /*!< MATERIALSHININESS */
ePVRTPFX_UsMATERIALCOLORAMBIENT, /*!< MATERIALCOLORAMBIENT */
ePVRTPFX_UsMATERIALCOLORDIFFUSE, /*!< MATERIALCOLORDIFFUSE */
ePVRTPFX_UsMATERIALCOLORSPECULAR, /*!< MATERIALCOLORSPECULAR */
ePVRTPFX_UsLIGHTCOLOR, /*!< LIGHTCOLOR */
ePVRTPFX_UsLIGHTPOSMODEL, /*!< LIGHTPOSMODEL */
ePVRTPFX_UsLIGHTPOSWORLD, /*!< LIGHTPOSWORLD */
ePVRTPFX_UsLIGHTPOSEYE, /*!< LIGHTPOSEYE */
ePVRTPFX_UsLIGHTDIRMODEL, /*!< LIGHTDIRMODEL */
ePVRTPFX_UsLIGHTDIRWORLD, /*!< LIGHTDIRWORLD */
ePVRTPFX_UsLIGHTDIREYE, /*!< LIGHTDIREYE */
ePVRTPFX_UsLIGHTATTENUATION, /*!< LIGHTATTENUATION */
ePVRTPFX_UsLIGHTFALLOFF, /*!< LIGHTFALLOFF */
ePVRTPFX_UsEYEPOSMODEL, /*!< EYEPOSMODEL */
ePVRTPFX_UsEYEPOSWORLD, /*!< EYEPOSWORLD */
ePVRTPFX_UsTEXTURE, /*!< TEXTURE */
ePVRTPFX_UsANIMATION, /*!< ANIMATION */
ePVRTPFX_UsVIEWPORTPIXELSIZE, /*!< VIEWPORTPIXELSIZE */
ePVRTPFX_UsVIEWPORTCLIPPING, /*!< VIEWPORTCLIPPING */
ePVRTPFX_UsTIME, /*!< TIME */
ePVRTPFX_UsTIMECOS, /*!< TIMECOS */
ePVRTPFX_UsTIMESIN, /*!< TIMESIN */
ePVRTPFX_UsTIMETAN, /*!< TIMETAN */
ePVRTPFX_UsTIME2PI, /*!< TIME2PI */
ePVRTPFX_UsTIME2PICOS, /*!< TIME2PICOS */
ePVRTPFX_UsTIME2PISIN, /*!< TIME2PISIN */
ePVRTPFX_UsTIME2PITAN, /*!< TIME2PITAN */
ePVRTPFX_UsRANDOM, /*!< RANDOM */
ePVRTPFX_NumSemantics /*!< Semantic number */
};
/*!**************************************************************************
@brief Retrieves the list of semantics.
***************************************************************************/
const SPVRTPFXUniformSemantic* PVRTPFXSemanticsGetSemanticList();
/*! @} */
#endif /* PVRTPFXSEMANTICS_H */
/*****************************************************************************
End of file (PVRTPFXSemantics.h)
*****************************************************************************/
/*!****************************************************************************
@file OGLES2/PVRTPrint3DShaders.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief The shaders used by Print3D. Created by Filewrap 1.0. DO NOT EDIT.
******************************************************************************/
// This file was created by Filewrap 1.1
// Little endian mode
// DO NOT EDIT
// ******** Start: Print3DFragShader.fsh ********
// File data
static const char _Print3DFragShader_fsh[] =
"uniform sampler2D\tsampler2d;\n"
"\n"
"varying lowp vec4\t\tvarColour;\n"
"varying mediump vec2\ttexCoord;\n"
"\n"
"void main()\n"
"{\n"
"\tlowp vec4 vTex = texture2D(sampler2d, texCoord);\n"
"\tgl_FragColor = vec4(varColour.rgb * vTex.r, varColour.a * vTex.a);\n"
"}\n";
// ******** End: Print3DFragShader.fsh ********
// ******** Start: Print3DVertShader.vsh ********
// File data
static const char _Print3DVertShader_vsh[] =
"attribute highp vec4\tmyVertex;\n"
"attribute mediump vec2\tmyUV;\n"
"attribute lowp vec4\t\tmyColour;\n"
"\n"
"uniform highp mat4\t\tmyMVPMatrix;\n"
"\n"
"varying lowp vec4\t\tvarColour;\n"
"varying mediump vec2\ttexCoord;\n"
"\n"
"void main()\n"
"{\n"
"\tgl_Position = myMVPMatrix * myVertex;\n"
"\ttexCoord = myUV.st;\n"
"\tvarColour = myColour;\n"
"}\n";
// ******** End: Print3DVertShader.vsh ********
// ******** Start: Print3DFragShaderLogo.fsh ********
// File data
static const char _Print3DFragShaderLogo_fsh[] =
"uniform sampler2D\tsampler2d;\n"
"\n"
"varying mediump vec2\ttexCoord;\n"
"\n"
"void main()\n"
"{\n"
"\tgl_FragColor = texture2D(sampler2d, texCoord);\n"
"}\n";
// ******** End: Print3DFragShaderLogo.fsh ********
// ******** Start: Print3DVertShaderLogo.vsh ********
// File data
static const char _Print3DVertShaderLogo_vsh[] =
"attribute highp vec4\tmyVertex;\n"
"attribute mediump vec2\tmyUV;\n"
"\n"
"uniform highp mat4\t\tmyMVPMatrix;\n"
"\n"
"varying mediump vec2\ttexCoord;\n"
"\n"
"void main()\n"
"{\n"
"\tgl_Position = myMVPMatrix * myVertex;\n"
"\ttexCoord = myUV.st;\n"
"}\n";
// ******** End: Print3DVertShaderLogo.vsh ********
/******************************************************************************
@File OGLES2/PVRTShader.cpp
@Title OGLES2/PVRTShader
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform ANSI compatible
@Description Shader handling for OpenGL ES 2.0
******************************************************************************/
#include "PVRTString.h"
#include "PVRTShader.h"
#include "PVRTResourceFile.h"
#include "PVRTGlobal.h"
#include <ctype.h>
#include <string.h>
/*!***************************************************************************
@Function PVRTShaderLoadSourceFromMemory
@Input pszShaderCode shader source code
@Input Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
@Output pObject the resulting shader object
@Output pReturnError the error message if it failed
@Input aszDefineArray Array of defines to be pre-appended to shader string
@Input uiDefArraySize Size of the define array
@Return PVR_SUCCESS on success and PVR_FAIL on failure (also fills the str string)
@Description Loads a shader source code into memory and compiles it.
It also pre-appends the array of defines that have been passed in
to the source code before compilation.
*****************************************************************************/
EPVRTError PVRTShaderLoadSourceFromMemory( const char* pszShaderCode,
const GLenum Type,
GLuint* const pObject,
CPVRTString* const pReturnError,
const char* const* aszDefineArray, GLuint uiDefArraySize)
{
// Append define's here if there are any
CPVRTString pszShaderString;
if(uiDefArraySize > 0)
{
while(isspace(*pszShaderCode))
++pszShaderCode;
if(*pszShaderCode == '#')
{
const char* tmp = pszShaderCode + 1;
while(isspace(*tmp))
++tmp;
if(strncmp(tmp, "version", 7) == 0)
{
const char* c = strchr(pszShaderCode, '\n');
if(c)
{
size_t length = c - pszShaderCode + 1;
pszShaderString = CPVRTString(pszShaderCode, length);
pszShaderCode += length;
}
else
{
pszShaderString = CPVRTString(pszShaderCode) + "\n";
pszShaderCode = '\0';
}
}
}
for(GLuint i = 0 ; i < uiDefArraySize; ++i)
{
pszShaderString += "#define ";
pszShaderString += aszDefineArray[i];
pszShaderString += "\n";
}
}
// Append the shader code to the string
pszShaderString += pszShaderCode;
/* Create and compile the shader object */
*pObject = glCreateShader(Type);
const char* pszString(pszShaderString.c_str());
glShaderSource(*pObject, 1, &pszString, NULL);
glCompileShader(*pObject);
/* Test if compilation succeeded */
GLint ShaderCompiled;
glGetShaderiv(*pObject, GL_COMPILE_STATUS, &ShaderCompiled);
if (!ShaderCompiled)
{
int i32InfoLogLength, i32CharsWritten;
glGetShaderiv(*pObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
char* pszInfoLog = new char[i32InfoLogLength];
glGetShaderInfoLog(*pObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
*pReturnError = CPVRTString("Failed to compile shader: ") + pszInfoLog + "\n";
delete [] pszInfoLog;
glDeleteShader(*pObject);
return PVR_FAIL;
}
return PVR_SUCCESS;
}
/*!***************************************************************************
@Function PVRTShaderLoadBinaryFromMemory
@Input ShaderData shader compiled binary data
@Input Size size of shader binary data in bytes
@Input Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
@Input Format shader binary format
@Output pObject the resulting shader object
@Output pReturnError the error message if it failed
@Return PVR_SUCCESS on success and PVR_FAIL on failure (also fills the str string)
@Description Takes a shader binary from memory and passes it to the GL.
*****************************************************************************/
EPVRTError PVRTShaderLoadBinaryFromMemory( const void* const ShaderData,
const size_t Size,
const GLenum Type,
const GLenum Format,
GLuint* const pObject,
CPVRTString* const pReturnError)
{
/* Create and compile the shader object */
*pObject = glCreateShader(Type);
// Get the list of supported binary formats
// and if (more then 0) find given Format among them
GLint numFormats = 0;
GLint *listFormats;
int i;
glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS,&numFormats);
if(numFormats != 0) {
listFormats = new GLint[numFormats];
for(i=0;i<numFormats;++i)
listFormats[i] = 0;
glGetIntegerv(GL_SHADER_BINARY_FORMATS,listFormats);
for(i=0;i<numFormats;++i) {
if(listFormats[i] == (int) Format) {
glShaderBinary(1, pObject, Format, ShaderData, (GLint)Size);
if (glGetError() != GL_NO_ERROR)
{
*pReturnError = CPVRTString("Failed to load binary shader\n");
glDeleteShader(*pObject);
return PVR_FAIL;
}
return PVR_SUCCESS;
}
}
delete [] listFormats;
}
*pReturnError = CPVRTString("Failed to load binary shader\n");
glDeleteShader(*pObject);
return PVR_FAIL;
}
/*!***************************************************************************
@Function PVRTShaderLoadFromFile
@Input pszBinFile binary shader filename
@Input pszSrcFile source shader filename
@Input Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
@Input Format shader binary format, or 0 for source shader
@Output pObject the resulting shader object
@Output pReturnError the error message if it failed
@Input pContext Context
@Input aszDefineArray Array of defines to be pre-appended to shader string
@Input uiDefArraySize Size of the define array
@Return PVR_SUCCESS on success and PVR_FAIL on failure (also fills pReturnError)
@Description Loads a shader file into memory and passes it to the GL.
It also passes defines that need to be pre-appended to the shader before compilation.
*****************************************************************************/
EPVRTError PVRTShaderLoadFromFile( const char* const pszBinFile,
const char* const pszSrcFile,
const GLenum Type,
const GLenum Format,
GLuint* const pObject,
CPVRTString* const pReturnError,
const SPVRTContext* const pContext,
const char* const* aszDefineArray, GLuint uiDefArraySize)
{
PVRT_UNREFERENCED_PARAMETER(pContext);
*pReturnError = "";
/*
Prepending defines relies on altering the source file that is loaded.
For this reason, the function calls the source loader instead of the binary loader if defines have
been passed in.
*/
if(Format && pszBinFile && uiDefArraySize == 0)
{
CPVRTResourceFile ShaderFile(pszBinFile);
if (ShaderFile.IsOpen())
{
if(PVRTShaderLoadBinaryFromMemory(ShaderFile.DataPtr(), ShaderFile.Size(), Type, Format, pObject, pReturnError) == PVR_SUCCESS)
return PVR_SUCCESS;
}
*pReturnError += CPVRTString("Failed to open shader ") + pszBinFile + "\n";
}
CPVRTResourceFile ShaderFile(pszSrcFile);
if (!ShaderFile.IsOpen())
{
*pReturnError += CPVRTString("Failed to open shader ") + pszSrcFile + "\n";
return PVR_FAIL;
}
CPVRTString ShaderFileString;
const char* pShaderData = (const char*) ShaderFile.DataPtr();
// Is our shader resource file data null terminated?
if(pShaderData[ShaderFile.Size()-1] != '\0')
{
// If not create a temporary null-terminated string
ShaderFileString.assign(pShaderData, ShaderFile.Size());
pShaderData = ShaderFileString.c_str();
}
return PVRTShaderLoadSourceFromMemory(pShaderData, Type, pObject, pReturnError, aszDefineArray, uiDefArraySize);
}
/*!***************************************************************************
@Function PVRTCreateProgram
@Output pProgramObject the created program object
@Input VertexShader the vertex shader to link
@Input FragmentShader the fragment shader to link
@Input pszAttribs an array of attribute names
@Input i32NumAttribs the number of attributes to bind
@Output pReturnError the error message if it failed
@Returns PVR_SUCCESS on success, PVR_FAIL if failure
@Description Links a shader program.
*****************************************************************************/
EPVRTError PVRTCreateProgram( GLuint* const pProgramObject,
const GLuint VertexShader,
const GLuint FragmentShader,
const char** const pszAttribs,
const int i32NumAttribs,
CPVRTString* const pReturnError)
{
*pProgramObject = glCreateProgram();
glAttachShader(*pProgramObject, FragmentShader);
glAttachShader(*pProgramObject, VertexShader);
for (int i = 0; i < i32NumAttribs; ++i)
{
glBindAttribLocation(*pProgramObject, i, pszAttribs[i]);
}
// Link the program object
glLinkProgram(*pProgramObject);
GLint Linked;
glGetProgramiv(*pProgramObject, GL_LINK_STATUS, &Linked);
if (!Linked)
{
int i32InfoLogLength, i32CharsWritten;
glGetProgramiv(*pProgramObject, GL_INFO_LOG_LENGTH, &i32InfoLogLength);
char* pszInfoLog = new char[i32InfoLogLength];
glGetProgramInfoLog(*pProgramObject, i32InfoLogLength, &i32CharsWritten, pszInfoLog);
*pReturnError = CPVRTString("Failed to link: ") + pszInfoLog + "\n";
delete [] pszInfoLog;
return PVR_FAIL;
}
glUseProgram(*pProgramObject);
return PVR_SUCCESS;
}
/*****************************************************************************
End of file (PVRTShader.cpp)
*****************************************************************************/
/*!****************************************************************************
@file OGLES2/PVRTShader.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief Shader handling for OpenGL ES 2.0
******************************************************************************/
#ifndef _PVRTSHADER_H_
#define _PVRTSHADER_H_
/*!
@addtogroup API_OGLES2
@{
*/
#include "PVRTContext.h"
#include "../PVRTString.h"
#include "../PVRTError.h"
/*!***************************************************************************
@brief Loads a shader source code into memory and compiles it.
It also pre-appends the array of defines that have been passed in
to the source code before compilation.
@param[in] pszShaderCode shader source code
@param[in] Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
@param[out] pObject the resulting shader object
@param[out] pReturnError the error message if it failed
@param[in] aszDefineArray Array of defines to be pre-appended to shader string
@param[in] uiDefArraySize Size of the define array
@return PVR_SUCCESS on success and PVR_FAIL on failure (also fills the str string)
*****************************************************************************/
EPVRTError PVRTShaderLoadSourceFromMemory( const char* pszShaderCode,
const GLenum Type,
GLuint* const pObject,
CPVRTString* const pReturnError,
const char* const* aszDefineArray=0, GLuint uiDefArraySize=0);
/*!***************************************************************************
@brief Takes a shader binary from memory and passes it to the GL.
@param[in] ShaderData shader compiled binary data
@param[in] Size size of shader binary data in bytes
@param[in] Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
@param[in] Format shader binary format
@param[out] pObject the resulting shader object
@param[out] pReturnError the error message if it failed
@return PVR_SUCCESS on success and PVR_FAIL on failure (also fills the str string)
*****************************************************************************/
EPVRTError PVRTShaderLoadBinaryFromMemory( const void* const ShaderData,
const size_t Size,
const GLenum Type,
const GLenum Format,
GLuint* const pObject,
CPVRTString* const pReturnError);
/*!***************************************************************************
@brief Loads a shader file into memory and passes it to the GL.
It also passes defines that need to be pre-appended to the shader before compilation.
@param[in] pszBinFile binary shader filename
@param[in] pszSrcFile source shader filename
@param[in] Type type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
@param[in] Format shader binary format, or 0 for source shader
@param[out] pObject the resulting shader object
@param[out] pReturnError the error message if it failed
@param[in] pContext Context
@param[in] aszDefineArray Array of defines to be pre-appended to shader string
@param[in] uiDefArraySize Size of the define array
@return PVR_SUCCESS on success and PVR_FAIL on failure (also fills pReturnError)
*****************************************************************************/
EPVRTError PVRTShaderLoadFromFile( const char* const pszBinFile,
const char* const pszSrcFile,
const GLenum Type,
const GLenum Format,
GLuint* const pObject,
CPVRTString* const pReturnError,
const SPVRTContext* const pContext=0,
const char* const* aszDefineArray=0, GLuint uiDefArraySize=0);
/*!***************************************************************************
@brief Links a shader program.
@param[out] pProgramObject the created program object
@param[in] VertexShader the vertex shader to link
@param[in] FragmentShader the fragment shader to link
@param[in] pszAttribs an array of attribute names
@param[in] i32NumAttribs the number of attributes to bind
@param[out] pReturnError the error message if it failed
@return PVR_SUCCESS on success, PVR_FAIL if failure
*****************************************************************************/
EPVRTError PVRTCreateProgram( GLuint* const pProgramObject,
const GLuint VertexShader,
const GLuint FragmentShader,
const char** const pszAttribs,
const int i32NumAttribs,
CPVRTString* const pReturnError);
/*! @} */
#endif
/*****************************************************************************
End of file (PVRTShader.h)
*****************************************************************************/
/*!****************************************************************************
@file OGLES2/PVRTTextureAPI.h
@ingroup API_OGLES2
@copyright Copyright (c) Imagination Technologies Limited.
@brief OGLES2 texture loading.
******************************************************************************/
#ifndef _PVRTTEXTUREAPI_H_
#define _PVRTTEXTUREAPI_H_
/*!
@addtogroup API_OGLES2
@{
*/
#include "../PVRTError.h"
/****************************************************************************
** Functions
****************************************************************************/
template <typename KeyType, typename DataType>
class CPVRTMap;
/*!***************************************************************************
@brief Allows textures to be stored in C header files and loaded in. Can load parts of a
mipmaped texture (ie skipping the highest detailed levels).
Sets the texture MIN/MAG filter to GL_LINEAR_MIPMAP_NEAREST/GL_LINEAR
if mipmaps are present, GL_LINEAR/GL_LINEAR otherwise.
@param[in] pointer Pointer to header-texture's structure
@param[in,out] texName the OpenGL ES texture name as returned by glBindTexture
@param[in,out] psTextureHeader Pointer to a PVRTextureHeaderV3 struct. Modified to
contain the header data of the returned texture Ignored if NULL.
@param[in] bAllowDecompress Allow decompression if PVRTC is not supported in hardware.
@param[in] nLoadFromLevel Which mipmap level to start loading from (0=all)
@param[in] texPtr If null, texture follows header, else texture is here.
@param[in,out] pMetaData If a valid map is supplied, this will return any and all
MetaDataBlocks stored in the texture, organised by DevFourCC
then identifier. Supplying NULL will ignore all MetaData.
@return PVR_SUCCESS on success
*****************************************************************************/
EPVRTError PVRTTextureLoadFromPointer( const void* pointer,
GLuint *const texName,
const void *psTextureHeader=NULL,
bool bAllowDecompress = true,
const unsigned int nLoadFromLevel=0,
const void * const texPtr=0,
CPVRTMap<unsigned int, CPVRTMap<unsigned int, struct MetaDataBlock> > *pMetaData=NULL);
/*!***************************************************************************
@brief Allows textures to be stored in binary PVR files and loaded in. Can load parts of a
mipmaped texture (ie skipping the highest detailed levels).
Sets the texture MIN/MAG filter to GL_LINEAR_MIPMAP_NEAREST/GL_LINEAR
if mipmaps are present, GL_LINEAR/GL_LINEAR otherwise.
@param[in] filename Filename of the .PVR file to load the texture from
@param[in,out] texName the OpenGL ES texture name as returned by glBindTexture
@param[in,out] psTextureHeader Pointer to a PVRTextureHeaderV3 struct. Modified to
contain the header data of the returned texture Ignored if NULL.
@param[in] bAllowDecompress Allow decompression if PVRTC is not supported in hardware.
@param[in] nLoadFromLevel Which mipmap level to start loading from (0=all)
@param[in,out] pMetaData If a valid map is supplied, this will return any and all
MetaDataBlocks stored in the texture, organised by DevFourCC
then identifier. Supplying NULL will ignore all MetaData.
@return PVR_SUCCESS on success
*****************************************************************************/
EPVRTError PVRTTextureLoadFromPVR( const char * const filename,
GLuint * const texName,
const void *psTextureHeader=NULL,
bool bAllowDecompress = true,
const unsigned int nLoadFromLevel=0,
CPVRTMap<unsigned int, CPVRTMap<unsigned int, struct MetaDataBlock> > *pMetaData=NULL);
/*!***************************************************************************
@brief Returns the bits per pixel (BPP) of the format.
@param[in] nFormat
@param[in] nType
@return Unsigned integer representing the bits per pixel of the format
*****************************************************************************/
unsigned int PVRTTextureFormatGetBPP(const GLuint nFormat, const GLuint nType);
/*! @} */
#endif /* _PVRTTEXTUREAPI_H_ */
/*****************************************************************************
End of file (PVRTTextureAPI.h)
*****************************************************************************/
/******************************************************************************
@File OGLES2/PVRTgles2Ext.cpp
@Title OGLES2/PVRTgles2Ext
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform Independent
@Description OpenGL ES 2.0 extensions
******************************************************************************/
#include <string.h>
#include "PVRTContext.h"
#include "PVRTgles2Ext.h"
/****************************************************************************
** Local code
****************************************************************************/
/****************************************************************************
** Class: CPVRTgles2Ext
****************************************************************************/
/*!***************************************************************************
@Function LoadExtensions
@Description Initialises IMG extensions
*****************************************************************************/
void CPVRTgles2Ext::LoadExtensions()
{
glMultiDrawElementsEXT = 0;
glMultiDrawArraysEXT = 0;
glMapBufferOES = 0;
glUnmapBufferOES = 0;
glGetBufferPointervOES = 0;
glDiscardFramebufferEXT = 0;
glBindVertexArrayOES = 0;
glDeleteVertexArraysOES = 0;
glGenVertexArraysOES = 0;
glIsVertexArrayOES = 0;
glRenderbufferStorageMultisampleIMG = 0;
glFramebufferTexture2DMultisampleIMG = 0;
glGenQueriesEXT = 0;
glDeleteQueriesEXT = 0;
glIsQueryEXT = 0;
glBeginQueryEXT = 0;
glEndQueryEXT = 0;
glGetQueryivEXT = 0;
glGetQueryObjectuivEXT = 0;
glRenderbufferStorageMultisampleEXT = 0;
glFramebufferTexture2DMultisampleEXT = 0;
glDrawBuffersEXT = 0;
// Supported extensions provide new entry points for OpenGL ES 2.0.
const GLubyte *pszGLExtensions;
/* Retrieve GL extension string */
pszGLExtensions = glGetString(GL_EXTENSIONS);
#if !defined(TARGET_OS_IPHONE)
/* GL_EXT_multi_draw_arrays */
if (strstr((char *)pszGLExtensions, "GL_EXT_multi_draw_arrays"))
{
glMultiDrawElementsEXT = (PFNGLMULTIDRAWELEMENTS) PVRGetProcAddress(glMultiDrawElementsEXT);
glMultiDrawArraysEXT = (PFNGLMULTIDRAWARRAYS) PVRGetProcAddress(glMultiDrawArraysEXT);
}
/* GL_EXT_multi_draw_arrays */
if (strstr((char *)pszGLExtensions, "GL_OES_mapbuffer"))
{
glMapBufferOES = (PFNGLMAPBUFFEROES) PVRGetProcAddress(glMapBufferOES);
glUnmapBufferOES = (PFNGLUNMAPBUFFEROES) PVRGetProcAddress(glUnmapBufferOES);
glGetBufferPointervOES = (PFNGLGETBUFFERPOINTERVOES) PVRGetProcAddress(glGetBufferPointervOES);
}
/* GL_OES_vertex_array_object */
if (strstr((char *)pszGLExtensions, "GL_OES_vertex_array_object"))
{
glBindVertexArrayOES = (PFNGLBINDVERTEXARRAYOES) PVRGetProcAddress(glBindVertexArrayOES);
glDeleteVertexArraysOES = (PFNGLDELETEVERTEXARRAYSOES) PVRGetProcAddress(glDeleteVertexArraysOES);
glGenVertexArraysOES = (PFNGLGENVERTEXARRAYSOES) PVRGetProcAddress(glGenVertexArraysOES);
glIsVertexArrayOES = (PFNGLISVERTEXARRAYOES) PVRGetProcAddress(glIsVertexArrayOES);
}
/* GL_IMG_multisampled_render_to_texture */
if (strstr((char *)pszGLExtensions, "GL_IMG_multisampled_render_to_texture"))
{
glRenderbufferStorageMultisampleIMG = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEIMG) PVRGetProcAddress(glRenderbufferStorageMultisampleIMG);
glFramebufferTexture2DMultisampleIMG = (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMG) PVRGetProcAddress(glFramebufferTexture2DMultisampleIMG);
}
/* GL_EXT_multisampled_render_to_texture */
if (strstr((char *)pszGLExtensions, "GL_EXT_multisampled_render_to_texture"))
{
glRenderbufferStorageMultisampleEXT = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXT) PVRGetProcAddress(glRenderbufferStorageMultisampleEXT);
glFramebufferTexture2DMultisampleEXT = (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXT) PVRGetProcAddress(glFramebufferTexture2DMultisampleEXT);
}
/* GL_EXT_draw_buffers */
if (strstr((char *)pszGLExtensions, "GL_EXT_draw_buffers"))
{
glDrawBuffersEXT = (PFNGLDRAWBUFFERSEXT) PVRGetProcAddress(glDrawBuffersEXT);
}
#endif
#if defined(GL_EXT_discard_framebuffer)
/* GL_EXT_discard_framebuffer */
if (strstr((char *)pszGLExtensions, "GL_EXT_discard_framebuffer"))
{
glDiscardFramebufferEXT = (PFNGLDISCARDFRAMEBUFFEREXT) PVRGetProcAddress(glDiscardFramebufferEXT);
}
#endif
/* GL_EXT_occlusion_query_boolean */
if (strstr((char *)pszGLExtensions, "GL_EXT_occlusion_query_boolean"))
{
glGenQueriesEXT = (PFNGLGENQUERIESEXT) PVRGetProcAddress(glGenQueriesEXT);
glDeleteQueriesEXT = (PFNGLDELETEQUERIESEXT) PVRGetProcAddress(glDeleteQueriesEXT);
glIsQueryEXT = (PFNGLISQUERYEXT) PVRGetProcAddress(glIsQueryEXT);
glBeginQueryEXT = (PFNGLBEGINQUERYEXT) PVRGetProcAddress(glBeginQueryEXT);
glEndQueryEXT = (PFNGLENDQUERYEXT) PVRGetProcAddress(glEndQueryEXT);
glGetQueryivEXT = (PFNGLGETQUERYIVEXT) PVRGetProcAddress(glGetQueryivEXT);
glGetQueryObjectuivEXT = (PFNGLGETQUERYOBJECTUIVEXT) PVRGetProcAddress(glGetQueryObjectuivEXT);
}
}
/*!***********************************************************************
@Function IsGLExtensionSupported
@Input extension extension to query for
@Returns True if the extension is supported
@Description Queries for support of an extension
*************************************************************************/
bool CPVRTgles2Ext::IsGLExtensionSupported(const char * const extension)
{
// The recommended technique for querying OpenGL extensions;
// from http://opengl.org/resources/features/OGLextensions/
const GLubyte *extensions = NULL;
const GLubyte *start;
GLubyte *where, *terminator;
/* Extension names should not have spaces. */
where = (GLubyte *) strchr(extension, ' ');
if (where || *extension == '\0')
return 0;
extensions = glGetString(GL_EXTENSIONS);
/* It takes a bit of care to be fool-proof about parsing the
OpenGL extensions string. Don't be fooled by sub-strings, etc. */
start = extensions;
for (;;) {
where = (GLubyte *) strstr((const char *) start, extension);
if (!where)
break;
terminator = where + strlen(extension);
if (where == start || *(where - 1) == ' ')
if (*terminator == ' ' || *terminator == '\0')
return true;
start = terminator;
}
return false;
}
/*****************************************************************************
End of file (PVRTglesExt.cpp)
*****************************************************************************/
/*!****************************************************************************
@file PVRTBackground.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Function to draw a background texture.
******************************************************************************/
#ifndef __PVRTBACKGROUND_H__
#define __PVRTBACKGROUND_H__
#include "PVRTGlobal.h"
#include "PVRTContext.h"
#include "PVRTString.h"
#include "PVRTError.h"
/****************************************************************************
** Structures
****************************************************************************/
/*!***************************************************************************
@struct SPVRTBackgroundAPI
@brief A struct for storing API specific variables
*****************************************************************************/
struct SPVRTBackgroundAPI;
/*!***************************************************************************
@class CPVRTBackground
@brief A class for drawing a fullscreen textured background
*****************************************************************************/
class CPVRTBackground
{
public:
/*!***************************************************************************
@brief Initialise some values.
*****************************************************************************/
CPVRTBackground(void);
/*!***************************************************************************
@brief Calls Destroy()
*****************************************************************************/
~CPVRTBackground(void);
/*!***************************************************************************
@brief Destroys the background and releases API specific resources
*****************************************************************************/
void Destroy();
/*!***************************************************************************
@brief Initialises the background
@param[in] pContext A pointer to a PVRTContext
@param[in] bRotate true to rotate texture 90 degrees.
@param[in] pszError An option string for returning errors
@return PVR_SUCCESS on success
*****************************************************************************/
EPVRTError Init(const SPVRTContext * const pContext, const bool bRotate, CPVRTString *pszError = 0);
#if defined(BUILD_OGL) || defined(BUILD_OGLES) || defined(BUILD_OGLES2) || defined(BUILD_OGLES3)
/*!***************************************************************************
@brief Draws a texture on a quad covering the whole screen.
@param[in] ui32Texture Texture to use
@return PVR_SUCCESS on success
*****************************************************************************/
EPVRTError Draw(const GLuint ui32Texture);
#elif defined(BUILD_DX11)
/*!***************************************************************************
@brief Draws a texture on a quad covering the whole screen.
@param[in] pTexture Texture to use
@return PVR_SUCCESS on success
*****************************************************************************/
EPVRTError Draw(ID3D11ShaderResourceView *pTexture);
#endif
protected:
bool m_bInit;
SPVRTBackgroundAPI *m_pAPI;
};
#endif /* __PVRTBACKGROUND_H__ */
/*****************************************************************************
End of file (PVRTBackground.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTBoneBatch.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Utility functions which process vertices.
******************************************************************************/
#ifndef _PVRTBONEBATCH_H_
#define _PVRTBONEBATCH_H_
#include "PVRTVertex.h"
#include <stdlib.h>
/*!***************************************************************************
Handles a batch of bones
*****************************************************************************/
/*!***************************************************************************
@class CPVRTBoneBatches
@brief A class for processing vertices into bone batches
*****************************************************************************/
class CPVRTBoneBatches
{
public:
int *pnBatches; /*!< Space for nBatchBoneMax bone indices, per batch */
int *pnBatchBoneCnt; /*!< Actual number of bone indices, per batch */
int *pnBatchOffset; /*!< Offset into triangle array, per batch */
int nBatchBoneMax; /*!< Stored value as was passed into Create() */
int nBatchCnt; /*!< Number of batches to render */
/*!***********************************************************************
@brief Fills the bone batch structure
@param[out] pnVtxNumOut vertex count
@param[out] pVtxOut Output vertices (program must free() this)
@param[in,out] pui32Idx index array for triangle list
@param[in] nVtxNum vertex count
@param[in] pVtx vertices
@param[in] nStride Size of a vertex (in bytes)
@param[in] nOffsetWeight Offset in bytes to the vertex bone-weights
@param[in] eTypeWeight Data type of the vertex bone-weights
@param[in] nOffsetIdx Offset in bytes to the vertex bone-indices
@param[in] eTypeIdx Data type of the vertex bone-indices
@param[in] nTriNum Number of triangles
@param[in] nBatchBoneMax Number of bones a batch can reference
@param[in] nVertexBones Number of bones affecting each vertex
@return PVR_SUCCESS if successful
*************************************************************************/
EPVRTError Create(
int * const pnVtxNumOut,
char ** const pVtxOut,
unsigned int * const pui32Idx,
const int nVtxNum,
const char * const pVtx,
const int nStride,
const int nOffsetWeight,
const EPVRTDataType eTypeWeight,
const int nOffsetIdx,
const EPVRTDataType eTypeIdx,
const int nTriNum,
const int nBatchBoneMax,
const int nVertexBones);
/*!***********************************************************************
@brief Destroy the bone batch structure
*************************************************************************/
void Release()
{
FREE(pnBatches);
FREE(pnBatchBoneCnt);
FREE(pnBatchOffset);
nBatchCnt = 0;
}
};
#endif /* _PVRTBONEBATCH_H_ */
/*****************************************************************************
End of file (PVRTBoneBatch.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTDecompress.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief PVRTC and ETC Texture Decompression.
******************************************************************************/
#ifndef _PVRTDECOMPRESS_H_
#define _PVRTDECOMPRESS_H_
/*!***********************************************************************
@brief Decompresses PVRTC to RGBA 8888
@param[in] pCompressedData The PVRTC texture data to decompress
@param[in] Do2bitMode Signifies whether the data is PVRTC2 or PVRTC4
@param[in] XDim X dimension of the texture
@param[in] YDim Y dimension of the texture
@param[in,out] pResultImage The decompressed texture data
@return Returns the amount of data that was decompressed.
*************************************************************************/
int PVRTDecompressPVRTC(const void *pCompressedData,
const int Do2bitMode,
const int XDim,
const int YDim,
unsigned char* pResultImage);
/*!***********************************************************************
@brief Decompresses ETC to RGBA 8888
@param[in] pSrcData The ETC texture data to decompress
@param[in] x X dimension of the texture
@param[in] y Y dimension of the texture
@param[in,out] pDestData The decompressed texture data
@param[in] nMode The format of the data
@return The number of bytes of ETC data decompressed
*************************************************************************/
int PVRTDecompressETC(const void * const pSrcData,
const unsigned int &x,
const unsigned int &y,
void *pDestData,
const int &nMode);
#endif /* _PVRTDECOMPRESS_H_ */
/*****************************************************************************
End of file (PVRTBoneBatch.h)
*****************************************************************************/
/******************************************************************************
@File PVRTError.cpp
@Title PVRTError
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform ANSI compatible
@Description
******************************************************************************/
#include "PVRTError.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32)
#define vsnprintf _vsnprintf
#endif
/*!***************************************************************************
@Function PVRTErrorOutputDebug
@Input format printf style format followed by arguments it requires
@Description Outputs a string to the standard error.
*****************************************************************************/
void PVRTErrorOutputDebug(char const * const format, ...)
{
va_list arg;
char pszString[1024];
va_start(arg, format);
vsnprintf(pszString, 1024, format, arg);
va_end(arg);
#if defined(UNICODE)
wchar_t *pswzString = (wchar_t *)malloc((strlen(pszString) + 1) * sizeof(wchar_t));
int i;
for(i = 0; pszString[i] != '\0'; i++)
{
pswzString[i] = (wchar_t)(pszString[i]);
}
pswzString[i] = '\0';
#if defined(_WIN32)
OutputDebugString(pswzString);
#else
fprintf(stderr, pswzString);
#endif
free(pswzString);
#else
#if defined(_WIN32)
OutputDebugString(pszString);
#else
fprintf(stderr, "%s", pszString);
#endif
#endif
}
/*****************************************************************************
End of file (PVRTError.cpp)
*****************************************************************************/
/*!****************************************************************************
@file PVRTError.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief PVRT error codes.
******************************************************************************/
#ifndef _PVRTERROR_H_
#define _PVRTERROR_H_
#if defined(ANDROID)
#include <android/log.h>
#else
#if defined(_WIN32)
#include <windows.h>
#else
#include <stdio.h>
#endif
#endif
/*!***************************************************************************
Macros
*****************************************************************************/
/*! Outputs a string to the standard error if built for debugging. */
#if !defined(PVRTERROR_OUTPUT_DEBUG)
#if defined(_DEBUG) || defined(DEBUG)
#if defined(ANDROID)
#define PVRTERROR_OUTPUT_DEBUG(A) __android_log_print(ANDROID_LOG_INFO, "PVRTools", A);
#elif defined(_WIN32) && !defined(UNDER_CE)
#define PVRTERROR_OUTPUT_DEBUG(A) OutputDebugStringA(A);
#else
#define PVRTERROR_OUTPUT_DEBUG(A) fprintf(stderr,A);
#endif
#else
#define PVRTERROR_OUTPUT_DEBUG(A)
#endif
#endif
/*!***************************************************************************
Enums
*****************************************************************************/
/*!***************************************************************************
@enum EPVRTError
@brief EPVRT error conditions.
*****************************************************************************/
enum EPVRTError
{
PVR_SUCCESS = 0, /*!< Success! :D */
PVR_FAIL = 1, /*!< Failed :( */
PVR_OVERFLOW = 2 /*!< Overflow error :| */
};
/*!***************************************************************************
@brief Outputs a string to the standard error.
@param[in] format printf style format followed by arguments it requires.
*****************************************************************************/
void PVRTErrorOutputDebug(char const * const format, ...);
#endif // _PVRTERROR_H_
/*****************************************************************************
End of file (PVRTError.h)
*****************************************************************************/
/******************************************************************************
@File PVRTFixedPoint.cpp
@Title PVRTFixedPoint
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform Independant
@Description Converts MAX exported meshes to fixed point objects for use with
opengles lite.
******************************************************************************/
#include <math.h>
#include <string.h>
#include "PVRTContext.h"
#include "PVRTFixedPoint.h"
/********************************************************
** Most of the code only applies to CommonLite profile **
********************************************************/
#ifdef PVRT_FIXED_POINT_ENABLE
/*!***************************************************************************
@Function CreateFixedObjectMesh
@Input mesh The mesh to create the fixed point version from
@Returns A fixed point version of mesh
@Description Converts model floating point data to fixed point
*****************************************************************************/
HeaderStruct_Fixed_Mesh *CreateFixedObjectMesh(HeaderStruct_Mesh *mesh)
{
HeaderStruct_Fixed_Mesh *new_mesh = new HeaderStruct_Fixed_Mesh;
new_mesh->fCenter[0] = PVRTF2X(mesh->fCenter[0]);
new_mesh->fCenter[1] = PVRTF2X(mesh->fCenter[1]);
new_mesh->fCenter[2] = PVRTF2X(mesh->fCenter[2]);
new_mesh->nNumVertex = mesh->nNumVertex;
new_mesh->nNumFaces = mesh->nNumFaces;
new_mesh->nNumStrips = mesh->nNumStrips;
new_mesh->nMaterial = mesh->nMaterial;
if(mesh->nNumVertex)
{
new_mesh->pVertex = new VERTTYPE[mesh->nNumVertex*3];
for(unsigned int i = 0; i < mesh->nNumVertex*3; i++) // each vertex is 3 floats
new_mesh->pVertex[i] = PVRTF2X(mesh->pVertex[i]);
}
else
{
new_mesh->pVertex = 0;
new_mesh->nNumVertex = 0;
}
if(mesh->pUV)
{
new_mesh->pUV = new VERTTYPE[mesh->nNumVertex*2];
for(unsigned int i = 0; i < mesh->nNumVertex*2; i++) // UVs come in pairs of floats
new_mesh->pUV[i] = PVRTF2X(mesh->pUV[i]);
}
else
new_mesh->pUV = 0;
if(mesh->pNormals)
{
new_mesh->pNormals = new VERTTYPE[mesh->nNumVertex*3];
for(unsigned int i = 0; i < mesh->nNumVertex*3; i++) // each normal is 3 floats
new_mesh->pNormals[i] = PVRTF2X(mesh->pNormals[i]);
}
else
{
new_mesh->pNormals = 0;
}
/*
* Format of packedVerts is
* Position
* Normal / Colour
* UVs
*/
#define MF_NORMALS 1
#define MF_VERTEXCOLOR 2
#define MF_UV 3
if(mesh->pPackedVertex)
{
unsigned int nPackedVertSize = mesh->nNumVertex * 3 +
(mesh->nFlags & MF_NORMALS ? mesh->nNumVertex * 3 : 0) +
(mesh->nFlags & MF_VERTEXCOLOR ? mesh->nNumVertex * 3 : 0) +
(mesh->nFlags & MF_UV ? mesh->nNumVertex * 2 : 0);
new_mesh->pPackedVertex = new VERTTYPE[nPackedVertSize];
for(unsigned int i = 0; i < nPackedVertSize; i++)
new_mesh->pPackedVertex[i] = PVRTF2X(mesh->pPackedVertex[i]);
}
else
new_mesh->pPackedVertex = 0;
// simply copy reference to all properties which do not need conversion (indicies)
new_mesh->pVertexColor = mesh->pVertexColor;
new_mesh->pVertexMaterial = mesh->pVertexMaterial;
new_mesh->pFaces = mesh->pFaces;
new_mesh->pStrips = mesh->pStrips;
new_mesh->pStripLength = mesh->pStripLength;
// we're leaving the patch stuff alone
new_mesh->Patch.nType = mesh->Patch.nType;
new_mesh->Patch.nNumPatches = mesh->Patch.nNumPatches;
new_mesh->Patch.nNumVertices = mesh->Patch.nNumVertices;
new_mesh->Patch.nNumSubdivisions = mesh->Patch.nNumSubdivisions;
new_mesh->Patch.pControlPoints = mesh->Patch.pControlPoints;
new_mesh->Patch.pUVs = mesh->Patch.pUVs;
return new_mesh;
}
/*!***************************************************************************
@Function FreeFixedObjectMesh
@Input mesh The mesh to delete
@Description Release memory allocated in CreateFixedObjectMesh()
*****************************************************************************/
void FreeFixedObjectMesh(HeaderStruct_Fixed_Mesh* mesh)
{
delete[] mesh->pVertex;
delete[] mesh->pUV;
delete[] mesh->pNormals;
delete[] mesh->pPackedVertex;
delete mesh;
}
#endif
/*!***************************************************************************
@Function PVRTLoadHeaderObject
@Input headerObj Pointer to object structure in the header file
@Return directly usable geometry in fixed or float format as appropriate
@Description Converts the data exported by MAX to fixed point when used in OpenGL
ES common-lite profile.
*****************************************************************************/
HeaderStruct_Mesh_Type *PVRTLoadHeaderObject(const void *headerObj)
{
#ifdef PVRT_FIXED_POINT_ENABLE
return (HeaderStruct_Mesh_Type*) CreateFixedObjectMesh((HeaderStruct_Mesh *) headerObj);
#else
HeaderStruct_Mesh_Type *new_mesh = new HeaderStruct_Mesh_Type;
memcpy (new_mesh,headerObj,sizeof(HeaderStruct_Mesh_Type));
return (HeaderStruct_Mesh_Type*) new_mesh;
#endif
}
/*!***************************************************************************
@Function PVRTUnloadHeaderObject
@Input headerObj Pointer returned by LoadHeaderObject
@Description Releases memory allocated by LoadHeaderObject when geometry no longer
needed.
*****************************************************************************/
void PVRTUnloadHeaderObject(HeaderStruct_Mesh_Type* headerObj)
{
#ifdef PVRT_FIXED_POINT_ENABLE
FreeFixedObjectMesh(headerObj);
#else
delete headerObj;
#endif
}
/*****************************************************************************
End of file (PVRTFixedPoint.cpp)
*****************************************************************************/
/*!****************************************************************************
@file PVRTFixedPoint.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Set of macros and functions to make fixed-point easier to program.
******************************************************************************/
#ifndef _PVRTFIXEDPOINT_H_
#define _PVRTFIXEDPOINT_H_
#include "PVRTGlobal.h"
#if defined(BUILD_OGLES)
#include "PVRTFixedPointAPI.h"
#else
#define VERTTYPE PVRTfloat32
#ifdef PVRT_FIXED_POINT_ENABLE
#error Build option not supported: PVRT_FIXED_POINT_ENABLE
#endif
#endif
/* Fixed-point macros */
#define PVRTF2X(f) ( (int) ( (f)*(65536) ) )
#define PVRTX2F(x) ((float)(x)/65536.0f)
#define PVRTXMUL(a,b) ( (int)( ((PVRTint64)(a)*(b)) / 65536 ) )
#define PVRTXDIV(a,b) ( (int)( (((PVRTint64)(a))<<16)/(b) ) )
#define PVRTABS(a) ((a) <= 0 ? -(a) : (a) )
/* Define trig table macros */
#include "PVRTMathTable.h"
/* Useful values */
#define PVRT_PI_OVER_TWOf (3.1415926535f / 2.0f)
#define PVRT_PIf (3.1415926535f)
#define PVRT_TWO_PIf (3.1415926535f * 2.0f)
#define PVRT_ONEf (1.0f)
#define PVRT_PI_OVER_TWOx PVRTF2X(PVRT_PI_OVER_TWOf)
#define PVRT_PIx PVRTF2X(PVRT_PIf)
#define PVRT_TWO_PIx PVRTF2X(PVRT_TWO_PIf)
#define PVRT_ONEx PVRTF2X(PVRT_ONEf)
/* Fixed-point trig function lookups */
#define PVRTXCOS(x) (cos_val[(PVRTXMUL(((PVRTXDIV((x)<0? -(x):(x), PVRT_TWO_PIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))])
#define PVRTXSIN(x) (sin_val[(PVRTXMUL(((PVRTXDIV((x)<0 ? PVRT_PIx-(x):(x), PVRT_TWO_PIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))])
#define PVRTXTAN(x) ( (x)<0 ? -tan_val[(PVRTXMUL(((PVRTXDIV(-(x), PVRT_TWO_PIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))] : tan_val[(PVRTXMUL(((PVRTXDIV(x, PVRT_TWO_PIx)) & 0x0000FFFF), (NUM_ENTRIES-1)))] )
#define PVRTXACOS(x) (acos_val[PVRTXMUL(((((x) + PVRTF2X(1.0f))>>1) & 0x0000FFFF), (NUM_ENTRIES-1))])
/* Floating-point trig functions lookups (needed by some tools chains that have problems with real math functions) */
#ifdef USE_TRIGONOMETRIC_LOOKUP_TABLES
/* If trig tables are forced ON in non-fixed-point builds then convert fixed-point trig tables results to float */
#define PVRTFCOS(x) PVRTX2F(PVRTXCOS(PVRTF2X(x)))
#define PVRTFSIN(x) PVRTX2F(PVRTXSIN(PVRTF2X(x)))
#define PVRTFTAN(x) PVRTX2F(PVRTXTAN(PVRTF2X(x)))
#define PVRTFACOS(x) PVRTX2F(PVRTXACOS(PVRTF2X(x)))
#else
/* Trig abstraction macros default to normal math trig functions for full float mode */
#define PVRTFCOS(x) ((float)cos(x))
#define PVRTFSIN(x) ((float)sin(x))
#define PVRTFTAN(x) ((float)tan(x))
#define PVRTFACOS(x) ((float)acos(x))
#endif
/* Fixed/float macro abstraction */
#ifdef PVRT_FIXED_POINT_ENABLE
/* Fixed-point operations, including trig tables */
#define VERTTYPEMUL(a,b) PVRTXMUL(a,b)
#define VERTTYPEDIV(a,b) PVRTXDIV(a,b)
#define VERTTYPEABS(a) PVRTABS(a)
#define f2vt(f) PVRTF2X(f)
#define vt2f(x) PVRTX2F(x)
#define PVRT_PI_OVER_TWO PVRT_PI_OVER_TWOx
#define PVRT_PI PVRT_PIx
#define PVRT_TWO_PI PVRT_TWO_PIx
#define PVRT_ONE PVRT_ONEx
#define PVRTCOS(x) PVRTXCOS(x)
#define PVRTSIN(x) PVRTXSIN(x)
#define PVRTTAN(x) PVRTXTAN(x)
#define PVRTACOS(x) PVRTXACOS(x)
#else
/* Floating-point operations */
#define VERTTYPEMUL(a,b) ( (VERTTYPE)((a)*(b)) )
#define VERTTYPEDIV(a,b) ( (VERTTYPE)((a)/(b)) )
#define VERTTYPEABS(a) ( (VERTTYPE)(fabs(a)) )
#define f2vt(x) (x)
#define vt2f(x) (x)
#define PVRT_PI_OVER_TWO PVRT_PI_OVER_TWOf
#define PVRT_PI PVRT_PIf
#define PVRT_TWO_PI PVRT_TWO_PIf
#define PVRT_ONE PVRT_ONEf
/* If trig tables are forced ON in non-fixed-point builds then convert fixed-point trig tables results to float */
#define PVRTCOS(x) PVRTFCOS(x)
#define PVRTSIN(x) PVRTFSIN(x)
#define PVRTTAN(x) PVRTFTAN(x)
#define PVRTACOS(x) PVRTFACOS(x)
#endif
// Structure Definitions
/*!***************************************************************************
@struct HeaderStruct_Mesh
@brief Defines the format of a header-object as exported by the MAX plugin.
*****************************************************************************/
typedef struct {
unsigned int nNumVertex;
unsigned int nNumFaces;
unsigned int nNumStrips;
unsigned int nFlags;
unsigned int nMaterial;
float fCenter[3];
float *pVertex;
float *pUV;
float *pNormals;
float *pPackedVertex;
unsigned int *pVertexColor;
unsigned int *pVertexMaterial;
unsigned short *pFaces;
unsigned short *pStrips;
unsigned short *pStripLength;
struct
{
unsigned int nType;
unsigned int nNumPatches;
unsigned int nNumVertices;
unsigned int nNumSubdivisions;
float *pControlPoints;
float *pUVs;
} Patch;
} HeaderStruct_Mesh;
#ifdef PVRT_FIXED_POINT_ENABLE
/*!***************************************************************************
@struct HeaderStruct_Fixed_Mesh
@brief Defines the format of a header-object as when converted to fixed point.
*****************************************************************************/
typedef struct {
unsigned int nNumVertex;
unsigned int nNumFaces;
unsigned int nNumStrips;
unsigned int nFlags;
unsigned int nMaterial;
VERTTYPE fCenter[3];
VERTTYPE *pVertex;
VERTTYPE *pUV;
VERTTYPE *pNormals;
VERTTYPE *pPackedVertex;
unsigned int *pVertexColor;
unsigned int *pVertexMaterial;
unsigned short *pFaces;
unsigned short *pStrips;
unsigned short *pStripLength;
struct
{
unsigned int nType; // for the moment, these are left as floats
unsigned int nNumPatches;
unsigned int nNumVertices;
unsigned int nNumSubdivisions;
float *pControlPoints;
float *pUVs;
} Patch;
} HeaderStruct_Fixed_Mesh;
typedef HeaderStruct_Fixed_Mesh HeaderStruct_Mesh_Type;
#else
typedef HeaderStruct_Mesh HeaderStruct_Mesh_Type;
#endif
// Function prototypes
/*!***************************************************************************
@brief Converts the data exported by MAX to fixed point when used in OpenGL
ES common-lite profile.
@param[in] headerObj Pointer to object structure in the header file
@return directly usable geometry in fixed or float format as appropriate
*****************************************************************************/
HeaderStruct_Mesh_Type* PVRTLoadHeaderObject(const void *headerObj);
/*!***************************************************************************
@brief Releases memory allocated by LoadHeaderObject when geometry no longer
needed.
@param[in] headerObj Pointer returned by LoadHeaderObject
*****************************************************************************/
void PVRTUnloadHeaderObject(HeaderStruct_Mesh_Type* headerObj);
#endif /* _PVRTFIXEDPOINT_H_ */
/*****************************************************************************
End of file (PVRTFixedPoint.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTGeometry.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Code to affect triangle mesh geometry.
******************************************************************************/
#ifndef _PVRTGEOMETRY_H_
#define _PVRTGEOMETRY_H_
/****************************************************************************
** Defines
****************************************************************************/
#define PVRTGEOMETRY_IDX unsigned int
#define PVRTGEOMETRY_SORT_VERTEXCACHE (0x01 /* Sort triangles for optimal vertex cache usage */)
#define PVRTGEOMETRY_SORT_IGNOREVERTS (0x02 /* Do not sort vertices for optimal memory cache usage */)
/****************************************************************************
** Functions
****************************************************************************/
/*!***************************************************************************
@brief Triangle sorter
@param[in,out] pVtxData Pointer to array of vertices
@param[in,out] pwIdx Pointer to array of indices
@param[in] nStride Size of a vertex (in bytes)
@param[in] nVertNum Number of vertices. Length of pVtxData array
@param[in] nTriNum Number of triangles. Length of pwIdx array is 3* this
@param[in] nBufferVtxLimit Number of vertices that can be stored in a buffer
@param[in] nBufferTriLimit Number of triangles that can be stored in a buffer
@param[in] dwFlags PVRTGEOMETRY_SORT_* flags
*****************************************************************************/
void PVRTGeometrySort(
void * const pVtxData,
PVRTGEOMETRY_IDX * const pwIdx,
const int nStride,
const int nVertNum,
const int nTriNum,
const int nBufferVtxLimit,
const int nBufferTriLimit,
const unsigned int dwFlags);
#endif /* _PVRTGEOMETRY_H_ */
/*****************************************************************************
End of file (PVRTGeometry.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTGlobal.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Global defines and typedefs for PVRTools
******************************************************************************/
#ifndef _PVRTGLOBAL_H_
#define _PVRTGLOBAL_H_
/*!***************************************************************************
Macros
*****************************************************************************/
#define PVRT_MIN(a,b) (((a) < (b)) ? (a) : (b))
#define PVRT_MAX(a,b) (((a) > (b)) ? (a) : (b))
#define PVRT_CLAMP(x, l, h) (PVRT_MIN((h), PVRT_MAX((x), (l))))
// avoid warning about unused parameter
#define PVRT_UNREFERENCED_PARAMETER(x) ((void) x)
#if defined(_WIN32) && !defined(__QT__) && !defined(UNDER_CE) /* Windows desktop */
#if !defined(_CRTDBG_MAP_ALLOC)
#define _CRTDBG_MAP_ALLOC
#endif
#include <windows.h>
#include <crtdbg.h>
#include <tchar.h>
#endif
#if defined(UNDER_CE)
#include <windows.h>
#ifndef _ASSERT
#ifdef _DEBUG
#define _ASSERT(X) { (X) ? 0 : DebugBreak(); }
#else
#define _ASSERT(X)
#endif
#endif
#ifndef _ASSERTE
#ifdef _DEBUG
#define _ASSERTE _ASSERT
#else
#define _ASSERTE(X)
#endif
#endif
#define _RPT0(a,b)
#define _RPT1(a,b,c)
#define _RPT2(a,b,c,d)
#define _RPT3(a,b,c,d,e)
#define _RPT4(a,b,c,d,e,f)
#else
#if defined(_WIN32) && !defined(__QT__)
#else
#if defined(__linux__) || defined(__APPLE__)
#include <assert.h>
#ifdef _DEBUG
#ifndef _RPT0
#define _RPT0(a,b) printf(b)
#endif
#ifndef _RPT1
#define _RPT1(a,b,c) printf(b,c)
#endif
#ifndef _ASSERT
#define _ASSERT(a) assert(a)
#endif
#ifndef _ASSERTE
#define _ASSERTE(a) assert(a)
#endif
#else
#ifndef _RPT0
#define _RPT0(a,b)((void)0)
#endif
#ifndef _RPT1
#define _RPT1(a,b,c)((void)0)
#endif
#ifndef _ASSERT
#define _ASSERT(a)((void)0)
#endif
#ifndef _ASSERTE
#define _ASSERTE(a)((void)0)
#endif
#endif
#ifndef _RPT2
#define _RPT2(a,b,c,d)((void)0)
#endif
#ifndef _RPT3
#define _RPT3(a,b,c,d,e)((void)0)
#endif
#ifndef _RPT4
#define _RPT4(a,b,c,d,e,f)((void)0)
#endif
#include <stdlib.h>
#include <string.h>
#ifndef BYTE
#define BYTE unsigned char
#endif
#ifndef WORD
#define WORD unsigned short
#endif
#ifndef DWORD
#define DWORD unsigned int
#endif
#if !defined(BOOL) && !defined(OBJC_BOOL_DEFINED)
#define BOOL int
#endif
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
#if !defined(TRUE)
#define TRUE 1
#endif
#if !defined(FALSE)
#define FALSE 0
#endif
#else
#define _CRT_WARN 0
#define _RPT0(a,b)
#define _RPT1(a,b,c)
#define _RPT2(a,b,c,d)
#define _RPT3(a,b,c,d,e)
#define _RPT4(a,b,c,d,e,f)
#define _ASSERT(X)
#define _ASSERTE(X)
#endif
#endif
#endif
#include <stdio.h>
#define FREE(X) { if(X) { free(X); (X) = 0; } }
// This macro is used to check at compile time that types are of a certain size
// If the size does not equal the expected size, this typedefs an array of size 0
// which causes a compile error
#define PVRTSIZEASSERT(T, size) typedef int (sizeof_##T)[sizeof(T) == (size)]
#define PVRTCOMPILEASSERT(T, expr) typedef int (assert_##T)[expr]
/****************************************************************************
** Integer types
****************************************************************************/
typedef char PVRTchar8;
typedef signed char PVRTint8;
typedef signed short PVRTint16;
typedef signed int PVRTint32;
typedef unsigned char PVRTuint8;
typedef unsigned short PVRTuint16;
typedef unsigned int PVRTuint32;
typedef float PVRTfloat32;
#if (defined(__int64) || defined(_WIN32))
typedef signed __int64 PVRTint64;
typedef unsigned __int64 PVRTuint64;
#elif defined(__GNUC__)
__extension__ typedef signed long long PVRTint64;
__extension__ typedef unsigned long long PVRTuint64;
#else
typedef signed long long PVRTint64;
typedef unsigned long long PVRTuint64;
#endif
#if __SIZEOF_WCHAR_T__ == 4 || __WCHAR_MAX__ > 0x10000
#define PVRTSIZEOFWCHAR 4
#else
#define PVRTSIZEOFWCHAR 2
#endif
PVRTSIZEASSERT(PVRTchar8, 1);
PVRTSIZEASSERT(PVRTint8, 1);
PVRTSIZEASSERT(PVRTuint8, 1);
PVRTSIZEASSERT(PVRTint16, 2);
PVRTSIZEASSERT(PVRTuint16, 2);
PVRTSIZEASSERT(PVRTint32, 4);
PVRTSIZEASSERT(PVRTuint32, 4);
PVRTSIZEASSERT(PVRTint64, 8);
PVRTSIZEASSERT(PVRTuint64, 8);
PVRTSIZEASSERT(PVRTfloat32, 4);
/*!**************************************************************************
@enum ETextureFilter
@brief Enum values for defining texture filtering
****************************************************************************/
enum ETextureFilter
{
eFilter_Nearest,
eFilter_Linear,
eFilter_None,
eFilter_Size,
eFilter_Default = eFilter_Linear,
eFilter_MipDefault = eFilter_None
};
/*!**************************************************************************
@enum ETextureWrap
@brief Enum values for defining texture wrapping
****************************************************************************/
enum ETextureWrap
{
eWrap_Clamp,
eWrap_Repeat,
eWrap_Size,
eWrap_Default = eWrap_Repeat
};
/****************************************************************************
** swap template function
****************************************************************************/
/*!***************************************************************************
@brief A swap template function that swaps a and b
@param[in] a Type a
@param[in] b Type b
*****************************************************************************/
template <typename T>
inline void PVRTswap(T& a, T& b)
{
T temp = a;
a = b;
b = temp;
}
/*!***************************************************************************
@brief A clamp template function that clamps val between min and max.
@param[in] val Value to clamp
@param[in] min Minimum legal value
@param[in] max Maximum legal value
*****************************************************************************/
template <typename T>
inline T PVRTClamp(const T& val, const T& min, const T& max)
{
if(val > max)
return max;
if(val < min)
return min;
return val;
}
/*!***************************************************************************
@brief Swaps the endianness of pBytes in place
@param[in] pBytes A number
@param[in] i32ByteNo Number of bytes in pBytes
*****************************************************************************/
inline void PVRTByteSwap(unsigned char* pBytes, int i32ByteNo)
{
int i = 0, j = i32ByteNo - 1;
while(i < j)
PVRTswap<unsigned char>(pBytes[i++], pBytes[j--]);
}
/*!***************************************************************************
@brief Converts the endianness of an unsigned int
@param[in] ui32Long A number
@return ui32Long with its endianness changed
*****************************************************************************/
inline unsigned int PVRTByteSwap32(unsigned int ui32Long)
{
return ((ui32Long&0x000000FF)<<24) + ((ui32Long&0x0000FF00)<<8) + ((ui32Long&0x00FF0000)>>8) + ((ui32Long&0xFF000000) >> 24);
}
/*!***************************************************************************
@brief Converts the endianness of a unsigned short
@param[in] ui16Short A number
@return ui16Short with its endianness changed
*****************************************************************************/
inline unsigned short PVRTByteSwap16(unsigned short ui16Short)
{
return (ui16Short>>8) | (ui16Short<<8);
}
/*!***************************************************************************
@brief Returns true if the platform the code is ran on is little endian
@return True if the platform the code is ran on is little endian
*****************************************************************************/
inline bool PVRTIsLittleEndian()
{
static bool bLittleEndian;
static bool bIsInit = false;
if(!bIsInit)
{
short int word = 0x0001;
char *byte = (char*) &word;
bLittleEndian = byte[0] ? true : false;
bIsInit = true;
}
return bLittleEndian;
}
#endif // _PVRTGLOBAL_H_
/*****************************************************************************
End of file (Tools.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTHash.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief A simple hash class which uses TEA to hash a string or given data
into a 32-bit unsigned int.
******************************************************************************/
#ifndef PVRTHASH_H
#define PVRTHASH_H
#include "PVRTString.h"
#include "PVRTGlobal.h"
/*!****************************************************************************
@class CPVRTHash
@brief A simple hash class which uses TEA to hash a string or other given
data into a 32-bit unsigned int.
******************************************************************************/
class CPVRTHash
{
public:
/*!***************************************************************************
@brief Constructor
*****************************************************************************/
CPVRTHash() : m_uiHash(0) {}
/*!***************************************************************************
@brief Copy Constructor
@param[in] rhs CPVRTHash to copy.
*****************************************************************************/
CPVRTHash(const CPVRTHash& rhs) : m_uiHash(rhs.m_uiHash) {}
/*!***************************************************************************
@brief Overloaded constructor
@param[in] String CPVRTString to create the CPVRTHash with.
*****************************************************************************/
CPVRTHash(const CPVRTString& String) : m_uiHash(0)
{
if(String.length() > 0) // Empty string. Don't set.
{
m_uiHash = MakeHash(String);
}
}
/*!***************************************************************************
@brief Overloaded constructor
@param[in] c_pszString String to create the CPVRTHash with.
*****************************************************************************/
CPVRTHash(const char* c_pszString) : m_uiHash(0)
{
_ASSERT(c_pszString);
if(c_pszString[0] != 0) // Empty string. Don't set.
{
m_uiHash = MakeHash(c_pszString);
}
}
/*!***************************************************************************
@brief Overloaded constructor
@param[in] pData
@param[in] dataSize
@param[in] dataCount
*****************************************************************************/
CPVRTHash(const void* pData, unsigned int dataSize, unsigned int dataCount) : m_uiHash(0)
{
_ASSERT(pData);
_ASSERT(dataSize > 0);
if(dataCount > 0)
{
m_uiHash = MakeHash(pData, dataSize, dataCount);
}
}
/*!***************************************************************************
@brief Overloaded assignment.
@param[in] rhs
@return CPVRTHash &
*****************************************************************************/
CPVRTHash& operator=(const CPVRTHash& rhs)
{
if(this != &rhs)
{
m_uiHash = rhs.m_uiHash;
}
return *this;
}
/*!***************************************************************************
@brief Converts to unsigned int.
@return int
*****************************************************************************/
operator unsigned int() const
{
return m_uiHash;
}
/*!***************************************************************************
@brief Generates a hash from a CPVRTString.
@param[in] String
@return The hash.
*****************************************************************************/
static CPVRTHash MakeHash(const CPVRTString& String)
{
if(String.length() > 0)
return MakeHash(String.c_str(), sizeof(char), (unsigned int) String.length());
return CPVRTHash();
}
/*!***************************************************************************
@brief Generates a hash from a null terminated char array.
@param[in] c_pszString
@return The hash.
*****************************************************************************/
static CPVRTHash MakeHash(const char* c_pszString)
{
_ASSERT(c_pszString);
if(c_pszString[0] == 0)
return CPVRTHash();
const char* pCursor = c_pszString;
while(*pCursor) pCursor++;
return MakeHash(c_pszString, sizeof(char), (unsigned int) (pCursor - c_pszString));
}
/*!***************************************************************************
@brief Generates a hash from generic data. This function uses the
32-bit Fowler/Noll/Vo algorithm which trades efficiency for
slightly increased risk of collisions. This algorithm is
public domain. More information can be found at:
http://www.isthe.com/chongo/tech/comp/fnv/.
@param[in] pData
@param[in] dataSize
@param[in] dataCount
@return unsigned int The hash.
*****************************************************************************/
static CPVRTHash MakeHash(const void* pData, unsigned int dataSize, unsigned int dataCount)
{
_ASSERT(pData);
_ASSERT(dataSize > 0);
#define FNV_PRIME 16777619U
#define FNV_OFFSETBIAS 2166136261U
if(dataCount == 0)
return CPVRTHash();
CPVRTHash pvrHash;
unsigned char* p = (unsigned char*)pData;
pvrHash.m_uiHash = FNV_OFFSETBIAS;
for(unsigned int i = 0; i < dataSize * dataCount; ++i)
{
pvrHash.m_uiHash = (pvrHash.m_uiHash * FNV_PRIME) ^ p[i];
}
return pvrHash;
}
private:
unsigned int m_uiHash; /// The hashed data.
};
#endif
/*!****************************************************************************
@file PVRTMap.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief A simple and easy-to-use implementation of a map.
******************************************************************************/
#ifndef __PVRTMAP_H__
#define __PVRTMAP_H__
#include "PVRTArray.h"
/*!***************************************************************************
@class CPVRTMap
@brief Expanding map template class.
@details A simple and easy-to-use implementation of a map.
*****************************************************************************/
template <typename KeyType, typename DataType>
class CPVRTMap
{
public:
/*!***********************************************************************
@brief Constructor for a CPVRTMap.
@return A new CPVRTMap.
*************************************************************************/
CPVRTMap() : m_Keys(), m_Data(), m_uiSize(0)
{}
/*!***********************************************************************
@brief Destructor for a CPVRTMap.
*************************************************************************/
~CPVRTMap()
{
//Clear the map, that's enough - the CPVRTArray members will tidy everything else up.
Clear();
}
EPVRTError Reserve(const PVRTuint32 uiSize)
{
//Sets the capacity of each member array to the requested size. The array used will only expand.
//Returns the most serious error from either method.
return PVRT_MAX(m_Keys.SetCapacity(uiSize),m_Data.SetCapacity(uiSize));
}
/*!***********************************************************************
@brief Returns the number of meaningful members in the map.
@return Number of meaningful members in the map.
*************************************************************************/
PVRTuint32 GetSize() const
{
//Return the size.
return m_uiSize;
}
/*!***********************************************************************
@brief Gets the position of a particular key/data within the map.
If the return value is exactly equal to the value of
GetSize() then the item has not been found.
@param[in] key Key type
@return The index value for a mapped item.
*************************************************************************/
PVRTuint32 GetIndexOf(const KeyType key) const
{
//Loop through all the valid keys.
for (PVRTuint32 i=0; i<m_uiSize; ++i)
{
//Check if a key matches.
if (m_Keys[i]==key)
{
//If a matched key is found, return the position.
return i;
}
}
//If not found, return the number of meaningful members.
return m_uiSize;
}
/*!***********************************************************************
@brief Returns a pointer to the Data at a particular index.
If the index supplied is not valid, NULL is returned
instead. Deletion of data at this pointer will lead
to undefined behaviour.
@param[in] uiIndex Index number
@return Data type at the specified position.
*************************************************************************/
const DataType* GetDataAtIndex(const PVRTuint32 uiIndex) const
{
if (uiIndex>=m_uiSize)
return NULL;
return &(m_Data[uiIndex]);
}
/*!***********************************************************************
@brief If a mapping already exists for 'key' then it will return
the associated data. If no mapping currently exists, a new
element is created in place.
@param[in] key Key type
@return Data that is mapped to 'key'.
*************************************************************************/
DataType& operator[] (const KeyType key)
{
//Get the index of the key.
PVRTuint32 uiIndex = GetIndexOf(key);
//Check the index is valid
if (uiIndex != m_uiSize)
{
//Return mapped data if the index is valid.
return m_Data[uiIndex];
}
else
{
//Append the key to the Keys array.
m_Keys.Append(key);
//Create a new DataType.
DataType sNewData;
//Append the new pointer to the Data array.
m_Data.Append(sNewData);
//Increment the size of meaningful data.
++m_uiSize;
//Return the contents of pNewData.
return m_Data[m_Keys.GetSize()-1];
}
}
/*!***********************************************************************
@brief Removes an element from the map if it exists.
@param[in] key Key type
@return Returns PVR_FAIL if item doesn't exist.
Otherwise returns PVR_SUCCESS.
*************************************************************************/
EPVRTError Remove(const KeyType key)
{
//Finds the index of the key.
PVRTuint32 uiIndex=GetIndexOf(key);
//If the key is invalid, fail.
if (uiIndex==m_uiSize)
{
//Return failure.
return PVR_FAIL;
}
//Decrement the size of the map to ignore the last element in each array.
m_uiSize--;
//Copy the last key over the deleted key. There are now two copies of one element,
//but the one at the end of the array is ignored.
m_Keys[uiIndex]=m_Keys[m_uiSize-1];
//Copy the last data over the deleted data in the same way as the keys.
m_Data[uiIndex]=m_Data[m_uiSize-1];
//Return success.
return PVR_SUCCESS;
}
/*!***********************************************************************
@brief Clears the Map of all data values.
*************************************************************************/
void Clear()
{
//Set the size to 0.
m_uiSize=0;
m_Keys.Clear();
m_Data.Clear();
}
/*!***********************************************************************
@brief Checks whether or not data exists for the specified key.
@param[in] key Key type
@return Whether data exists for the specified key or not.
*************************************************************************/
bool Exists(const KeyType key) const
{
//Checks for a valid index for key, if not, returns false.
return (GetIndexOf(key) != m_uiSize);
}
private:
CPVRTArray<KeyType> m_Keys; /*!< Array of all the keys. Indices match m_Data. */
CPVRTArray<DataType> m_Data; /*!< Array of pointers to all the allocated data. */
PVRTuint32 m_uiSize; /*!< The number of meaningful members in the map. */
};
#endif // __PVRTMAP_H__
/*****************************************************************************
End of file (PVRTMap.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTMemoryFileSystem.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Memory file system for resource files.
******************************************************************************/
#ifndef _PVRTMEMORYFILE_H_
#define _PVRTMEMORYFILE_H_
#include "PVRTGlobal.h"
#include <stddef.h>
/*!****************************************************************************
@class CPVRTMemoryFileSystem
@brief Memory file system for resource files.
******************************************************************************/
class CPVRTMemoryFileSystem
{
public:
/*!***************************************************************************
@brief Constructor. Creates a CPVRTMemoryFileSystem object based on the parameters supplied.
@param[in] pszFilename Name of file to register
@param[in] pBuffer Pointer to file data
@param[in] Size File size
@param[in] bCopy Name and data should be copied?
*****************************************************************************/
CPVRTMemoryFileSystem(const char* pszFilename, const void* pBuffer, size_t Size, bool bCopy = false);
/*!***************************************************************************
@fn RegisterMemoryFile
@param[in] pszFilename Name of file to register
@param[in] pBuffer Pointer to file data
@param[in] Size File size
@param[in] bCopy Name and data should be copied?
@brief Registers a block of memory as a file that can be looked up
by name.
*****************************************************************************/
static void RegisterMemoryFile(const char* pszFilename, const void* pBuffer, size_t Size, bool bCopy = false);
/*!***************************************************************************
@fn GetFile
@param[in] pszFilename Name of file to open
@param[out] ppBuffer Pointer to file data
@param[out] pSize File size
@return true if the file was found in memory, false otherwise
@brief Looks up a file in the memory file system by name. Returns a
pointer to the file data as well as its size on success.
*****************************************************************************/
static bool GetFile(const char* pszFilename, const void** ppBuffer, size_t* pSize);
/*!***************************************************************************
@fn GetNumFiles
@return The number of registered files
@brief Getter for the number of registered files
*****************************************************************************/
static int GetNumFiles();
/*!***************************************************************************
@fn GetFilename
@param[in] i32Index Index of file
@return A pointer to the filename of the requested file
@brief Looks up a file in the memory file system by name. Returns a
pointer to the file data as well as its size on success.
*****************************************************************************/
static const char* GetFilename(int i32Index);
protected:
/*!***************************************************************************
@class CAtExit
@brief Provides a deconstructor for platforms that don't support the atexit() function.
*****************************************************************************/
class CAtExit
{
public:
/*!***************************************************************************
@brief Destructor of CAtExit class. Workaround for platforms that
don't support the atexit() function. This deletes any memory
file system data.
*****************************************************************************/
~CAtExit();
};
static CAtExit s_AtExit;
friend class CAtExit;
/*!***************************************************************************
@struct SFileInfo
@brief Struct which contains information on a single file.
*****************************************************************************/
struct SFileInfo
{
const char* pszFilename; ///< File name.
const void* pBuffer; ///< Pointer to file data.
size_t Size; ///< File size.
bool bAllocated; ///< File was allocated. If true, this file will be deleted on exit.
};
static SFileInfo* s_pFileInfo;
static int s_i32NumFiles;
static int s_i32Capacity;
};
#endif // _PVRTMEMORYFILE_H_
/*****************************************************************************
End of file (PVRTMemoryFileSystem.h)
*****************************************************************************/
/*!****************************************************************************
@file PVRTMisc.h
@copyright Copyright (c) Imagination Technologies Limited.
@brief Miscellaneous functions used in 3D rendering.
******************************************************************************/
#ifndef _PVRTMISC_H_
#define _PVRTMISC_H_
#include "PVRTMatrix.h"
#include "PVRTFixedPoint.h"
/****************************************************************************
** Functions
****************************************************************************/
/*!***************************************************************************
@brief Calculates coords of the intersection of a line and an
infinite plane
@param[out] pvIntersection The point of intersection
@param[in] pfPlane Length 4 [A,B,C,D], values for plane equation
@param[in] pv0 A point on the line
@param[in] pv1 Another point on the line
*****************************************************************************/
void PVRTMiscCalculateIntersectionLinePlane(
PVRTVECTOR3 * const pvIntersection,
const VERTTYPE pfPlane[4],
const PVRTVECTOR3 * const pv0,
const PVRTVECTOR3 * const pv1);
/*!***************************************************************************
@brief Calculates world-space coords of a screen-filling
representation of an infinite plane The resulting vertices run
counter-clockwise around the screen, and can be simply drawn using
non-indexed TRIANGLEFAN
@param[out] pfVtx Position of the first of 3 floats to receive
the position of vertex 0; up to 5 vertex positions
will be written (5 is the maximum number of vertices
required to draw an infinite polygon clipped to screen
and far clip plane).
@param[in] nStride Size of each vertex structure containing pfVtx
@param[in] pvPlane Length 4 [A,B,C,D], values for plane equation
@param[in] pmViewProjInv The inverse of the View Projection matrix
@param[in] pFrom Position of the camera
@param[in] fFar Far clipping distance
@return Number of vertices in the polygon fan (Can be 0, 3, 4 or 5)
*****************************************************************************/
int PVRTMiscCalculateInfinitePlane(
VERTTYPE * const pfVtx,
const int nStride,
const PVRTVECTOR4 * const pvPlane,
const PVRTMATRIX * const pmViewProjInv,
const PVRTVECTOR3 * const pFrom,
const VERTTYPE fFar);
/*!***************************************************************************
@brief Creates the vertices and texture coordinates for a skybox
@param[in] scale Scale the skybox
@param[in] adjustUV Adjust or not UVs for PVRT compression
@param[in] textureSize Texture size in pixels
@param[out] Vertices Array of vertices
@param[out] UVs Array of UVs
*****************************************************************************/
void PVRTCreateSkybox(float scale, bool adjustUV, int textureSize, VERTTYPE** Vertices, VERTTYPE** UVs);
/*!***************************************************************************
@brief Destroy the memory allocated for a skybox
@param[in] Vertices Vertices array to destroy
@param[in] UVs UVs array to destroy
*****************************************************************************/
void PVRTDestroySkybox(VERTTYPE* Vertices, VERTTYPE* UVs);
/*!***************************************************************************
@brief When iTimesHigher is one, this function will return the closest
power-of-two value above the base value.
For every increment beyond one for the iTimesHigher value,
the next highest power-of-two value will be calculated.
@param[in] uiOriginalValue Base value
@param[in] iTimesHigher Multiplier
*****************************************************************************/
unsigned int PVRTGetPOTHigher(unsigned int uiOriginalValue, int iTimesHigher);
/*!***************************************************************************
@brief When iTimesLower is one, this function will return the closest
power-of-two value below the base value.
For every increment beyond one for the iTimesLower value,
the next lowest power-of-two value will be calculated. The lowest
value that can be reached is 1.
@param[in] uiOriginalValue Base value
@param[in] iTimesLower Multiplier
*****************************************************************************/
unsigned int PVRTGetPOTLower(unsigned int uiOriginalValue, int iTimesLower);
#endif /* _PVRTMISC_H_ */
/*****************************************************************************
End of file (PVRTMisc.h)
*****************************************************************************/
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.
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