Commit 6b8dc3e2 by Nicolas Capens Committed by Nicolas Capens

Add the BasicTnL PowerVR sample.

BUG=18110152 Change-Id: I83792f8235663a6f59c08ad874f743a8b59ac337 Reviewed-on: https://swiftshader-review.googlesource.com/1256Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 702aabdb
...@@ -227,6 +227,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2DisplacementMap", ".. ...@@ -227,6 +227,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLES2DisplacementMap", "..
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLES_CM", "GLES2\libGLES_CM\libGLES_CM.vcxproj", "{235B1D85-E6B6-45E2-BA5D-5C60396428FF}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libGLES_CM", "GLES2\libGLES_CM\libGLES_CM.vcxproj", "{235B1D85-E6B6-45E2-BA5D-5C60396428FF}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OGLESBasicTnL", "..\tests\third_party\PowerVR\Examples\Beginner\04_BasicTnL\OGLES\Build\WindowsVC2010\OGLESBasicTnL.vcxproj", "{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}"
ProjectSection(ProjectDependencies) = postProject
{235B1D85-E6B6-45E2-BA5D-5C60396428FF} = {235B1D85-E6B6-45E2-BA5D-5C60396428FF}
{E746FCA9-64C3-433E-85E8-9A5A67AB7ED6} = {E746FCA9-64C3-433E-85E8-9A5A67AB7ED6}
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
...@@ -606,6 +612,18 @@ Global ...@@ -606,6 +612,18 @@ Global
{235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|Win32.ActiveCfg = Release|Win32 {235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|Win32.ActiveCfg = Release|Win32
{235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|Win32.Build.0 = Release|Win32 {235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|Win32.Build.0 = Release|Win32
{235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|x64.ActiveCfg = Release|Win32 {235B1D85-E6B6-45E2-BA5D-5C60396428FF}.Release|x64.ActiveCfg = Release|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Debug|Win32.ActiveCfg = Debug|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Debug|Win32.Build.0 = Debug|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Debug|x64.ActiveCfg = Debug|x64
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Debug|x64.Build.0 = Debug|x64
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Profile|Win32.ActiveCfg = Release|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Profile|Win32.Build.0 = Release|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Profile|x64.ActiveCfg = Release|x64
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Profile|x64.Build.0 = Release|x64
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Release|Win32.ActiveCfg = Release|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Release|Win32.Build.0 = Release|Win32
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Release|x64.ActiveCfg = Release|x64
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -641,5 +659,6 @@ Global ...@@ -641,5 +659,6 @@ Global
{9CF4408B-9B08-481F-95DA-3DF0846DABE4} = {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} {09ABE661-9BC0-4152-A820-1FB0522CAC01} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{04FC5430-3F1B-42A2-A18A-D8BB7E5B2733} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D} {04FC5430-3F1B-42A2-A18A-D8BB7E5B2733} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
{AB1EB229-D86C-41B3-8E20-7A7E1FF5DDF5} = {ED25C308-5BDB-43A7-BED6-C2C059FC2D7D}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
:Title:
BasicTnL
:ShortDescription:
This training course consists of a demonstration of basic transformation and lighting.
:FullDescription:
This training course consists of a demonstration of basic transformation and lighting, growing on the basic drawing techniques learnt in HelloTriangle.
Controls:
- Esc - Close the application
:VGP:
Not Required
:PolyCount:
1
:VertexCount:
3
<?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>
</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="..\..\OGLESBasicTnL.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>
</ItemGroup>
<ItemGroup>
</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
/******************************************************************************
@File OGLESBasicTnL.cpp
@Title Shows basic transformations and lighting
@Version
@Copyright Copyright (c) Imagination Technologies Limited.
@Platform Independant
@Description Shows basic transformations and lighting
******************************************************************************/
#include "PVRShell.h"
#include <math.h>
#if defined(__APPLE__) && defined (TARGET_OS_IPHONE)
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#else
#include <GLES/gl.h>
#endif
/******************************************************************************
Defines
******************************************************************************/
// Size of the texture we create
const int g_i32TexSize = 128;
/*!****************************************************************************
Class implementing the PVRShell functions.
******************************************************************************/
class OGLESBasicTnL : public PVRShell
{
// Texture handle
GLuint m_ui32Texture;
// Angle to rotate the triangle
float m_fAngle;
// Vertex Buffer Object (VBO) handle
GLuint m_ui32Vbo;
public:
virtual bool InitApplication();
virtual bool InitView();
virtual bool ReleaseView();
virtual bool QuitApplication();
virtual bool RenderScene();
};
/*!****************************************************************************
@Function InitApplication
@Return bool true if no error occured
@Description Code in InitApplication() will be called by PVRShell once per
run, before the rendering context is created.
Used to initialize variables that are not dependant on it
(e.g. external modules, loading meshes, etc.)
If the rendering context is lost, InitApplication() will
not be called again.
******************************************************************************/
bool OGLESBasicTnL::InitApplication()
{
m_fAngle = 0;
return true;
}
/*!****************************************************************************
@Function QuitApplication
@Return bool true if no error occured
@Description Code in QuitApplication() will be called by PVRShell once per
run, just before exiting the program.
If the rendering context is lost, QuitApplication() will
not be called.
******************************************************************************/
bool OGLESBasicTnL::QuitApplication()
{
return true;
}
/*!****************************************************************************
@Function InitView
@Return bool true if no error occured
@Description Code in InitView() will be called by PVRShell upon
initialization or after a change in the rendering context.
Used to initialize variables that are dependant on the rendering
context (e.g. textures, vertex buffers, etc.)
******************************************************************************/
bool OGLESBasicTnL::InitView()
{
// Sets the clear color
glClearColor(0.6f, 0.8f, 1.0f, 1.0f);
// Enables texturing
glEnable(GL_TEXTURE_2D);
/*
Creates the texture.
Please refer to the training course "Texturing" for a detailed explanation.
*/
glGenTextures(1, &m_ui32Texture);
glBindTexture(GL_TEXTURE_2D, m_ui32Texture);
GLuint* pTexData = new GLuint[g_i32TexSize*g_i32TexSize];
for(int i = 0; i < g_i32TexSize; ++i)
{
for(int j = 0; j < g_i32TexSize; ++j)
{
GLuint col = (255<<24) + ((255-j*2)<<16) + ((255-i)<<8) + (255-i*2);
if ( ((i*j)/8) % 2 )
col = 0xffff00ff;
pTexData[j*g_i32TexSize+i] = col;
}
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g_i32TexSize, g_i32TexSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTexData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
delete[] pTexData;
// Enables lighting and light 0
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
/*
Specifies the light direction.
If the 4th component is 0, it's a parallel light (the case here).
If the 4th component is not 0, it's a point light.
*/
float aLightPosition[] = {0.0f,0.0f,1.0f,0.0f};
/*
Assigns the light direction to the light number 0.
This function allows you to set also the ambiant, diffuse,
specular, emission colors of the light as well as attenuation parameters.
We keep the other parameters to their default value in this demo.
*/
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, aLightPosition);
// Create VBO for the triangle from our data
// Interleaved vertex data
float afVertices[] = { -0.4f,-0.4f,0.0f, // Position
0.0f,0.0f, // UV
0,0,1, // Normal
0.4f,-0.4f,0.0f,
1.0f,0.0f,
0,0,1,
0.0f,0.4f,0.0f,
0.5f,1.0f,
0,0,1};
glGenBuffers(1, &m_ui32Vbo);
unsigned int uiSize = 3 * (sizeof(float) * 8); // 3 vertices * stride (8 verttypes per vertex)
// Bind the VBO
glBindBuffer(GL_ARRAY_BUFFER, m_ui32Vbo);
// Set the buffer's data
glBufferData(GL_ARRAY_BUFFER, uiSize, afVertices, GL_STATIC_DRAW);
// Unbind the VBO
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
}
/*!****************************************************************************
@Function ReleaseView
@Return bool true if no error occured
@Description Code in ReleaseView() will be called by PVRShell when the
application quits or before a change in the rendering context.
******************************************************************************/
bool OGLESBasicTnL::ReleaseView()
{
// Frees the texture
glDeleteTextures(1, &m_ui32Texture);
return true;
}
/*!****************************************************************************
@Function RenderScene
@Return bool true if no error occured
@Description Main rendering loop function of the program. The shell will
call this function every frame.
eglSwapBuffers() will be performed by PVRShell automatically.
PVRShell will also manage important OS events.
Will also manage relevent OS events. The user has access to
these events through an abstraction layer provided by PVRShell.
******************************************************************************/
bool OGLESBasicTnL::RenderScene()
{
// Clears the color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Model view matrix
float aModelView[] =
{
(float)cos(m_fAngle), 0, (float)sin(m_fAngle), 0,
0, 1, 0, 0,
-(float)sin(m_fAngle), 0, (float)cos(m_fAngle), 0,
0, 0, 0, 1
};
// Sets the matrix mode to modify the Model View matrix
glMatrixMode(GL_MODELVIEW);
// Loads our matrix into OpenGL Model View matrix
glLoadMatrixf(aModelView);
// Increments the angle of the view
m_fAngle += .02f;
/*
Draw a triangle.
Please refer to the training course IntroducingPVRShell for a detailed explanation.
*/
// bind the VBO for the triangle
glBindBuffer(GL_ARRAY_BUFFER, m_ui32Vbo);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,sizeof(float) * 8, 0);
// Pass the texture coordinates data
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,sizeof(float) * 8, (unsigned char*) (sizeof(float) * 3));
// Pass the normals data
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT,sizeof(float) * 8, (unsigned char*) (sizeof(float) * 5));
// Draws a non-indexed triangle array
glDrawArrays(GL_TRIANGLES, 0, 3);
// unbind the vertex buffer as we don't need it bound anymore
glBindBuffer(GL_ARRAY_BUFFER, 0);
return true;
}
/*!****************************************************************************
@Function NewDemo
@Return PVRShell* The demo supplied by the user
@Description This function must be implemented by the user of the shell.
The user should return its PVRShell object defining the
behaviour of the application.
******************************************************************************/
PVRShell* NewDemo()
{
return new OGLESBasicTnL();
}
/******************************************************************************
End of file (OGLESBasicTnL.cpp)
******************************************************************************/
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