port from perforce
This commit is contained in:
44
demo09/demo09.sln
Normal file
44
demo09/demo09.sln
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "demo09", "src\demo09\demo09.vcxproj", "{AC19F6C1-CA28-4DCA-A36A-3D4E6CEA0281}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C9652FA7-B497-4B70-8CF0-EADE953D7C60} = {C9652FA7-B497-4B70-8CF0-EADE953D7C60}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libjpeg", "src\jpeglib\libjpeg.vcxproj", "{C9652FA7-B497-4B70-8CF0-EADE953D7C60}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{9B82203B-9845-482A-A0DA-C94127BE5D79} = {9B82203B-9845-482A-A0DA-C94127BE5D79}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "src\zlib\zlib.vcxproj", "{9B82203B-9845-482A-A0DA-C94127BE5D79}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "src\libpng\libpng.vcxproj", "{FFF693C4-DE84-4F03-A90C-1E8BF1072B4A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AC19F6C1-CA28-4DCA-A36A-3D4E6CEA0281}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{AC19F6C1-CA28-4DCA-A36A-3D4E6CEA0281}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{AC19F6C1-CA28-4DCA-A36A-3D4E6CEA0281}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{AC19F6C1-CA28-4DCA-A36A-3D4E6CEA0281}.Release|Win32.Build.0 = Release|Win32
|
||||
{C9652FA7-B497-4B70-8CF0-EADE953D7C60}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{C9652FA7-B497-4B70-8CF0-EADE953D7C60}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{C9652FA7-B497-4B70-8CF0-EADE953D7C60}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{C9652FA7-B497-4B70-8CF0-EADE953D7C60}.Release|Win32.Build.0 = Release|Win32
|
||||
{9B82203B-9845-482A-A0DA-C94127BE5D79}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9B82203B-9845-482A-A0DA-C94127BE5D79}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9B82203B-9845-482A-A0DA-C94127BE5D79}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9B82203B-9845-482A-A0DA-C94127BE5D79}.Release|Win32.Build.0 = Release|Win32
|
||||
{FFF693C4-DE84-4F03-A90C-1E8BF1072B4A}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{FFF693C4-DE84-4F03-A90C-1E8BF1072B4A}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{FFF693C4-DE84-4F03-A90C-1E8BF1072B4A}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{FFF693C4-DE84-4F03-A90C-1E8BF1072B4A}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
demo09/lib/Debug/libjpeg.lib
Normal file
BIN
demo09/lib/Debug/libjpeg.lib
Normal file
Binary file not shown.
BIN
demo09/lib/Debug/libjpeg.pdb
Normal file
BIN
demo09/lib/Debug/libjpeg.pdb
Normal file
Binary file not shown.
BIN
demo09/lib/Debug/libpng.lib
Normal file
BIN
demo09/lib/Debug/libpng.lib
Normal file
Binary file not shown.
BIN
demo09/lib/Debug/libpng.pdb
Normal file
BIN
demo09/lib/Debug/libpng.pdb
Normal file
Binary file not shown.
BIN
demo09/lib/Debug/zlib.lib
Normal file
BIN
demo09/lib/Debug/zlib.lib
Normal file
Binary file not shown.
BIN
demo09/lib/Debug/zlib.pdb
Normal file
BIN
demo09/lib/Debug/zlib.pdb
Normal file
Binary file not shown.
BIN
demo09/lib/Release/libjpeg.lib
Normal file
BIN
demo09/lib/Release/libjpeg.lib
Normal file
Binary file not shown.
BIN
demo09/lib/Release/libpng.lib
Normal file
BIN
demo09/lib/Release/libpng.lib
Normal file
Binary file not shown.
BIN
demo09/lib/Release/zlib.lib
Normal file
BIN
demo09/lib/Release/zlib.lib
Normal file
Binary file not shown.
162
demo09/src/demo09/AnimationManager/AnimationManager.cpp
Normal file
162
demo09/src/demo09/AnimationManager/AnimationManager.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
#include "stdafx.h"
|
||||
#include "ITimeline.h"
|
||||
#include "AnimationManager.h"
|
||||
|
||||
|
||||
AnimationManager::AnimationManager(IEngine* engine)
|
||||
: engine(engine)
|
||||
, previousDemoTime(0.0)
|
||||
, previousRealTime(0.0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AnimationManager::~AnimationManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddDemoTimeAnimation(double beginTime, double endTime, IAnimateable* value, unsigned int userData)
|
||||
{
|
||||
forwardSortedAnimations[AnimationInterval(beginTime, endTime)].push_back(std::make_pair(value, userData));
|
||||
backwardSortedAnimations[AnimationInterval(beginTime, endTime)].push_back(std::make_pair(value, userData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddRealTimeAnimation(double beginTime, double endTime, IAnimateable* value, unsigned int userData)
|
||||
{
|
||||
realTimeAnimations[AnimationInterval(beginTime, endTime)].push_back(std::make_pair(value, userData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddDemoTimeEvent(double time, IEvent* value, unsigned int userData)
|
||||
{
|
||||
demoTimeEvents[time].push_back(std::make_pair(value, userData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::AddRealTimeEvent(double time, IEvent* value, unsigned int userData)
|
||||
{
|
||||
realTimeEvents[time].push_back(std::make_pair(value, userData));
|
||||
}
|
||||
|
||||
|
||||
void AnimationManager::Animate()
|
||||
{
|
||||
ITimeline* timeline = engine->GetTimeline();
|
||||
double demoTime = timeline->GetDemoTime();
|
||||
double realTime = timeline->GetRealTime();
|
||||
|
||||
// Gather all active animations, they are the ones that started before now and end after now.
|
||||
// Do this for both the demo time and real time.
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> > activeAnimations;
|
||||
std::vector<double> animationTimes;
|
||||
|
||||
// Demo time animations: Demo time can go backwards, so search from both directions
|
||||
if (timeline->GetSpeedAndDirection() > 0)
|
||||
{
|
||||
forwardAnims::iterator iter = forwardSortedAnimations.begin();
|
||||
for (; iter != forwardSortedAnimations.end(); ++iter)
|
||||
{
|
||||
if (iter->first.begin <= demoTime && iter->first.end >= demoTime)
|
||||
{
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator animIter = iter->second.begin();
|
||||
for (; animIter != iter->second.end(); ++animIter)
|
||||
{
|
||||
activeAnimations.push_back(*animIter);
|
||||
animationTimes.push_back((demoTime - iter->first.begin) / (iter->first.end - iter->first.begin));
|
||||
}
|
||||
}
|
||||
|
||||
if (iter->first.begin > demoTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (timeline->GetSpeedAndDirection() < 0)
|
||||
{
|
||||
backwardAnims::iterator iter = backwardSortedAnimations.begin();
|
||||
for (; iter != backwardSortedAnimations.end(); ++iter)
|
||||
{
|
||||
if (iter->first.end >= demoTime && iter->first.begin <= demoTime)
|
||||
{
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator animIter = iter->second.begin();
|
||||
for (; animIter != iter->second.end(); ++animIter)
|
||||
{
|
||||
activeAnimations.push_back(*animIter);
|
||||
animationTimes.push_back((demoTime - iter->first.begin) / (iter->first.end - iter->first.begin));
|
||||
}
|
||||
}
|
||||
|
||||
if (iter->first.end < demoTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Real time animations: The time that we know doesn't allow us to travel to the past, so just check into the future:
|
||||
{
|
||||
forwardAnims::iterator iter = realTimeAnimations.begin();
|
||||
for (; iter != realTimeAnimations.end(); ++iter)
|
||||
{
|
||||
if (iter->first.begin <= realTime && iter->first.end >= realTime)
|
||||
{
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator animIter = iter->second.begin();
|
||||
for (; animIter != iter->second.end(); ++animIter)
|
||||
{
|
||||
activeAnimations.push_back(*animIter);
|
||||
animationTimes.push_back((realTime - iter->first.end) / (iter->first.begin - iter->first.end));
|
||||
}
|
||||
}
|
||||
|
||||
if (iter->first.begin > realTime)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we know what animations correspond to this time, animate them!
|
||||
std::vector<std::pair<IAnimateable*, unsigned int> >::iterator animIter = activeAnimations.begin();
|
||||
std::vector<double>::iterator timeIter = animationTimes.begin();
|
||||
for (; animIter != activeAnimations.end(); ++animIter, ++timeIter)
|
||||
{
|
||||
IAnimateable* animateable = animIter->first;
|
||||
animateable->OnAnimate(*timeIter, animIter->second);
|
||||
}
|
||||
|
||||
// Fire all events that happened since last time:
|
||||
events::iterator eventIter = demoTimeEvents.begin();
|
||||
for (; eventIter != demoTimeEvents.end(); ++eventIter)
|
||||
{
|
||||
double time = eventIter->first;
|
||||
|
||||
std::vector<std::pair<IEvent*, unsigned int> >::iterator eventVecIter = eventIter->second.begin();
|
||||
for (; eventVecIter != eventIter->second.end(); ++eventVecIter)
|
||||
{
|
||||
IEvent* event = eventVecIter->first;
|
||||
unsigned int userData = eventVecIter->second;
|
||||
if (((timeline->GetSpeedAndDirection() > 0) && (time >= previousDemoTime && time <= demoTime)) ||
|
||||
((timeline->GetSpeedAndDirection() < 0) && (time <= previousDemoTime && time >= demoTime)))
|
||||
{
|
||||
event->OnEvent(userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eventIter = realTimeEvents.begin();
|
||||
for (; eventIter != realTimeEvents.end(); ++eventIter)
|
||||
{
|
||||
double time = eventIter->first;
|
||||
|
||||
std::vector<std::pair<IEvent*, unsigned int> >::iterator eventVecIter = eventIter->second.begin();
|
||||
for (; eventVecIter != eventIter->second.end(); ++eventVecIter)
|
||||
{
|
||||
IEvent* event = eventVecIter->first;
|
||||
unsigned int userData = eventVecIter->second;
|
||||
if (time >= previousRealTime && time <= realTime)
|
||||
{
|
||||
event->OnEvent(userData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousDemoTime = demoTime;
|
||||
previousRealTime = realTime;
|
||||
}
|
||||
63
demo09/src/demo09/AnimationManager/AnimationManager.h
Normal file
63
demo09/src/demo09/AnimationManager/AnimationManager.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "IAnimationManager.h"
|
||||
|
||||
|
||||
class AnimationManager
|
||||
: public IAnimationManager
|
||||
{
|
||||
public:
|
||||
AnimationManager(IEngine* engine);
|
||||
virtual ~AnimationManager();
|
||||
|
||||
virtual void AddDemoTimeAnimation(double beginTime, double endTime, IAnimateable* value, unsigned int userData = 0);
|
||||
virtual void AddRealTimeAnimation(double beginTime, double endTime, IAnimateable* value, unsigned int userData = 0);
|
||||
|
||||
virtual void AddDemoTimeEvent(double time, IEvent* value, unsigned int userData = 0);
|
||||
virtual void AddRealTimeEvent(double time, IEvent* value, unsigned int userData = 0);
|
||||
|
||||
virtual void Animate();
|
||||
|
||||
private:
|
||||
struct AnimationInterval
|
||||
{
|
||||
AnimationInterval(double begin, double end)
|
||||
: begin(begin)
|
||||
, end(end)
|
||||
{
|
||||
};
|
||||
|
||||
double begin;
|
||||
double end;
|
||||
};
|
||||
|
||||
struct ForwardSort
|
||||
{
|
||||
bool operator ()(const AnimationInterval& a, const AnimationInterval& b) const
|
||||
{
|
||||
return a.begin < b.begin;
|
||||
}
|
||||
};
|
||||
|
||||
struct BackwardSort
|
||||
{
|
||||
bool operator ()(const AnimationInterval& a, const AnimationInterval& b) const
|
||||
{
|
||||
return a.end > b.end;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<AnimationInterval, std::vector<std::pair<IAnimateable*, unsigned int> >, ForwardSort> forwardAnims;
|
||||
typedef std::map<AnimationInterval, std::vector<std::pair<IAnimateable*, unsigned int> >, BackwardSort> backwardAnims;
|
||||
typedef std::map<double, std::vector<std::pair<IEvent*, unsigned int> > > events;
|
||||
|
||||
IEngine* engine;
|
||||
forwardAnims forwardSortedAnimations;
|
||||
backwardAnims backwardSortedAnimations;
|
||||
forwardAnims realTimeAnimations;
|
||||
events demoTimeEvents;
|
||||
events realTimeEvents;
|
||||
|
||||
double previousDemoTime;
|
||||
double previousRealTime;
|
||||
};
|
||||
99
demo09/src/demo09/ConsoleColor.h
Normal file
99
demo09/src/demo09/ConsoleColor.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
inline std::ostream& blue(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE
|
||||
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& red(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& green(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& yellow(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::ostream& white(std::ostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
|
||||
return s;
|
||||
}
|
||||
|
||||
struct color {
|
||||
color(WORD attribute):m_color(attribute){};
|
||||
WORD m_color;
|
||||
};
|
||||
|
||||
template <class elem, class traits>
|
||||
std::basic_ostream<elem,traits>&
|
||||
operator<<(std::basic_ostream<elem,traits>& i, color& c)
|
||||
{
|
||||
HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,c.m_color);
|
||||
return i;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
inline std::wostream& blue(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE
|
||||
|FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& red(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& green(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& yellow(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::wostream& white(std::wostream &s)
|
||||
{
|
||||
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hStdout,
|
||||
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
|
||||
return s;
|
||||
}
|
||||
33
demo09/src/demo09/Demo/AfterWorld/AfterWorld.cpp
Normal file
33
demo09/src/demo09/Demo/AfterWorld/AfterWorld.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "StdAfx.h"
|
||||
#include "AfterWorld.h"
|
||||
#include "Quad.h"
|
||||
|
||||
|
||||
AfterWorld::AfterWorld(IEngine* engine)
|
||||
: World(engine, "AfterWorld")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AfterWorld::~AfterWorld(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AfterWorld::Initialize()
|
||||
{
|
||||
BluFlame = new BluFlameLogo(engine);
|
||||
this->AddRenderable(BluFlame->GetRenderable());
|
||||
BluFlame->material->FindRelevantSubMaterial(this)->ShaderProgram->SetParam("alpha", 0.0f);
|
||||
}
|
||||
|
||||
|
||||
void AfterWorld::Render(WorldRenderStage::Enumeration)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AfterWorld::Clear()
|
||||
{
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
31
demo09/src/demo09/Demo/AfterWorld/AfterWorld.h
Normal file
31
demo09/src/demo09/Demo/AfterWorld/AfterWorld.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "../World/World.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "ICamera.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IRenderer.h"
|
||||
#include "ILight.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderable.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderTarget.h"
|
||||
#include "Quad.h"
|
||||
#include "BluFlameLogo.h"
|
||||
#include "DistortedQuad.h"
|
||||
|
||||
|
||||
class AfterWorld
|
||||
: public World
|
||||
{
|
||||
public:
|
||||
AfterWorld(IEngine* engine);
|
||||
virtual ~AfterWorld(void);
|
||||
|
||||
virtual void Render(WorldRenderStage::Enumeration stage);
|
||||
virtual void Initialize();
|
||||
virtual void Clear();
|
||||
BluFlameLogo* BluFlame;
|
||||
};
|
||||
53
demo09/src/demo09/Demo/AfterWorld/BluFlameLogo.h
Normal file
53
demo09/src/demo09/Demo/AfterWorld/BluFlameLogo.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
class BluFlameLogo
|
||||
{
|
||||
public:
|
||||
BluFlameLogo(IEngine* engine)
|
||||
{
|
||||
material = engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("BluFlame.mat"), _T("BluFlame.mat"));
|
||||
screenQuad = engine->GetResourceFactory()->CreateMeshBuffer();
|
||||
screenQuad->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
screenQuad->SetMaterial(material);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
screenQuad->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
screenQuad->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
}
|
||||
|
||||
virtual ~BluFlameLogo()
|
||||
{
|
||||
}
|
||||
|
||||
IRenderable* GetRenderable()
|
||||
{
|
||||
return dynamic_cast<IRenderable*>(screenQuad);
|
||||
}
|
||||
|
||||
IMaterial* material;
|
||||
|
||||
private:
|
||||
IMeshBuffer* screenQuad;
|
||||
};
|
||||
70
demo09/src/demo09/Demo/AfterWorld/DistortedQuad.h
Normal file
70
demo09/src/demo09/Demo/AfterWorld/DistortedQuad.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Resources/MeshBuffer/MeshBuffer.h"
|
||||
|
||||
|
||||
class DistortedQuad
|
||||
: public MeshBuffer
|
||||
{
|
||||
public:
|
||||
DistortedQuad(IEngine* engine, ITexture* texture)
|
||||
: MeshBuffer(engine)
|
||||
, texture(texture)
|
||||
{
|
||||
TCHAR matName[13];
|
||||
_stprintf_s(matName, 13, _T("Quad%x"), texture);
|
||||
material = engine->GetResourceFactory()->TryGetOrCreateMaterial(matName, _T("Common/DistortedQuad.mat"));
|
||||
material->GetSubMaterials()[0]->Textures[0] = texture;
|
||||
this->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
this->SetMaterial(material);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
this->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
this->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
}
|
||||
|
||||
virtual ~DistortedQuad()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage == RenderStage::BeforeRender)
|
||||
{
|
||||
material->GetSubMaterials()[0]->ShaderProgram->SetParam("texAspectRatio", float(texture->GetWidth()) / texture->GetHeight());
|
||||
}
|
||||
|
||||
MeshBuffer::RenderInternal(stage);
|
||||
}
|
||||
|
||||
virtual void RenderInternal(SubMaterial* subMaterial)
|
||||
{
|
||||
MeshBuffer::RenderInternal(subMaterial);
|
||||
}
|
||||
|
||||
private:
|
||||
IMaterial* material;
|
||||
ITexture* texture;
|
||||
};
|
||||
55
demo09/src/demo09/Demo/AfterWorld/Quad.h
Normal file
55
demo09/src/demo09/Demo/AfterWorld/Quad.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
class SAQuad
|
||||
{
|
||||
public:
|
||||
SAQuad(IEngine* engine, ITexture* texture)
|
||||
{
|
||||
TCHAR matName[19];
|
||||
_stprintf_s(matName, 19, _T("NormalQuad%x"), texture);
|
||||
material = engine->GetResourceFactory()->TryGetOrCreateMaterial(matName, _T("Common/ScreenAlignedQuad.mat"));
|
||||
material->GetSubMaterials()[0]->Textures[0] = texture;
|
||||
screenQuad = engine->GetResourceFactory()->CreateMeshBuffer();
|
||||
screenQuad->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
screenQuad->SetMaterial(material);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
screenQuad->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
screenQuad->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
}
|
||||
|
||||
virtual ~SAQuad()
|
||||
{
|
||||
}
|
||||
|
||||
IRenderable* GetRenderable()
|
||||
{
|
||||
return dynamic_cast<IRenderable*>(screenQuad);
|
||||
}
|
||||
|
||||
private:
|
||||
IMeshBuffer* screenQuad;
|
||||
IMaterial* material;
|
||||
};
|
||||
BIN
demo09/src/demo09/Demo/Demo.cpp
Normal file
BIN
demo09/src/demo09/Demo/Demo.cpp
Normal file
Binary file not shown.
352
demo09/src/demo09/Demo/Demo.h
Normal file
352
demo09/src/demo09/Demo/Demo.h
Normal file
@@ -0,0 +1,352 @@
|
||||
#pragma once
|
||||
|
||||
#include "IWorld.h"
|
||||
#include "ICamera.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IAnimationManager.h"
|
||||
#include "IResourceFactory.h"
|
||||
|
||||
#include "DriftWorld/DriftWorld.h"
|
||||
#include "AfterWorld/AfterWorld.h"
|
||||
#include "AfterWorld/DistortedQuad.h"
|
||||
#include "../Resources/Renderable/Renderable.h"
|
||||
#include "PlasmaWorld/PlasmaWorld.h"
|
||||
|
||||
|
||||
class TextEvent;
|
||||
|
||||
|
||||
class Demo
|
||||
: public IEvent
|
||||
, public IAnimateable
|
||||
{
|
||||
public:
|
||||
Demo(IEngine* engine);
|
||||
virtual ~Demo();
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void OnEvent(unsigned int data);
|
||||
virtual void OnAnimate(double position, unsigned int data);
|
||||
virtual void Process();
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
|
||||
std::vector<TextEvent*> events;
|
||||
PlasmaWorld* plasmaWorld;
|
||||
AfterWorld* afterWorld;
|
||||
IWorld* defaultWorld;
|
||||
IWorld* depthNear;
|
||||
IWorld* depthFar;
|
||||
IWorld* hdrToLdr;
|
||||
IWorld* clouds;
|
||||
IWorld* drift;
|
||||
};
|
||||
|
||||
|
||||
__declspec(align(16)) class CameraAttachedRenderable
|
||||
: public Renderable
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
CameraAttachedRenderable(IEngine* engine, const Vector& position)
|
||||
: Renderable(engine)
|
||||
, position(position)
|
||||
{
|
||||
|
||||
}
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage == RenderStage::BeforeRender)
|
||||
{
|
||||
ICamera* cam = this->GetWorld()->GetCamera();
|
||||
|
||||
Vector camPos = cam->GetPosition();
|
||||
Vector camDir = cam->GetDirection();
|
||||
Vector camRight = cam->GetRight();
|
||||
camDir.normalize();
|
||||
|
||||
Matrix viewMatrix = cam->GetViewMatrix();
|
||||
Matrix viewMatrixI = viewMatrix;
|
||||
viewMatrixI.m[3] = 0;
|
||||
viewMatrixI.m[7] = 0;
|
||||
viewMatrixI.m[11] = 0;
|
||||
viewMatrixI.inverse();
|
||||
|
||||
viewMatrix.m[0] = viewMatrix.m[5] = viewMatrix.m[10] = 1;
|
||||
viewMatrix.m[1] = viewMatrix.m[2] = viewMatrix.m[4] = viewMatrix.m[6] = viewMatrix.m[8] = viewMatrix.m[9] = 0;
|
||||
|
||||
Matrix transform = viewMatrix * viewMatrixI;
|
||||
this->SetAdditionalTransformation(transform);
|
||||
|
||||
IRenderable* textRenderable = this->GetRenderables()[0];
|
||||
this->SetTranslation(camPos + camDir * position.m[2]);
|
||||
|
||||
Matrix mTransform = Matrix(
|
||||
Vector(1, 0, 0, position.m[0]),
|
||||
Vector(0, 1, 0, position.m[1]),
|
||||
Vector(0, 0, 1, 0),
|
||||
Vector(0, 0, 0, 1)
|
||||
);
|
||||
mTransform.transpose();
|
||||
textRenderable->SetAdditionalTransformation(mTransform);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Vector position;
|
||||
float distance;
|
||||
};
|
||||
|
||||
|
||||
struct EnterEffects
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Appear,
|
||||
Fadein,
|
||||
Flyin,
|
||||
Distort
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ExitEffects
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Disappear,
|
||||
Fadeout,
|
||||
Flyout,
|
||||
Dissolve,
|
||||
Distort
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct EffectParams
|
||||
{
|
||||
EffectParams()
|
||||
: enterEffect(EnterEffects::Appear)
|
||||
, enterEffectDuration(0.1f)
|
||||
, exitEffect(ExitEffects::Disappear)
|
||||
, exitEffectDuration(0.1f)
|
||||
{
|
||||
}
|
||||
|
||||
EnterEffects::Enumeration enterEffect;
|
||||
float enterEffectDuration;
|
||||
ExitEffects::Enumeration exitEffect;
|
||||
float exitEffectDuration;
|
||||
};
|
||||
|
||||
|
||||
class TextEvent
|
||||
: public IEvent
|
||||
, public IAnimateable
|
||||
{
|
||||
public:
|
||||
static const int ENTER_EFFECT_START = 1;
|
||||
static const int ENTER_EFFECT_END = 2;
|
||||
static const int EXIT_EFFECT_START = 3;
|
||||
static const int EXIT_EFFECT_END = 4;
|
||||
static int COUNT;
|
||||
|
||||
TextEvent(IWorld* defaultWorld, IWorld* driftWorld, IEngine* engine, const std::wstring& font, const std::string& sText, double displayTime, double displayDuration, const Vector& position, EffectParams effectParams)
|
||||
: driftWorld(driftWorld)
|
||||
, defaultWorld(defaultWorld)
|
||||
, engine(engine)
|
||||
, displayTime(displayTime)
|
||||
, displayDuration(displayDuration)
|
||||
, effectParams(effectParams)
|
||||
, text(NULL)
|
||||
, textRenderable(NULL)
|
||||
{
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
|
||||
if (sText.empty())
|
||||
{
|
||||
textRenderable = new DistortedQuad(engine, engine->GetResourceFactory()->TryGetOrCreateTexture(font.c_str(), font.c_str()));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring materialName = _T("Common/TextLight.mat");
|
||||
materialName += (wchar_t)((int)_T('0') + COUNT);
|
||||
COUNT++;
|
||||
IText* text = factory->CreateText(sText, font, 200, 0.2f);
|
||||
this->text = dynamic_cast<IRenderable*>(text);
|
||||
text->SetMaterial(
|
||||
engine->GetResourceFactory()->TryGetOrCreateMaterial(materialName.c_str(), _T("Common/TextLight.mat"))
|
||||
);
|
||||
|
||||
textRenderable = new CameraAttachedRenderable(engine, position);
|
||||
textRenderable->AddRenderable(this->text);
|
||||
}
|
||||
|
||||
IAnimationManager* animManager = engine->GetAnimationManager();
|
||||
animManager->AddDemoTimeEvent(displayTime, this, ENTER_EFFECT_START);
|
||||
if (effectParams.enterEffectDuration != 0)
|
||||
{
|
||||
animManager->AddDemoTimeEvent(displayTime + effectParams.enterEffectDuration, this, ENTER_EFFECT_END);
|
||||
animManager->AddDemoTimeAnimation(displayTime, displayTime + effectParams.enterEffectDuration, this, ENTER_EFFECT_START);
|
||||
}
|
||||
if (effectParams.exitEffectDuration != 0)
|
||||
{
|
||||
animManager->AddDemoTimeEvent(displayTime + displayDuration - effectParams.exitEffectDuration, this, EXIT_EFFECT_START);
|
||||
animManager->AddDemoTimeAnimation(displayTime + displayDuration - effectParams.exitEffectDuration, displayTime + displayDuration, this, EXIT_EFFECT_START);
|
||||
}
|
||||
animManager->AddDemoTimeEvent(displayTime + displayDuration, this, EXIT_EFFECT_END);
|
||||
}
|
||||
|
||||
virtual ~TextEvent()
|
||||
{
|
||||
if (textRenderable != NULL)
|
||||
delete textRenderable;
|
||||
}
|
||||
|
||||
virtual void OnAnimate(double position, unsigned int userData)
|
||||
{
|
||||
if (userData == ENTER_EFFECT_START)
|
||||
{
|
||||
switch (effectParams.enterEffect)
|
||||
{
|
||||
case EnterEffects::Appear:
|
||||
break;
|
||||
case EnterEffects::Fadein:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("alpha", (float)position);
|
||||
break;
|
||||
case EnterEffects::Flyin:
|
||||
break;
|
||||
case EnterEffects::Distort:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("animPos", (float)position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (userData == EXIT_EFFECT_START)
|
||||
{
|
||||
switch (effectParams.exitEffect)
|
||||
{
|
||||
case ExitEffects::Disappear:
|
||||
break;
|
||||
case ExitEffects::Dissolve:
|
||||
break;
|
||||
case ExitEffects::Fadeout:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("alpha", 1.0f - (float)position);
|
||||
break;
|
||||
case ExitEffects::Flyout:
|
||||
break;
|
||||
case ExitEffects::Distort:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("animPos", 1.0f - (float)position);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnEvent(unsigned int userData)
|
||||
{
|
||||
if (userData == ENTER_EFFECT_START)
|
||||
{
|
||||
switch (effectParams.enterEffect)
|
||||
{
|
||||
case EnterEffects::Appear:
|
||||
defaultWorld->AddRenderable(textRenderable);
|
||||
break;
|
||||
case EnterEffects::Fadein:
|
||||
defaultWorld->AddRenderable(textRenderable);
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("animPos", 1.0f);
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("alpha", 0.0f);
|
||||
break;
|
||||
case EnterEffects::Flyin:
|
||||
defaultWorld->AddRenderable(textRenderable);
|
||||
break;
|
||||
case EnterEffects::Distort:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("animPos", 0.0f);
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("alpha", 1.0f);
|
||||
defaultWorld->AddRenderable(textRenderable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (userData == ENTER_EFFECT_END)
|
||||
{
|
||||
switch (effectParams.enterEffect)
|
||||
{
|
||||
case EnterEffects::Appear:
|
||||
break;
|
||||
case EnterEffects::Fadein:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("alpha", 1.0f);
|
||||
break;
|
||||
case EnterEffects::Flyin:
|
||||
break;
|
||||
case EnterEffects::Distort:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("animPos", 1.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (userData == EXIT_EFFECT_START)
|
||||
{
|
||||
switch (effectParams.exitEffect)
|
||||
{
|
||||
case ExitEffects::Disappear:
|
||||
break;
|
||||
case ExitEffects::Dissolve:
|
||||
defaultWorld->RemoveRenderable(textRenderable);
|
||||
driftWorld->AddRenderable(textRenderable);
|
||||
break;
|
||||
case ExitEffects::Fadeout:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("alpha", 1.0f);
|
||||
break;
|
||||
case ExitEffects::Flyout:
|
||||
GetMaterial()->FindRelevantSubMaterial(defaultWorld)->ShaderProgram->SetParam("animPos", 1.0f);
|
||||
break;
|
||||
case ExitEffects::Distort:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (userData == EXIT_EFFECT_END)
|
||||
{
|
||||
switch (effectParams.exitEffect)
|
||||
{
|
||||
case ExitEffects::Disappear:
|
||||
defaultWorld->RemoveRenderable(textRenderable);
|
||||
break;
|
||||
case ExitEffects::Dissolve:
|
||||
driftWorld->RemoveRenderable(textRenderable);
|
||||
break;
|
||||
case ExitEffects::Fadeout:
|
||||
defaultWorld->RemoveRenderable(textRenderable);
|
||||
break;
|
||||
case ExitEffects::Flyout:
|
||||
defaultWorld->RemoveRenderable(textRenderable);
|
||||
break;
|
||||
case ExitEffects::Distort:
|
||||
defaultWorld->RemoveRenderable(textRenderable);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IMaterial* GetMaterial()
|
||||
{
|
||||
if (dynamic_cast<IText*>(text) != 0)
|
||||
{
|
||||
return dynamic_cast<IText*>(text)->GetMaterial();
|
||||
}
|
||||
else if (dynamic_cast<IMeshBuffer*>(textRenderable) != 0)
|
||||
{
|
||||
return dynamic_cast<IMeshBuffer*>(textRenderable)->GetMaterial();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
private:
|
||||
IWorld* driftWorld;
|
||||
IWorld* defaultWorld;
|
||||
IRenderable* textRenderable;
|
||||
IRenderable* text;
|
||||
|
||||
IEngine* engine;
|
||||
|
||||
double displayTime;
|
||||
double displayDuration;
|
||||
EffectParams effectParams;
|
||||
};
|
||||
178
demo09/src/demo09/Demo/DriftWorld/DriftWorld.cpp
Normal file
178
demo09/src/demo09/Demo/DriftWorld/DriftWorld.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
#include "stdafx.h"
|
||||
#include "DriftWorld.h"
|
||||
#include "../HdrToLdrWorld/DeltaTimeShaderCallback.h"
|
||||
|
||||
#include "IResourceFactory.h"
|
||||
#include "IRenderer.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderable.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ICamera.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderTarget.h"
|
||||
|
||||
|
||||
DriftWorld::DriftWorld(IEngine* engine)
|
||||
: World(engine, "Drift")
|
||||
, screenQuad(NULL)
|
||||
, renderedOnce(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
DriftWorld::~DriftWorld()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void DriftWorld::Initialize()
|
||||
{
|
||||
if (this->GetRenderTarget() == NULL)
|
||||
throw _T("DriftWorld: Unable to work without a rendertarget.");
|
||||
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
IShaderCallback* callback = new DeltaTimeShaderCallback(engine);
|
||||
if (!factory->RegisterShaderCallback(callback))
|
||||
delete callback;
|
||||
|
||||
if (this->GetCamera() == NULL)
|
||||
{
|
||||
ICamera* camera = factory->CreateCamera();
|
||||
this->SetCamera(camera);
|
||||
}
|
||||
|
||||
showMaterial = factory->TryGetOrCreateMaterial(_T("Drift/ShowDrift.mat"), _T("Drift/ShowDrift.mat"));
|
||||
processMaterial = factory->TryGetOrCreateMaterial(_T("Drift/ProcessDrift.mat"), _T("Drift/ProcessDrift.mat"));
|
||||
|
||||
{
|
||||
screenQuad = factory->CreateMeshBuffer();
|
||||
screenQuad->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
screenQuad->SetMaterial(processMaterial);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
screenQuad->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
screenQuad->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
}
|
||||
|
||||
IRenderTarget* rt = this->GetRenderTarget();
|
||||
ITexture* rtTex = rt->GetTextures()[0];
|
||||
unsigned int width = rt->GetWidth();
|
||||
unsigned int height = rt->GetHeight();
|
||||
TextureFormat::Enumeration format = rtTex->GetFormat();
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
RenderBuffer renderTarget;
|
||||
renderTarget.renderTarget = factory->CreateRenderTarget(width, height);
|
||||
renderTarget.texture = renderTarget.renderTarget->AddRenderTargetTexture(format);
|
||||
processRenderTargets.push_back(renderTarget);
|
||||
}
|
||||
|
||||
processSubMaterial = processMaterial->FindRelevantSubMaterial(this);
|
||||
|
||||
showSubMaterial = showMaterial->FindRelevantSubMaterial(this);
|
||||
showSubMaterial->Textures[0].Texture = rtTex;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
/*IText* text = factory->CreateText("Hallo Welt", L"Times New Roman", 200, 0.2f);
|
||||
text->GetMaterial(
|
||||
engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("Common/Plain.mat"), _T("Common/Plain.mat"))
|
||||
);
|
||||
IRenderable* textRen = dynamic_cast<IRenderable*>(text);
|
||||
textRen->GetTranslation(Vector(2.0f, 0.0f, 0.0f));
|
||||
textRen->GetScale(Vector(-1.0f, 1.0f, 1.0f));
|
||||
this->AddRenderable(textRen);
|
||||
|
||||
text = factory->CreateText("Und huhu Frank :D", L"Times New Roman", 200, 0.2f);
|
||||
text->GetMaterial(
|
||||
engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("Common/Plain.mat"), _T("Common/Plain.mat"))
|
||||
);
|
||||
textRen = dynamic_cast<IRenderable*>(text);
|
||||
textRen->GetTranslation(Vector(3.0f, -1.0f, 0.0f));
|
||||
textRen->GetScale(Vector(-1.0f, 1.0f, 1.0f));
|
||||
this->AddRenderable(textRen);*/
|
||||
}
|
||||
|
||||
|
||||
void DriftWorld::Render(WorldRenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage == WorldRenderStage::PostUnbind)
|
||||
{
|
||||
// Disable the color buffer clearing so our feedback effect may take action
|
||||
if (!renderedOnce)
|
||||
{
|
||||
this->SetRenderTargetBindFlags((BindFlags::Enumeration)(BindFlags::BindAllTextures | BindFlags::ClearDepth));
|
||||
renderedOnce = true;
|
||||
}
|
||||
|
||||
this->ProcessData(2);
|
||||
|
||||
std::vector<IRenderable*>& renderables = this->GetRenderables();
|
||||
for (unsigned int i = 0; i < renderables.size(); ++i)
|
||||
renderables[i]->SetVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DriftWorld::ProcessData(int passes)
|
||||
{
|
||||
IRenderTarget* rt = this->GetRenderTarget();
|
||||
ITexture* rtTex = rt->GetTextures()[0];
|
||||
|
||||
IRenderable* quad = dynamic_cast<IRenderable*>(screenQuad);
|
||||
screenQuad->SetMaterial(processMaterial);
|
||||
|
||||
// O - Original
|
||||
// A, B - Ping pong buffers
|
||||
// O -> B -> A -> B -> O (for i < 4)
|
||||
for (unsigned int i = 0; i < (unsigned int)passes; ++i) // use an even number here
|
||||
{
|
||||
unsigned int destinationIndex = i % 2; // index of the source giver
|
||||
unsigned int sourceIndex = destinationIndex == 0 ? 1U : 0U; // Index of the render to target
|
||||
|
||||
if (i == 0) // Start
|
||||
processSubMaterial->Textures[0].Texture = rtTex;
|
||||
else
|
||||
processSubMaterial->Textures[0].Texture = processRenderTargets[sourceIndex].texture;
|
||||
|
||||
if (i + 1 == (unsigned int)passes) // Final reached
|
||||
rt->Bind(BindFlags::BindAllTextures);
|
||||
else
|
||||
processRenderTargets[destinationIndex].renderTarget->Bind(BindFlags::BindAllTextures);
|
||||
|
||||
quad->Render();
|
||||
|
||||
if (i + 1 == (unsigned int)passes)
|
||||
rt->Unbind();
|
||||
else
|
||||
processRenderTargets[destinationIndex].renderTarget->Unbind();
|
||||
}
|
||||
|
||||
|
||||
// Render screen quad to display crazy stuff, wheeeee
|
||||
screenQuad->SetMaterial(showMaterial);
|
||||
quad->Render();
|
||||
}
|
||||
38
demo09/src/demo09/Demo/DriftWorld/DriftWorld.h
Normal file
38
demo09/src/demo09/Demo/DriftWorld/DriftWorld.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "../World/World.h"
|
||||
#include "IAnimationManager.h"
|
||||
#include "IMaterial.h"
|
||||
|
||||
|
||||
class DriftWorld
|
||||
: public World
|
||||
{
|
||||
public:
|
||||
DriftWorld(IEngine* engine);
|
||||
virtual ~DriftWorld();
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Render(WorldRenderStage::Enumeration stage);
|
||||
|
||||
private:
|
||||
|
||||
struct RenderBuffer
|
||||
{
|
||||
ITexture* texture;
|
||||
IRenderTarget* renderTarget;
|
||||
};
|
||||
|
||||
void ProcessData(int passes);
|
||||
|
||||
IMeshBuffer* screenQuad;
|
||||
|
||||
IMaterial* processMaterial;
|
||||
SubMaterial* processSubMaterial;
|
||||
std::vector<RenderBuffer> processRenderTargets;
|
||||
|
||||
IMaterial* showMaterial;
|
||||
SubMaterial* showSubMaterial;
|
||||
|
||||
bool renderedOnce;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "stdafx.h"
|
||||
#include "ITimeline.h"
|
||||
#include "DeltaTimeShaderCallback.h"
|
||||
|
||||
|
||||
DeltaTimeShaderCallback::DeltaTimeShaderCallback(IEngine* engine)
|
||||
: engine(engine)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DeltaTimeShaderCallback::OnShaderProgramActivate(IShaderProgram& program, void*)
|
||||
{
|
||||
double deltaTime = engine->GetTimeline()->GetDeltaTime();
|
||||
program.SetParam("deltatime", (float)deltaTime);
|
||||
}
|
||||
|
||||
|
||||
bool DeltaTimeShaderCallback::IsFunctionalWithShaderProgram(IShaderProgram& program)
|
||||
{
|
||||
return program.GetUniformHandle("deltatime") != (unsigned int)-1;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "IShader.h"
|
||||
|
||||
|
||||
class DeltaTimeShaderCallback
|
||||
: public IShaderCallback
|
||||
{
|
||||
public:
|
||||
DeltaTimeShaderCallback(IEngine* engine);
|
||||
virtual ~DeltaTimeShaderCallback() {};
|
||||
|
||||
virtual std::wstring GetName() const { return _T("deltatime"); }
|
||||
|
||||
virtual void OnShaderProgramActivate(IShaderProgram& program, void* additionalData);
|
||||
virtual bool IsFunctionalWithShaderProgram(IShaderProgram& program);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
};
|
||||
177
demo09/src/demo09/Demo/HdrToLdrWorld/HdrToLdrWorld.cpp
Normal file
177
demo09/src/demo09/Demo/HdrToLdrWorld/HdrToLdrWorld.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
#include "stdafx.h"
|
||||
#include "HdrToLdrWorld.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IRenderer.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderable.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ICamera.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderTarget.h"
|
||||
|
||||
#include "DeltaTimeShaderCallback.h"
|
||||
|
||||
|
||||
HdrToLdrWorld::HdrToLdrWorld(IEngine* engine, ITexture* hdrTexture)
|
||||
: World(engine, "Hdr")
|
||||
, hdrTexture(hdrTexture)
|
||||
, screenQuad(NULL)
|
||||
, exposure(1.0f)
|
||||
, glowStrength(0.25f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
HdrToLdrWorld::~HdrToLdrWorld()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void HdrToLdrWorld::Initialize()
|
||||
{
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
IShaderCallback* callback = new DeltaTimeShaderCallback(engine);
|
||||
if (!factory->RegisterShaderCallback(callback))
|
||||
delete callback;
|
||||
|
||||
ICamera* camera = factory->CreateCamera();
|
||||
this->SetCamera(camera);
|
||||
|
||||
hdrToLdrMaterial = factory->TryGetOrCreateMaterial(_T("Hdr/HdrToLdr.mat"), _T("Hdr/HdrToLdr.mat"));
|
||||
hdrToLdrSubMaterial = hdrToLdrMaterial->FindRelevantSubMaterial(this);
|
||||
hdrToLdrSubMaterial->Textures[0].Texture = hdrTexture;
|
||||
hdrToLdrSubMaterial->ShaderProgram->SetParam("Exposure", exposure);
|
||||
|
||||
{
|
||||
screenQuad = factory->CreateMeshBuffer();
|
||||
screenQuad->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
screenQuad->SetMaterial(hdrToLdrMaterial);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
screenQuad->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
screenQuad->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
|
||||
this->AddRenderable(dynamic_cast<IRenderable*>(screenQuad));
|
||||
}
|
||||
|
||||
luminanceMaterial = factory->TryGetOrCreateMaterial(_T("Hdr/Luminance.mat"), _T("Hdr/Luminance.mat"));
|
||||
luminanceSubMaterial = luminanceMaterial->FindRelevantSubMaterial(this);
|
||||
luminanceAdaptionMaterial = factory->TryGetOrCreateMaterial(_T("Hdr/LuminanceAdaption.mat"), _T("Hdr/LuminanceAdaption.mat"));
|
||||
luminanceAdaptionSubMaterial = luminanceAdaptionMaterial->FindRelevantSubMaterial(this);
|
||||
|
||||
unsigned int currentSize = (unsigned int)min(hdrTexture->GetWidth(), hdrTexture->GetHeight()) / 4;
|
||||
while (currentSize > 1)
|
||||
{
|
||||
currentSize = max(1, currentSize / 4);
|
||||
|
||||
RenderBuffer renderTarget;
|
||||
renderTarget.renderTarget = factory->CreateRenderTarget(currentSize, currentSize);
|
||||
renderTarget.texture = renderTarget.renderTarget->AddRenderTargetTexture(TextureFormat::RGBf);
|
||||
luminanceTargets.push_back(renderTarget);
|
||||
}
|
||||
finalLuminanceRenderTarget.renderTarget = factory->CreateRenderTarget(1, 1);
|
||||
finalLuminanceRenderTarget.texture = finalLuminanceRenderTarget.renderTarget->AddRenderTargetTexture(TextureFormat::RGBf);
|
||||
lastLuminanceRenderTarget.renderTarget = factory->CreateRenderTarget(1, 1);
|
||||
lastLuminanceRenderTarget.texture = lastLuminanceRenderTarget.renderTarget->AddRenderTargetTexture(TextureFormat::RGBf);
|
||||
|
||||
currentSize = (unsigned int)min(hdrTexture->GetWidth(), hdrTexture->GetHeight());
|
||||
for (int i = 0; i < 3; ++i, currentSize /= 2)
|
||||
{
|
||||
RenderBuffer renderTarget;
|
||||
renderTarget.renderTarget = factory->CreateRenderTarget(currentSize, currentSize);
|
||||
renderTarget.texture = renderTarget.renderTarget->AddRenderTargetTexture(TextureFormat::RGBf);
|
||||
blurRenderTargets.push_back(renderTarget);
|
||||
}
|
||||
|
||||
blurMaterial = factory->TryGetOrCreateMaterial(_T("Common/Blur.mat"), _T("Common/Blur.mat"));
|
||||
blurSubMaterial = blurMaterial->FindRelevantSubMaterial(this);
|
||||
|
||||
glowMaterial = factory->TryGetOrCreateMaterial(_T("Hdr/Glow.mat"), _T("Hdr/Glow.mat"));
|
||||
glowSubMaterial = glowMaterial->FindRelevantSubMaterial(this);
|
||||
glowSubMaterial->ShaderProgram->SetParam("Exposure", exposure);
|
||||
glowSubMaterial->ShaderProgram->SetParam("GlowStrength", glowStrength);
|
||||
}
|
||||
|
||||
|
||||
void HdrToLdrWorld::Process()
|
||||
{
|
||||
engine->GetRenderer()->SetCurrentWorld(this);
|
||||
IRenderable* quad = dynamic_cast<IRenderable*>(screenQuad);
|
||||
|
||||
// calculate currentsframeluminance value
|
||||
screenQuad->SetMaterial(luminanceMaterial);
|
||||
for (unsigned int i = 0; i < luminanceTargets.size(); ++i)
|
||||
{
|
||||
luminanceTargets[i].renderTarget->Bind();
|
||||
if (i == 0)
|
||||
luminanceSubMaterial->Textures[0].Texture = hdrTexture;
|
||||
else
|
||||
luminanceSubMaterial->Textures[0].Texture = luminanceTargets[i - 1].texture;
|
||||
|
||||
quad->Render();
|
||||
luminanceTargets[i].renderTarget->Unbind();
|
||||
}
|
||||
|
||||
// create a glowing image version of the raw hdr image, we use this later for our bluring steps
|
||||
{
|
||||
glowSubMaterial->Textures[0].Texture = hdrTexture;
|
||||
glowSubMaterial->Textures[1].Texture = finalLuminanceRenderTarget.texture;
|
||||
screenQuad->SetMaterial(glowMaterial);
|
||||
|
||||
blurRenderTargets[0].renderTarget->Bind();
|
||||
quad->Render();
|
||||
blurRenderTargets[0].renderTarget->Unbind();
|
||||
}
|
||||
|
||||
// now blur our glow texture
|
||||
screenQuad->SetMaterial(blurMaterial);
|
||||
for (unsigned int i = 1; i < blurRenderTargets.size(); ++i)
|
||||
{
|
||||
blurSubMaterial->Textures[0].Texture = blurRenderTargets[i - 1].texture;
|
||||
|
||||
blurRenderTargets[i].renderTarget->Bind();
|
||||
quad->Render();
|
||||
blurRenderTargets[i].renderTarget->Unbind();
|
||||
}
|
||||
|
||||
// adapt current luminance level to old luminance level
|
||||
{
|
||||
screenQuad->SetMaterial(luminanceAdaptionMaterial);
|
||||
finalLuminanceRenderTarget.renderTarget->Bind();
|
||||
luminanceAdaptionSubMaterial->Textures[0].Texture = lastLuminanceRenderTarget.texture;
|
||||
luminanceAdaptionSubMaterial->Textures[2].Texture = luminanceTargets[luminanceTargets.size() - 1].texture;
|
||||
quad->Render();
|
||||
finalLuminanceRenderTarget.renderTarget->Unbind();
|
||||
}
|
||||
|
||||
hdrToLdrSubMaterial->Textures[1].Texture = finalLuminanceRenderTarget.texture;
|
||||
hdrToLdrSubMaterial->Textures[2].Texture = blurRenderTargets[blurRenderTargets.size() - 1].texture;
|
||||
screenQuad->SetMaterial(hdrToLdrMaterial);
|
||||
|
||||
// flip luminance stuff
|
||||
std::swap(lastLuminanceRenderTarget, finalLuminanceRenderTarget);
|
||||
}
|
||||
52
demo09/src/demo09/Demo/HdrToLdrWorld/HdrToLdrWorld.h
Normal file
52
demo09/src/demo09/Demo/HdrToLdrWorld/HdrToLdrWorld.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "../World/World.h"
|
||||
#include "IAnimationManager.h"
|
||||
#include "IMaterial.h"
|
||||
|
||||
|
||||
class HdrToLdrWorld
|
||||
: public World
|
||||
{
|
||||
public:
|
||||
HdrToLdrWorld(IEngine* engine, ITexture* hdrTexture);
|
||||
virtual ~HdrToLdrWorld();
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Process();
|
||||
|
||||
private:
|
||||
|
||||
struct RenderBuffer
|
||||
{
|
||||
ITexture* texture;
|
||||
IRenderTarget* renderTarget;
|
||||
};
|
||||
|
||||
// Generic
|
||||
IMeshBuffer* screenQuad;
|
||||
|
||||
// HdrToLdr
|
||||
IMaterial* hdrToLdrMaterial;
|
||||
SubMaterial* hdrToLdrSubMaterial;
|
||||
ITexture* hdrTexture;
|
||||
|
||||
// luminance
|
||||
IMaterial* luminanceMaterial;
|
||||
SubMaterial* luminanceSubMaterial;
|
||||
std::vector<RenderBuffer> luminanceTargets;
|
||||
IMaterial* luminanceAdaptionMaterial;
|
||||
SubMaterial* luminanceAdaptionSubMaterial;
|
||||
RenderBuffer finalLuminanceRenderTarget;
|
||||
RenderBuffer lastLuminanceRenderTarget;
|
||||
|
||||
// Blur/Glow
|
||||
IMaterial* glowMaterial;
|
||||
SubMaterial* glowSubMaterial;
|
||||
IMaterial* blurMaterial;
|
||||
SubMaterial* blurSubMaterial;
|
||||
std::vector<RenderBuffer> blurRenderTargets;
|
||||
|
||||
float exposure;
|
||||
float glowStrength;
|
||||
};
|
||||
244
demo09/src/demo09/Demo/PinkyWorld/PinkyWorld.cpp
Normal file
244
demo09/src/demo09/Demo/PinkyWorld/PinkyWorld.cpp
Normal file
@@ -0,0 +1,244 @@
|
||||
#include "stdafx.h"
|
||||
#include "PinkyWorld.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IMaterial.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderer.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderable.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ICamera.h"
|
||||
#include "ILight.h"
|
||||
#include "IBillboard.h"
|
||||
#include "IBone.h"
|
||||
#include "../Resources/MeshBuffer/MeshBuffer.h"
|
||||
#include "../Resources/MeshBuffer/MD5Loader/Md5Loader.h"
|
||||
#include "../Resources/BLUImporter/BLUImporter.h"
|
||||
|
||||
|
||||
PinkyWorld::PinkyWorld(IEngine* engine, ITexture* depthTexture)
|
||||
: World(engine, "Default")
|
||||
, pinky(NULL)
|
||||
, depthTexture(depthTexture)
|
||||
, blurUtility(engine)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PinkyWorld::~PinkyWorld()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void PinkyWorld::Initialize()
|
||||
{
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
|
||||
camera = factory->CreateCamera();
|
||||
camera->SetPosition(Vector(-1.0f, 0.0f, 80.0f, 0.0f));
|
||||
camera->SetUp(Vector(0.0f, 0.0f, 1.0f, 0.0f));
|
||||
this->SetCamera(camera);
|
||||
|
||||
light = factory->CreateLight();
|
||||
light->SetAmbient(Vector(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
light->SetDiffuse(Vector(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
light->SetAttenuation(1.0f, 0.0f, 0.0f);
|
||||
light->SetPosition(Vector(20.0f, 0.0f, 0.0f));
|
||||
this->AddLight(light);
|
||||
|
||||
IMaterial* boxMaterial = engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("Common/Phong_simple.mat"), _T("Common/Phong_simple.mat"));
|
||||
boxMaterial->FindRelevantSubMaterial(this)->Textures[0] = factory->TryGetOrCreateTexture(L"DarkSand.jpg", L"DarkSand.jpg");
|
||||
/*pinky = BluImporter::Load(engine, _T("ChamferBox.blu"), boxMaterial);
|
||||
this->AddRenderable(pinky);*/
|
||||
|
||||
cloud = BluImporter::Load(engine, _T("Cloud.blu"));
|
||||
this->AddRenderable(cloud);
|
||||
|
||||
blurUtility.Initialize(depthTexture->GetWidth()/1, depthTexture->GetHeight()/1, TextureFormat::RGBAf);
|
||||
|
||||
IMaterial* softParticleMaterial = engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("SoftParticle"), _T("SoftParticle.mat"));
|
||||
//softParticleMaterial->FindRelevantSubMaterial(this)->Textures[2] = blurUtility.GetResult();//depthTexture;
|
||||
softParticleMaterial->FindRelevantSubMaterial(this)->Textures[2] = depthTexture;
|
||||
|
||||
/*
|
||||
const int particleCount = 500;
|
||||
IBillboardBatch* billboardBatch = factory->CreateBillboardBatch(particleCount, softParticleMaterial);
|
||||
billboardBatch->GetMaterial(softParticleMaterial);
|
||||
for (int i = 0; i < particleCount; ++i)
|
||||
{
|
||||
IBillboard* billboard = factory->CreateBillboard();
|
||||
billboard->GetOrientation(BillboardOrientation::Spherical);
|
||||
|
||||
IRenderable* renderable = dynamic_cast<IRenderable*>(billboard);
|
||||
renderable->GetScale(Vector(rand() % 500) / 50.0 + 1.0);
|
||||
renderable->GetRotation(Quaternion(
|
||||
(rand() % 5000 - 2500) / 1000.0f,
|
||||
(rand() % 5000 - 2500) / 1000.0f,
|
||||
(rand() % 5000 - 2500) / 1000.0f,
|
||||
(rand() % 36000) / 10.0f
|
||||
));
|
||||
renderable->GetTranslation(Vector(
|
||||
(rand() % 10000 - 5000) / 100.0f,
|
||||
(rand() % 10000 - 5000) / 100.0f,
|
||||
(rand() % 1000 - 250) / 1000.0f
|
||||
));
|
||||
|
||||
billboards.push_back(billboard);
|
||||
dynamic_cast<IRenderable*>(billboardBatch)->AddRenderable(renderable);
|
||||
}
|
||||
this->AddRenderable(dynamic_cast<IRenderable*>(billboardBatch));
|
||||
*/
|
||||
|
||||
//IText* text = factory->CreateText("Hallo Welt", L"Times New Roman", 200, 0.2f);
|
||||
//text->GetMaterial(
|
||||
// engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("Common/Depth.mat"), _T("Common/Depth.mat"))
|
||||
// );
|
||||
//IRenderable* textRen = dynamic_cast<IRenderable*>(text);
|
||||
//textRen->GetTranslation(Vector(0.0f, 0.0f, 0.0f, 0.0f));
|
||||
//textRen->GetScale(Vector(10.0f, 10.0f, 10.0f));
|
||||
//this->AddRenderable(textRen);
|
||||
|
||||
engine->GetAnimationManager()->AddRealTimeEvent(0.5, this, 1);
|
||||
engine->GetAnimationManager()->AddRealTimeEvent(4.0, this, 2);
|
||||
engine->GetAnimationManager()->AddRealTimeEvent(4.5, this, 3);
|
||||
}
|
||||
|
||||
|
||||
void PinkyWorld::OnAnimate(double time, unsigned int)
|
||||
{
|
||||
/*if (pinky != NULL)
|
||||
{
|
||||
Quaternion rotation(0.0f, 1.0f, 0.0f, float(time * 720.0), true);
|
||||
pinky->GetRotation(rotation);
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void PinkyWorld::OnEvent(unsigned int userData)
|
||||
{
|
||||
switch (userData)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
engine->GetAnimationManager()->AddDemoTimeAnimation(1.0, 5.0, this);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
//engine->GetTimeline()->SetSpeedAndDirection(-4.0);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
engine->GetTimeline()->SetSpeedAndDirection(1.0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PinkyWorld::Process()
|
||||
{
|
||||
engine->GetRenderer()->SetCurrentWorld(this);
|
||||
blurUtility.Blur(depthTexture, 2);
|
||||
|
||||
float demoTime = (float) (engine->GetTimeline()->GetDemoTime() * 10.0f);
|
||||
|
||||
Vector cameraPosition(sin(demoTime / 10.0f), cos(demoTime / 20.0f), -sin(demoTime / 40.0f), sin(demoTime / 40.0f));
|
||||
cameraPosition *= 60.0f;
|
||||
camera->SetPosition(cameraPosition);
|
||||
|
||||
if (pinky != NULL)
|
||||
pinky->SetTranslation(Vector(0.0f, 0.0f, sin(demoTime*0.1f) * 10.0f));
|
||||
|
||||
//light->SetPosition(Vector(5.0f, 5.0f, sin(demoTime*1) * 20.0f));
|
||||
|
||||
//demoTime *= 0.1;
|
||||
//Vector pinkyPos = pinky->GetTranslation();
|
||||
//std::vector<IBillboard*>::iterator iter = billboards.begin();
|
||||
//for (int i = 0; iter != billboards.end(); ++iter, ++i)
|
||||
//{
|
||||
// IRenderable* particle = dynamic_cast<IRenderable*>(*iter);
|
||||
// srand(i);
|
||||
// particle->SetScale(Vector((sin(demoTime+rand() % 500) * 0.5 + 0.5) * (rand() % 500) / 50.0 + 5.0));
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
BlurUtility::BlurUtility(IEngine* engine)
|
||||
: engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BlurUtility::Initialize(int width, int height, TextureFormat::Enumeration format)
|
||||
{
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
|
||||
screenQuad = factory->CreateMeshBuffer();
|
||||
screenQuad->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
screenQuad->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
screenQuad->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
RenderBuffer renderTarget;
|
||||
renderTarget.renderTarget = factory->CreateRenderTarget((unsigned int)width, (unsigned int)height);
|
||||
renderTarget.texture = renderTarget.renderTarget->AddRenderTargetTexture(format);
|
||||
pingPongRenderTargets.push_back(renderTarget);
|
||||
}
|
||||
|
||||
blurMaterial = factory->TryGetOrCreateMaterial(_T("Common/Blur.mat"), _T("Common/Blur.mat"));
|
||||
blurSubMaterial = blurMaterial->FindRelevantSubMaterial(NULL);
|
||||
}
|
||||
|
||||
|
||||
void BlurUtility::Blur(ITexture* sourceTexture, int passes)
|
||||
{
|
||||
passes *= 2;
|
||||
|
||||
IRenderable* quad = dynamic_cast<IRenderable*>(screenQuad);
|
||||
screenQuad->SetMaterial(blurMaterial);
|
||||
|
||||
for (unsigned int i = 0; i < (unsigned int)passes; ++i) // use an even number here
|
||||
{
|
||||
unsigned int destinationIndex = i % 2; // index of the source giver
|
||||
unsigned int sourceIndex = destinationIndex == 0 ? 1U : 0U; // Index of the render to target
|
||||
|
||||
blurSubMaterial->Textures[0].Texture = i == 0 && sourceTexture != NULL ? // Start?
|
||||
sourceTexture : // Use input texture
|
||||
pingPongRenderTargets[sourceIndex].texture; // Use pingpong buffer
|
||||
|
||||
pingPongRenderTargets[destinationIndex].renderTarget->Bind();
|
||||
|
||||
quad->Render();
|
||||
|
||||
pingPongRenderTargets[destinationIndex].renderTarget->Unbind();
|
||||
}
|
||||
}
|
||||
77
demo09/src/demo09/Demo/PinkyWorld/PinkyWorld.h
Normal file
77
demo09/src/demo09/Demo/PinkyWorld/PinkyWorld.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include "../World/World.h"
|
||||
|
||||
#include "IAnimationManager.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IRenderTarget.h"
|
||||
|
||||
|
||||
class BlurUtility
|
||||
{
|
||||
public:
|
||||
struct RenderBuffer
|
||||
{
|
||||
ITexture* texture;
|
||||
IRenderTarget* renderTarget;
|
||||
};
|
||||
|
||||
BlurUtility(IEngine* engine);
|
||||
|
||||
void Initialize(int width, int height, TextureFormat::Enumeration format);
|
||||
|
||||
void Blur(ITexture* sourceTexture, int passes);
|
||||
ITexture* GetResult() const { return pingPongRenderTargets[1].texture; }
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
// Generic
|
||||
IMeshBuffer* screenQuad;
|
||||
std::vector<RenderBuffer> pingPongRenderTargets;
|
||||
|
||||
// Blur
|
||||
IMaterial* blurMaterial;
|
||||
SubMaterial* blurSubMaterial;
|
||||
};
|
||||
|
||||
|
||||
class PinkyWorld
|
||||
: public World
|
||||
, public IAnimateable
|
||||
, public IEvent
|
||||
{
|
||||
public:
|
||||
PinkyWorld(IEngine* engine, ITexture* depthTexture);
|
||||
virtual ~PinkyWorld();
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Process();
|
||||
virtual void OnAnimate(double time, unsigned int userData);
|
||||
virtual void OnEvent(unsigned int userData);
|
||||
|
||||
std::wstring ConvertToString16(const std::string& string) const
|
||||
{
|
||||
unsigned int codePage = 0;
|
||||
if (string.size() == 0)
|
||||
return std::wstring();
|
||||
|
||||
int length = ::MultiByteToWideChar(codePage, 0, string.c_str(), (int)string.size() + 1, NULL, 0);
|
||||
if (length == 0)
|
||||
return std::wstring();
|
||||
|
||||
wchar_t* newBuffer = new wchar_t[(unsigned int)length];
|
||||
::MultiByteToWideChar(codePage, 0, string.c_str(), (int)string.size() + 1, newBuffer, length);
|
||||
return std::wstring(newBuffer);
|
||||
}
|
||||
|
||||
private:
|
||||
ILight* light;
|
||||
ICamera* camera;
|
||||
std::vector<IBillboard*> billboards;
|
||||
IRenderable* pinky;
|
||||
IRenderable* cloud;
|
||||
|
||||
ITexture* depthTexture;
|
||||
|
||||
BlurUtility blurUtility;
|
||||
};
|
||||
91
demo09/src/demo09/Demo/PlasmaWorld/PlasmaWorld.cpp
Normal file
91
demo09/src/demo09/Demo/PlasmaWorld/PlasmaWorld.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
#include "stdafx.h"
|
||||
#include "PlasmaWorld.h"
|
||||
|
||||
#include "IResourceFactory.h"
|
||||
#include "IRenderer.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderable.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ICamera.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderTarget.h"
|
||||
|
||||
|
||||
PlasmaWorld::PlasmaWorld(IEngine* engine)
|
||||
: World(engine, "Plasma")
|
||||
, screenQuad(NULL)
|
||||
, plasmaMaterial(NULL)
|
||||
, plasmaSubMaterial(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PlasmaWorld::~PlasmaWorld()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void PlasmaWorld::Initialize()
|
||||
{
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
|
||||
if (this->GetCamera() == NULL)
|
||||
{
|
||||
ICamera* camera = factory->CreateCamera();
|
||||
this->SetCamera(camera);
|
||||
}
|
||||
|
||||
plasmaMaterial = factory->TryGetOrCreateMaterial(_T("Plasma.mat"), _T("Plasma.mat"));
|
||||
plasmaSubMaterial = plasmaMaterial->FindRelevantSubMaterial(this);
|
||||
plasmaSubMaterial->ShaderProgram->SetParam("fadeColor", Vector(0.0, 0.0, 0.0, 0.5));
|
||||
plasmaSubMaterial->ShaderProgram->SetParam("disablePlasma", 1);
|
||||
|
||||
{
|
||||
screenQuad = factory->CreateMeshBuffer();
|
||||
screenQuad->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
screenQuad->SetMaterial(plasmaMaterial);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = 1.0f; vertexBufferBufferData[0].Y = 1.0f; vertexBufferBufferData[0].Z = 0.5f;
|
||||
vertexBufferBufferData[0].U = 1.0f; vertexBufferBufferData[0].V = 1.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = 1.0f; vertexBufferBufferData[1].Y = 0.0f; vertexBufferBufferData[1].Z = 0.5f;
|
||||
vertexBufferBufferData[1].U = 1.0f; vertexBufferBufferData[1].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 0.0f; vertexBufferBufferData[2].Y = 0.0f; vertexBufferBufferData[2].Z = 0.5f;
|
||||
vertexBufferBufferData[2].U = 0.0f; vertexBufferBufferData[2].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 0.0f; vertexBufferBufferData[3].Y = 1.0f; vertexBufferBufferData[3].Z = 0.5f;
|
||||
vertexBufferBufferData[3].U = 0.0f; vertexBufferBufferData[3].V = 1.0f;
|
||||
|
||||
screenQuad->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
screenQuad->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PlasmaWorld::Render(WorldRenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage == WorldRenderStage::PostRenderables)
|
||||
{
|
||||
IRenderable* quad = dynamic_cast<IRenderable*>(screenQuad);
|
||||
quad->Render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PlasmaWorld::Clear()
|
||||
{
|
||||
}
|
||||
31
demo09/src/demo09/Demo/PlasmaWorld/PlasmaWorld.h
Normal file
31
demo09/src/demo09/Demo/PlasmaWorld/PlasmaWorld.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "../World/World.h"
|
||||
#include "IAnimationManager.h"
|
||||
#include "IMaterial.h"
|
||||
|
||||
|
||||
class PlasmaWorld
|
||||
: public World
|
||||
{
|
||||
public:
|
||||
PlasmaWorld(IEngine* engine);
|
||||
virtual ~PlasmaWorld();
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Render(WorldRenderStage::Enumeration stage);
|
||||
virtual void Clear();
|
||||
|
||||
SubMaterial* plasmaSubMaterial;
|
||||
|
||||
private:
|
||||
|
||||
struct RenderBuffer
|
||||
{
|
||||
ITexture* texture;
|
||||
IRenderTarget* renderTarget;
|
||||
};
|
||||
|
||||
IMeshBuffer* screenQuad;
|
||||
IMaterial* plasmaMaterial;
|
||||
};
|
||||
43
demo09/src/demo09/Demo/TerrainWorld/Step1.h
Normal file
43
demo09/src/demo09/Demo/TerrainWorld/Step1.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Resources/Renderable/Renderable.h"
|
||||
|
||||
|
||||
class FirstRenderStep
|
||||
: public Renderable
|
||||
{
|
||||
public:
|
||||
FirstRenderStep(IEngine* engine, IRenderable* terrain)
|
||||
: Renderable(engine)
|
||||
, terrain(terrain)
|
||||
{
|
||||
refraction = engine->GetResourceFactory()->CreateRenderTarget(
|
||||
512,
|
||||
512);
|
||||
refractionTexture = refraction->AddRenderTargetTexture(TextureFormat::RGBAf);
|
||||
depthTexture = refraction->AddRenderTargetTexture(TextureFormat::RGBAf);
|
||||
}
|
||||
|
||||
virtual ~FirstRenderStep()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage != RenderStage::Render)
|
||||
return;
|
||||
|
||||
engine->GetRenderer()->GetCurrentWorld()->SetClearColor(Vector());
|
||||
refraction->Bind();
|
||||
IMeshBuffer* meshBuffer = dynamic_cast<IMeshBuffer*>(terrain);
|
||||
meshBuffer->GetMaterial()->GetSubMaterials()[0]->ShaderProgram->SetParam("fogEnabled", 0);
|
||||
terrain->Render();
|
||||
meshBuffer->GetMaterial()->GetSubMaterials()[0]->ShaderProgram->SetParam("fogEnabled", 1);
|
||||
refraction->Unbind();
|
||||
}
|
||||
|
||||
ITexture* refractionTexture;
|
||||
ITexture* depthTexture;
|
||||
IRenderTarget* refraction;
|
||||
IRenderable* terrain;
|
||||
};
|
||||
54
demo09/src/demo09/Demo/TerrainWorld/Step2.h
Normal file
54
demo09/src/demo09/Demo/TerrainWorld/Step2.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class SecondRenderStep
|
||||
: public Renderable
|
||||
{
|
||||
public:
|
||||
SecondRenderStep(IEngine* engine, FirstRenderStep* firstRenderStep)
|
||||
: Renderable(engine)
|
||||
, firstRenderStep(firstRenderStep)
|
||||
{
|
||||
reflection = engine->GetResourceFactory()->CreateRenderTarget(
|
||||
512,
|
||||
512);
|
||||
reflectionTexture = reflection->AddRenderTargetTexture(TextureFormat::RGBAf);
|
||||
depthTexture = reflection->AddRenderTargetTexture(TextureFormat::RGBAf);
|
||||
reflection->Check();
|
||||
}
|
||||
|
||||
virtual ~SecondRenderStep()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage != RenderStage::Render)
|
||||
return;
|
||||
|
||||
Matrix scaleMatrix = Matrix(
|
||||
Vector(1, 0, 0, 0),
|
||||
Vector(0, -1, 0, 0),
|
||||
Vector(0, 0, 1, 0),
|
||||
Vector(0, 0, 0, 1)
|
||||
);
|
||||
engine->GetRenderer()->GetCurrentWorld()->SetClearColor(Vector(0.7f, 0.8f, 0.9f, 1.0f));
|
||||
reflection->Bind();
|
||||
IMeshBuffer* meshBuffer = dynamic_cast<IMeshBuffer*>(firstRenderStep->terrain);
|
||||
firstRenderStep->terrain->SetAdditionalTransformation(scaleMatrix);
|
||||
firstRenderStep->terrain->SetTranslation(Vector(0, 16, 0, 0));
|
||||
meshBuffer->GetMaterial()->GetSubMaterials()[0]->ShaderProgram->SetParam("fogEnabled", 0);
|
||||
meshBuffer->GetMaterial()->GetSubMaterials()[0]->Culling = Culling::None;
|
||||
firstRenderStep->terrain->Render();
|
||||
meshBuffer->GetMaterial()->GetSubMaterials()[0]->Culling = Culling::Back;
|
||||
meshBuffer->GetMaterial()->GetSubMaterials()[0]->ShaderProgram->SetParam("fogEnabled", 1);
|
||||
firstRenderStep->terrain->SetTranslation(Vector(0, 0, 0, 0));
|
||||
firstRenderStep->terrain->SetAdditionalTransformation(Matrix());
|
||||
reflection->Unbind();
|
||||
}
|
||||
|
||||
FirstRenderStep* firstRenderStep;
|
||||
ITexture* reflectionTexture;
|
||||
ITexture* depthTexture;
|
||||
IRenderTarget* reflection;
|
||||
};
|
||||
69
demo09/src/demo09/Demo/TerrainWorld/Step3.h
Normal file
69
demo09/src/demo09/Demo/TerrainWorld/Step3.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class ThirdRenderStep
|
||||
: public Renderable
|
||||
{
|
||||
public:
|
||||
ThirdRenderStep(IEngine* engine, FirstRenderStep* firstRenderStep, SecondRenderStep* secondRenderStep)
|
||||
: Renderable(engine)
|
||||
, firstRenderStep(firstRenderStep)
|
||||
, secondRenderStep(secondRenderStep)
|
||||
{
|
||||
IMaterial* material = engine->GetResourceFactory()->TryGetOrCreateMaterial(_T("Terrain/Water.mat"), _T("Terrain/Water.mat"));
|
||||
material->GetSubMaterials()[0]->Textures[0] = TextureInfo(firstRenderStep->refractionTexture);
|
||||
material->GetSubMaterials()[0]->Textures[1] = TextureInfo(secondRenderStep->reflectionTexture);
|
||||
material->GetSubMaterials()[0]->Textures[2] = TextureInfo(firstRenderStep->depthTexture);
|
||||
waterPlane = engine->GetResourceFactory()->CreateMeshBuffer();
|
||||
waterPlane->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
waterPlane->SetMaterial(material);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[4];
|
||||
|
||||
vertexBufferBufferData[0].X = -64.0f; vertexBufferBufferData[0].Y = 8.0f; vertexBufferBufferData[0].Z = -64.0f;
|
||||
vertexBufferBufferData[0].U = 0.0f; vertexBufferBufferData[0].V = 0.0f;
|
||||
|
||||
vertexBufferBufferData[1].X = -64.0f; vertexBufferBufferData[1].Y = 8.0f; vertexBufferBufferData[1].Z = 63.0f;
|
||||
vertexBufferBufferData[1].U = 0.0f; vertexBufferBufferData[1].V = 127.0f / 129.0f;
|
||||
|
||||
vertexBufferBufferData[2].X = 63.0f; vertexBufferBufferData[2].Y = 8.0f; vertexBufferBufferData[2].Z = 63.0f;
|
||||
vertexBufferBufferData[2].U = 127.0f / 129.0f; vertexBufferBufferData[2].V = 127.0f / 129.0f;
|
||||
|
||||
vertexBufferBufferData[3].X = 63.0f; vertexBufferBufferData[3].Y = 8.0f; vertexBufferBufferData[3].Z = -64.0f;
|
||||
vertexBufferBufferData[3].U = 127.0f / 129.0f; vertexBufferBufferData[3].V = 0.0f;
|
||||
|
||||
waterPlane->SetVertexBuffer(vertexBufferBufferData, 4, vertexElements, MeshBufferUsage::Static, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4];
|
||||
for (unsigned int i = 0; i < 4; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
waterPlane->SetIndexBuffer(indexBufferData, 4, MeshBufferUsage::Static, true);
|
||||
}
|
||||
|
||||
virtual ~ThirdRenderStep()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage != RenderStage::Render)
|
||||
return;
|
||||
|
||||
IRenderTarget* renderTarget = this->GetWorld()->GetRenderTarget();
|
||||
if (renderTarget != NULL) renderTarget->Bind(BindFlags::BindAllTextures);
|
||||
IRenderable* water = dynamic_cast<IRenderable*>(waterPlane);
|
||||
waterPlane->GetMaterial()->GetSubMaterials()[0]->ShaderProgram->SetParam("time", (float)engine->GetTimeline()->GetDemoTime());
|
||||
water->Render();
|
||||
}
|
||||
|
||||
FirstRenderStep* firstRenderStep;
|
||||
SecondRenderStep* secondRenderStep;
|
||||
ITexture* reflectionTexture;
|
||||
IRenderTarget* reflection;
|
||||
IMeshBuffer* waterPlane;
|
||||
};
|
||||
38
demo09/src/demo09/Demo/TerrainWorld/Step4.h
Normal file
38
demo09/src/demo09/Demo/TerrainWorld/Step4.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Resources/Renderable/Renderable.h"
|
||||
|
||||
|
||||
class FourthRenderStep
|
||||
: public Renderable
|
||||
{
|
||||
public:
|
||||
FourthRenderStep(IEngine* engine, IRenderable* terrain)
|
||||
: Renderable(engine)
|
||||
, terrain(terrain)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~FourthRenderStep()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage != RenderStage::Render)
|
||||
return;
|
||||
|
||||
if (!this->GetVisible())
|
||||
return;
|
||||
|
||||
IMeshBuffer* terrain = dynamic_cast<IMeshBuffer*>(this->terrain);
|
||||
SubMaterial* submaterial = terrain->GetMaterial()->GetSubMaterials()[0];
|
||||
submaterial->ShaderProgram->SetParam("clipPlaneEnabled", 0);
|
||||
this->terrain->Render();
|
||||
submaterial->ShaderProgram->SetParam("clipPlaneEnabled", 1);
|
||||
}
|
||||
|
||||
ITexture* refractionTexture;
|
||||
IRenderTarget* refraction;
|
||||
IRenderable* terrain;
|
||||
};
|
||||
106
demo09/src/demo09/Demo/TerrainWorld/TerrainWorld.cpp
Normal file
106
demo09/src/demo09/Demo/TerrainWorld/TerrainWorld.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "StdAfx.h"
|
||||
#include "TerrainWorld.h"
|
||||
|
||||
|
||||
TerrainWorld::TerrainWorld(IEngine* engine)
|
||||
: World(engine, "Terrain")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TerrainWorld::~TerrainWorld(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void TerrainWorld::Initialize()
|
||||
{
|
||||
int textureWidth = 128;
|
||||
int textureHeight = 128;
|
||||
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
|
||||
light = factory->CreateLight();
|
||||
light->SetAmbient(Vector(0.1f, 0.3f, 0.5f, 1.0f));
|
||||
light->SetPosition(Vector(-1000.0f, 1000.0f, -1000.0f, 1.0f));
|
||||
this->AddLight(light);
|
||||
|
||||
camera = factory->CreateCamera();
|
||||
this->SetCamera(camera);
|
||||
|
||||
terraformMaterial = factory->TryGetOrCreateMaterial(_T("Terrain/Terraform.mat"), _T("Terrain/Terraform.mat"));
|
||||
|
||||
{
|
||||
terrainGrid = factory->CreateMeshBuffer();
|
||||
terrainGrid->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
terrainGrid->SetMaterial(terraformMaterial);
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
ScreenQuadVertex* vertexBufferBufferData = new ScreenQuadVertex[(unsigned int)(textureWidth * textureHeight * 4)];
|
||||
unsigned int* indexBufferData = new unsigned int[(unsigned int)(textureWidth * textureHeight * 4)];
|
||||
|
||||
int i = 0;
|
||||
for (int z = -textureHeight / 2; z < textureHeight / 2; ++z)
|
||||
{
|
||||
for (int x = -textureWidth / 2; x < textureWidth / 2; ++x)
|
||||
{
|
||||
vertexBufferBufferData[i + 0].X = x + 1.0f; vertexBufferBufferData[i + 3].Y = 1.0f; vertexBufferBufferData[i + 3].Z = z + 0.0f;
|
||||
vertexBufferBufferData[i + 0].U = (x + textureWidth / 2.0f + 1.0f) / (textureWidth + 1.0f); vertexBufferBufferData[i + 3].V = (z + textureHeight / 2.0f) / (textureHeight + 1.0f);
|
||||
vertexBufferBufferData[i + 1].X = x + 1.0f; vertexBufferBufferData[i + 2].Y = 1.0f; vertexBufferBufferData[i + 2].Z = z + 1.0f;
|
||||
vertexBufferBufferData[i + 1].U = (x + textureWidth / 2.0f + 1.0f) / (textureWidth + 1.0f); vertexBufferBufferData[i + 2].V = (z + textureHeight / 2.0f + 1.0f) / (textureHeight + 1.0f);
|
||||
vertexBufferBufferData[i + 2].X = x + 0.0f; vertexBufferBufferData[i + 1].Y = 1.0f; vertexBufferBufferData[i + 1].Z = z + 1.0f;
|
||||
vertexBufferBufferData[i + 2].U = (x + textureWidth / 2.0f) / (textureWidth + 1.0f); vertexBufferBufferData[i + 1].V = (z + textureHeight / 2.0f + 1.0f) / (textureHeight + 1.0f);
|
||||
vertexBufferBufferData[i + 3].X = x + 0.0f; vertexBufferBufferData[i + 0].Y = 1.0f; vertexBufferBufferData[i + 0].Z = z + 0.0f;
|
||||
vertexBufferBufferData[i + 3].U = (x + textureWidth / 2.0f) / (textureWidth + 1.0f); vertexBufferBufferData[i + 0].V = (z + textureHeight / 2.0f) / (textureHeight + 1.0f);
|
||||
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < textureWidth * textureHeight * 4; ++i)
|
||||
indexBufferData[i] = (unsigned int)i;
|
||||
|
||||
terrainGrid->SetVertexBuffer(vertexBufferBufferData, (unsigned int)(textureWidth * textureHeight * 4), vertexElements, MeshBufferUsage::Static, true);
|
||||
terrainGrid->SetIndexBuffer(indexBufferData, (unsigned int)(textureWidth * textureHeight * 4), MeshBufferUsage::Static, true);
|
||||
|
||||
Step1 = new FirstRenderStep(engine, dynamic_cast<IRenderable*>(terrainGrid));
|
||||
Step2 = new SecondRenderStep(engine, Step1);
|
||||
Step3 = new ThirdRenderStep(engine, Step1, Step2);
|
||||
Step4 = new FourthRenderStep(engine, dynamic_cast<IRenderable*>(terrainGrid));
|
||||
|
||||
//Refraction texture quad
|
||||
//this->AddRenderable(Step1);
|
||||
//this->AddRenderable((new SAQuad(engine, Step1->refractionTexture))->GetRenderable());
|
||||
|
||||
//Depth texture quad
|
||||
//this->AddRenderable(Step1);
|
||||
//this->AddRenderable((new SAQuad(engine, Step1->depthTexture))->GetRenderable());
|
||||
|
||||
//Reflection texture quad
|
||||
/*this->AddRenderable(Step1);
|
||||
this->AddRenderable(Step2);
|
||||
this->AddRenderable((new SAQuad(engine, Step2->reflectionTexture))->GetRenderable());*/
|
||||
|
||||
//the real thing
|
||||
this->AddRenderable(Step1);
|
||||
this->AddRenderable(Step2);
|
||||
this->AddRenderable(Step3);
|
||||
this->AddRenderable(Step4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TerrainWorld::Process()
|
||||
{
|
||||
this->SetClearColor(Vector(0.7f, 0.8f, 0.9f, 1.0f));
|
||||
World::Process();
|
||||
|
||||
float time = (float)engine->GetTimeline()->GetDemoTime() / 20.0f;
|
||||
light->SetDiffuse(Vector(1.3f, 1.1f, 0.6f, 1.0f) * (sin(time) * 0.5f + 0.75f));
|
||||
camera->SetPosition(Vector(sin(time * 3) * 64.0f, 0.0f, cos(time * 5) * 64.0f, 0.0f));
|
||||
camera->SetCenter(Vector());
|
||||
camera->SetUp(Vector(0.0f, 1.0f, 0.0f, 0.0f));
|
||||
}
|
||||
40
demo09/src/demo09/Demo/TerrainWorld/TerrainWorld.h
Normal file
40
demo09/src/demo09/Demo/TerrainWorld/TerrainWorld.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "../World/World.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "ICamera.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IRenderer.h"
|
||||
#include "ILight.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderable.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ITexture.h"
|
||||
#include "IRenderTarget.h"
|
||||
#include "Step1.h"
|
||||
#include "Step2.h"
|
||||
#include "Step3.h"
|
||||
#include "Step4.h"
|
||||
|
||||
|
||||
class TerrainWorld
|
||||
: public World
|
||||
{
|
||||
public:
|
||||
TerrainWorld(IEngine* engine);
|
||||
virtual ~TerrainWorld(void);
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Process();
|
||||
|
||||
private:
|
||||
ICamera* camera;
|
||||
IMeshBuffer* terrainGrid;
|
||||
IMaterial* terraformMaterial;
|
||||
ILight* light;
|
||||
FirstRenderStep* Step1;
|
||||
SecondRenderStep* Step2;
|
||||
ThirdRenderStep* Step3;
|
||||
FourthRenderStep* Step4;
|
||||
};
|
||||
175
demo09/src/demo09/Engine/Engine.cpp
Normal file
175
demo09/src/demo09/Engine/Engine.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
#include "stdafx.h"
|
||||
#include "Engine.h"
|
||||
#include "IWindow.h"
|
||||
#include "IWorld.h"
|
||||
#include "../Graphics/OpenGL.h"
|
||||
#include "../Renderer/Renderer.h"
|
||||
#include "../FileSystem/FileSystem.h"
|
||||
#include "../Resources/ResourceFactory.h"
|
||||
#include "../Timeline/Timeline.h"
|
||||
#include "../AnimationManager/AnimationManager.h"
|
||||
|
||||
|
||||
Engine::Engine()
|
||||
: graphics(NULL)
|
||||
, window(NULL)
|
||||
, renderer(NULL)
|
||||
, resourceFactory(NULL)
|
||||
, fileSystem(NULL)
|
||||
, timeline(NULL)
|
||||
, animationManager(NULL)
|
||||
, terminate(false)
|
||||
{
|
||||
graphics = new OpenGl(this);
|
||||
renderer = new Renderer(this);
|
||||
resourceFactory = new ResourceFactory(this);
|
||||
fileSystem = new FileSystem(this);
|
||||
timeline = new Timeline(this);
|
||||
animationManager = new AnimationManager(this);
|
||||
}
|
||||
|
||||
|
||||
Engine::~Engine()
|
||||
{
|
||||
if (graphics != NULL)
|
||||
{
|
||||
graphics->FreeRenderingContext();
|
||||
delete graphics;
|
||||
graphics = NULL;
|
||||
}
|
||||
|
||||
if (renderer != NULL)
|
||||
{
|
||||
delete renderer;
|
||||
renderer = NULL;
|
||||
}
|
||||
|
||||
if (resourceFactory != NULL)
|
||||
{
|
||||
delete resourceFactory;
|
||||
resourceFactory = NULL;
|
||||
}
|
||||
|
||||
if (fileSystem != NULL)
|
||||
{
|
||||
delete fileSystem;
|
||||
fileSystem = NULL;
|
||||
}
|
||||
|
||||
if (timeline != NULL)
|
||||
{
|
||||
delete timeline;
|
||||
timeline = NULL;
|
||||
}
|
||||
|
||||
if (animationManager != NULL)
|
||||
{
|
||||
delete animationManager;
|
||||
animationManager = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Engine::Initialize()
|
||||
{
|
||||
std::cout << "Initializing engine..." << white << std::endl;
|
||||
fileSystem->InitializeFromZipFile(); //fileSystem->InitializeFromDirectory();
|
||||
//graphics->Initialize();
|
||||
resourceFactory->Initialize();
|
||||
renderer->Initialize();
|
||||
renderer->SetMotionBlurSteps(0);
|
||||
renderer->SetAdaptiveMotionBlur(false);
|
||||
}
|
||||
|
||||
|
||||
IGraphics* Engine::GetGraphics()
|
||||
{
|
||||
return graphics;
|
||||
}
|
||||
|
||||
|
||||
IRenderer* Engine::GetRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
|
||||
IResourceFactory* Engine::GetResourceFactory()
|
||||
{
|
||||
return resourceFactory;
|
||||
}
|
||||
|
||||
|
||||
IFileSystem* Engine::GetFileSystem()
|
||||
{
|
||||
return fileSystem;
|
||||
}
|
||||
|
||||
|
||||
IAnimationManager* Engine::GetAnimationManager()
|
||||
{
|
||||
return animationManager;
|
||||
}
|
||||
|
||||
|
||||
ITimeline* Engine::GetTimeline()
|
||||
{
|
||||
return timeline;
|
||||
}
|
||||
|
||||
|
||||
void Engine::SetTerminate(bool terminate)
|
||||
{
|
||||
this->terminate = terminate;
|
||||
}
|
||||
|
||||
|
||||
bool Engine::GetTerminate()
|
||||
{
|
||||
return terminate;
|
||||
}
|
||||
|
||||
|
||||
void Engine::SetWindow(IWindow* window)
|
||||
{
|
||||
this->window = window;
|
||||
}
|
||||
|
||||
|
||||
IWindow* Engine::GetWindow()
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
void Engine::Process(double time)
|
||||
{
|
||||
this->renderer->Render(time);
|
||||
}
|
||||
|
||||
|
||||
void Engine::AddWorld(IWorld* world)
|
||||
{
|
||||
mWorlds.push_back(world);
|
||||
world->Initialize();
|
||||
GetGraphics()->PrintErrors();
|
||||
}
|
||||
|
||||
|
||||
std::vector<IWorld*> Engine::GetWorlds()
|
||||
{
|
||||
return mWorlds;
|
||||
}
|
||||
|
||||
|
||||
void Engine::ProcessWorlds()
|
||||
{
|
||||
std::vector<IWorld*>::iterator iter = mWorlds.begin();
|
||||
for (; iter != mWorlds.end(); ++iter)
|
||||
{
|
||||
IWorld* world = *iter;
|
||||
if (!world->GetActiveProcessing())
|
||||
continue;
|
||||
world->Process();
|
||||
}
|
||||
}
|
||||
44
demo09/src/demo09/Engine/Engine.h
Normal file
44
demo09/src/demo09/Engine/Engine.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
class Engine
|
||||
: public IEngine
|
||||
{
|
||||
public:
|
||||
Engine();
|
||||
virtual ~Engine();
|
||||
|
||||
// IEngine:
|
||||
virtual void Initialize();
|
||||
virtual void Process(double time);
|
||||
|
||||
virtual IGraphics* GetGraphics();
|
||||
virtual IRenderer* GetRenderer();
|
||||
virtual IResourceFactory* GetResourceFactory();
|
||||
virtual IFileSystem* GetFileSystem();
|
||||
virtual IAnimationManager* GetAnimationManager();
|
||||
virtual ITimeline* GetTimeline();
|
||||
|
||||
virtual void AddWorld(IWorld* world);
|
||||
virtual std::vector<IWorld*> GetWorlds();
|
||||
virtual void ProcessWorlds();
|
||||
|
||||
virtual void SetTerminate(bool active);
|
||||
virtual bool GetTerminate();
|
||||
|
||||
virtual IWindow* GetWindow();
|
||||
virtual void SetWindow(IWindow* window);
|
||||
|
||||
|
||||
private:
|
||||
IGraphics* graphics;
|
||||
IWindow* window;
|
||||
IRenderer* renderer;
|
||||
IResourceFactory* resourceFactory;
|
||||
IFileSystem* fileSystem;
|
||||
IAnimationManager* animationManager;
|
||||
ITimeline* timeline;
|
||||
|
||||
std::vector<IWorld*> mWorlds;
|
||||
bool terminate;
|
||||
};
|
||||
BIN
demo09/src/demo09/FileSystem/7za.exe
Normal file
BIN
demo09/src/demo09/FileSystem/7za.exe
Normal file
Binary file not shown.
89
demo09/src/demo09/FileSystem/CFileLoader/CFileLoader.cpp
Normal file
89
demo09/src/demo09/FileSystem/CFileLoader/CFileLoader.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "stdafx.h"
|
||||
#include "CFileLoader.h"
|
||||
|
||||
#include "IFileSystem.h"
|
||||
|
||||
|
||||
CFileLoader::~CFileLoader()
|
||||
{
|
||||
this->FreeFile();
|
||||
}
|
||||
|
||||
|
||||
bool CFileLoader::LoadFile(LPCTSTR filename)
|
||||
{
|
||||
file = engine->GetFileSystem()->Open(filename);
|
||||
if (file != NULL)
|
||||
{
|
||||
std::stringstream dataStream;
|
||||
dataStream.write(file->GetBuffer(), file->GetBufferLength());
|
||||
|
||||
while (!dataStream.eof())
|
||||
{
|
||||
currentLineOfCode++;
|
||||
|
||||
std::string currentReadLine;
|
||||
std::getline(dataStream, currentReadLine);
|
||||
if (currentReadLine.empty())
|
||||
continue;
|
||||
|
||||
std::vector<std::string> token = this->SplitString(currentReadLine);
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
currentSection = token[0];
|
||||
if (!this->OnSectionBegin(currentSection, token))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (token[token.size() - 1] == "{{")
|
||||
endSectionMarker = "}}";
|
||||
else
|
||||
endSectionMarker = "}";
|
||||
|
||||
while (!dataStream.eof())
|
||||
{
|
||||
currentLineOfCode++;
|
||||
std::getline(dataStream, currentReadLine);
|
||||
if (currentReadLine.empty())
|
||||
continue;
|
||||
|
||||
std::vector<std::string> token = this->SplitString(currentReadLine, ", \t()\r");
|
||||
if (token.empty())
|
||||
continue;
|
||||
|
||||
if (token[0] == endSectionMarker)
|
||||
{
|
||||
if (!this->OnSectionEnd(currentSection))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
currentSection = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this->OnContentReceived(token, currentReadLine))
|
||||
{
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->FreeFile();
|
||||
return true;
|
||||
}
|
||||
this->FreeFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CFileLoader::FreeFile()
|
||||
{
|
||||
if (file != NULL)
|
||||
delete file;
|
||||
file = NULL;
|
||||
}
|
||||
72
demo09/src/demo09/FileSystem/CFileLoader/CFileLoader.h
Normal file
72
demo09/src/demo09/FileSystem/CFileLoader/CFileLoader.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "IEngine.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
class CFileLoader
|
||||
{
|
||||
public:
|
||||
CFileLoader(IEngine* engine) : engine(engine), currentLineOfCode(0), file(NULL), endSectionMarker("}") {}
|
||||
virtual ~CFileLoader();
|
||||
|
||||
bool LoadFile(LPCTSTR filename);
|
||||
const std::string& GetCurrentSection() const { return currentSection; }
|
||||
|
||||
virtual bool OnSectionBegin(const std::string&, const std::vector<std::string>&) { return true; }
|
||||
virtual bool OnContentReceived(const std::vector<std::string>&, const std::string&) { return true; }
|
||||
virtual bool OnSectionEnd(const std::string&) { return true; }
|
||||
|
||||
unsigned int GetCurrentLineNumber() const { return currentLineOfCode; }
|
||||
|
||||
protected:
|
||||
std::vector<std::string> SplitString(const std::string & string, const std::string & delimiters=", \t\r")
|
||||
{
|
||||
// Skip delims at beginning, find start of first token
|
||||
std::string::size_type lastPos = string.find_first_not_of(delimiters, 0);
|
||||
// Find next delimiter @ end of token
|
||||
std::string::size_type pos = string.find_first_of(delimiters, lastPos);
|
||||
|
||||
// output vector
|
||||
std::vector<std::string> tokens;
|
||||
while (std::string::npos != pos || std::string::npos != lastPos)
|
||||
{
|
||||
// Found a token, add it to the vector.
|
||||
tokens.push_back(string.substr(lastPos, pos - lastPos));
|
||||
// Skip delims. Note the "not_of". this is beginning of token
|
||||
lastPos = string.find_first_not_of(delimiters, pos);
|
||||
// Find next delimiter at end of token.
|
||||
pos = string.find_first_of(delimiters, lastPos);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
std::wstring ConvertToString16(const std::string& string) const
|
||||
{
|
||||
unsigned int codePage = 0;
|
||||
if (string.size() == 0)
|
||||
return std::wstring();
|
||||
|
||||
int length = ::MultiByteToWideChar(codePage, 0, string.c_str(), (int)string.size() + 1, NULL, 0);
|
||||
if (length == 0)
|
||||
return std::wstring();
|
||||
|
||||
wchar_t* newBuffer = new wchar_t[(unsigned int)length];
|
||||
::MultiByteToWideChar(codePage, 0, string.c_str(), (int)string.size() + 1, newBuffer, length);
|
||||
return std::wstring(newBuffer);
|
||||
}
|
||||
|
||||
IEngine* engine;
|
||||
|
||||
void FreeFile();
|
||||
|
||||
private:
|
||||
std::string currentSection;
|
||||
IFile* file;
|
||||
|
||||
std::string endSectionMarker;
|
||||
unsigned int currentLineOfCode;
|
||||
};
|
||||
122
demo09/src/demo09/FileSystem/File.cpp
Normal file
122
demo09/src/demo09/FileSystem/File.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include "stdafx.h"
|
||||
#include "File.h"
|
||||
|
||||
|
||||
File::File(IEngine* engine, char* buffer, unsigned int bufferLength)
|
||||
: engine(engine)
|
||||
, buffer(buffer)
|
||||
, bufferPosition(buffer)
|
||||
, bufferLength(bufferLength)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
File::~File()
|
||||
{
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
|
||||
char* File::GetBuffer()
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
unsigned int File::GetBufferLength()
|
||||
{
|
||||
return bufferLength;
|
||||
}
|
||||
|
||||
|
||||
void File::SaveAs(LPCTSTR fileName)
|
||||
{
|
||||
FILE* file;
|
||||
_tfopen_s(&file, fileName, _T("wb"));
|
||||
fwrite(buffer, 1, bufferLength, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
std::string File::ReadString()
|
||||
{
|
||||
std::string result;
|
||||
char readChar = 0;
|
||||
do
|
||||
{
|
||||
this->CheckIntegrity(sizeof(char));
|
||||
|
||||
readChar = *bufferPosition;
|
||||
if (readChar != '\0')
|
||||
result += readChar;
|
||||
bufferPosition++;
|
||||
}
|
||||
while (readChar != '\0');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
float File::ReadFloat()
|
||||
{
|
||||
this->CheckIntegrity(sizeof(float));
|
||||
|
||||
float result = *(float*)bufferPosition;
|
||||
bufferPosition += sizeof(float);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int File::ReadInt()
|
||||
{
|
||||
this->CheckIntegrity(sizeof(int));
|
||||
|
||||
int result = *(int*)bufferPosition;
|
||||
bufferPosition += sizeof(int);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void* File::ReadDataArray(unsigned int bytes)
|
||||
{
|
||||
this->CheckIntegrity(bytes);
|
||||
|
||||
char* data = new char[bytes];
|
||||
|
||||
memcpy(data, bufferPosition, bytes);
|
||||
|
||||
bufferPosition += sizeof(char) * bytes;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
void File::RewindFilePointer()
|
||||
{
|
||||
bufferPosition = buffer;
|
||||
}
|
||||
|
||||
|
||||
char* File::GetFilePointer() const
|
||||
{
|
||||
return bufferPosition;
|
||||
}
|
||||
|
||||
|
||||
void File::SetFilePointer(char* position)
|
||||
{
|
||||
bufferPosition = position;
|
||||
this->CheckIntegrity(0);
|
||||
}
|
||||
|
||||
|
||||
bool File::IsEof() const
|
||||
{
|
||||
return bufferPosition == (buffer + bufferLength);
|
||||
}
|
||||
|
||||
|
||||
void File::CheckIntegrity(unsigned int bytes)
|
||||
{
|
||||
if (bufferPosition + bytes > buffer + bufferLength || bufferPosition < buffer)
|
||||
throw _T("File integrity is broken.");
|
||||
}
|
||||
35
demo09/src/demo09/FileSystem/File.h
Normal file
35
demo09/src/demo09/FileSystem/File.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "IFileSystem.h"
|
||||
|
||||
|
||||
class File
|
||||
: public IFile
|
||||
{
|
||||
public:
|
||||
File(IEngine* engine, char* buffer, unsigned int bufferLength);
|
||||
virtual ~File();
|
||||
|
||||
virtual char* GetBuffer();
|
||||
virtual unsigned int GetBufferLength();
|
||||
virtual void SaveAs(LPCTSTR fileName);
|
||||
|
||||
virtual std::string ReadString();
|
||||
virtual float ReadFloat();
|
||||
virtual int ReadInt();
|
||||
virtual void* ReadDataArray(unsigned int bytes);
|
||||
|
||||
virtual void RewindFilePointer();
|
||||
virtual char* GetFilePointer() const;
|
||||
virtual void SetFilePointer(char* position);
|
||||
virtual bool IsEof() const;
|
||||
|
||||
protected:
|
||||
void CheckIntegrity(unsigned int bytes);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
char* buffer;
|
||||
char* bufferPosition;
|
||||
unsigned int bufferLength;
|
||||
};
|
||||
81
demo09/src/demo09/FileSystem/FileSystem.cpp
Normal file
81
demo09/src/demo09/FileSystem/FileSystem.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "stdafx.h"
|
||||
#include "FileSystem.h"
|
||||
#include "File.h"
|
||||
|
||||
|
||||
FileSystem::FileSystem(IEngine* engine)
|
||||
: engine(engine)
|
||||
, zip(false)
|
||||
{
|
||||
::GetModuleFileName(NULL, appDirectory, MAX_PATH);
|
||||
::PathRemoveFileSpec(appDirectory);
|
||||
}
|
||||
|
||||
|
||||
FileSystem::~FileSystem()
|
||||
{
|
||||
if (zip)
|
||||
{
|
||||
::CloseZip(zipHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FileSystem::InitializeFromDirectory(LPCTSTR directory)
|
||||
{
|
||||
zip = false;
|
||||
::PathCombine(this->directory, appDirectory, directory);
|
||||
}
|
||||
|
||||
|
||||
void FileSystem::InitializeFromZipFile(LPCTSTR zipFile)
|
||||
{
|
||||
std::cout << "Initializing file system with data file: ";
|
||||
std::wcout << zipFile << white << std::endl;
|
||||
zip = true;
|
||||
TCHAR fullPath[MAX_PATH];
|
||||
::PathCombine(fullPath, appDirectory, zipFile);
|
||||
zipHandle = ::OpenZip(fullPath, 0);
|
||||
if (zipHandle == NULL)
|
||||
{
|
||||
std::cout << red << "FAILED!" << white << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IFile* FileSystem::Open(LPCTSTR fileName)
|
||||
{
|
||||
if (zip)
|
||||
{
|
||||
ZIPENTRY zipEntry;
|
||||
int index;
|
||||
::FindZipItem(zipHandle, fileName, true, &index, &zipEntry);
|
||||
if (index == -1)
|
||||
return NULL;
|
||||
|
||||
unsigned int bufferSize = (unsigned int)zipEntry.unc_size;
|
||||
char* buffer = new char[bufferSize];
|
||||
::UnzipItem(zipHandle, index, buffer, bufferSize);
|
||||
|
||||
return new File(engine, buffer, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
TCHAR fullPath[MAX_PATH];
|
||||
PathCombine(fullPath, directory, fileName);
|
||||
|
||||
FILE* file = NULL;
|
||||
_tfopen_s(&file, fullPath, _T("rb"));
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
unsigned int bufferSize = (unsigned int)ftell(file);
|
||||
rewind(file);
|
||||
char* buffer = new char[bufferSize];
|
||||
fread_s(buffer, bufferSize, 1, bufferSize, file);
|
||||
fclose(file);
|
||||
|
||||
return new File(engine, buffer, bufferSize);
|
||||
}
|
||||
}
|
||||
24
demo09/src/demo09/FileSystem/FileSystem.h
Normal file
24
demo09/src/demo09/FileSystem/FileSystem.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "IFileSystem.h"
|
||||
#include "unzip.h"
|
||||
|
||||
|
||||
class FileSystem
|
||||
: public IFileSystem
|
||||
{
|
||||
public:
|
||||
FileSystem(IEngine* engine);
|
||||
virtual ~FileSystem();
|
||||
|
||||
virtual void InitializeFromDirectory(LPCTSTR directory = _T("data"));
|
||||
virtual void InitializeFromZipFile(LPCTSTR zipFile = _T("data.pak"));
|
||||
virtual IFile* Open(LPCTSTR fileName);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
bool zip;
|
||||
HZIP zipHandle;
|
||||
TCHAR directory[MAX_PATH];
|
||||
TCHAR appDirectory[MAX_PATH];
|
||||
};
|
||||
4162
demo09/src/demo09/FileSystem/unzip.cpp
Normal file
4162
demo09/src/demo09/FileSystem/unzip.cpp
Normal file
File diff suppressed because it is too large
Load Diff
214
demo09/src/demo09/FileSystem/unzip.h
Normal file
214
demo09/src/demo09/FileSystem/unzip.h
Normal file
@@ -0,0 +1,214 @@
|
||||
#ifndef _unzip_H
|
||||
#define _unzip_H
|
||||
|
||||
// UNZIPPING functions -- for unzipping.
|
||||
// This file is a repackaged form of extracts from the zlib code available
|
||||
// at www.gzip.org/zlib, by Jean-Loup Gailly and Mark Adler. The original
|
||||
// copyright notice may be found in unzip.cpp. The repackaging was done
|
||||
// by Lucian Wischik to simplify and extend its use in Windows/C++. Also
|
||||
// encryption and unicode filenames have been added.
|
||||
|
||||
|
||||
#ifndef _zip_H
|
||||
DECLARE_HANDLE(HZIP);
|
||||
#endif
|
||||
// An HZIP identifies a zip file that has been opened
|
||||
|
||||
typedef DWORD ZRESULT;
|
||||
// return codes from any of the zip functions. Listed later.
|
||||
|
||||
typedef struct
|
||||
{ int index; // index of this file within the zip
|
||||
TCHAR name[MAX_PATH]; // filename within the zip
|
||||
DWORD attr; // attributes, as in GetFileAttributes.
|
||||
FILETIME atime,ctime,mtime;// access, create, modify filetimes
|
||||
long comp_size; // sizes of item, compressed and uncompressed. These
|
||||
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
|
||||
} ZIPENTRY;
|
||||
|
||||
|
||||
HZIP OpenZip(const TCHAR *fn, const char *password);
|
||||
HZIP OpenZip(void *z,unsigned int len, const char *password);
|
||||
HZIP OpenZipHandle(HANDLE h, const char *password);
|
||||
// OpenZip - opens a zip file and returns a handle with which you can
|
||||
// subsequently examine its contents. You can open a zip file from:
|
||||
// from a pipe: OpenZipHandle(hpipe_read,0);
|
||||
// from a file (by handle): OpenZipHandle(hfile,0);
|
||||
// from a file (by name): OpenZip("c:\\test.zip","password");
|
||||
// from a memory block: OpenZip(bufstart, buflen,0);
|
||||
// If the file is opened through a pipe, then items may only be
|
||||
// accessed in increasing order, and an item may only be unzipped once,
|
||||
// although GetZipItem can be called immediately before and after unzipping
|
||||
// it. If it's opened in any other way, then full random access is possible.
|
||||
// Note: pipe input is not yet implemented.
|
||||
// Note: zip passwords are ascii, not unicode.
|
||||
// Note: for windows-ce, you cannot close the handle until after CloseZip.
|
||||
// but for real windows, the zip makes its own copy of your handle, so you
|
||||
// can close yours anytime.
|
||||
|
||||
ZRESULT GetZipItem(HZIP hz, int index, ZIPENTRY *ze);
|
||||
// GetZipItem - call this to get information about an item in the zip.
|
||||
// If index is -1 and the file wasn't opened through a pipe,
|
||||
// then it returns information about the whole zipfile
|
||||
// (and in particular ze.index returns the number of index items).
|
||||
// Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY)
|
||||
// See below for notes on what happens when you unzip such an item.
|
||||
// Note: if you are opening the zip through a pipe, then random access
|
||||
// is not possible and GetZipItem(-1) fails and you can't discover the number
|
||||
// of items except by calling GetZipItem on each one of them in turn,
|
||||
// starting at 0, until eventually the call fails. Also, in the event that
|
||||
// you are opening through a pipe and the zip was itself created into a pipe,
|
||||
// then then comp_size and sometimes unc_size as well may not be known until
|
||||
// after the item has been unzipped.
|
||||
|
||||
ZRESULT FindZipItem(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze);
|
||||
// FindZipItem - finds an item by name. ic means 'insensitive to case'.
|
||||
// It returns the index of the item, and returns information about it.
|
||||
// If nothing was found, then index is set to -1 and the function returns
|
||||
// an error code.
|
||||
|
||||
ZRESULT UnzipItem(HZIP hz, int index, const TCHAR *fn);
|
||||
ZRESULT UnzipItem(HZIP hz, int index, void *z,unsigned int len);
|
||||
ZRESULT UnzipItemHandle(HZIP hz, int index, HANDLE h);
|
||||
// UnzipItem - given an index to an item, unzips it. You can unzip to:
|
||||
// to a pipe: UnzipItemHandle(hz,i, hpipe_write);
|
||||
// to a file (by handle): UnzipItemHandle(hz,i, hfile);
|
||||
// to a file (by name): UnzipItem(hz,i, ze.name);
|
||||
// to a memory block: UnzipItem(hz,i, buf,buflen);
|
||||
// In the final case, if the buffer isn't large enough to hold it all,
|
||||
// then the return code indicates that more is yet to come. If it was
|
||||
// large enough, and you want to know precisely how big, GetZipItem.
|
||||
// Note: zip files are normally stored with relative pathnames. If you
|
||||
// unzip with ZIP_FILENAME a relative pathname then the item gets created
|
||||
// relative to the current directory - it first ensures that all necessary
|
||||
// subdirectories have been created. Also, the item may itself be a directory.
|
||||
// If you unzip a directory with ZIP_FILENAME, then the directory gets created.
|
||||
// If you unzip it to a handle or a memory block, then nothing gets created
|
||||
// and it emits 0 bytes.
|
||||
ZRESULT SetUnzipBaseDir(HZIP hz, const TCHAR *dir);
|
||||
// if unzipping to a filename, and it's a relative filename, then it will be relative to here.
|
||||
// (defaults to current-directory).
|
||||
|
||||
|
||||
ZRESULT CloseZip(HZIP hz);
|
||||
// CloseZip - the zip handle must be closed with this function.
|
||||
|
||||
unsigned int FormatZipMessage(ZRESULT code, TCHAR *buf,unsigned int len);
|
||||
// FormatZipMessage - given an error code, formats it as a string.
|
||||
// It returns the length of the error message. If buf/len points
|
||||
// to a real buffer, then it also writes as much as possible into there.
|
||||
|
||||
|
||||
// These are the result codes:
|
||||
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
|
||||
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
|
||||
// The following come from general system stuff (e.g. files not openable)
|
||||
#define ZR_GENMASK 0x0000FF00
|
||||
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
|
||||
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
|
||||
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
|
||||
#define ZR_WRITE 0x00000400 // a general error writing to the file
|
||||
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
|
||||
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
|
||||
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
|
||||
#define ZR_READ 0x00000800 // a general error reading the file
|
||||
#define ZR_PASSWORD 0x00001000 // we didn't get the right password to unzip the file
|
||||
// The following come from mistakes on the part of the caller
|
||||
#define ZR_CALLERMASK 0x00FF0000
|
||||
#define ZR_ARGS 0x00010000 // general mistake with the arguments
|
||||
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
|
||||
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
|
||||
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
|
||||
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
|
||||
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
|
||||
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
|
||||
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
|
||||
// The following come from bugs within the zip library itself
|
||||
#define ZR_BUGMASK 0xFF000000
|
||||
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
|
||||
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
|
||||
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
|
||||
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// e.g.
|
||||
//
|
||||
// SetCurrentDirectory("c:\\docs\\stuff");
|
||||
// HZIP hz = OpenZip("c:\\stuff.zip",0);
|
||||
// ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
|
||||
// for (int i=0; i<numitems; i++)
|
||||
// { GetZipItem(hz,i,&ze);
|
||||
// UnzipItem(hz,i,ze.name);
|
||||
// }
|
||||
// CloseZip(hz);
|
||||
//
|
||||
//
|
||||
// HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA);
|
||||
// HANDLE hglob = LoadResource(hInstance,hrsrc);
|
||||
// void *zipbuf=LockResource(hglob);
|
||||
// unsigned int ziplen=SizeofResource(hInstance,hrsrc);
|
||||
// HZIP hz = OpenZip(zipbuf, ziplen, 0);
|
||||
// - unzip to a membuffer -
|
||||
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
|
||||
// char *ibuf = new char[ze.unc_size];
|
||||
// UnzipItem(hz,i, ibuf, ze.unc_size);
|
||||
// delete[] ibuf;
|
||||
// - unzip to a fixed membuff -
|
||||
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",true,&i,&ze);
|
||||
// char ibuf[1024]; ZRESULT zr=ZR_MORE; unsigned long totsize=0;
|
||||
// while (zr==ZR_MORE)
|
||||
// { zr = UnzipItem(hz,i, ibuf,1024);
|
||||
// unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize;
|
||||
// totsize+=bufsize;
|
||||
// }
|
||||
// - unzip to a pipe -
|
||||
// HANDLE hwrite; HANDLE hthread=CreateWavReaderThread(&hwrite);
|
||||
// int i; ZIPENTRY ze; FindZipItem(hz,"sound.wav",true,&i,&ze);
|
||||
// UnzipItemHandle(hz,i, hwrite);
|
||||
// CloseHandle(hwrite);
|
||||
// WaitForSingleObject(hthread,INFINITE);
|
||||
// CloseHandle(hwrite); CloseHandle(hthread);
|
||||
// - finished -
|
||||
// CloseZip(hz);
|
||||
// // note: no need to free resources obtained through Find/Load/LockResource
|
||||
//
|
||||
//
|
||||
// SetCurrentDirectory("c:\\docs\\pipedzipstuff");
|
||||
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite,0,0);
|
||||
// CreateZipWriterThread(hwrite);
|
||||
// HZIP hz = OpenZipHandle(hread,0);
|
||||
// for (int i=0; ; i++)
|
||||
// { ZIPENTRY ze;
|
||||
// ZRESULT zr=GetZipItem(hz,i,&ze); if (zr!=ZR_OK) break; // no more
|
||||
// UnzipItem(hz,i, ze.name);
|
||||
// }
|
||||
// CloseZip(hz);
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
// Now we indulge in a little skullduggery so that the code works whether
|
||||
// the user has included just zip or both zip and unzip.
|
||||
// Idea: if header files for both zip and unzip are present, then presumably
|
||||
// the cpp files for zip and unzip are both present, so we will call
|
||||
// one or the other of them based on a dynamic choice. If the header file
|
||||
// for only one is present, then we will bind to that particular one.
|
||||
ZRESULT CloseZipU(HZIP hz);
|
||||
unsigned int FormatZipMessageU(ZRESULT code, TCHAR *buf,unsigned int len);
|
||||
bool IsZipHandleU(HZIP hz);
|
||||
#ifdef _zip_H
|
||||
#undef CloseZip
|
||||
#define CloseZip(hz) (IsZipHandleU(hz)?CloseZipU(hz):CloseZipZ(hz))
|
||||
#else
|
||||
#define CloseZip CloseZipU
|
||||
#define FormatZipMessage FormatZipMessageU
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // _unzip_H
|
||||
187
demo09/src/demo09/Graphics/OpenGl.cpp
Normal file
187
demo09/src/demo09/Graphics/OpenGl.cpp
Normal file
@@ -0,0 +1,187 @@
|
||||
#include "stdafx.h"
|
||||
#include "OpenGl.h"
|
||||
|
||||
|
||||
OpenGl::OpenGl(IEngine* engine)
|
||||
: engine(engine)
|
||||
, width(0)
|
||||
, height(0)
|
||||
, maxTextureSize(0)
|
||||
, renderingContext(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline void OpenGl::Resize(int sizeX, int sizeY)
|
||||
{
|
||||
if (sizeY == 0)
|
||||
{
|
||||
sizeY = 1;
|
||||
}
|
||||
|
||||
width = sizeX;
|
||||
height = sizeY;
|
||||
glViewport(0, 0, sizeX, sizeY);
|
||||
}
|
||||
|
||||
|
||||
inline int OpenGl::Initialize()
|
||||
{
|
||||
std::cout << "Initializing OpenGL..." << white << std::endl;
|
||||
glewInit();
|
||||
|
||||
char* vendor = (char*)glGetString(GL_VENDOR);
|
||||
std::cout << "OPENGL :: Vendor: " << vendor << white << std::endl;
|
||||
|
||||
char* renderer = (char*)glGetString(GL_RENDERER);
|
||||
std::cout << "OPENGL :: Renderer: " << renderer << white << std::endl;
|
||||
|
||||
char* version = (char*)glGetString(GL_VERSION);
|
||||
std::cout << "OPENGL :: Version: " << version << white << std::endl;
|
||||
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
|
||||
char maxTexture[255];
|
||||
sprintf_s(maxTexture, 255, "OPENGL :: Maximum texture size: %d", maxTextureSize);
|
||||
std::cout << maxTexture << white << std::endl;
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glClearDepth(1.0f);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
glFrontFace(GL_CCW);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
this->Progress(0.0f);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
inline int OpenGl::GetMaxTextureSize()
|
||||
{
|
||||
return maxTextureSize;
|
||||
}
|
||||
|
||||
|
||||
inline int OpenGl::GetWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
inline int OpenGl::GetHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
|
||||
inline void OpenGl::InitRenderingContext(HDC deviceContext)
|
||||
{
|
||||
if (!(renderingContext = wglCreateContext(deviceContext)))
|
||||
{
|
||||
throw "Cannot create OpenGl Rendering Context!";
|
||||
}
|
||||
|
||||
if(!wglMakeCurrent(deviceContext, renderingContext))
|
||||
{
|
||||
throw "Cannot make OpenGl Rendering Context current!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void OpenGl::FreeRenderingContext()
|
||||
{
|
||||
if (renderingContext)
|
||||
{
|
||||
wglMakeCurrent(NULL,NULL);
|
||||
wglDeleteContext(renderingContext);
|
||||
renderingContext = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void OpenGl::PrintErrors()
|
||||
{
|
||||
GLenum error = GL_NO_ERROR;
|
||||
int errorCount = 5;
|
||||
do
|
||||
{
|
||||
error = glGetError();
|
||||
if (error != GL_NO_ERROR)
|
||||
{
|
||||
errorCount--;
|
||||
char* errorString = (char*)gluErrorString(error);
|
||||
// assert(!errorString);
|
||||
if (errorString != 0)
|
||||
std::cout << "OPENGL :: ERROR " << errorString << white << std::endl;
|
||||
else
|
||||
std::cout << "OPENGL :: UNKNOWN ERROR!" << white << std::endl;
|
||||
}
|
||||
if (errorCount == 0)
|
||||
{
|
||||
std::cout << "OPENGL :: ERROR Too many errors!" << white << std::endl;
|
||||
break;
|
||||
}
|
||||
} while (error != GL_NO_ERROR);
|
||||
}
|
||||
|
||||
|
||||
void OpenGl::SetAspectRatio(float value)
|
||||
{
|
||||
aspectRatio = value;
|
||||
}
|
||||
|
||||
|
||||
float OpenGl::GetAspectRatio()
|
||||
{
|
||||
return aspectRatio;
|
||||
}
|
||||
|
||||
|
||||
void OpenGl::Progress(float position)
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
glUseProgram(0);
|
||||
glDisable(GL_LIGHTING);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClearDepth(0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glColor3f(0.2f, 0.5f, 0.9f);
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex2d(-0.91, 0.06);
|
||||
glVertex2d(0.91, 0.06);
|
||||
glVertex2d(0.91, -0.06);
|
||||
glVertex2d(-0.91, -0.06);
|
||||
glEnd();
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glVertex2d(-0.9, 0.05);
|
||||
glVertex2d(-0.9 + 1.8 * position, 0.05);
|
||||
glVertex2d(-0.9 + 1.8 * position, -0.05);
|
||||
glVertex2d(-0.9, -0.05);
|
||||
glEnd();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
33
demo09/src/demo09/Graphics/OpenGl.h
Normal file
33
demo09/src/demo09/Graphics/OpenGl.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "IGraphics.h"
|
||||
|
||||
|
||||
class OpenGl
|
||||
: public IGraphics
|
||||
{
|
||||
public:
|
||||
OpenGl(IEngine* engine);
|
||||
virtual ~OpenGl() {};
|
||||
|
||||
virtual void Resize(int sizeX, int sizeY);
|
||||
virtual int Initialize();
|
||||
virtual void InitRenderingContext(HDC deviceContext);
|
||||
virtual void FreeRenderingContext();
|
||||
virtual int GetMaxTextureSize();
|
||||
virtual int GetWidth();
|
||||
virtual int GetHeight();
|
||||
virtual float GetAspectRatio();
|
||||
virtual void SetAspectRatio(float value);
|
||||
virtual void PrintErrors();
|
||||
|
||||
virtual void Progress(float position);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
int width;
|
||||
int height;
|
||||
int maxTextureSize;
|
||||
float aspectRatio;
|
||||
HGLRC renderingContext;
|
||||
};
|
||||
10716
demo09/src/demo09/Graphics/glew/glew.h
Normal file
10716
demo09/src/demo09/Graphics/glew/glew.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
demo09/src/demo09/Graphics/glew/glew32.dll
Normal file
BIN
demo09/src/demo09/Graphics/glew/glew32.dll
Normal file
Binary file not shown.
BIN
demo09/src/demo09/Graphics/glew/glew32.lib
Normal file
BIN
demo09/src/demo09/Graphics/glew/glew32.lib
Normal file
Binary file not shown.
998
demo09/src/demo09/Graphics/glew/wglew.h
Normal file
998
demo09/src/demo09/Graphics/glew/wglew.h
Normal file
@@ -0,0 +1,998 @@
|
||||
/*
|
||||
** The OpenGL Extension Wrangler Library
|
||||
** Copyright (C) 2002-2007, Milan Ikits <milan ikits[]ieee org>
|
||||
** Copyright (C) 2002-2007, Marcelo E. Magallon <mmagallo[]debian org>
|
||||
** Copyright (C) 2002, Lev Povalahev
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions are met:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
** * Redistributions in binary form must reproduce the above copyright notice,
|
||||
** this list of conditions and the following disclaimer in the documentation
|
||||
** and/or other materials provided with the distribution.
|
||||
** * The name of the author may be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
** THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __wglew_h__
|
||||
#define __wglew_h__
|
||||
#define __WGLEW_H__
|
||||
|
||||
#ifdef __wglext_h_
|
||||
#error wglext.h included before wglew.h
|
||||
#endif
|
||||
|
||||
#define __wglext_h_
|
||||
|
||||
#if !defined(APIENTRY) && !defined(__CYGWIN__)
|
||||
# ifndef WIN32_LEAN_AND_MEAN
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* GLEW_STATIC needs to be set when using the static version.
|
||||
* GLEW_BUILD is set when building the DLL version.
|
||||
*/
|
||||
#ifdef GLEW_STATIC
|
||||
# define GLEWAPI extern
|
||||
#else
|
||||
# ifdef GLEW_BUILD
|
||||
# define GLEWAPI extern __declspec(dllexport)
|
||||
# else
|
||||
# define GLEWAPI extern __declspec(dllimport)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -------------------------- WGL_3DFX_multisample ------------------------- */
|
||||
|
||||
#ifndef WGL_3DFX_multisample
|
||||
#define WGL_3DFX_multisample 1
|
||||
|
||||
#define WGL_SAMPLE_BUFFERS_3DFX 0x2060
|
||||
#define WGL_SAMPLES_3DFX 0x2061
|
||||
|
||||
#define WGLEW_3DFX_multisample WGLEW_GET_VAR(__WGLEW_3DFX_multisample)
|
||||
|
||||
#endif /* WGL_3DFX_multisample */
|
||||
|
||||
/* ------------------------- WGL_3DL_stereo_control ------------------------ */
|
||||
|
||||
#ifndef WGL_3DL_stereo_control
|
||||
#define WGL_3DL_stereo_control 1
|
||||
|
||||
#define WGL_STEREO_EMITTER_ENABLE_3DL 0x2055
|
||||
#define WGL_STEREO_EMITTER_DISABLE_3DL 0x2056
|
||||
#define WGL_STEREO_POLARITY_NORMAL_3DL 0x2057
|
||||
#define WGL_STEREO_POLARITY_INVERT_3DL 0x2058
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLSETSTEREOEMITTERSTATE3DLPROC) (HDC hDC, UINT uState);
|
||||
|
||||
#define wglSetStereoEmitterState3DL WGLEW_GET_FUN(__wglewSetStereoEmitterState3DL)
|
||||
|
||||
#define WGLEW_3DL_stereo_control WGLEW_GET_VAR(__WGLEW_3DL_stereo_control)
|
||||
|
||||
#endif /* WGL_3DL_stereo_control */
|
||||
|
||||
/* ------------------------- WGL_ARB_buffer_region ------------------------- */
|
||||
|
||||
#ifndef WGL_ARB_buffer_region
|
||||
#define WGL_ARB_buffer_region 1
|
||||
|
||||
#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
|
||||
#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002
|
||||
#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004
|
||||
#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008
|
||||
|
||||
typedef HANDLE (WINAPI * PFNWGLCREATEBUFFERREGIONARBPROC) (HDC hDC, int iLayerPlane, UINT uType);
|
||||
typedef VOID (WINAPI * PFNWGLDELETEBUFFERREGIONARBPROC) (HANDLE hRegion);
|
||||
typedef BOOL (WINAPI * PFNWGLRESTOREBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height, int xSrc, int ySrc);
|
||||
typedef BOOL (WINAPI * PFNWGLSAVEBUFFERREGIONARBPROC) (HANDLE hRegion, int x, int y, int width, int height);
|
||||
|
||||
#define wglCreateBufferRegionARB WGLEW_GET_FUN(__wglewCreateBufferRegionARB)
|
||||
#define wglDeleteBufferRegionARB WGLEW_GET_FUN(__wglewDeleteBufferRegionARB)
|
||||
#define wglRestoreBufferRegionARB WGLEW_GET_FUN(__wglewRestoreBufferRegionARB)
|
||||
#define wglSaveBufferRegionARB WGLEW_GET_FUN(__wglewSaveBufferRegionARB)
|
||||
|
||||
#define WGLEW_ARB_buffer_region WGLEW_GET_VAR(__WGLEW_ARB_buffer_region)
|
||||
|
||||
#endif /* WGL_ARB_buffer_region */
|
||||
|
||||
/* ----------------------- WGL_ARB_extensions_string ----------------------- */
|
||||
|
||||
#ifndef WGL_ARB_extensions_string
|
||||
#define WGL_ARB_extensions_string 1
|
||||
|
||||
typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
|
||||
|
||||
#define wglGetExtensionsStringARB WGLEW_GET_FUN(__wglewGetExtensionsStringARB)
|
||||
|
||||
#define WGLEW_ARB_extensions_string WGLEW_GET_VAR(__WGLEW_ARB_extensions_string)
|
||||
|
||||
#endif /* WGL_ARB_extensions_string */
|
||||
|
||||
/* ----------------------- WGL_ARB_make_current_read ----------------------- */
|
||||
|
||||
#ifndef WGL_ARB_make_current_read
|
||||
#define WGL_ARB_make_current_read 1
|
||||
|
||||
typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCARBPROC) (VOID);
|
||||
typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
|
||||
|
||||
#define wglGetCurrentReadDCARB WGLEW_GET_FUN(__wglewGetCurrentReadDCARB)
|
||||
#define wglMakeContextCurrentARB WGLEW_GET_FUN(__wglewMakeContextCurrentARB)
|
||||
|
||||
#define WGLEW_ARB_make_current_read WGLEW_GET_VAR(__WGLEW_ARB_make_current_read)
|
||||
|
||||
#endif /* WGL_ARB_make_current_read */
|
||||
|
||||
/* -------------------------- WGL_ARB_multisample -------------------------- */
|
||||
|
||||
#ifndef WGL_ARB_multisample
|
||||
#define WGL_ARB_multisample 1
|
||||
|
||||
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
|
||||
#define WGL_SAMPLES_ARB 0x2042
|
||||
|
||||
#define WGLEW_ARB_multisample WGLEW_GET_VAR(__WGLEW_ARB_multisample)
|
||||
|
||||
#endif /* WGL_ARB_multisample */
|
||||
|
||||
/* ---------------------------- WGL_ARB_pbuffer ---------------------------- */
|
||||
|
||||
#ifndef WGL_ARB_pbuffer
|
||||
#define WGL_ARB_pbuffer 1
|
||||
|
||||
#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
|
||||
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
|
||||
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
|
||||
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
|
||||
#define WGL_PBUFFER_LARGEST_ARB 0x2033
|
||||
#define WGL_PBUFFER_WIDTH_ARB 0x2034
|
||||
#define WGL_PBUFFER_HEIGHT_ARB 0x2035
|
||||
#define WGL_PBUFFER_LOST_ARB 0x2036
|
||||
|
||||
DECLARE_HANDLE(HPBUFFERARB);
|
||||
|
||||
typedef HPBUFFERARB (WINAPI * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList);
|
||||
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERARBPROC) (HPBUFFERARB hPbuffer);
|
||||
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYPBUFFERARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int* piValue);
|
||||
typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCARBPROC) (HPBUFFERARB hPbuffer, HDC hDC);
|
||||
|
||||
#define wglCreatePbufferARB WGLEW_GET_FUN(__wglewCreatePbufferARB)
|
||||
#define wglDestroyPbufferARB WGLEW_GET_FUN(__wglewDestroyPbufferARB)
|
||||
#define wglGetPbufferDCARB WGLEW_GET_FUN(__wglewGetPbufferDCARB)
|
||||
#define wglQueryPbufferARB WGLEW_GET_FUN(__wglewQueryPbufferARB)
|
||||
#define wglReleasePbufferDCARB WGLEW_GET_FUN(__wglewReleasePbufferDCARB)
|
||||
|
||||
#define WGLEW_ARB_pbuffer WGLEW_GET_VAR(__WGLEW_ARB_pbuffer)
|
||||
|
||||
#endif /* WGL_ARB_pbuffer */
|
||||
|
||||
/* -------------------------- WGL_ARB_pixel_format ------------------------- */
|
||||
|
||||
#ifndef WGL_ARB_pixel_format
|
||||
#define WGL_ARB_pixel_format 1
|
||||
|
||||
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
|
||||
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
|
||||
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
|
||||
#define WGL_ACCELERATION_ARB 0x2003
|
||||
#define WGL_NEED_PALETTE_ARB 0x2004
|
||||
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
|
||||
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
|
||||
#define WGL_SWAP_METHOD_ARB 0x2007
|
||||
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
|
||||
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
|
||||
#define WGL_TRANSPARENT_ARB 0x200A
|
||||
#define WGL_SHARE_DEPTH_ARB 0x200C
|
||||
#define WGL_SHARE_STENCIL_ARB 0x200D
|
||||
#define WGL_SHARE_ACCUM_ARB 0x200E
|
||||
#define WGL_SUPPORT_GDI_ARB 0x200F
|
||||
#define WGL_SUPPORT_OPENGL_ARB 0x2010
|
||||
#define WGL_DOUBLE_BUFFER_ARB 0x2011
|
||||
#define WGL_STEREO_ARB 0x2012
|
||||
#define WGL_PIXEL_TYPE_ARB 0x2013
|
||||
#define WGL_COLOR_BITS_ARB 0x2014
|
||||
#define WGL_RED_BITS_ARB 0x2015
|
||||
#define WGL_RED_SHIFT_ARB 0x2016
|
||||
#define WGL_GREEN_BITS_ARB 0x2017
|
||||
#define WGL_GREEN_SHIFT_ARB 0x2018
|
||||
#define WGL_BLUE_BITS_ARB 0x2019
|
||||
#define WGL_BLUE_SHIFT_ARB 0x201A
|
||||
#define WGL_ALPHA_BITS_ARB 0x201B
|
||||
#define WGL_ALPHA_SHIFT_ARB 0x201C
|
||||
#define WGL_ACCUM_BITS_ARB 0x201D
|
||||
#define WGL_ACCUM_RED_BITS_ARB 0x201E
|
||||
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
|
||||
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
|
||||
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
|
||||
#define WGL_DEPTH_BITS_ARB 0x2022
|
||||
#define WGL_STENCIL_BITS_ARB 0x2023
|
||||
#define WGL_AUX_BUFFERS_ARB 0x2024
|
||||
#define WGL_NO_ACCELERATION_ARB 0x2025
|
||||
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
|
||||
#define WGL_FULL_ACCELERATION_ARB 0x2027
|
||||
#define WGL_SWAP_EXCHANGE_ARB 0x2028
|
||||
#define WGL_SWAP_COPY_ARB 0x2029
|
||||
#define WGL_SWAP_UNDEFINED_ARB 0x202A
|
||||
#define WGL_TYPE_RGBA_ARB 0x202B
|
||||
#define WGL_TYPE_COLORINDEX_ARB 0x202C
|
||||
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
|
||||
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
|
||||
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
|
||||
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
|
||||
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, FLOAT *pfValues);
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int* piAttributes, int *piValues);
|
||||
|
||||
#define wglChoosePixelFormatARB WGLEW_GET_FUN(__wglewChoosePixelFormatARB)
|
||||
#define wglGetPixelFormatAttribfvARB WGLEW_GET_FUN(__wglewGetPixelFormatAttribfvARB)
|
||||
#define wglGetPixelFormatAttribivARB WGLEW_GET_FUN(__wglewGetPixelFormatAttribivARB)
|
||||
|
||||
#define WGLEW_ARB_pixel_format WGLEW_GET_VAR(__WGLEW_ARB_pixel_format)
|
||||
|
||||
#endif /* WGL_ARB_pixel_format */
|
||||
|
||||
/* ----------------------- WGL_ARB_pixel_format_float ---------------------- */
|
||||
|
||||
#ifndef WGL_ARB_pixel_format_float
|
||||
#define WGL_ARB_pixel_format_float 1
|
||||
|
||||
#define WGL_TYPE_RGBA_FLOAT_ARB 0x21A0
|
||||
|
||||
#define WGLEW_ARB_pixel_format_float WGLEW_GET_VAR(__WGLEW_ARB_pixel_format_float)
|
||||
|
||||
#endif /* WGL_ARB_pixel_format_float */
|
||||
|
||||
/* ------------------------- WGL_ARB_render_texture ------------------------ */
|
||||
|
||||
#ifndef WGL_ARB_render_texture
|
||||
#define WGL_ARB_render_texture 1
|
||||
|
||||
#define WGL_BIND_TO_TEXTURE_RGB_ARB 0x2070
|
||||
#define WGL_BIND_TO_TEXTURE_RGBA_ARB 0x2071
|
||||
#define WGL_TEXTURE_FORMAT_ARB 0x2072
|
||||
#define WGL_TEXTURE_TARGET_ARB 0x2073
|
||||
#define WGL_MIPMAP_TEXTURE_ARB 0x2074
|
||||
#define WGL_TEXTURE_RGB_ARB 0x2075
|
||||
#define WGL_TEXTURE_RGBA_ARB 0x2076
|
||||
#define WGL_NO_TEXTURE_ARB 0x2077
|
||||
#define WGL_TEXTURE_CUBE_MAP_ARB 0x2078
|
||||
#define WGL_TEXTURE_1D_ARB 0x2079
|
||||
#define WGL_TEXTURE_2D_ARB 0x207A
|
||||
#define WGL_MIPMAP_LEVEL_ARB 0x207B
|
||||
#define WGL_CUBE_MAP_FACE_ARB 0x207C
|
||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB 0x207D
|
||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB 0x207E
|
||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB 0x207F
|
||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB 0x2080
|
||||
#define WGL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB 0x2081
|
||||
#define WGL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB 0x2082
|
||||
#define WGL_FRONT_LEFT_ARB 0x2083
|
||||
#define WGL_FRONT_RIGHT_ARB 0x2084
|
||||
#define WGL_BACK_LEFT_ARB 0x2085
|
||||
#define WGL_BACK_RIGHT_ARB 0x2086
|
||||
#define WGL_AUX0_ARB 0x2087
|
||||
#define WGL_AUX1_ARB 0x2088
|
||||
#define WGL_AUX2_ARB 0x2089
|
||||
#define WGL_AUX3_ARB 0x208A
|
||||
#define WGL_AUX4_ARB 0x208B
|
||||
#define WGL_AUX5_ARB 0x208C
|
||||
#define WGL_AUX6_ARB 0x208D
|
||||
#define WGL_AUX7_ARB 0x208E
|
||||
#define WGL_AUX8_ARB 0x208F
|
||||
#define WGL_AUX9_ARB 0x2090
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLBINDTEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASETEXIMAGEARBPROC) (HPBUFFERARB hPbuffer, int iBuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLSETPBUFFERATTRIBARBPROC) (HPBUFFERARB hPbuffer, const int* piAttribList);
|
||||
|
||||
#define wglBindTexImageARB WGLEW_GET_FUN(__wglewBindTexImageARB)
|
||||
#define wglReleaseTexImageARB WGLEW_GET_FUN(__wglewReleaseTexImageARB)
|
||||
#define wglSetPbufferAttribARB WGLEW_GET_FUN(__wglewSetPbufferAttribARB)
|
||||
|
||||
#define WGLEW_ARB_render_texture WGLEW_GET_VAR(__WGLEW_ARB_render_texture)
|
||||
|
||||
#endif /* WGL_ARB_render_texture */
|
||||
|
||||
/* ----------------------- WGL_ATI_pixel_format_float ---------------------- */
|
||||
|
||||
#ifndef WGL_ATI_pixel_format_float
|
||||
#define WGL_ATI_pixel_format_float 1
|
||||
|
||||
#define WGL_TYPE_RGBA_FLOAT_ATI 0x21A0
|
||||
#define GL_RGBA_FLOAT_MODE_ATI 0x8820
|
||||
#define GL_COLOR_CLEAR_UNCLAMPED_VALUE_ATI 0x8835
|
||||
|
||||
#define WGLEW_ATI_pixel_format_float WGLEW_GET_VAR(__WGLEW_ATI_pixel_format_float)
|
||||
|
||||
#endif /* WGL_ATI_pixel_format_float */
|
||||
|
||||
/* -------------------- WGL_ATI_render_texture_rectangle ------------------- */
|
||||
|
||||
#ifndef WGL_ATI_render_texture_rectangle
|
||||
#define WGL_ATI_render_texture_rectangle 1
|
||||
|
||||
#define WGL_TEXTURE_RECTANGLE_ATI 0x21A5
|
||||
|
||||
#define WGLEW_ATI_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_ATI_render_texture_rectangle)
|
||||
|
||||
#endif /* WGL_ATI_render_texture_rectangle */
|
||||
|
||||
/* -------------------------- WGL_EXT_depth_float -------------------------- */
|
||||
|
||||
#ifndef WGL_EXT_depth_float
|
||||
#define WGL_EXT_depth_float 1
|
||||
|
||||
#define WGL_DEPTH_FLOAT_EXT 0x2040
|
||||
|
||||
#define WGLEW_EXT_depth_float WGLEW_GET_VAR(__WGLEW_EXT_depth_float)
|
||||
|
||||
#endif /* WGL_EXT_depth_float */
|
||||
|
||||
/* ---------------------- WGL_EXT_display_color_table ---------------------- */
|
||||
|
||||
#ifndef WGL_EXT_display_color_table
|
||||
#define WGL_EXT_display_color_table 1
|
||||
|
||||
typedef GLboolean (WINAPI * PFNWGLBINDDISPLAYCOLORTABLEEXTPROC) (GLushort id);
|
||||
typedef GLboolean (WINAPI * PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC) (GLushort id);
|
||||
typedef void (WINAPI * PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC) (GLushort id);
|
||||
typedef GLboolean (WINAPI * PFNWGLLOADDISPLAYCOLORTABLEEXTPROC) (GLushort* table, GLuint length);
|
||||
|
||||
#define wglBindDisplayColorTableEXT WGLEW_GET_FUN(__wglewBindDisplayColorTableEXT)
|
||||
#define wglCreateDisplayColorTableEXT WGLEW_GET_FUN(__wglewCreateDisplayColorTableEXT)
|
||||
#define wglDestroyDisplayColorTableEXT WGLEW_GET_FUN(__wglewDestroyDisplayColorTableEXT)
|
||||
#define wglLoadDisplayColorTableEXT WGLEW_GET_FUN(__wglewLoadDisplayColorTableEXT)
|
||||
|
||||
#define WGLEW_EXT_display_color_table WGLEW_GET_VAR(__WGLEW_EXT_display_color_table)
|
||||
|
||||
#endif /* WGL_EXT_display_color_table */
|
||||
|
||||
/* ----------------------- WGL_EXT_extensions_string ----------------------- */
|
||||
|
||||
#ifndef WGL_EXT_extensions_string
|
||||
#define WGL_EXT_extensions_string 1
|
||||
|
||||
typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGEXTPROC) (void);
|
||||
|
||||
#define wglGetExtensionsStringEXT WGLEW_GET_FUN(__wglewGetExtensionsStringEXT)
|
||||
|
||||
#define WGLEW_EXT_extensions_string WGLEW_GET_VAR(__WGLEW_EXT_extensions_string)
|
||||
|
||||
#endif /* WGL_EXT_extensions_string */
|
||||
|
||||
/* ------------------------ WGL_EXT_framebuffer_sRGB ----------------------- */
|
||||
|
||||
#ifndef WGL_EXT_framebuffer_sRGB
|
||||
#define WGL_EXT_framebuffer_sRGB 1
|
||||
|
||||
#define WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT 0x20A9
|
||||
|
||||
#define WGLEW_EXT_framebuffer_sRGB WGLEW_GET_VAR(__WGLEW_EXT_framebuffer_sRGB)
|
||||
|
||||
#endif /* WGL_EXT_framebuffer_sRGB */
|
||||
|
||||
/* ----------------------- WGL_EXT_make_current_read ----------------------- */
|
||||
|
||||
#ifndef WGL_EXT_make_current_read
|
||||
#define WGL_EXT_make_current_read 1
|
||||
|
||||
typedef HDC (WINAPI * PFNWGLGETCURRENTREADDCEXTPROC) (VOID);
|
||||
typedef BOOL (WINAPI * PFNWGLMAKECONTEXTCURRENTEXTPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc);
|
||||
|
||||
#define wglGetCurrentReadDCEXT WGLEW_GET_FUN(__wglewGetCurrentReadDCEXT)
|
||||
#define wglMakeContextCurrentEXT WGLEW_GET_FUN(__wglewMakeContextCurrentEXT)
|
||||
|
||||
#define WGLEW_EXT_make_current_read WGLEW_GET_VAR(__WGLEW_EXT_make_current_read)
|
||||
|
||||
#endif /* WGL_EXT_make_current_read */
|
||||
|
||||
/* -------------------------- WGL_EXT_multisample -------------------------- */
|
||||
|
||||
#ifndef WGL_EXT_multisample
|
||||
#define WGL_EXT_multisample 1
|
||||
|
||||
#define WGL_SAMPLE_BUFFERS_EXT 0x2041
|
||||
#define WGL_SAMPLES_EXT 0x2042
|
||||
|
||||
#define WGLEW_EXT_multisample WGLEW_GET_VAR(__WGLEW_EXT_multisample)
|
||||
|
||||
#endif /* WGL_EXT_multisample */
|
||||
|
||||
/* ---------------------------- WGL_EXT_pbuffer ---------------------------- */
|
||||
|
||||
#ifndef WGL_EXT_pbuffer
|
||||
#define WGL_EXT_pbuffer 1
|
||||
|
||||
#define WGL_DRAW_TO_PBUFFER_EXT 0x202D
|
||||
#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E
|
||||
#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F
|
||||
#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030
|
||||
#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031
|
||||
#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032
|
||||
#define WGL_PBUFFER_LARGEST_EXT 0x2033
|
||||
#define WGL_PBUFFER_WIDTH_EXT 0x2034
|
||||
#define WGL_PBUFFER_HEIGHT_EXT 0x2035
|
||||
|
||||
DECLARE_HANDLE(HPBUFFEREXT);
|
||||
|
||||
typedef HPBUFFEREXT (WINAPI * PFNWGLCREATEPBUFFEREXTPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList);
|
||||
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer);
|
||||
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYPBUFFEREXTPROC) (HPBUFFEREXT hPbuffer, int iAttribute, int* piValue);
|
||||
typedef int (WINAPI * PFNWGLRELEASEPBUFFERDCEXTPROC) (HPBUFFEREXT hPbuffer, HDC hDC);
|
||||
|
||||
#define wglCreatePbufferEXT WGLEW_GET_FUN(__wglewCreatePbufferEXT)
|
||||
#define wglDestroyPbufferEXT WGLEW_GET_FUN(__wglewDestroyPbufferEXT)
|
||||
#define wglGetPbufferDCEXT WGLEW_GET_FUN(__wglewGetPbufferDCEXT)
|
||||
#define wglQueryPbufferEXT WGLEW_GET_FUN(__wglewQueryPbufferEXT)
|
||||
#define wglReleasePbufferDCEXT WGLEW_GET_FUN(__wglewReleasePbufferDCEXT)
|
||||
|
||||
#define WGLEW_EXT_pbuffer WGLEW_GET_VAR(__WGLEW_EXT_pbuffer)
|
||||
|
||||
#endif /* WGL_EXT_pbuffer */
|
||||
|
||||
/* -------------------------- WGL_EXT_pixel_format ------------------------- */
|
||||
|
||||
#ifndef WGL_EXT_pixel_format
|
||||
#define WGL_EXT_pixel_format 1
|
||||
|
||||
#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000
|
||||
#define WGL_DRAW_TO_WINDOW_EXT 0x2001
|
||||
#define WGL_DRAW_TO_BITMAP_EXT 0x2002
|
||||
#define WGL_ACCELERATION_EXT 0x2003
|
||||
#define WGL_NEED_PALETTE_EXT 0x2004
|
||||
#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005
|
||||
#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006
|
||||
#define WGL_SWAP_METHOD_EXT 0x2007
|
||||
#define WGL_NUMBER_OVERLAYS_EXT 0x2008
|
||||
#define WGL_NUMBER_UNDERLAYS_EXT 0x2009
|
||||
#define WGL_TRANSPARENT_EXT 0x200A
|
||||
#define WGL_TRANSPARENT_VALUE_EXT 0x200B
|
||||
#define WGL_SHARE_DEPTH_EXT 0x200C
|
||||
#define WGL_SHARE_STENCIL_EXT 0x200D
|
||||
#define WGL_SHARE_ACCUM_EXT 0x200E
|
||||
#define WGL_SUPPORT_GDI_EXT 0x200F
|
||||
#define WGL_SUPPORT_OPENGL_EXT 0x2010
|
||||
#define WGL_DOUBLE_BUFFER_EXT 0x2011
|
||||
#define WGL_STEREO_EXT 0x2012
|
||||
#define WGL_PIXEL_TYPE_EXT 0x2013
|
||||
#define WGL_COLOR_BITS_EXT 0x2014
|
||||
#define WGL_RED_BITS_EXT 0x2015
|
||||
#define WGL_RED_SHIFT_EXT 0x2016
|
||||
#define WGL_GREEN_BITS_EXT 0x2017
|
||||
#define WGL_GREEN_SHIFT_EXT 0x2018
|
||||
#define WGL_BLUE_BITS_EXT 0x2019
|
||||
#define WGL_BLUE_SHIFT_EXT 0x201A
|
||||
#define WGL_ALPHA_BITS_EXT 0x201B
|
||||
#define WGL_ALPHA_SHIFT_EXT 0x201C
|
||||
#define WGL_ACCUM_BITS_EXT 0x201D
|
||||
#define WGL_ACCUM_RED_BITS_EXT 0x201E
|
||||
#define WGL_ACCUM_GREEN_BITS_EXT 0x201F
|
||||
#define WGL_ACCUM_BLUE_BITS_EXT 0x2020
|
||||
#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021
|
||||
#define WGL_DEPTH_BITS_EXT 0x2022
|
||||
#define WGL_STENCIL_BITS_EXT 0x2023
|
||||
#define WGL_AUX_BUFFERS_EXT 0x2024
|
||||
#define WGL_NO_ACCELERATION_EXT 0x2025
|
||||
#define WGL_GENERIC_ACCELERATION_EXT 0x2026
|
||||
#define WGL_FULL_ACCELERATION_EXT 0x2027
|
||||
#define WGL_SWAP_EXCHANGE_EXT 0x2028
|
||||
#define WGL_SWAP_COPY_EXT 0x2029
|
||||
#define WGL_SWAP_UNDEFINED_EXT 0x202A
|
||||
#define WGL_TYPE_RGBA_EXT 0x202B
|
||||
#define WGL_TYPE_COLORINDEX_EXT 0x202C
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATEXTPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBFVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, FLOAT *pfValues);
|
||||
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVEXTPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues);
|
||||
|
||||
#define wglChoosePixelFormatEXT WGLEW_GET_FUN(__wglewChoosePixelFormatEXT)
|
||||
#define wglGetPixelFormatAttribfvEXT WGLEW_GET_FUN(__wglewGetPixelFormatAttribfvEXT)
|
||||
#define wglGetPixelFormatAttribivEXT WGLEW_GET_FUN(__wglewGetPixelFormatAttribivEXT)
|
||||
|
||||
#define WGLEW_EXT_pixel_format WGLEW_GET_VAR(__WGLEW_EXT_pixel_format)
|
||||
|
||||
#endif /* WGL_EXT_pixel_format */
|
||||
|
||||
/* ------------------- WGL_EXT_pixel_format_packed_float ------------------- */
|
||||
|
||||
#ifndef WGL_EXT_pixel_format_packed_float
|
||||
#define WGL_EXT_pixel_format_packed_float 1
|
||||
|
||||
#define WGL_TYPE_RGBA_UNSIGNED_FLOAT_EXT 0x20A8
|
||||
|
||||
#define WGLEW_EXT_pixel_format_packed_float WGLEW_GET_VAR(__WGLEW_EXT_pixel_format_packed_float)
|
||||
|
||||
#endif /* WGL_EXT_pixel_format_packed_float */
|
||||
|
||||
/* -------------------------- WGL_EXT_swap_control ------------------------- */
|
||||
|
||||
#ifndef WGL_EXT_swap_control
|
||||
#define WGL_EXT_swap_control 1
|
||||
|
||||
typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
|
||||
|
||||
#define wglGetSwapIntervalEXT WGLEW_GET_FUN(__wglewGetSwapIntervalEXT)
|
||||
#define wglSwapIntervalEXT WGLEW_GET_FUN(__wglewSwapIntervalEXT)
|
||||
|
||||
#define WGLEW_EXT_swap_control WGLEW_GET_VAR(__WGLEW_EXT_swap_control)
|
||||
|
||||
#endif /* WGL_EXT_swap_control */
|
||||
|
||||
/* --------------------- WGL_I3D_digital_video_control --------------------- */
|
||||
|
||||
#ifndef WGL_I3D_digital_video_control
|
||||
#define WGL_I3D_digital_video_control 1
|
||||
|
||||
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050
|
||||
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051
|
||||
#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052
|
||||
#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int* piValue);
|
||||
typedef BOOL (WINAPI * PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int* piValue);
|
||||
|
||||
#define wglGetDigitalVideoParametersI3D WGLEW_GET_FUN(__wglewGetDigitalVideoParametersI3D)
|
||||
#define wglSetDigitalVideoParametersI3D WGLEW_GET_FUN(__wglewSetDigitalVideoParametersI3D)
|
||||
|
||||
#define WGLEW_I3D_digital_video_control WGLEW_GET_VAR(__WGLEW_I3D_digital_video_control)
|
||||
|
||||
#endif /* WGL_I3D_digital_video_control */
|
||||
|
||||
/* ----------------------------- WGL_I3D_gamma ----------------------------- */
|
||||
|
||||
#ifndef WGL_I3D_gamma
|
||||
#define WGL_I3D_gamma 1
|
||||
|
||||
#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E
|
||||
#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, USHORT* puRed, USHORT *puGreen, USHORT *puBlue);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, int* piValue);
|
||||
typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEI3DPROC) (HDC hDC, int iEntries, const USHORT* puRed, const USHORT *puGreen, const USHORT *puBlue);
|
||||
typedef BOOL (WINAPI * PFNWGLSETGAMMATABLEPARAMETERSI3DPROC) (HDC hDC, int iAttribute, const int* piValue);
|
||||
|
||||
#define wglGetGammaTableI3D WGLEW_GET_FUN(__wglewGetGammaTableI3D)
|
||||
#define wglGetGammaTableParametersI3D WGLEW_GET_FUN(__wglewGetGammaTableParametersI3D)
|
||||
#define wglSetGammaTableI3D WGLEW_GET_FUN(__wglewSetGammaTableI3D)
|
||||
#define wglSetGammaTableParametersI3D WGLEW_GET_FUN(__wglewSetGammaTableParametersI3D)
|
||||
|
||||
#define WGLEW_I3D_gamma WGLEW_GET_VAR(__WGLEW_I3D_gamma)
|
||||
|
||||
#endif /* WGL_I3D_gamma */
|
||||
|
||||
/* ---------------------------- WGL_I3D_genlock ---------------------------- */
|
||||
|
||||
#ifndef WGL_I3D_genlock
|
||||
#define WGL_I3D_genlock 1
|
||||
|
||||
#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044
|
||||
#define WGL_GENLOCK_SOURCE_EXTERNAL_SYNC_I3D 0x2045
|
||||
#define WGL_GENLOCK_SOURCE_EXTERNAL_FIELD_I3D 0x2046
|
||||
#define WGL_GENLOCK_SOURCE_EXTERNAL_TTL_I3D 0x2047
|
||||
#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048
|
||||
#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049
|
||||
#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A
|
||||
#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B
|
||||
#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLDISABLEGENLOCKI3DPROC) (HDC hDC);
|
||||
typedef BOOL (WINAPI * PFNWGLENABLEGENLOCKI3DPROC) (HDC hDC);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT uRate);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT uDelay);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT uEdge);
|
||||
typedef BOOL (WINAPI * PFNWGLGENLOCKSOURCEI3DPROC) (HDC hDC, UINT uSource);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSAMPLERATEI3DPROC) (HDC hDC, UINT* uRate);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEDELAYI3DPROC) (HDC hDC, UINT* uDelay);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEEDGEI3DPROC) (HDC hDC, UINT* uEdge);
|
||||
typedef BOOL (WINAPI * PFNWGLGETGENLOCKSOURCEI3DPROC) (HDC hDC, UINT* uSource);
|
||||
typedef BOOL (WINAPI * PFNWGLISENABLEDGENLOCKI3DPROC) (HDC hDC, BOOL* pFlag);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC) (HDC hDC, UINT* uMaxLineDelay, UINT *uMaxPixelDelay);
|
||||
|
||||
#define wglDisableGenlockI3D WGLEW_GET_FUN(__wglewDisableGenlockI3D)
|
||||
#define wglEnableGenlockI3D WGLEW_GET_FUN(__wglewEnableGenlockI3D)
|
||||
#define wglGenlockSampleRateI3D WGLEW_GET_FUN(__wglewGenlockSampleRateI3D)
|
||||
#define wglGenlockSourceDelayI3D WGLEW_GET_FUN(__wglewGenlockSourceDelayI3D)
|
||||
#define wglGenlockSourceEdgeI3D WGLEW_GET_FUN(__wglewGenlockSourceEdgeI3D)
|
||||
#define wglGenlockSourceI3D WGLEW_GET_FUN(__wglewGenlockSourceI3D)
|
||||
#define wglGetGenlockSampleRateI3D WGLEW_GET_FUN(__wglewGetGenlockSampleRateI3D)
|
||||
#define wglGetGenlockSourceDelayI3D WGLEW_GET_FUN(__wglewGetGenlockSourceDelayI3D)
|
||||
#define wglGetGenlockSourceEdgeI3D WGLEW_GET_FUN(__wglewGetGenlockSourceEdgeI3D)
|
||||
#define wglGetGenlockSourceI3D WGLEW_GET_FUN(__wglewGetGenlockSourceI3D)
|
||||
#define wglIsEnabledGenlockI3D WGLEW_GET_FUN(__wglewIsEnabledGenlockI3D)
|
||||
#define wglQueryGenlockMaxSourceDelayI3D WGLEW_GET_FUN(__wglewQueryGenlockMaxSourceDelayI3D)
|
||||
|
||||
#define WGLEW_I3D_genlock WGLEW_GET_VAR(__WGLEW_I3D_genlock)
|
||||
|
||||
#endif /* WGL_I3D_genlock */
|
||||
|
||||
/* -------------------------- WGL_I3D_image_buffer ------------------------- */
|
||||
|
||||
#ifndef WGL_I3D_image_buffer
|
||||
#define WGL_I3D_image_buffer 1
|
||||
|
||||
#define WGL_IMAGE_BUFFER_MIN_ACCESS_I3D 0x00000001
|
||||
#define WGL_IMAGE_BUFFER_LOCK_I3D 0x00000002
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC) (HDC hdc, HANDLE* pEvent, LPVOID *pAddress, DWORD *pSize, UINT count);
|
||||
typedef LPVOID (WINAPI * PFNWGLCREATEIMAGEBUFFERI3DPROC) (HDC hDC, DWORD dwSize, UINT uFlags);
|
||||
typedef BOOL (WINAPI * PFNWGLDESTROYIMAGEBUFFERI3DPROC) (HDC hDC, LPVOID pAddress);
|
||||
typedef BOOL (WINAPI * PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC) (HDC hdc, LPVOID* pAddress, UINT count);
|
||||
|
||||
#define wglAssociateImageBufferEventsI3D WGLEW_GET_FUN(__wglewAssociateImageBufferEventsI3D)
|
||||
#define wglCreateImageBufferI3D WGLEW_GET_FUN(__wglewCreateImageBufferI3D)
|
||||
#define wglDestroyImageBufferI3D WGLEW_GET_FUN(__wglewDestroyImageBufferI3D)
|
||||
#define wglReleaseImageBufferEventsI3D WGLEW_GET_FUN(__wglewReleaseImageBufferEventsI3D)
|
||||
|
||||
#define WGLEW_I3D_image_buffer WGLEW_GET_VAR(__WGLEW_I3D_image_buffer)
|
||||
|
||||
#endif /* WGL_I3D_image_buffer */
|
||||
|
||||
/* ------------------------ WGL_I3D_swap_frame_lock ------------------------ */
|
||||
|
||||
#ifndef WGL_I3D_swap_frame_lock
|
||||
#define WGL_I3D_swap_frame_lock 1
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLDISABLEFRAMELOCKI3DPROC) (VOID);
|
||||
typedef BOOL (WINAPI * PFNWGLENABLEFRAMELOCKI3DPROC) (VOID);
|
||||
typedef BOOL (WINAPI * PFNWGLISENABLEDFRAMELOCKI3DPROC) (BOOL* pFlag);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYFRAMELOCKMASTERI3DPROC) (BOOL* pFlag);
|
||||
|
||||
#define wglDisableFrameLockI3D WGLEW_GET_FUN(__wglewDisableFrameLockI3D)
|
||||
#define wglEnableFrameLockI3D WGLEW_GET_FUN(__wglewEnableFrameLockI3D)
|
||||
#define wglIsEnabledFrameLockI3D WGLEW_GET_FUN(__wglewIsEnabledFrameLockI3D)
|
||||
#define wglQueryFrameLockMasterI3D WGLEW_GET_FUN(__wglewQueryFrameLockMasterI3D)
|
||||
|
||||
#define WGLEW_I3D_swap_frame_lock WGLEW_GET_VAR(__WGLEW_I3D_swap_frame_lock)
|
||||
|
||||
#endif /* WGL_I3D_swap_frame_lock */
|
||||
|
||||
/* ------------------------ WGL_I3D_swap_frame_usage ----------------------- */
|
||||
|
||||
#ifndef WGL_I3D_swap_frame_usage
|
||||
#define WGL_I3D_swap_frame_usage 1
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLBEGINFRAMETRACKINGI3DPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLENDFRAMETRACKINGI3DPROC) (void);
|
||||
typedef BOOL (WINAPI * PFNWGLGETFRAMEUSAGEI3DPROC) (float* pUsage);
|
||||
typedef BOOL (WINAPI * PFNWGLQUERYFRAMETRACKINGI3DPROC) (DWORD* pFrameCount, DWORD *pMissedFrames, float *pLastMissedUsage);
|
||||
|
||||
#define wglBeginFrameTrackingI3D WGLEW_GET_FUN(__wglewBeginFrameTrackingI3D)
|
||||
#define wglEndFrameTrackingI3D WGLEW_GET_FUN(__wglewEndFrameTrackingI3D)
|
||||
#define wglGetFrameUsageI3D WGLEW_GET_FUN(__wglewGetFrameUsageI3D)
|
||||
#define wglQueryFrameTrackingI3D WGLEW_GET_FUN(__wglewQueryFrameTrackingI3D)
|
||||
|
||||
#define WGLEW_I3D_swap_frame_usage WGLEW_GET_VAR(__WGLEW_I3D_swap_frame_usage)
|
||||
|
||||
#endif /* WGL_I3D_swap_frame_usage */
|
||||
|
||||
/* -------------------------- WGL_NV_float_buffer -------------------------- */
|
||||
|
||||
#ifndef WGL_NV_float_buffer
|
||||
#define WGL_NV_float_buffer 1
|
||||
|
||||
#define WGL_FLOAT_COMPONENTS_NV 0x20B0
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_R_NV 0x20B1
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RG_NV 0x20B2
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGB_NV 0x20B3
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV 0x20B4
|
||||
#define WGL_TEXTURE_FLOAT_R_NV 0x20B5
|
||||
#define WGL_TEXTURE_FLOAT_RG_NV 0x20B6
|
||||
#define WGL_TEXTURE_FLOAT_RGB_NV 0x20B7
|
||||
#define WGL_TEXTURE_FLOAT_RGBA_NV 0x20B8
|
||||
|
||||
#define WGLEW_NV_float_buffer WGLEW_GET_VAR(__WGLEW_NV_float_buffer)
|
||||
|
||||
#endif /* WGL_NV_float_buffer */
|
||||
|
||||
/* -------------------------- WGL_NV_gpu_affinity -------------------------- */
|
||||
|
||||
#ifndef WGL_NV_gpu_affinity
|
||||
#define WGL_NV_gpu_affinity 1
|
||||
|
||||
#define WGL_ERROR_INCOMPATIBLE_AFFINITY_MASKS_NV 0x20D0
|
||||
#define WGL_ERROR_MISSING_AFFINITY_MASK_NV 0x20D1
|
||||
|
||||
DECLARE_HANDLE(HGPUNV);
|
||||
typedef struct _GPU_DEVICE {
|
||||
DWORD cb;
|
||||
CHAR DeviceName[32];
|
||||
CHAR DeviceString[128];
|
||||
DWORD Flags;
|
||||
RECT rcVirtualScreen;
|
||||
} GPU_DEVICE, *PGPU_DEVICE;
|
||||
|
||||
typedef HDC (WINAPI * PFNWGLCREATEAFFINITYDCNVPROC) (const HGPUNV *phGpuList);
|
||||
typedef BOOL (WINAPI * PFNWGLDELETEDCNVPROC) (HDC hdc);
|
||||
typedef BOOL (WINAPI * PFNWGLENUMGPUDEVICESNVPROC) (HGPUNV hGpu, UINT iDeviceIndex, PGPU_DEVICE lpGpuDevice);
|
||||
typedef BOOL (WINAPI * PFNWGLENUMGPUSFROMAFFINITYDCNVPROC) (HDC hAffinityDC, UINT iGpuIndex, HGPUNV *hGpu);
|
||||
typedef BOOL (WINAPI * PFNWGLENUMGPUSNVPROC) (UINT iGpuIndex, HGPUNV *phGpu);
|
||||
|
||||
#define wglCreateAffinityDCNV WGLEW_GET_FUN(__wglewCreateAffinityDCNV)
|
||||
#define wglDeleteDCNV WGLEW_GET_FUN(__wglewDeleteDCNV)
|
||||
#define wglEnumGpuDevicesNV WGLEW_GET_FUN(__wglewEnumGpuDevicesNV)
|
||||
#define wglEnumGpusFromAffinityDCNV WGLEW_GET_FUN(__wglewEnumGpusFromAffinityDCNV)
|
||||
#define wglEnumGpusNV WGLEW_GET_FUN(__wglewEnumGpusNV)
|
||||
|
||||
#define WGLEW_NV_gpu_affinity WGLEW_GET_VAR(__WGLEW_NV_gpu_affinity)
|
||||
|
||||
#endif /* WGL_NV_gpu_affinity */
|
||||
|
||||
/* ---------------------- WGL_NV_render_depth_texture ---------------------- */
|
||||
|
||||
#ifndef WGL_NV_render_depth_texture
|
||||
#define WGL_NV_render_depth_texture 1
|
||||
|
||||
#define WGL_NO_TEXTURE_ARB 0x2077
|
||||
#define WGL_BIND_TO_TEXTURE_DEPTH_NV 0x20A3
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV 0x20A4
|
||||
#define WGL_DEPTH_TEXTURE_FORMAT_NV 0x20A5
|
||||
#define WGL_TEXTURE_DEPTH_COMPONENT_NV 0x20A6
|
||||
#define WGL_DEPTH_COMPONENT_NV 0x20A7
|
||||
|
||||
#define WGLEW_NV_render_depth_texture WGLEW_GET_VAR(__WGLEW_NV_render_depth_texture)
|
||||
|
||||
#endif /* WGL_NV_render_depth_texture */
|
||||
|
||||
/* -------------------- WGL_NV_render_texture_rectangle -------------------- */
|
||||
|
||||
#ifndef WGL_NV_render_texture_rectangle
|
||||
#define WGL_NV_render_texture_rectangle 1
|
||||
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV 0x20A0
|
||||
#define WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV 0x20A1
|
||||
#define WGL_TEXTURE_RECTANGLE_NV 0x20A2
|
||||
|
||||
#define WGLEW_NV_render_texture_rectangle WGLEW_GET_VAR(__WGLEW_NV_render_texture_rectangle)
|
||||
|
||||
#endif /* WGL_NV_render_texture_rectangle */
|
||||
|
||||
/* ----------------------- WGL_NV_vertex_array_range ----------------------- */
|
||||
|
||||
#ifndef WGL_NV_vertex_array_range
|
||||
#define WGL_NV_vertex_array_range 1
|
||||
|
||||
typedef void * (WINAPI * PFNWGLALLOCATEMEMORYNVPROC) (GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority);
|
||||
typedef void (WINAPI * PFNWGLFREEMEMORYNVPROC) (void *pointer);
|
||||
|
||||
#define wglAllocateMemoryNV WGLEW_GET_FUN(__wglewAllocateMemoryNV)
|
||||
#define wglFreeMemoryNV WGLEW_GET_FUN(__wglewFreeMemoryNV)
|
||||
|
||||
#define WGLEW_NV_vertex_array_range WGLEW_GET_VAR(__WGLEW_NV_vertex_array_range)
|
||||
|
||||
#endif /* WGL_NV_vertex_array_range */
|
||||
|
||||
/* -------------------------- WGL_OML_sync_control ------------------------- */
|
||||
|
||||
#ifndef WGL_OML_sync_control
|
||||
#define WGL_OML_sync_control 1
|
||||
|
||||
typedef BOOL (WINAPI * PFNWGLGETMSCRATEOMLPROC) (HDC hdc, INT32* numerator, INT32 *denominator);
|
||||
typedef BOOL (WINAPI * PFNWGLGETSYNCVALUESOMLPROC) (HDC hdc, INT64* ust, INT64 *msc, INT64 *sbc);
|
||||
typedef INT64 (WINAPI * PFNWGLSWAPBUFFERSMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder);
|
||||
typedef INT64 (WINAPI * PFNWGLSWAPLAYERBUFFERSMSCOMLPROC) (HDC hdc, INT fuPlanes, INT64 target_msc, INT64 divisor, INT64 remainder);
|
||||
typedef BOOL (WINAPI * PFNWGLWAITFORMSCOMLPROC) (HDC hdc, INT64 target_msc, INT64 divisor, INT64 remainder, INT64* ust, INT64 *msc, INT64 *sbc);
|
||||
typedef BOOL (WINAPI * PFNWGLWAITFORSBCOMLPROC) (HDC hdc, INT64 target_sbc, INT64* ust, INT64 *msc, INT64 *sbc);
|
||||
|
||||
#define wglGetMscRateOML WGLEW_GET_FUN(__wglewGetMscRateOML)
|
||||
#define wglGetSyncValuesOML WGLEW_GET_FUN(__wglewGetSyncValuesOML)
|
||||
#define wglSwapBuffersMscOML WGLEW_GET_FUN(__wglewSwapBuffersMscOML)
|
||||
#define wglSwapLayerBuffersMscOML WGLEW_GET_FUN(__wglewSwapLayerBuffersMscOML)
|
||||
#define wglWaitForMscOML WGLEW_GET_FUN(__wglewWaitForMscOML)
|
||||
#define wglWaitForSbcOML WGLEW_GET_FUN(__wglewWaitForSbcOML)
|
||||
|
||||
#define WGLEW_OML_sync_control WGLEW_GET_VAR(__WGLEW_OML_sync_control)
|
||||
|
||||
#endif /* WGL_OML_sync_control */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef GLEW_MX
|
||||
#define WGLEW_EXPORT
|
||||
#else
|
||||
#define WGLEW_EXPORT GLEWAPI
|
||||
#endif /* GLEW_MX */
|
||||
|
||||
#ifdef GLEW_MX
|
||||
struct WGLEWContextStruct
|
||||
{
|
||||
#endif /* GLEW_MX */
|
||||
|
||||
WGLEW_EXPORT PFNWGLSETSTEREOEMITTERSTATE3DLPROC __wglewSetStereoEmitterState3DL;
|
||||
|
||||
WGLEW_EXPORT PFNWGLCREATEBUFFERREGIONARBPROC __wglewCreateBufferRegionARB;
|
||||
WGLEW_EXPORT PFNWGLDELETEBUFFERREGIONARBPROC __wglewDeleteBufferRegionARB;
|
||||
WGLEW_EXPORT PFNWGLRESTOREBUFFERREGIONARBPROC __wglewRestoreBufferRegionARB;
|
||||
WGLEW_EXPORT PFNWGLSAVEBUFFERREGIONARBPROC __wglewSaveBufferRegionARB;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETEXTENSIONSSTRINGARBPROC __wglewGetExtensionsStringARB;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETCURRENTREADDCARBPROC __wglewGetCurrentReadDCARB;
|
||||
WGLEW_EXPORT PFNWGLMAKECONTEXTCURRENTARBPROC __wglewMakeContextCurrentARB;
|
||||
|
||||
WGLEW_EXPORT PFNWGLCREATEPBUFFERARBPROC __wglewCreatePbufferARB;
|
||||
WGLEW_EXPORT PFNWGLDESTROYPBUFFERARBPROC __wglewDestroyPbufferARB;
|
||||
WGLEW_EXPORT PFNWGLGETPBUFFERDCARBPROC __wglewGetPbufferDCARB;
|
||||
WGLEW_EXPORT PFNWGLQUERYPBUFFERARBPROC __wglewQueryPbufferARB;
|
||||
WGLEW_EXPORT PFNWGLRELEASEPBUFFERDCARBPROC __wglewReleasePbufferDCARB;
|
||||
|
||||
WGLEW_EXPORT PFNWGLCHOOSEPIXELFORMATARBPROC __wglewChoosePixelFormatARB;
|
||||
WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBFVARBPROC __wglewGetPixelFormatAttribfvARB;
|
||||
WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBIVARBPROC __wglewGetPixelFormatAttribivARB;
|
||||
|
||||
WGLEW_EXPORT PFNWGLBINDTEXIMAGEARBPROC __wglewBindTexImageARB;
|
||||
WGLEW_EXPORT PFNWGLRELEASETEXIMAGEARBPROC __wglewReleaseTexImageARB;
|
||||
WGLEW_EXPORT PFNWGLSETPBUFFERATTRIBARBPROC __wglewSetPbufferAttribARB;
|
||||
|
||||
WGLEW_EXPORT PFNWGLBINDDISPLAYCOLORTABLEEXTPROC __wglewBindDisplayColorTableEXT;
|
||||
WGLEW_EXPORT PFNWGLCREATEDISPLAYCOLORTABLEEXTPROC __wglewCreateDisplayColorTableEXT;
|
||||
WGLEW_EXPORT PFNWGLDESTROYDISPLAYCOLORTABLEEXTPROC __wglewDestroyDisplayColorTableEXT;
|
||||
WGLEW_EXPORT PFNWGLLOADDISPLAYCOLORTABLEEXTPROC __wglewLoadDisplayColorTableEXT;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETEXTENSIONSSTRINGEXTPROC __wglewGetExtensionsStringEXT;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETCURRENTREADDCEXTPROC __wglewGetCurrentReadDCEXT;
|
||||
WGLEW_EXPORT PFNWGLMAKECONTEXTCURRENTEXTPROC __wglewMakeContextCurrentEXT;
|
||||
|
||||
WGLEW_EXPORT PFNWGLCREATEPBUFFEREXTPROC __wglewCreatePbufferEXT;
|
||||
WGLEW_EXPORT PFNWGLDESTROYPBUFFEREXTPROC __wglewDestroyPbufferEXT;
|
||||
WGLEW_EXPORT PFNWGLGETPBUFFERDCEXTPROC __wglewGetPbufferDCEXT;
|
||||
WGLEW_EXPORT PFNWGLQUERYPBUFFEREXTPROC __wglewQueryPbufferEXT;
|
||||
WGLEW_EXPORT PFNWGLRELEASEPBUFFERDCEXTPROC __wglewReleasePbufferDCEXT;
|
||||
|
||||
WGLEW_EXPORT PFNWGLCHOOSEPIXELFORMATEXTPROC __wglewChoosePixelFormatEXT;
|
||||
WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBFVEXTPROC __wglewGetPixelFormatAttribfvEXT;
|
||||
WGLEW_EXPORT PFNWGLGETPIXELFORMATATTRIBIVEXTPROC __wglewGetPixelFormatAttribivEXT;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETSWAPINTERVALEXTPROC __wglewGetSwapIntervalEXT;
|
||||
WGLEW_EXPORT PFNWGLSWAPINTERVALEXTPROC __wglewSwapIntervalEXT;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETDIGITALVIDEOPARAMETERSI3DPROC __wglewGetDigitalVideoParametersI3D;
|
||||
WGLEW_EXPORT PFNWGLSETDIGITALVIDEOPARAMETERSI3DPROC __wglewSetDigitalVideoParametersI3D;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETGAMMATABLEI3DPROC __wglewGetGammaTableI3D;
|
||||
WGLEW_EXPORT PFNWGLGETGAMMATABLEPARAMETERSI3DPROC __wglewGetGammaTableParametersI3D;
|
||||
WGLEW_EXPORT PFNWGLSETGAMMATABLEI3DPROC __wglewSetGammaTableI3D;
|
||||
WGLEW_EXPORT PFNWGLSETGAMMATABLEPARAMETERSI3DPROC __wglewSetGammaTableParametersI3D;
|
||||
|
||||
WGLEW_EXPORT PFNWGLDISABLEGENLOCKI3DPROC __wglewDisableGenlockI3D;
|
||||
WGLEW_EXPORT PFNWGLENABLEGENLOCKI3DPROC __wglewEnableGenlockI3D;
|
||||
WGLEW_EXPORT PFNWGLGENLOCKSAMPLERATEI3DPROC __wglewGenlockSampleRateI3D;
|
||||
WGLEW_EXPORT PFNWGLGENLOCKSOURCEDELAYI3DPROC __wglewGenlockSourceDelayI3D;
|
||||
WGLEW_EXPORT PFNWGLGENLOCKSOURCEEDGEI3DPROC __wglewGenlockSourceEdgeI3D;
|
||||
WGLEW_EXPORT PFNWGLGENLOCKSOURCEI3DPROC __wglewGenlockSourceI3D;
|
||||
WGLEW_EXPORT PFNWGLGETGENLOCKSAMPLERATEI3DPROC __wglewGetGenlockSampleRateI3D;
|
||||
WGLEW_EXPORT PFNWGLGETGENLOCKSOURCEDELAYI3DPROC __wglewGetGenlockSourceDelayI3D;
|
||||
WGLEW_EXPORT PFNWGLGETGENLOCKSOURCEEDGEI3DPROC __wglewGetGenlockSourceEdgeI3D;
|
||||
WGLEW_EXPORT PFNWGLGETGENLOCKSOURCEI3DPROC __wglewGetGenlockSourceI3D;
|
||||
WGLEW_EXPORT PFNWGLISENABLEDGENLOCKI3DPROC __wglewIsEnabledGenlockI3D;
|
||||
WGLEW_EXPORT PFNWGLQUERYGENLOCKMAXSOURCEDELAYI3DPROC __wglewQueryGenlockMaxSourceDelayI3D;
|
||||
|
||||
WGLEW_EXPORT PFNWGLASSOCIATEIMAGEBUFFEREVENTSI3DPROC __wglewAssociateImageBufferEventsI3D;
|
||||
WGLEW_EXPORT PFNWGLCREATEIMAGEBUFFERI3DPROC __wglewCreateImageBufferI3D;
|
||||
WGLEW_EXPORT PFNWGLDESTROYIMAGEBUFFERI3DPROC __wglewDestroyImageBufferI3D;
|
||||
WGLEW_EXPORT PFNWGLRELEASEIMAGEBUFFEREVENTSI3DPROC __wglewReleaseImageBufferEventsI3D;
|
||||
|
||||
WGLEW_EXPORT PFNWGLDISABLEFRAMELOCKI3DPROC __wglewDisableFrameLockI3D;
|
||||
WGLEW_EXPORT PFNWGLENABLEFRAMELOCKI3DPROC __wglewEnableFrameLockI3D;
|
||||
WGLEW_EXPORT PFNWGLISENABLEDFRAMELOCKI3DPROC __wglewIsEnabledFrameLockI3D;
|
||||
WGLEW_EXPORT PFNWGLQUERYFRAMELOCKMASTERI3DPROC __wglewQueryFrameLockMasterI3D;
|
||||
|
||||
WGLEW_EXPORT PFNWGLBEGINFRAMETRACKINGI3DPROC __wglewBeginFrameTrackingI3D;
|
||||
WGLEW_EXPORT PFNWGLENDFRAMETRACKINGI3DPROC __wglewEndFrameTrackingI3D;
|
||||
WGLEW_EXPORT PFNWGLGETFRAMEUSAGEI3DPROC __wglewGetFrameUsageI3D;
|
||||
WGLEW_EXPORT PFNWGLQUERYFRAMETRACKINGI3DPROC __wglewQueryFrameTrackingI3D;
|
||||
|
||||
WGLEW_EXPORT PFNWGLCREATEAFFINITYDCNVPROC __wglewCreateAffinityDCNV;
|
||||
WGLEW_EXPORT PFNWGLDELETEDCNVPROC __wglewDeleteDCNV;
|
||||
WGLEW_EXPORT PFNWGLENUMGPUDEVICESNVPROC __wglewEnumGpuDevicesNV;
|
||||
WGLEW_EXPORT PFNWGLENUMGPUSFROMAFFINITYDCNVPROC __wglewEnumGpusFromAffinityDCNV;
|
||||
WGLEW_EXPORT PFNWGLENUMGPUSNVPROC __wglewEnumGpusNV;
|
||||
|
||||
WGLEW_EXPORT PFNWGLALLOCATEMEMORYNVPROC __wglewAllocateMemoryNV;
|
||||
WGLEW_EXPORT PFNWGLFREEMEMORYNVPROC __wglewFreeMemoryNV;
|
||||
|
||||
WGLEW_EXPORT PFNWGLGETMSCRATEOMLPROC __wglewGetMscRateOML;
|
||||
WGLEW_EXPORT PFNWGLGETSYNCVALUESOMLPROC __wglewGetSyncValuesOML;
|
||||
WGLEW_EXPORT PFNWGLSWAPBUFFERSMSCOMLPROC __wglewSwapBuffersMscOML;
|
||||
WGLEW_EXPORT PFNWGLSWAPLAYERBUFFERSMSCOMLPROC __wglewSwapLayerBuffersMscOML;
|
||||
WGLEW_EXPORT PFNWGLWAITFORMSCOMLPROC __wglewWaitForMscOML;
|
||||
WGLEW_EXPORT PFNWGLWAITFORSBCOMLPROC __wglewWaitForSbcOML;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_3DFX_multisample;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_3DL_stereo_control;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_buffer_region;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_extensions_string;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_make_current_read;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_multisample;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_pbuffer;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_pixel_format;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_pixel_format_float;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ARB_render_texture;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ATI_pixel_format_float;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_ATI_render_texture_rectangle;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_depth_float;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_display_color_table;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_extensions_string;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_framebuffer_sRGB;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_make_current_read;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_multisample;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_pbuffer;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_pixel_format;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_pixel_format_packed_float;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_EXT_swap_control;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_I3D_digital_video_control;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_I3D_gamma;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_I3D_genlock;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_I3D_image_buffer;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_I3D_swap_frame_lock;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_I3D_swap_frame_usage;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_NV_float_buffer;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_NV_gpu_affinity;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_NV_render_depth_texture;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_NV_render_texture_rectangle;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_NV_vertex_array_range;
|
||||
WGLEW_EXPORT GLboolean __WGLEW_OML_sync_control;
|
||||
|
||||
#ifdef GLEW_MX
|
||||
}; /* WGLEWContextStruct */
|
||||
#endif /* GLEW_MX */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef GLEW_MX
|
||||
|
||||
typedef struct WGLEWContextStruct WGLEWContext;
|
||||
GLEWAPI GLenum wglewContextInit (WGLEWContext* ctx);
|
||||
GLEWAPI GLboolean wglewContextIsSupported (WGLEWContext* ctx, const char* name);
|
||||
|
||||
#define wglewInit() wglewContextInit(wglewGetContext())
|
||||
#define wglewIsSupported(x) wglewContextIsSupported(wglewGetContext(), x)
|
||||
|
||||
#define WGLEW_GET_VAR(x) (*(const GLboolean*)&(wglewGetContext()->x))
|
||||
#define WGLEW_GET_FUN(x) wglewGetContext()->x
|
||||
|
||||
#else /* GLEW_MX */
|
||||
|
||||
#define WGLEW_GET_VAR(x) (*(const GLboolean*)&x)
|
||||
#define WGLEW_GET_FUN(x) x
|
||||
|
||||
GLEWAPI GLboolean wglewIsSupported (const char* name);
|
||||
|
||||
#endif /* GLEW_MX */
|
||||
|
||||
GLEWAPI GLboolean wglewGetExtension (const char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef GLEWAPI
|
||||
|
||||
#endif /* __wglew_h__ */
|
||||
31
demo09/src/demo09/Interfaces/IAnimationManager.h
Normal file
31
demo09/src/demo09/Interfaces/IAnimationManager.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{D46BAD55-0DD9-470b-95B0-851C0373F4D2}")) IAnimateable
|
||||
{
|
||||
virtual ~IAnimateable() {};
|
||||
|
||||
virtual void OnAnimate(double position, unsigned int userData) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{9D5986E5-DD71-4dd0-9F73-349530C5A816}")) IEvent
|
||||
{
|
||||
virtual ~IEvent() {};
|
||||
|
||||
virtual void OnEvent(unsigned int userData) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{1E04CB98-6EA8-43b1-BCF3-534205BCBD9A}")) IAnimationManager
|
||||
{
|
||||
virtual ~IAnimationManager() {};
|
||||
|
||||
virtual void AddDemoTimeAnimation(double beginTime, double endTime, IAnimateable* value, unsigned int userData = 0) = 0;
|
||||
virtual void AddRealTimeAnimation(double beginTime, double endTime, IAnimateable* value, unsigned int userData = 0) = 0;
|
||||
|
||||
virtual void AddDemoTimeEvent(double time, IEvent* value, unsigned int userData = 0) = 0;
|
||||
virtual void AddRealTimeEvent(double time, IEvent* value, unsigned int userData = 0) = 0;
|
||||
|
||||
virtual void Animate() = 0;
|
||||
};
|
||||
33
demo09/src/demo09/Interfaces/IBillboard.h
Normal file
33
demo09/src/demo09/Interfaces/IBillboard.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct BillboardOrientation
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
World,
|
||||
Cylindrical,
|
||||
Spherical
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{B8B837EC-5634-4813-BC7F-8D273BD9A4CE}")) IBillboard
|
||||
{
|
||||
virtual ~IBillboard() {};
|
||||
|
||||
virtual BillboardOrientation::Enumeration GetOrientation() = 0;
|
||||
virtual void SetOrientation(BillboardOrientation::Enumeration value) = 0;
|
||||
|
||||
virtual void SetTexture(ITexture* value) = 0;
|
||||
virtual ITexture* GetTexture() = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{E3850D03-58B6-4e04-AAC9-2DE19EC8C611}")) IBillboardBatch
|
||||
{
|
||||
virtual ~IBillboardBatch() {};
|
||||
|
||||
virtual void SetMaterial(IMaterial* value) = 0;
|
||||
virtual IMaterial* GetMaterial() = 0;
|
||||
};
|
||||
25
demo09/src/demo09/Interfaces/IBone.h
Normal file
25
demo09/src/demo09/Interfaces/IBone.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
struct ITransformationAnimation;
|
||||
struct __declspec(novtable) __declspec(uuid("{E0648A1F-E18F-40e9-A54E-E9F6F5D13AFB}")) IBone
|
||||
{
|
||||
virtual ~IBone() {};
|
||||
|
||||
virtual const Matrix& GetTransformationAtTime(float t, const Matrix& rootTransformationMatrix) = 0;
|
||||
virtual const Matrix& GetPoseTransformation() const = 0;
|
||||
|
||||
virtual void SetParent(IBone* parent) = 0;
|
||||
virtual IBone* GetParent() const = 0;
|
||||
virtual std::vector<IBone*>& GetChildBones() = 0;
|
||||
|
||||
virtual std::wstring GetName() const = 0;
|
||||
virtual int GetIndex() const = 0;
|
||||
|
||||
virtual void SetTransformationAnimation(ITransformationAnimation* ta) = 0;
|
||||
virtual ITransformationAnimation* GetTransformationAnimation() const = 0;
|
||||
|
||||
virtual std::map<int, IBone*>& GetBoneIndexList() = 0;
|
||||
|
||||
virtual Matrix* GetMatrixArray() = 0;
|
||||
virtual unsigned int GetMatrixArraySize() = 0;
|
||||
};
|
||||
65
demo09/src/demo09/Interfaces/ICamera.h
Normal file
65
demo09/src/demo09/Interfaces/ICamera.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct CameraType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Perspective,
|
||||
Orthogonal
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ClipTestResult
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Outside,
|
||||
Intersect,
|
||||
Inside
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{D1B182FF-BED9-439e-952B-E4FC513E5466}")) IFrustum
|
||||
{
|
||||
virtual ~IFrustum() {};
|
||||
|
||||
virtual void SetCameraInternals(float angle, float ratio, float nearD, float farD) = 0;
|
||||
virtual void SetCameraDefinition(Vector &p, Vector &l, Vector &u) = 0;
|
||||
virtual ClipTestResult::Enumeration TestPointInFrustum(Vector &p) = 0;
|
||||
virtual ClipTestResult::Enumeration TestSphereInFrustum(Vector &p, float raio) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{B3773DE4-C38F-4864-AE4F-F827D05C2798}")) ICamera
|
||||
{
|
||||
virtual ~ICamera() {};
|
||||
|
||||
virtual CameraType::Enumeration GetType() = 0;
|
||||
virtual void SetType(CameraType::Enumeration value) = 0;
|
||||
|
||||
virtual void SetPosition(const Vector& value) = 0;
|
||||
virtual void SetCenter(const Vector& value) = 0;
|
||||
virtual void SetDirection(const Vector& value) = 0;
|
||||
virtual void SetUp(const Vector& value) = 0;
|
||||
virtual void SetMoon(const Vector& value) = 0;
|
||||
|
||||
virtual Vector GetPosition() = 0;
|
||||
virtual Vector GetCenter() = 0;
|
||||
virtual Vector GetDirection() = 0;
|
||||
virtual Vector GetUp() = 0;
|
||||
virtual Vector GetMoon() = 0;
|
||||
virtual Vector GetRight() = 0;
|
||||
|
||||
virtual const Matrix& GetViewMatrix() = 0;
|
||||
virtual void GetViewMatrix(const Matrix& value) = 0;
|
||||
|
||||
virtual void GetFOV(float value) = 0;
|
||||
virtual float GetFOV() = 0;
|
||||
|
||||
virtual void Apply() = 0;
|
||||
|
||||
virtual IFrustum& GetFrustum() = 0;
|
||||
};
|
||||
10
demo09/src/demo09/Interfaces/IController.h
Normal file
10
demo09/src/demo09/Interfaces/IController.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
struct IRenderable;
|
||||
struct __declspec(novtable) __declspec(uuid("{C11C33B0-429E-4f32-BFF8-BB882C6893F2}")) IController
|
||||
{
|
||||
virtual ~IController() {};
|
||||
|
||||
virtual void Apply(IRenderable& renderable) = 0;
|
||||
virtual void Revert(IRenderable& renderable) = 0;
|
||||
};
|
||||
84
demo09/src/demo09/Interfaces/IEngine.h
Normal file
84
demo09/src/demo09/Interfaces/IEngine.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct IGraphics;
|
||||
struct IWindow;
|
||||
struct IRenderer;
|
||||
struct IResourceFactory;
|
||||
struct ITexture;
|
||||
struct IMaterial;
|
||||
struct IShaderProgram;
|
||||
struct IShader;
|
||||
struct IFileSystem;
|
||||
struct IFile;
|
||||
struct IRenderable;
|
||||
struct IMeshBuffer;
|
||||
struct IAnimateable;
|
||||
struct IAnimationManager;
|
||||
struct ITimeline;
|
||||
struct IWorld;
|
||||
struct ICamera;
|
||||
struct IBillboard;
|
||||
struct IBillboardBatch;
|
||||
struct ILight;
|
||||
struct IRenderTarget;
|
||||
struct IBone;
|
||||
struct IVoxelBox;
|
||||
struct ITransformationAnimation;
|
||||
template <typename T> struct IPath;
|
||||
|
||||
|
||||
struct PrimitiveTopology
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Triangle = GL_TRIANGLES,
|
||||
TriangleStrip = GL_TRIANGLE_STRIP,
|
||||
Line = GL_LINES,
|
||||
LineStrip = GL_LINE_STRIP,
|
||||
LineLoop = GL_LINE_LOOP,
|
||||
Quad = GL_QUADS,
|
||||
Point = GL_POINTS
|
||||
};
|
||||
|
||||
static Enumeration Parse(const std::string& string)
|
||||
{
|
||||
if (string == "Triangle") return Triangle;
|
||||
if (string == "TriangleStrip") return TriangleStrip;
|
||||
if (string == "Line") return Line;
|
||||
if (string == "LineStrip") return LineStrip;
|
||||
if (string == "LineLoop") return LineLoop;
|
||||
if (string == "Quad") return Quad;
|
||||
if (string == "Point") return Point;
|
||||
throw _T("Invalid value passed to PrimitiveTopology::Parse!");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Alle Wege führen zur Engine, von der Engine aus erreicht man alles
|
||||
// Dient als ServiceLocator ersatz, einfach GetBlablubb() aufrufen :)
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{B0C22276-C117-4868-BA59-5671D551C9EE}")) IEngine
|
||||
{
|
||||
virtual ~IEngine() {};
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void Process(double time) = 0;
|
||||
|
||||
virtual IGraphics* GetGraphics() = 0;
|
||||
virtual IRenderer* GetRenderer() = 0;
|
||||
virtual IResourceFactory* GetResourceFactory() = 0;
|
||||
virtual IFileSystem* GetFileSystem() = 0;
|
||||
virtual IAnimationManager* GetAnimationManager() = 0;
|
||||
virtual ITimeline* GetTimeline() = 0;
|
||||
|
||||
virtual void AddWorld(IWorld* world) = 0;
|
||||
virtual std::vector<IWorld*> GetWorlds() = 0;
|
||||
virtual void ProcessWorlds() = 0;
|
||||
|
||||
virtual void SetTerminate(bool active) = 0;
|
||||
virtual bool GetTerminate() = 0;
|
||||
|
||||
virtual void SetWindow(IWindow* window) = 0;
|
||||
virtual IWindow* GetWindow() = 0;
|
||||
};
|
||||
32
demo09/src/demo09/Interfaces/IFileSystem.h
Normal file
32
demo09/src/demo09/Interfaces/IFileSystem.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{96CB0CD8-2738-41f5-B04E-2494FAA8A718}")) IFile
|
||||
{
|
||||
virtual ~IFile() {};
|
||||
|
||||
virtual char* GetBuffer() = 0;
|
||||
virtual unsigned int GetBufferLength() = 0;
|
||||
virtual void SaveAs(LPCTSTR fileName) = 0;
|
||||
|
||||
virtual std::string ReadString() = 0;
|
||||
virtual float ReadFloat() = 0;
|
||||
virtual int ReadInt() = 0;
|
||||
virtual void* ReadDataArray(unsigned int bytes) = 0;
|
||||
|
||||
virtual void RewindFilePointer() = 0;
|
||||
virtual char* GetFilePointer() const = 0;
|
||||
virtual void SetFilePointer(char* position) = 0;
|
||||
virtual bool IsEof() const = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{D3B022CF-1DB9-479e-8D17-238A5F3A12ED}")) IFileSystem
|
||||
{
|
||||
virtual ~IFileSystem() {};
|
||||
|
||||
virtual void InitializeFromDirectory(LPCTSTR directory = _T("data")) = 0;
|
||||
virtual void InitializeFromZipFile(LPCTSTR zipFile = _T("data.pak")) = 0;
|
||||
|
||||
virtual IFile* Open(LPCTSTR fileName) = 0;
|
||||
};
|
||||
20
demo09/src/demo09/Interfaces/IGraphics.h
Normal file
20
demo09/src/demo09/Interfaces/IGraphics.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{752C49B3-4467-4c5c-A0F6-D62625809232}")) IGraphics
|
||||
{
|
||||
virtual ~IGraphics() {};
|
||||
|
||||
virtual void Resize(int sizeX, int sizeY) = 0;
|
||||
virtual int Initialize() = 0;
|
||||
virtual void InitRenderingContext(HDC deviceContext) = 0;
|
||||
virtual void FreeRenderingContext() = 0;
|
||||
virtual int GetMaxTextureSize() = 0;
|
||||
virtual int GetWidth() = 0;
|
||||
virtual int GetHeight() = 0;
|
||||
virtual float GetAspectRatio() = 0;
|
||||
virtual void SetAspectRatio(float value) = 0;
|
||||
virtual void PrintErrors() = 0;
|
||||
|
||||
virtual void Progress(float value) = 0;
|
||||
};
|
||||
27
demo09/src/demo09/Interfaces/ILight.h
Normal file
27
demo09/src/demo09/Interfaces/ILight.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{43C90804-020A-4fbd-92D5-03577CE59518}")) ILight
|
||||
{
|
||||
virtual ~ILight() {};
|
||||
|
||||
virtual void SetAmbient(const Vector& value) = 0;
|
||||
virtual Vector GetAmbient() const = 0;
|
||||
|
||||
virtual void SetDiffuse(const Vector& value) = 0;
|
||||
virtual Vector GetDiffuse() const = 0;
|
||||
|
||||
virtual void SetSpecular(const Vector& value) = 0;
|
||||
virtual Vector GetSpecular() const = 0;
|
||||
|
||||
virtual void SetPosition(const Vector& value) = 0;
|
||||
virtual Vector GetPosition() const = 0;
|
||||
|
||||
virtual void SetSpotLightParameters(const Vector& direction, const float exponent, const float cutoff) = 0;
|
||||
virtual void GetSpotLightParameters(Vector& direction, float& exponent, float& cutoff) const = 0;
|
||||
|
||||
virtual void SetAttenuation(const float constant, const float linear, const float quadratic) = 0;
|
||||
virtual void GetAttenuation(float& constant, float& linear, float& quadratic) const = 0;
|
||||
|
||||
virtual void Bind(unsigned int unit) = 0;
|
||||
};
|
||||
194
demo09/src/demo09/Interfaces/IMaterial.h
Normal file
194
demo09/src/demo09/Interfaces/IMaterial.h
Normal file
@@ -0,0 +1,194 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct CompareFunc
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Disabled = 0,
|
||||
Never = GL_NEVER,
|
||||
Less = GL_LESS,
|
||||
Equal = GL_EQUAL,
|
||||
LessEqual = GL_LEQUAL,
|
||||
Greater = GL_GREATER,
|
||||
NotEqual = GL_NOTEQUAL,
|
||||
GreaterEqual = GL_GEQUAL,
|
||||
Always = GL_ALWAYS
|
||||
};
|
||||
|
||||
static Enumeration Parse(const std::string& input)
|
||||
{
|
||||
Enumeration func = CompareFunc::Disabled;
|
||||
if (input == "never") func = CompareFunc::Never;
|
||||
else if (input == "disabled") func = CompareFunc::Disabled;
|
||||
else if (input == "less") func = CompareFunc::Less;
|
||||
else if (input == "equal") func = CompareFunc::Equal;
|
||||
else if (input == "lessequal") func = CompareFunc::LessEqual;
|
||||
else if (input == "greater") func = CompareFunc::Greater;
|
||||
else if (input == "notequal") func = CompareFunc::NotEqual;
|
||||
else if (input == "greaterequal") func = CompareFunc::GreaterEqual;
|
||||
else if (input == "always") func = CompareFunc::Always;
|
||||
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct Culling
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
None = GL_NONE,
|
||||
Front = GL_FRONT,
|
||||
Back = GL_BACK,
|
||||
All = GL_FRONT | GL_BACK
|
||||
};
|
||||
|
||||
static Enumeration Parse(const std::string& input)
|
||||
{
|
||||
Enumeration func = Culling::None;
|
||||
if (input == "none") func = Culling::None;
|
||||
else if (input == "front") func = Culling::Front;
|
||||
else if (input == "back") func = Culling::Back;
|
||||
else if (input == "all") func = Culling::All;
|
||||
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
struct BlendMode
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Zero = GL_ZERO,
|
||||
One = GL_ONE,
|
||||
SrcColor = GL_SRC_COLOR,
|
||||
OneMinusSrcColor = GL_ONE_MINUS_SRC_COLOR,
|
||||
DestColor = GL_DST_COLOR,
|
||||
OneMinusDestColor = GL_ONE_MINUS_DST_COLOR,
|
||||
SrcAlpha = GL_SRC_ALPHA,
|
||||
OneMinusSrcAlpha = GL_ONE_MINUS_SRC_ALPHA,
|
||||
DestAlpha = GL_DST_ALPHA,
|
||||
OneMinusDestAlpha = GL_ONE_MINUS_DST_ALPHA,
|
||||
SrcAlphaSaturate = GL_SRC_ALPHA_SATURATE
|
||||
};
|
||||
|
||||
static Enumeration Parse(const std::string& input)
|
||||
{
|
||||
Enumeration func = BlendMode::Zero;
|
||||
if (input == "zero") func = BlendMode::Zero;
|
||||
else if (input == "one") func = BlendMode::One;
|
||||
else if (input == "srccolor") func = BlendMode::SrcColor;
|
||||
else if (input == "oneminussrccolor") func = BlendMode::OneMinusSrcColor;
|
||||
else if (input == "destcolor") func = BlendMode::DestColor;
|
||||
else if (input == "oneminusdestcolor") func = BlendMode::OneMinusDestColor;
|
||||
else if (input == "srcalpha") func = BlendMode::SrcAlpha;
|
||||
else if (input == "oneminussrcalpha") func = BlendMode::OneMinusSrcAlpha;
|
||||
else if (input == "destalpha") func = BlendMode::DestAlpha;
|
||||
else if (input == "oneminusdestalpha") func = BlendMode::OneMinusDestAlpha;
|
||||
else if (input == "srcalphasaturate") func = BlendMode::SrcAlphaSaturate;
|
||||
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct TextureWrap
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Clamp = GL_CLAMP_TO_EDGE,
|
||||
Repeat = GL_REPEAT,
|
||||
Mirror = GL_MIRRORED_REPEAT
|
||||
};
|
||||
|
||||
static Enumeration Parse(const std::string& input)
|
||||
{
|
||||
Enumeration func = TextureWrap::Clamp;
|
||||
if (input == "clamp") func = TextureWrap::Clamp;
|
||||
else if (input == "repeat") func = TextureWrap::Repeat;
|
||||
else if (input == "mirror") func = TextureWrap::Mirror;
|
||||
|
||||
return func;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct TextureInfo
|
||||
{
|
||||
TextureInfo()
|
||||
: Texture(NULL)
|
||||
, TextureWrapS(TextureWrap::Repeat)
|
||||
, TextureWrapT(TextureWrap::Repeat)
|
||||
{}
|
||||
|
||||
TextureInfo(ITexture* texture)
|
||||
: Texture(texture)
|
||||
, TextureWrapS(TextureWrap::Repeat)
|
||||
, TextureWrapT(TextureWrap::Repeat)
|
||||
{}
|
||||
|
||||
TextureInfo(ITexture* texture, TextureWrap::Enumeration wrap)
|
||||
: Texture(texture)
|
||||
, TextureWrapS(wrap)
|
||||
, TextureWrapT(wrap)
|
||||
{}
|
||||
|
||||
ITexture* Texture;
|
||||
TextureWrap::Enumeration TextureWrapS;
|
||||
TextureWrap::Enumeration TextureWrapT;
|
||||
};
|
||||
|
||||
|
||||
struct SubMaterial
|
||||
{
|
||||
SubMaterial()
|
||||
: ShaderProgram(NULL)
|
||||
, Shininess(8.0f)
|
||||
, DepthWrite(true)
|
||||
, AlphaTestFunction(CompareFunc::Disabled)
|
||||
, DepthFunction(CompareFunc::Less)
|
||||
, AlphaTestValue(0.0f)
|
||||
, AlphaBlend(false)
|
||||
, Culling(Culling::Back)
|
||||
, SrcBlendMode(BlendMode::One)
|
||||
, DestBlendMode(BlendMode::Zero)
|
||||
{}
|
||||
|
||||
std::string TargetWorldName;
|
||||
|
||||
std::map<int, TextureInfo> Textures;
|
||||
|
||||
IShaderProgram* ShaderProgram;
|
||||
|
||||
Vector Ambient;
|
||||
Vector Diffuse;
|
||||
Vector Specular;
|
||||
Vector Emissive;
|
||||
float Shininess;
|
||||
|
||||
bool DepthWrite;
|
||||
CompareFunc::Enumeration DepthFunction;
|
||||
|
||||
CompareFunc::Enumeration AlphaTestFunction;
|
||||
float AlphaTestValue;
|
||||
|
||||
bool AlphaBlend;
|
||||
BlendMode::Enumeration SrcBlendMode;
|
||||
BlendMode::Enumeration DestBlendMode;
|
||||
|
||||
Culling::Enumeration Culling;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{DB53E2A3-9760-4a8e-BE3F-061AACF12B41}")) IMaterial
|
||||
{
|
||||
virtual ~IMaterial() {};
|
||||
|
||||
virtual bool Bind() = 0;
|
||||
|
||||
virtual void AddSubMaterial(SubMaterial* subMaterial) = 0;
|
||||
virtual const std::vector<SubMaterial*>& GetSubMaterials() const = 0;
|
||||
|
||||
virtual SubMaterial* FindRelevantSubMaterial(IWorld* world = NULL);
|
||||
};
|
||||
114
demo09/src/demo09/Interfaces/IMeshBuffer.h
Normal file
114
demo09/src/demo09/Interfaces/IMeshBuffer.h
Normal file
@@ -0,0 +1,114 @@
|
||||
#pragma once
|
||||
|
||||
#include "IRenderable.h"
|
||||
|
||||
|
||||
struct VertexElement
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Position2D,
|
||||
Position3D,
|
||||
Position4D,
|
||||
|
||||
Normal,
|
||||
|
||||
ColorRGB,
|
||||
ColorARGB,
|
||||
ColorRGBf,
|
||||
ColorARGBf,
|
||||
|
||||
Texture2D,
|
||||
Texture3D,
|
||||
Texture4D,
|
||||
|
||||
Tangent3D,
|
||||
Tangent4D,
|
||||
|
||||
BlendIndices,
|
||||
BlendWeights
|
||||
};
|
||||
|
||||
static unsigned int GetSize(Enumeration element)
|
||||
{
|
||||
switch (element)
|
||||
{
|
||||
case Position2D: return 2 * sizeof(float);
|
||||
case Position3D: return 3 * sizeof(float);
|
||||
case Position4D: return 4 * sizeof(float);
|
||||
case Normal: return 3 * sizeof(float);
|
||||
case ColorRGB: return 3 * sizeof(unsigned char);
|
||||
case ColorARGB: return 4 * sizeof(unsigned char);
|
||||
case ColorRGBf: return 3 * sizeof(float);
|
||||
case ColorARGBf: return 4 * sizeof(float);
|
||||
case Texture2D: return 2 * sizeof(float);
|
||||
case Texture3D: return 3 * sizeof(float);
|
||||
case Texture4D: return 4 * sizeof(float);
|
||||
case Tangent3D: return 3 * sizeof(float);
|
||||
case Tangent4D: return 4 * sizeof(float);
|
||||
case BlendIndices: return 4 * sizeof(float);
|
||||
case BlendWeights: return 4 * sizeof(float);
|
||||
default: return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct MeshBufferUsage
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Static = GL_STATIC_DRAW_ARB,
|
||||
Dynamic = GL_DYNAMIC_DRAW_ARB
|
||||
};
|
||||
};
|
||||
|
||||
struct MeshBufferAccessType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
ReadOnly = GL_READ_ONLY_ARB,
|
||||
WriteOnly = GL_WRITE_ONLY_ARB,
|
||||
ReadAndWrite = GL_READ_WRITE_ARB
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ScreenQuadVertex
|
||||
{
|
||||
float X;
|
||||
float Y;
|
||||
float Z;
|
||||
float U;
|
||||
float V;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{98AA5828-0290-4b7b-93DC-926F8C87733A}")) IMeshBuffer
|
||||
{
|
||||
virtual ~IMeshBuffer() {};
|
||||
|
||||
virtual PrimitiveTopology::Enumeration GetPrimitiveTopology() const = 0;
|
||||
virtual void SetPrimitiveTopology(PrimitiveTopology::Enumeration topology) = 0;
|
||||
|
||||
virtual void SetIndexBuffer(unsigned int* indexBufferData, unsigned int indexCount, MeshBufferUsage::Enumeration usage = MeshBufferUsage::Static, bool takeOwnership = true) = 0;
|
||||
virtual unsigned int* GetIndexBufferData() const = 0;
|
||||
virtual unsigned int GetIndexCount() const = 0;
|
||||
|
||||
virtual void SetVertexBuffer(void* vertexBufferData, unsigned int vertexCount, const std::vector<VertexElement::Enumeration>& vertexElements, MeshBufferUsage::Enumeration usage = MeshBufferUsage::Static, bool takeOwnership = true) = 0;
|
||||
virtual void* GetVertexBufferData() const = 0;
|
||||
virtual unsigned int GetVertexCount() const = 0;
|
||||
virtual const std::vector<VertexElement::Enumeration>& GetVertexElements() const = 0;
|
||||
|
||||
virtual void SetMaterial(IMaterial* material) = 0;
|
||||
virtual IMaterial* GetMaterial() const = 0;
|
||||
|
||||
virtual void SetUsedIndexCount(unsigned int indexCount) = 0;
|
||||
virtual unsigned int GetUsedIndexCount() const = 0;
|
||||
|
||||
virtual void* MapVertexBufferData(MeshBufferAccessType::Enumeration accessType) = 0;
|
||||
virtual unsigned int* MapIndexBufferData(MeshBufferAccessType::Enumeration accessType) = 0;
|
||||
|
||||
virtual void UnmapVertexBufferData() = 0;
|
||||
virtual void UnmapIndexBufferData() = 0;
|
||||
};
|
||||
35
demo09/src/demo09/Interfaces/IRenderTarget.h
Normal file
35
demo09/src/demo09/Interfaces/IRenderTarget.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
#include "ITexture.h"
|
||||
|
||||
|
||||
struct BindFlags
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
ClearDepth = 0x001,
|
||||
ClearColor = 0x002,
|
||||
BindTexture0 = 0x010,
|
||||
BindTexture1 = 0x020,
|
||||
BindTexture2 = 0x040,
|
||||
BindTexture3 = 0x080,
|
||||
BindAllTextures = 0x100,
|
||||
ClearAll = ClearDepth | ClearColor,
|
||||
Default = ClearAll | BindAllTextures
|
||||
};
|
||||
};
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{644F6836-007E-40e4-B255-0F845D9BB7A4}")) IRenderTarget
|
||||
{
|
||||
virtual ~IRenderTarget() {};
|
||||
|
||||
virtual ITexture* AddRenderTargetTexture(TextureFormat::Enumeration format) = 0;
|
||||
|
||||
virtual void Bind(DWORD bindFlags = BindFlags::Default) = 0;
|
||||
virtual void Unbind() = 0;
|
||||
|
||||
virtual unsigned int GetWidth() const = 0;
|
||||
virtual unsigned int GetHeight() const = 0;
|
||||
|
||||
virtual const std::vector<ITexture*>& GetTextures() const;
|
||||
virtual void Check();
|
||||
};
|
||||
36
demo09/src/demo09/Interfaces/IRenderable.h
Normal file
36
demo09/src/demo09/Interfaces/IRenderable.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
struct IController;
|
||||
struct __declspec(novtable) __declspec(uuid("{BA69B4EB-6B64-42e4-99D5-D58676CC653E}")) IRenderable
|
||||
{
|
||||
virtual ~IRenderable() {};
|
||||
|
||||
virtual void SetRotation(const Quaternion& value) = 0;
|
||||
virtual void SetScale(const Vector& value) = 0;
|
||||
virtual void SetTranslation(const Vector& value) = 0;
|
||||
virtual void SetAdditionalTransformation(const Matrix& value) = 0;
|
||||
|
||||
virtual Quaternion GetRotation() = 0;
|
||||
virtual Vector GetScale() = 0;
|
||||
virtual Vector GetTranslation() = 0;
|
||||
virtual Matrix GetAdditionalTransformation() = 0;
|
||||
|
||||
virtual void AddController(IController* controller) = 0;
|
||||
virtual void RemoveController(IController* controller) = 0;
|
||||
virtual const std::vector<IController*>& GetControllerList() const = 0;
|
||||
|
||||
virtual void AddRenderable(IRenderable* value) = 0;
|
||||
virtual void RemoveRenderable(IRenderable* value) = 0;
|
||||
virtual std::vector<IRenderable*> GetRenderables() = 0;
|
||||
|
||||
virtual void SetWorld(IWorld* value) = 0;
|
||||
virtual IWorld* GetWorld() const = 0;
|
||||
|
||||
virtual void SetIsSharedRenderable(bool state) = 0;
|
||||
virtual bool GetIsSharedRenderable() const = 0;
|
||||
|
||||
virtual void Render() = 0;
|
||||
|
||||
virtual void SetVisible(bool state) = 0;
|
||||
virtual bool GetVisible() const = 0;
|
||||
};
|
||||
19
demo09/src/demo09/Interfaces/IRenderer.h
Normal file
19
demo09/src/demo09/Interfaces/IRenderer.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{6C510736-7AE4-4bd2-8D8F-B54DE9655D23}")) IRenderer
|
||||
{
|
||||
virtual ~IRenderer() {};
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void Render(double time) = 0;
|
||||
|
||||
virtual void SetAdaptiveMotionBlur(bool value) = 0;
|
||||
virtual bool GetAdaptiveMotionBlur() = 0;
|
||||
|
||||
virtual void SetMotionBlurSteps(int value = 1) = 0;
|
||||
virtual int GetMotionBlurSteps() = 0;
|
||||
|
||||
virtual void SetCurrentWorld(IWorld* world) = 0;
|
||||
virtual IWorld* GetCurrentWorld() = 0;
|
||||
};
|
||||
34
demo09/src/demo09/Interfaces/IResourceFactory.h
Normal file
34
demo09/src/demo09/Interfaces/IResourceFactory.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "IShader.h"
|
||||
#include "IText.h"
|
||||
#include "ITexture.h"
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{110077D7-039A-4c2f-B49C-45A5240962C6}")) IResourceFactory
|
||||
{
|
||||
virtual ~IResourceFactory() {};
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual ITexture* TryGetOrCreateTexture(LPCTSTR name, LPCTSTR fileName = _T("")) = 0;
|
||||
virtual IMaterial* TryGetOrCreateMaterial(LPCTSTR name, LPCTSTR fileName = _T("")) = 0;
|
||||
virtual IShader* TryGetOrCreateShader(LPCTSTR name, ShaderType::Enumeration type, LPCTSTR fileName) = 0;
|
||||
virtual IShader* TryGetOrCreateShader(LPCTSTR name, ShaderType::Enumeration type, LPCTSTR fileName, const std::string source) = 0;
|
||||
virtual ITransformationAnimation* TryGetOrCreateTransformationAnimation(LPCTSTR name) = 0;
|
||||
virtual IShaderProgram* CreateShaderProgram(std::vector<IShader*> shaders) = 0;
|
||||
virtual IRenderable* CreateRenderable() = 0;
|
||||
virtual IMeshBuffer* CreateMeshBuffer() = 0;
|
||||
virtual IBillboard* CreateBillboard() = 0;
|
||||
virtual ICamera* CreateCamera() = 0;
|
||||
virtual ILight* CreateLight() = 0;
|
||||
virtual IBillboardBatch* CreateBillboardBatch(unsigned int initialSizeInBillboards, IMaterial* material) = 0;
|
||||
virtual IRenderTarget* CreateRenderTarget(unsigned int width, unsigned int height) = 0;
|
||||
virtual IRenderTarget* CreateRenderTarget(unsigned int width, unsigned int height, TextureFormat::Enumeration initialTextureFormat) = 0;
|
||||
virtual IBone* CreateBone(LPCTSTR name, int index, const Vector& poseTranslation, const Vector& poseScale, const Quaternion& poseRotation) = 0;
|
||||
virtual IVoxelBox* CreateVoxelBox(int sizeX, int sizeY, int sizeZ) = 0;
|
||||
virtual IText* CreateText(const std::string& text, const std::wstring& font, int height, float depth, FontFlags::Enumeration flags = FontFlags::None) = 0;
|
||||
|
||||
virtual bool RegisterShaderCallback(IShaderCallback* callback) = 0;
|
||||
virtual IShaderCallback* GetShaderCallback(const std::wstring& callbackName) = 0;
|
||||
};
|
||||
62
demo09/src/demo09/Interfaces/IShader.h
Normal file
62
demo09/src/demo09/Interfaces/IShader.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct ShaderType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Vertex,
|
||||
Geometry,
|
||||
Pixel
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct IShaderProgram;
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{79F5937C-C03E-4839-B9B2-935C7B374C12}")) IShaderCallback
|
||||
{
|
||||
virtual ~IShaderCallback() {};
|
||||
|
||||
virtual std::wstring GetName() const = 0;
|
||||
virtual void OnShaderProgramActivate(IShaderProgram& program, void* additionalData) = 0;
|
||||
|
||||
virtual bool IsFunctionalWithShaderProgram(IShaderProgram& program) = 0;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{976C79C2-54BF-4d5a-87A6-EC840F9E83E9}")) IShader
|
||||
{
|
||||
virtual ~IShader() {};
|
||||
|
||||
virtual ShaderType::Enumeration GetType() = 0;
|
||||
virtual unsigned int GetHandle() = 0;
|
||||
|
||||
virtual void SetGeometryShaderParams(const PrimitiveTopology::Enumeration input, const PrimitiveTopology::Enumeration output, const unsigned int verticesOut);
|
||||
virtual void GetGeometryShaderParams(PrimitiveTopology::Enumeration& input, PrimitiveTopology::Enumeration& output, unsigned int& verticesOut);
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{4111B97D-996C-4bd5-9911-02A552A46E39}")) IShaderProgram
|
||||
{
|
||||
virtual ~IShaderProgram() {};
|
||||
|
||||
virtual void SetParam(LPCSTR param, int value) = 0;
|
||||
virtual void SetParam(LPCSTR param, float value) = 0;
|
||||
virtual void SetParam(LPCSTR param, const Vector& value, int components = 4) = 0;
|
||||
virtual void SetParam(LPCSTR param, const Matrix& value, int components = 4) = 0;
|
||||
virtual void SetParam(LPCSTR param, Matrix* value, int count) = 0;
|
||||
|
||||
virtual int GetIntParam(LPCSTR param) = 0;
|
||||
virtual float GetFloatParam(LPCSTR param) = 0;
|
||||
virtual Vector GetVectorParam(LPCSTR param) = 0;
|
||||
virtual Matrix GetMatrixParam(LPCSTR param) = 0;
|
||||
|
||||
virtual int GetAttributeHandle(LPCSTR param) = 0;
|
||||
virtual int GetUniformHandle(LPCSTR param) = 0;
|
||||
|
||||
virtual void SetShaderCallbackUsage(const std::wstring& callbackName, void* additionalData = NULL) = 0;
|
||||
|
||||
virtual void Bind() = 0;
|
||||
};
|
||||
35
demo09/src/demo09/Interfaces/IText.h
Normal file
35
demo09/src/demo09/Interfaces/IText.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "IRenderable.h"
|
||||
|
||||
|
||||
struct FontFlags
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
None = 0x0,
|
||||
Bold = 0x1,
|
||||
Italic = 0x2,
|
||||
Strikeout = 0x4,
|
||||
Underline = 0x8
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{C3AD8923-DE81-4b03-8628-93F21677730D}")) IText
|
||||
{
|
||||
virtual ~IText() {};
|
||||
|
||||
virtual std::string GetText() const = 0;
|
||||
virtual void SetText(const std::string& text) = 0;
|
||||
|
||||
virtual int GetFontHeight() const = 0;
|
||||
virtual int GetTextWidth() const = 0;
|
||||
virtual float GetFontDepth() const = 0;
|
||||
virtual std::wstring GetFont() const = 0;
|
||||
virtual FontFlags::Enumeration GetFontFlags() const = 0;
|
||||
|
||||
virtual void SetMaterial(IMaterial* material) = 0;
|
||||
virtual IMaterial* GetMaterial() const = 0;
|
||||
};
|
||||
31
demo09/src/demo09/Interfaces/ITexture.h
Normal file
31
demo09/src/demo09/Interfaces/ITexture.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct TextureFormat
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
RGB,
|
||||
RGBf,
|
||||
RGBA,
|
||||
RGBAf,
|
||||
Depth,
|
||||
Depthf
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{366BBC0B-13C1-4e52-8000-0E5592BF848E}")) ITexture
|
||||
{
|
||||
virtual ~ITexture() {};
|
||||
|
||||
virtual int GetWidth() = 0;
|
||||
virtual int GetHeight() = 0;
|
||||
|
||||
virtual void Open(IFile* file) = 0;
|
||||
virtual void Bind(int textureUnit) = 0;
|
||||
|
||||
virtual TextureFormat::Enumeration GetFormat() const = 0;
|
||||
|
||||
virtual bool GetSupportsMipMaps() const = 0;
|
||||
};
|
||||
17
demo09/src/demo09/Interfaces/ITimeLine.h
Normal file
17
demo09/src/demo09/Interfaces/ITimeLine.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{9EF04E8F-CE38-494c-872D-DC50095AE444}")) ITimeline
|
||||
{
|
||||
virtual ~ITimeline() {};
|
||||
|
||||
virtual double GetDeltaTime() = 0;
|
||||
virtual double GetRealTime() = 0;
|
||||
virtual double GetDemoTime() = 0;
|
||||
|
||||
virtual void SetSpeedAndDirection(double value = 1.0) = 0;
|
||||
virtual double GetSpeedAndDirection() = 0;
|
||||
|
||||
virtual void Advance(double seconds) = 0;
|
||||
|
||||
};
|
||||
45
demo09/src/demo09/Interfaces/ITransformationAnimation.h
Normal file
45
demo09/src/demo09/Interfaces/ITransformationAnimation.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct KeyFrameTarget
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Position,
|
||||
Rotation,
|
||||
Scale
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct KeyFrame
|
||||
{
|
||||
KeyFrame()
|
||||
: target(KeyFrameTarget::Position)
|
||||
, time(0.0f)
|
||||
{}
|
||||
|
||||
KeyFrame(KeyFrameTarget::Enumeration target, const Vector& value, float time)
|
||||
: target(target)
|
||||
, value(value)
|
||||
, time(time)
|
||||
{}
|
||||
|
||||
KeyFrameTarget::Enumeration target;
|
||||
Vector value;
|
||||
float time;
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{5CE6F909-9A6F-4f09-95DB-8F56800C08F6}")) ITransformationAnimation
|
||||
{
|
||||
virtual ~ITransformationAnimation() {};
|
||||
|
||||
virtual std::wstring GetName() const = 0;
|
||||
|
||||
virtual void AddKeyFrame(const KeyFrame& keyFrame) = 0;
|
||||
virtual float GetDuration() const = 0;
|
||||
|
||||
virtual Matrix GetTransformationAtTime(float t) = 0; // [0.0] - [1.0]
|
||||
};
|
||||
|
||||
15
demo09/src/demo09/Interfaces/IUniverse.h
Normal file
15
demo09/src/demo09/Interfaces/IUniverse.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{41F3BEAD-0A31-4e34-A089-079218BCA051}")) IUniverse
|
||||
{
|
||||
virtual ~IUniverse() {};
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual void AddWorld(IWorld* world) = 0;
|
||||
virtual std::vector<IWorld*> GetWorlds() = 0;
|
||||
|
||||
virtual ITimeline* GetTimeline() = 0;
|
||||
virtual void Exist(double seconds) = 0;
|
||||
};
|
||||
14
demo09/src/demo09/Interfaces/IVoxelBox.h
Normal file
14
demo09/src/demo09/Interfaces/IVoxelBox.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{B974F0E1-AB94-48e7-A7BA-90E6651B9533}")) IVoxelBox
|
||||
{
|
||||
virtual ~IVoxelBox() {};
|
||||
|
||||
virtual void GetSize(int& x, int& y, int& z) const = 0;
|
||||
virtual void SetIsoValue(float value) = 0;
|
||||
virtual float GetIsoValue() = 0;
|
||||
|
||||
virtual float* Lock() = 0;
|
||||
virtual void Unlock() = 0;
|
||||
};
|
||||
25
demo09/src/demo09/Interfaces/IWindow.h
Normal file
25
demo09/src/demo09/Interfaces/IWindow.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{3ABA91B1-9B3E-4ae6-B5EA-EB24E77B6097}")) IWindow
|
||||
{
|
||||
virtual ~IWindow() {};
|
||||
virtual void Initialize() = 0;
|
||||
|
||||
virtual LRESULT ProcessMessage(UINT message, WPARAM wparam, LPARAM lparam) = 0;
|
||||
virtual void SwapBuffers() = 0;
|
||||
|
||||
virtual void SetActive(bool active) = 0;
|
||||
virtual bool GetActive() = 0;
|
||||
|
||||
virtual void SetFullscreen(bool fullscreen) = 0;
|
||||
virtual bool GetFullscreen() = 0;
|
||||
|
||||
virtual void SetDeviceContext(HDC deviceContext) = 0;
|
||||
virtual HDC GetDeviceContext() = 0;
|
||||
|
||||
virtual void SetTitle(LPCTSTR title) = 0;
|
||||
virtual LPCTSTR GetTitle() = 0;
|
||||
|
||||
virtual HWND GetHandle() = 0;
|
||||
};
|
||||
59
demo09/src/demo09/Interfaces/IWorld.h
Normal file
59
demo09/src/demo09/Interfaces/IWorld.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include "IRenderTarget.h"
|
||||
|
||||
|
||||
struct WorldRenderStage
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
PreBind,
|
||||
PreRenderables,
|
||||
PostRenderables,
|
||||
PostUnbind
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct __declspec(novtable) __declspec(uuid("{81037773-2A77-471a-A365-A33F95E12474}")) IWorld
|
||||
{
|
||||
virtual ~IWorld() {};
|
||||
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void Process() = 0;
|
||||
virtual void Render(WorldRenderStage::Enumeration stage) = 0;
|
||||
|
||||
virtual void SetActiveRendering(bool value) = 0;
|
||||
virtual bool GetActiveRendering() const = 0;
|
||||
|
||||
virtual void SetActiveProcessing(bool value) = 0;
|
||||
virtual bool GetActiveProcessing() const = 0;
|
||||
|
||||
virtual void AddRenderable(IRenderable* value) = 0;
|
||||
virtual void RemoveRenderable(IRenderable* value) = 0;
|
||||
virtual std::vector<IRenderable*>& GetRenderables() = 0;
|
||||
|
||||
virtual void AddLight(ILight* value) = 0;
|
||||
virtual std::vector<ILight*> GetLights() = 0;
|
||||
|
||||
virtual void SetCamera(ICamera* value) = 0;
|
||||
virtual ICamera* GetCamera() = 0;
|
||||
|
||||
virtual void SetRenderTarget(IRenderTarget* renderTarget) = 0;
|
||||
virtual IRenderTarget* GetRenderTarget() const = 0;
|
||||
|
||||
virtual void SetRenderTargetBindFlags(DWORD bindFlags) = 0;
|
||||
virtual DWORD GetRenderTargetBindFlags() const = 0;
|
||||
|
||||
virtual void SetSharedRenderables(IWorld* anotherWorld) = 0;
|
||||
virtual IWorld* GetSharedRenderables() const = 0;
|
||||
|
||||
virtual void SetClearColor(const Vector& clearColor) = 0;
|
||||
virtual const Vector& GetClearColor() const = 0;
|
||||
|
||||
virtual void SetClearDepth(float clearDepth) = 0;
|
||||
virtual float GetClearDepth() const = 0;
|
||||
|
||||
virtual void Clear() = 0;
|
||||
};
|
||||
174
demo09/src/demo09/Renderer/Renderer.cpp
Normal file
174
demo09/src/demo09/Renderer/Renderer.cpp
Normal file
@@ -0,0 +1,174 @@
|
||||
#include "stdafx.h"
|
||||
#include "Renderer.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ITexture.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IWorld.h"
|
||||
#include "ILight.h"
|
||||
#include "ICamera.h"
|
||||
#include "IRenderable.h"
|
||||
#include "ITimeline.h"
|
||||
#include "IRenderTarget.h"
|
||||
|
||||
|
||||
Renderer::Renderer(IEngine* engine)
|
||||
: engine(engine)
|
||||
, motionBlurSteps(1)
|
||||
, adaptiveMotionBlur(false)
|
||||
, currentWorld(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Renderer::Initialize()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Renderer::SetMotionBlurSteps(int value)
|
||||
{
|
||||
motionBlurSteps = value;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::SetAdaptiveMotionBlur(bool value)
|
||||
{
|
||||
adaptiveMotionBlur = value;
|
||||
}
|
||||
|
||||
|
||||
bool Renderer::GetAdaptiveMotionBlur()
|
||||
{
|
||||
return adaptiveMotionBlur;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::Render(double time)
|
||||
{
|
||||
double minFrameRate = 1.0 / 59.0;
|
||||
|
||||
int motionBlurSteps = this->motionBlurSteps;
|
||||
if (adaptiveMotionBlur)
|
||||
{
|
||||
++motionBlurSteps;
|
||||
|
||||
if (time > minFrameRate)
|
||||
motionBlurSteps -= 2;
|
||||
|
||||
if (motionBlurSteps == 0)
|
||||
motionBlurSteps = 1;
|
||||
this->motionBlurSteps = motionBlurSteps;
|
||||
}
|
||||
double step = time / motionBlurSteps;
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
ITimeline* timeline = engine->GetTimeline();
|
||||
if (motionBlurSteps <= 1)
|
||||
{
|
||||
timeline->Advance(time);
|
||||
this->RenderInternal(timeline->GetDemoTime());
|
||||
}
|
||||
else
|
||||
{
|
||||
glClear(GL_ACCUM_BUFFER_BIT);
|
||||
for (int i = 0; i < motionBlurSteps; ++i)
|
||||
{
|
||||
timeline->Advance(step);
|
||||
this->RenderInternal(timeline->GetDemoTime());
|
||||
glAccum(GL_ACCUM, 1.0f);
|
||||
}
|
||||
glAccum(GL_RETURN, 1.0f / motionBlurSteps);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Renderer::RenderInternal(double runningTime)
|
||||
{
|
||||
std::vector<IWorld*> lWorlds = engine->GetWorlds();
|
||||
std::vector<IWorld*>::const_iterator lWorldIter = lWorlds.begin();
|
||||
for (; lWorldIter != lWorlds.end(); ++lWorldIter)
|
||||
{
|
||||
if (!(*lWorldIter)->GetActiveRendering())
|
||||
continue;
|
||||
|
||||
this->SetCurrentWorld(*lWorldIter);
|
||||
|
||||
//glMatrixMode(GL_PROJECTION);
|
||||
//glLoadIdentity();
|
||||
//glMatrixMode(GL_MODELVIEW);
|
||||
//glLoadIdentity();
|
||||
|
||||
ICamera* camera = currentWorld->GetCamera();
|
||||
if (camera != NULL)
|
||||
camera->Apply();
|
||||
|
||||
std::vector<ILight*> lights = currentWorld->GetLights();
|
||||
if (lights.empty())
|
||||
{
|
||||
glDisable(GL_LIGHTING);
|
||||
}
|
||||
else
|
||||
{
|
||||
glEnable(GL_LIGHTING);
|
||||
std::vector<ILight*>::const_iterator lightIter = lights.begin();
|
||||
for (unsigned int i = 0; lightIter != lights.end(); ++lightIter, ++i)
|
||||
{
|
||||
ILight* light = *lightIter;
|
||||
light->Bind(i);
|
||||
}
|
||||
}
|
||||
|
||||
currentWorld->Render(WorldRenderStage::PreBind);
|
||||
if (currentWorld->GetRenderTarget() != NULL)
|
||||
currentWorld->GetRenderTarget()->Bind(currentWorld->GetRenderTargetBindFlags());
|
||||
else
|
||||
{
|
||||
glViewport(0, 0, engine->GetGraphics()->GetWidth(), engine->GetGraphics()->GetHeight());
|
||||
currentWorld->Clear();
|
||||
}
|
||||
|
||||
currentWorld->Render(WorldRenderStage::PreRenderables);
|
||||
if (currentWorld->GetSharedRenderables() != NULL)
|
||||
this->RenderWorld(currentWorld->GetSharedRenderables(), true);
|
||||
this->RenderWorld(currentWorld, false);
|
||||
currentWorld->Render(WorldRenderStage::PostRenderables);
|
||||
|
||||
if (currentWorld->GetRenderTarget() != NULL)
|
||||
currentWorld->GetRenderTarget()->Unbind();
|
||||
currentWorld->Render(WorldRenderStage::PostUnbind);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Renderer::GetMotionBlurSteps()
|
||||
{
|
||||
return motionBlurSteps;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::SetCurrentWorld(IWorld* world)
|
||||
{
|
||||
currentWorld = world;
|
||||
}
|
||||
|
||||
|
||||
IWorld* Renderer::GetCurrentWorld()
|
||||
{
|
||||
return currentWorld;
|
||||
}
|
||||
|
||||
|
||||
void Renderer::RenderWorld(IWorld* world, bool onlySharable)
|
||||
{
|
||||
std::vector<IRenderable*> renderables = world->GetRenderables();
|
||||
std::vector<IRenderable*>::const_iterator renderableIter = renderables.begin();
|
||||
for (; renderableIter != renderables.end(); ++renderableIter)
|
||||
{
|
||||
IRenderable* renderable = *renderableIter;
|
||||
if (!onlySharable || renderable->GetIsSharedRenderable())
|
||||
renderable->Render();
|
||||
}
|
||||
}
|
||||
31
demo09/src/demo09/Renderer/Renderer.h
Normal file
31
demo09/src/demo09/Renderer/Renderer.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "IRenderer.h"
|
||||
|
||||
|
||||
class Renderer
|
||||
: public IRenderer
|
||||
{
|
||||
public:
|
||||
Renderer(IEngine* engine);
|
||||
virtual ~Renderer() {};
|
||||
|
||||
virtual void Initialize();
|
||||
virtual void Render(double time);
|
||||
virtual void SetAdaptiveMotionBlur(bool value);
|
||||
virtual bool GetAdaptiveMotionBlur();
|
||||
virtual void SetMotionBlurSteps(int value = 1);
|
||||
virtual int GetMotionBlurSteps();
|
||||
virtual void SetCurrentWorld(IWorld* world);
|
||||
virtual IWorld* GetCurrentWorld();
|
||||
|
||||
private:
|
||||
void RenderInternal(double runningTime);
|
||||
void RenderWorld(IWorld* world, bool onlySharable);
|
||||
|
||||
IEngine* engine;
|
||||
IWorld* currentWorld;
|
||||
|
||||
bool adaptiveMotionBlur;
|
||||
int motionBlurSteps;
|
||||
};
|
||||
27
demo09/src/demo09/Resource.h
Normal file
27
demo09/src/demo09/Resource.h
Normal file
@@ -0,0 +1,27 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by demo09.rc
|
||||
//
|
||||
#define IDD_CONFIG 103
|
||||
#define IDI_SMALL 108
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDC_RESOLUTION 1000
|
||||
#define IDC_ASPECTRATIO 1001
|
||||
#define IDC_FULLSCREEN 1002
|
||||
#define IDC_BLURSTEPS 1004
|
||||
#define IDC_FIXED 1005
|
||||
#define IDC_ADAPTIVE 1006
|
||||
#define IDC_DISABLED 1007
|
||||
#define IDC_STATIC -1
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||
#define _APS_NEXT_CONTROL_VALUE 1009
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
#endif
|
||||
379
demo09/src/demo09/Resources/BLUImporter/BLUImporter.cpp
Normal file
379
demo09/src/demo09/Resources/BLUImporter/BLUImporter.cpp
Normal file
@@ -0,0 +1,379 @@
|
||||
#include "stdafx.h"
|
||||
#include "BLUImporter.h"
|
||||
|
||||
#include "IFileSystem.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "IMaterial.h"
|
||||
#include "IBone.h"
|
||||
#include "ITransformationAnimation.h"
|
||||
|
||||
|
||||
BluImporter::BluImporter(IEngine* engine)
|
||||
: engine(engine)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
BluImportResult BluImporter::Load(LPCTSTR fileName)
|
||||
{
|
||||
BluImportResult result;
|
||||
currentPath = result.fileName = fileName;
|
||||
unsigned int pos = currentPath.rfind(_T("/"));
|
||||
currentPath = currentPath.substr(0, pos + 1);
|
||||
|
||||
IFile* file = engine->GetFileSystem()->Open(fileName);
|
||||
if (file == NULL)
|
||||
return result;
|
||||
|
||||
file->GetBuffer(); // char* currentPos =
|
||||
|
||||
try
|
||||
{
|
||||
// header
|
||||
std::string fileTag = file->ReadString();
|
||||
if (fileTag != "BLUF")
|
||||
throw;
|
||||
|
||||
file->ReadInt(); // int fileVersion =
|
||||
|
||||
// sections
|
||||
while (!file->IsEof())
|
||||
{
|
||||
BluSectionType::Enumeration objectType = (BluSectionType::Enumeration)file->ReadInt();
|
||||
if (objectType > BluSectionType::LastKnownType)
|
||||
throw _T("BLUImporter: Unknown object section detected.");
|
||||
|
||||
std::string objectName = file->ReadString();
|
||||
if (objectName.empty())
|
||||
throw _T("BLUImporter: Objectname not set.");
|
||||
|
||||
// content
|
||||
switch (objectType)
|
||||
{
|
||||
case BluSectionType::Mesh:
|
||||
this->ImportMesh(file, objectName, result);
|
||||
break;
|
||||
case BluSectionType::Material:
|
||||
this->ImportMaterial(file, objectName, result);
|
||||
break;
|
||||
case BluSectionType::Bone:
|
||||
this->ImportBone(file, objectName, result);
|
||||
break;
|
||||
case BluSectionType::Animation:
|
||||
this->ImportAnimation(file, objectName, result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// put materials to meshbuffers
|
||||
std::map<std::wstring, BluImportedMeshBuffer>::iterator iter = result.meshBuffers.begin();
|
||||
for (; iter != result.meshBuffers.end(); ++iter)
|
||||
{
|
||||
BluImportedMeshBuffer mesh = iter->second;
|
||||
|
||||
std::map<std::wstring, IMaterial*>::iterator found = result.materials.find(mesh.materialName);
|
||||
if (found != result.materials.end())
|
||||
mesh.meshBuffer->SetMaterial(found->second);
|
||||
}
|
||||
|
||||
// build bone hierarchy
|
||||
std::map<std::wstring, BluImportedBone>::iterator bonesIter = result.bones.begin();
|
||||
for (; bonesIter != result.bones.end(); ++bonesIter)
|
||||
{
|
||||
BluImportedBone bone = bonesIter->second;
|
||||
|
||||
std::map<std::wstring, BluImportedBone>::iterator found = result.bones.find(bone.parentName);
|
||||
if (found != result.bones.end())
|
||||
bone.bone->SetParent(found->second.bone);
|
||||
}
|
||||
|
||||
// add bone animations to bones
|
||||
std::map<std::wstring, ITransformationAnimation*>::iterator animIter = result.animations.begin();
|
||||
for (; animIter != result.animations.end(); ++animIter)
|
||||
{
|
||||
std::map<std::wstring, BluImportedBone>::iterator found = result.bones.find(animIter->first);
|
||||
if (found != result.bones.end())
|
||||
{
|
||||
found->second.bone->SetTransformationAnimation(animIter->second);
|
||||
}
|
||||
}
|
||||
|
||||
// collapse bone map to super parent bones only
|
||||
bonesIter = result.bones.begin();
|
||||
for (; bonesIter != result.bones.end();)
|
||||
if (!bonesIter->second.parentName.empty())
|
||||
bonesIter = result.bones.erase(bonesIter);
|
||||
else
|
||||
{
|
||||
// create the boneindexlist structure while we are here
|
||||
bonesIter->second.bone->GetBoneIndexList();
|
||||
++bonesIter;
|
||||
}
|
||||
|
||||
if (result.bones.size() > 1)
|
||||
throw _T("BLUImporter: Only one bone root allowed!");
|
||||
|
||||
// when we have bones, try to register the bones shadercallback to all materials
|
||||
// also create a default BoneController
|
||||
if (!result.bones.empty())
|
||||
{
|
||||
std::map<std::wstring, IMaterial*>::iterator matIter = result.materials.begin();
|
||||
for (; matIter != result.materials.end(); ++matIter)
|
||||
{
|
||||
const std::vector<SubMaterial*>& subMaterials = matIter->second->GetSubMaterials();
|
||||
for (unsigned int i = 0; i < subMaterials.size(); ++i)
|
||||
subMaterials[i]->ShaderProgram->SetShaderCallbackUsage(_T("bones"), result.bones.begin()->second.bone);
|
||||
}
|
||||
|
||||
result.boneController = new BoneController(engine, result.bones.begin()->second.bone);
|
||||
float maxDuration = 0.0f;
|
||||
for (animIter = result.animations.begin(); animIter != result.animations.end(); ++animIter)
|
||||
{
|
||||
maxDuration = maxDuration < animIter->second->GetDuration() ? animIter->second->GetDuration() : maxDuration;
|
||||
}
|
||||
result.boneController->RegisterSequence(L"all", 0.0f, maxDuration, true);
|
||||
}
|
||||
|
||||
delete file;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
delete file;
|
||||
throw;
|
||||
}
|
||||
|
||||
result.successfullyLoaded = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
IRenderable* BluImporter::Load(IEngine* engine, LPCTSTR fileName, IMaterial* overrideMaterial)
|
||||
{
|
||||
BluImporter importer(engine);
|
||||
BluImportResult result = importer.Load(fileName);
|
||||
if (result.successfullyLoaded)
|
||||
return result.GenerateRootRenderable(engine, overrideMaterial);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportMesh(IFile* file, std::string objectName, BluImportResult& result)
|
||||
{
|
||||
std::string materialName = file->ReadString();
|
||||
int vertexCount = file->ReadInt();
|
||||
int vertexElementCount = file->ReadInt();
|
||||
|
||||
unsigned int vertexStride = 0;
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
for (int i = 0; i < vertexElementCount; ++i)
|
||||
{
|
||||
VertexElement::Enumeration vertexElement = (VertexElement::Enumeration)file->ReadInt();
|
||||
vertexStride += VertexElement::GetSize(vertexElement);
|
||||
vertexElements.push_back(vertexElement);
|
||||
}
|
||||
|
||||
ScopedBuffer<char> vertexData((char*)file->ReadDataArray(vertexCount * vertexStride));
|
||||
|
||||
int indexCount = file->ReadInt();
|
||||
ScopedBuffer<unsigned int> indexData((unsigned int*)file->ReadDataArray(indexCount * sizeof(unsigned int)));
|
||||
|
||||
std::wstring uniqueName = result.fileName + _T(".") + this->ConvertToString16(objectName);
|
||||
|
||||
IMeshBuffer* meshBuffer = engine->GetResourceFactory()->CreateMeshBuffer();
|
||||
meshBuffer->SetPrimitiveTopology(PrimitiveTopology::Triangle);
|
||||
meshBuffer->SetVertexBuffer((void*)vertexData.Detach(), (unsigned int)vertexCount, vertexElements, MeshBufferUsage::Static, true);
|
||||
meshBuffer->SetIndexBuffer((unsigned int*)indexData.Detach(), (unsigned int)indexCount, MeshBufferUsage::Static, true);
|
||||
|
||||
BluImportedMeshBuffer mesh;
|
||||
mesh.meshBuffer = meshBuffer;
|
||||
mesh.materialName = result.fileName + _T(".") + this->ConvertToString16(materialName);
|
||||
result.meshBuffers[uniqueName] = mesh;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportMaterial(IFile* file, std::string objectName, BluImportResult& result)
|
||||
{
|
||||
std::wstring diffuseTexture = this->ConvertPath(file->ReadString());
|
||||
std::wstring specularTexture = this->ConvertPath(file->ReadString());
|
||||
std::wstring normalTexture = this->ConvertPath(file->ReadString());
|
||||
std::wstring glowTexture = this->ConvertPath(file->ReadString());
|
||||
std::wstring reflectionTexture = this->ConvertPath(file->ReadString()); // not used yet
|
||||
|
||||
Vector ambientColor;
|
||||
ambientColor.x = file->ReadFloat() / 255.0f;
|
||||
ambientColor.y = file->ReadFloat() / 255.0f;
|
||||
ambientColor.z = file->ReadFloat() / 255.0f;
|
||||
ambientColor.w = file->ReadFloat() / 255.0f;
|
||||
|
||||
Vector diffuseColor;
|
||||
diffuseColor.x = file->ReadFloat() / 255.0f;
|
||||
diffuseColor.y = file->ReadFloat() / 255.0f;
|
||||
diffuseColor.z = file->ReadFloat() / 255.0f;
|
||||
diffuseColor.w = file->ReadFloat() / 255.0f;
|
||||
|
||||
Vector specularColor;
|
||||
specularColor.x = file->ReadFloat() / 255.0f;
|
||||
specularColor.y = file->ReadFloat() / 255.0f;
|
||||
specularColor.z = file->ReadFloat() / 255.0f;
|
||||
specularColor.w = file->ReadFloat() / 255.0f;
|
||||
|
||||
Vector emissiveColor;
|
||||
emissiveColor.x = file->ReadFloat() / 255.0f;
|
||||
emissiveColor.y = file->ReadFloat() / 255.0f;
|
||||
emissiveColor.z = file->ReadFloat() / 255.0f;
|
||||
emissiveColor.w = file->ReadFloat() / 255.0f;
|
||||
|
||||
float specularLevel = file->ReadFloat();
|
||||
float glossiness = file->ReadFloat();
|
||||
|
||||
std::wstring uniqueName = result.fileName + _T(".") + this->ConvertToString16(objectName);
|
||||
|
||||
IMaterial* material = engine->GetResourceFactory()->TryGetOrCreateMaterial(uniqueName.c_str());
|
||||
SubMaterial* subMaterial = new SubMaterial();
|
||||
material->AddSubMaterial(subMaterial);
|
||||
|
||||
subMaterial->Ambient = ambientColor;
|
||||
subMaterial->Diffuse = diffuseColor;
|
||||
subMaterial->Specular = specularColor * glossiness;
|
||||
subMaterial->Emissive = emissiveColor;
|
||||
subMaterial->Shininess = specularLevel;
|
||||
|
||||
IShader* vertexShader = NULL;
|
||||
if (normalTexture.empty())
|
||||
vertexShader = engine->GetResourceFactory()->TryGetOrCreateShader(_T("Common/Phong_simple.vs"), ShaderType::Vertex, _T("Common/Phong_simple.vs"));
|
||||
else if (result.bones.empty())
|
||||
vertexShader = engine->GetResourceFactory()->TryGetOrCreateShader(_T("Common/Phong.vs"), ShaderType::Vertex, _T("Common/Phong.vs"));
|
||||
else
|
||||
vertexShader = engine->GetResourceFactory()->TryGetOrCreateShader(_T("Common/PhongBones.vs"), ShaderType::Vertex, _T("Common/PhongBones.vs"));
|
||||
|
||||
IShader* pixelShader = NULL;
|
||||
if (normalTexture.empty())
|
||||
pixelShader = engine->GetResourceFactory()->TryGetOrCreateShader(_T("Common/Phong_simple.ps"), ShaderType::Pixel, _T("Common/Phong_simple.ps"));
|
||||
else
|
||||
pixelShader = engine->GetResourceFactory()->TryGetOrCreateShader(_T("Common/Phong.ps"), ShaderType::Pixel, _T("Common/Phong.ps"));
|
||||
|
||||
std::vector<IShader*> shaders;
|
||||
shaders.push_back(vertexShader);
|
||||
shaders.push_back(pixelShader);
|
||||
|
||||
subMaterial->ShaderProgram = engine->GetResourceFactory()->CreateShaderProgram(shaders);
|
||||
if (!diffuseTexture.empty())
|
||||
subMaterial->Textures[0].Texture = engine->GetResourceFactory()->TryGetOrCreateTexture(diffuseTexture.c_str(), diffuseTexture.c_str());
|
||||
if (!specularTexture.empty())
|
||||
subMaterial->Textures[1].Texture = engine->GetResourceFactory()->TryGetOrCreateTexture(specularTexture.c_str(), specularTexture.c_str());
|
||||
if (!normalTexture.empty())
|
||||
subMaterial->Textures[2].Texture = engine->GetResourceFactory()->TryGetOrCreateTexture(normalTexture.c_str(), normalTexture.c_str());
|
||||
if (!glowTexture.empty())
|
||||
subMaterial->Textures[3].Texture = engine->GetResourceFactory()->TryGetOrCreateTexture(glowTexture.c_str(), glowTexture.c_str());
|
||||
|
||||
result.materials[uniqueName] = material;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportBone(IFile* file, std::string objectName, BluImportResult& result)
|
||||
{
|
||||
std::string parentBoneName = file->ReadString();
|
||||
|
||||
// translation
|
||||
float transX = file->ReadFloat();
|
||||
float transY = file->ReadFloat();
|
||||
float transZ = file->ReadFloat();
|
||||
|
||||
// rotation
|
||||
float rotX = file->ReadFloat();
|
||||
float rotY = file->ReadFloat();
|
||||
float rotZ = file->ReadFloat();
|
||||
float rotW = file->ReadFloat();
|
||||
|
||||
// scale
|
||||
float scaleX = file->ReadFloat();
|
||||
float scaleY = file->ReadFloat();
|
||||
float scaleZ = file->ReadFloat();
|
||||
|
||||
std::wstring uniqueName = result.fileName + _T(".") + this->ConvertToString16(objectName);
|
||||
std::wstring uniqueParentName;
|
||||
if (!parentBoneName.empty())
|
||||
uniqueParentName = result.fileName + _T(".") + this->ConvertToString16(parentBoneName);
|
||||
|
||||
IBone* bone = engine->GetResourceFactory()->CreateBone(uniqueName.c_str(), (int)result.bones.size(),
|
||||
Vector(transX, transY, transZ, 1.0f),
|
||||
Vector(scaleX, scaleY, scaleZ, 1.0f),
|
||||
Quaternion(rotX, rotY, rotZ, rotW, 1.0f));
|
||||
|
||||
BluImportedBone importedBone;
|
||||
importedBone.bone = bone;
|
||||
importedBone.parentName = uniqueParentName;
|
||||
result.bones[uniqueName] = importedBone;
|
||||
}
|
||||
|
||||
|
||||
void BluImporter::ImportAnimation(IFile* file, std::string objectName, BluImportResult& result)
|
||||
{
|
||||
std::wstring uniqueName = result.fileName + _T(".") + this->ConvertToString16(objectName);
|
||||
|
||||
ITransformationAnimation* ta = engine->GetResourceFactory()->TryGetOrCreateTransformationAnimation(uniqueName.c_str());
|
||||
|
||||
int positionElementCount = file->ReadInt();
|
||||
for (int i = 0; i < positionElementCount; ++i)
|
||||
{
|
||||
float time = file->ReadFloat();
|
||||
float x = file->ReadFloat();
|
||||
float y = file->ReadFloat();
|
||||
float z = file->ReadFloat();
|
||||
|
||||
ta->AddKeyFrame(KeyFrame(KeyFrameTarget::Position, Vector(x, y, z, 1.0f), time));
|
||||
}
|
||||
|
||||
int scaleElementCount = file->ReadInt();
|
||||
for (int i = 0; i < scaleElementCount; ++i)
|
||||
{
|
||||
float time = file->ReadFloat();
|
||||
float x = file->ReadFloat();
|
||||
float y = file->ReadFloat();
|
||||
float z = file->ReadFloat();
|
||||
|
||||
ta->AddKeyFrame(KeyFrame(KeyFrameTarget::Scale, Vector(x, y, z, 1.0f), time));
|
||||
}
|
||||
|
||||
int rotationElementCount = file->ReadInt();
|
||||
for (int i = 0; i < rotationElementCount; ++i)
|
||||
{
|
||||
float time = file->ReadFloat();
|
||||
float x = file->ReadFloat();
|
||||
float y = file->ReadFloat();
|
||||
float z = file->ReadFloat();
|
||||
|
||||
ta->AddKeyFrame(KeyFrame(KeyFrameTarget::Rotation, Vector(x, y, z, 1.0f), time));
|
||||
}
|
||||
result.animations[uniqueName] = ta;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
IRenderable* BluImportResult::GenerateRootRenderable(IEngine* engine, IMaterial* overrideMaterial)
|
||||
{
|
||||
IResourceFactory* factory = engine->GetResourceFactory();
|
||||
IRenderable* resultRenderable = factory->CreateRenderable();
|
||||
|
||||
std::map<std::wstring, BluImportedMeshBuffer>::iterator iter = meshBuffers.begin();
|
||||
for (; iter != meshBuffers.end(); ++iter)
|
||||
{
|
||||
BluImportedMeshBuffer mesh = iter->second;
|
||||
if (overrideMaterial != NULL)
|
||||
mesh.meshBuffer->SetMaterial(overrideMaterial);
|
||||
resultRenderable->AddRenderable(dynamic_cast<IRenderable*>(mesh.meshBuffer));
|
||||
}
|
||||
|
||||
if (!bones.empty())
|
||||
bones.begin()->second.bone->GetTransformationAtTime(0.0f, Matrix());
|
||||
|
||||
if (boneController != NULL)
|
||||
{
|
||||
resultRenderable->AddController(boneController); // you can also clone it for instancing reasons :)
|
||||
boneController->PlaySequence(L"all");
|
||||
}
|
||||
|
||||
return resultRenderable;
|
||||
}
|
||||
132
demo09/src/demo09/Resources/BLUImporter/BLUImporter.h
Normal file
132
demo09/src/demo09/Resources/BLUImporter/BLUImporter.h
Normal file
@@ -0,0 +1,132 @@
|
||||
#pragma once
|
||||
#include "../Bone/BoneController.h"
|
||||
|
||||
struct BluSectionType
|
||||
{
|
||||
enum Enumeration
|
||||
{
|
||||
Mesh = 0,
|
||||
Material = 1,
|
||||
Bone = 2,
|
||||
Animation = 3,
|
||||
LastKnownType = 3
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template < typename T >
|
||||
struct ScopedBuffer
|
||||
{
|
||||
ScopedBuffer(T* ata)
|
||||
{
|
||||
this->ata = ata;
|
||||
}
|
||||
|
||||
ScopedBuffer(unsigned int count)
|
||||
{
|
||||
this->ata = new T[count];
|
||||
}
|
||||
|
||||
~ScopedBuffer()
|
||||
{
|
||||
if (ata != NULL)
|
||||
delete [] ata;
|
||||
}
|
||||
|
||||
T* Detach()
|
||||
{
|
||||
T* mp = ata;
|
||||
ata = NULL;
|
||||
return mp;
|
||||
}
|
||||
|
||||
T* GetData() const
|
||||
{
|
||||
return ata;
|
||||
}
|
||||
|
||||
operator const T* () { return ata; }
|
||||
|
||||
T* ata;
|
||||
};
|
||||
|
||||
|
||||
struct BluImportedMeshBuffer
|
||||
{
|
||||
IMeshBuffer* meshBuffer;
|
||||
std::wstring materialName;
|
||||
};
|
||||
|
||||
|
||||
struct BluImportedBone
|
||||
{
|
||||
IBone* bone;
|
||||
std::wstring parentName;
|
||||
};
|
||||
|
||||
|
||||
class BluImportResult
|
||||
{
|
||||
public:
|
||||
BluImportResult()
|
||||
: successfullyLoaded(false)
|
||||
, boneController(NULL)
|
||||
{}
|
||||
|
||||
bool successfullyLoaded;
|
||||
std::wstring fileName;
|
||||
std::map<std::wstring, BluImportedMeshBuffer> meshBuffers;
|
||||
std::map<std::wstring, IMaterial*> materials;
|
||||
std::map<std::wstring, BluImportedBone> bones;
|
||||
std::map<std::wstring, ITransformationAnimation*> animations;
|
||||
|
||||
BoneController* boneController;
|
||||
|
||||
IRenderable* GenerateRootRenderable(IEngine* engine, IMaterial* overrideMaterial);
|
||||
};
|
||||
|
||||
|
||||
class BluImporter
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
BluImporter(IEngine* engine);
|
||||
BluImportResult Load(LPCTSTR fileName);
|
||||
|
||||
static IRenderable* Load(IEngine* engine, LPCTSTR fileName, IMaterial* overrideMaterial = NULL);
|
||||
|
||||
protected:
|
||||
void ImportMesh(IFile* file, std::string objectName, BluImportResult& result);
|
||||
void ImportMaterial(IFile* file, std::string objectName, BluImportResult& result);
|
||||
void ImportBone(IFile* file, std::string objectName, BluImportResult& result);
|
||||
void ImportAnimation(IFile* file, std::string objectName, BluImportResult& result);
|
||||
|
||||
std::wstring ConvertToString16(const std::string& string) const
|
||||
{
|
||||
unsigned int codePage = 0;
|
||||
if (string.size() == 0)
|
||||
return std::wstring();
|
||||
|
||||
int length = ::MultiByteToWideChar(codePage, 0, string.c_str(), (int)string.size() + 1, NULL, 0);
|
||||
if (length == 0)
|
||||
return std::wstring();
|
||||
|
||||
wchar_t* newBuffer = new wchar_t[(unsigned int)length];
|
||||
::MultiByteToWideChar(codePage, 0, string.c_str(), (int)string.size() + 1, newBuffer, length);
|
||||
return std::wstring(newBuffer);
|
||||
}
|
||||
|
||||
std::wstring ConvertPath(const std::string& orignal)
|
||||
{
|
||||
if (orignal.empty())
|
||||
return this->ConvertToString16(orignal);
|
||||
|
||||
unsigned int pos = orignal.rfind("\\");
|
||||
return currentPath + this->ConvertToString16(orignal.substr(pos + 1, orignal.size() - pos));
|
||||
}
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
std::wstring currentPath;
|
||||
};
|
||||
98
demo09/src/demo09/Resources/Billboard/Billboard.cpp
Normal file
98
demo09/src/demo09/Resources/Billboard/Billboard.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "stdafx.h"
|
||||
#include "Billboard.h"
|
||||
#include "ITexture.h"
|
||||
|
||||
|
||||
Billboard::Billboard(IEngine* engine)
|
||||
: Renderable(engine)
|
||||
, texture(NULL)
|
||||
, orientation(BillboardOrientation::World)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Billboard::~Billboard()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BillboardOrientation::Enumeration Billboard::GetOrientation()
|
||||
{
|
||||
return orientation;
|
||||
}
|
||||
|
||||
|
||||
void Billboard::SetOrientation(BillboardOrientation::Enumeration value)
|
||||
{
|
||||
orientation = value;
|
||||
}
|
||||
|
||||
|
||||
void Billboard::SetTexture(ITexture* value)
|
||||
{
|
||||
texture = value;
|
||||
}
|
||||
|
||||
|
||||
ITexture* Billboard::GetTexture()
|
||||
{
|
||||
return texture;
|
||||
}
|
||||
|
||||
|
||||
void Billboard::RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage == RenderStage::BeforeRender)
|
||||
{
|
||||
if (orientation == BillboardOrientation::Spherical) // undo everything but translation
|
||||
{
|
||||
float m[16];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
||||
|
||||
// 1 0 0 x
|
||||
// 0 1 0 x
|
||||
// 0 0 1 x
|
||||
// x x x x
|
||||
|
||||
ZeroMemory(&m[1], 2 * sizeof(float));
|
||||
ZeroMemory(&m[4], 3 * sizeof(float));
|
||||
ZeroMemory(&m[8], 2 * sizeof(float));
|
||||
m[0] = m[5] = m[10] = 1.0f;
|
||||
|
||||
glLoadMatrixf(m);
|
||||
}
|
||||
else if (orientation == BillboardOrientation::Cylindrical) // undo everything but translation and Y-orientation
|
||||
{
|
||||
float m[16];
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
||||
|
||||
// 1 0 0 x
|
||||
// x x x x
|
||||
// 0 0 1 x
|
||||
// x x x x
|
||||
|
||||
ZeroMemory(&m[1], 2 * sizeof(float));
|
||||
ZeroMemory(&m[8], 2 * sizeof(float));
|
||||
m[0] = m[10] = 1.0f;
|
||||
glLoadMatrixf(m);
|
||||
}
|
||||
}
|
||||
else if (stage == RenderStage::Render)
|
||||
{
|
||||
float ratio = (float(texture->GetWidth()) / float(texture->GetHeight())) / 2.0f;
|
||||
glUseProgram(0);
|
||||
texture->Bind(0);
|
||||
glDisable(GL_LIGHTING);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex2f(ratio, 0.5f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex2f(-ratio, 0.5f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex2f(-ratio, -0.5f);
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex2f(ratio, -0.5f);
|
||||
glEnd();
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
}
|
||||
26
demo09/src/demo09/Resources/Billboard/Billboard.h
Normal file
26
demo09/src/demo09/Resources/Billboard/Billboard.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "IBillboard.h"
|
||||
#include "../Renderable/Renderable.h"
|
||||
|
||||
|
||||
class Billboard
|
||||
: public IBillboard
|
||||
, public Renderable
|
||||
{
|
||||
public:
|
||||
Billboard(IEngine* engine);
|
||||
virtual ~Billboard();
|
||||
|
||||
virtual BillboardOrientation::Enumeration GetOrientation();
|
||||
virtual void SetOrientation(BillboardOrientation::Enumeration value);
|
||||
virtual void SetTexture(ITexture* value);
|
||||
virtual ITexture* GetTexture();
|
||||
|
||||
protected:
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage);
|
||||
|
||||
private:
|
||||
ITexture* texture;
|
||||
BillboardOrientation::Enumeration orientation;
|
||||
};
|
||||
132
demo09/src/demo09/Resources/Billboard/BillboardBatch.cpp
Normal file
132
demo09/src/demo09/Resources/Billboard/BillboardBatch.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include "stdafx.h"
|
||||
#include "BillboardBatch.h"
|
||||
#include "IBillboard.h"
|
||||
#include "IMeshBuffer.h"
|
||||
#include "IResourceFactory.h"
|
||||
#include "IWorld.h"
|
||||
#include "ICamera.h"
|
||||
|
||||
BillboardBatch::BillboardBatch(IEngine* engine, unsigned int initialSizeInBillboards, IMaterial* material)
|
||||
: Renderable(engine)
|
||||
, maxSizeInBillboards(0)
|
||||
, batchMeshBuffer(NULL)
|
||||
{
|
||||
batchMeshBuffer = engine->GetResourceFactory()->CreateMeshBuffer();
|
||||
batchMeshBuffer->SetPrimitiveTopology(PrimitiveTopology::Quad);
|
||||
batchMeshBuffer->SetMaterial(material);
|
||||
this->Grow(initialSizeInBillboards);
|
||||
}
|
||||
|
||||
|
||||
void BillboardBatch::SetMaterial(IMaterial* value)
|
||||
{
|
||||
batchMeshBuffer->SetMaterial(value);
|
||||
}
|
||||
|
||||
|
||||
IMaterial* BillboardBatch::GetMaterial()
|
||||
{
|
||||
return batchMeshBuffer->GetMaterial();
|
||||
}
|
||||
|
||||
|
||||
void BillboardBatch::RenderInternal(RenderStage::Enumeration stage)
|
||||
{
|
||||
if (stage == RenderStage::BeforeRender)
|
||||
{
|
||||
Vector right = this->GetWorld()->GetCamera()->GetRight();
|
||||
Vector up = this->GetWorld()->GetCamera()->GetUp();
|
||||
|
||||
BillboardVertex* vertexData = (BillboardVertex*)batchMeshBuffer->MapVertexBufferData(MeshBufferAccessType::WriteOnly);
|
||||
|
||||
for (unsigned int i = 0; i < billboards.size(); ++i, vertexData += 4)
|
||||
this->FillVertexDataWithBillboard(billboards[i], vertexData, right, up);
|
||||
|
||||
batchMeshBuffer->UnmapVertexBufferData();
|
||||
|
||||
}
|
||||
else if (stage == RenderStage::Render)
|
||||
{
|
||||
dynamic_cast<IRenderable*>(batchMeshBuffer)->Render();
|
||||
}
|
||||
else if (stage == RenderStage::AfterRender)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BillboardBatch::AddRenderable(IRenderable* value)
|
||||
{
|
||||
IBillboard* billboard = dynamic_cast<IBillboard*>(value);
|
||||
|
||||
if (billboard == NULL)
|
||||
Renderable::AddRenderable(value);
|
||||
else
|
||||
{
|
||||
billboards.push_back(billboard);
|
||||
if (billboards.size() >= maxSizeInBillboards)
|
||||
this->Grow(maxSizeInBillboards);
|
||||
else
|
||||
batchMeshBuffer->SetUsedIndexCount(4 * billboards.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BillboardBatch::Grow(unsigned int additionalSize)
|
||||
{
|
||||
if (additionalSize == 0)
|
||||
return;
|
||||
|
||||
maxSizeInBillboards += additionalSize;
|
||||
|
||||
std::vector<VertexElement::Enumeration> vertexElements;
|
||||
vertexElements.push_back(VertexElement::Position3D);
|
||||
vertexElements.push_back(VertexElement::Texture2D);
|
||||
|
||||
BillboardVertex* vertexBufferBufferData = new BillboardVertex[4 * maxSizeInBillboards];
|
||||
batchMeshBuffer->SetVertexBuffer(vertexBufferBufferData, 4 * maxSizeInBillboards, vertexElements, MeshBufferUsage::Dynamic, true);
|
||||
|
||||
unsigned int* indexBufferData = new unsigned int[4 * maxSizeInBillboards];
|
||||
for (unsigned int i = 0; i < 4 * maxSizeInBillboards; ++i)
|
||||
indexBufferData[i] = i;
|
||||
|
||||
batchMeshBuffer->SetIndexBuffer(indexBufferData, 4 * maxSizeInBillboards, MeshBufferUsage::Static, true);
|
||||
batchMeshBuffer->SetUsedIndexCount(4 * billboards.size());
|
||||
}
|
||||
|
||||
|
||||
void BillboardBatch::FillVertexDataWithBillboard(IBillboard* billboard, BillboardVertex* vertexData, const Vector& aright, const Vector& aup)
|
||||
{
|
||||
IRenderable* renderable = dynamic_cast<IRenderable*>(billboard);
|
||||
Vector translation = renderable->GetTranslation();
|
||||
|
||||
Vector right = aright * renderable->GetScale().x;
|
||||
Vector up = aup * renderable->GetScale().y;
|
||||
|
||||
if (billboard->GetOrientation() == BillboardOrientation::Cylindrical)
|
||||
{
|
||||
up.x = 0.0f;
|
||||
up.y = 1.0f;
|
||||
up.z = 0.0f;
|
||||
}
|
||||
|
||||
vertexData[0].X = translation.x + right.x + up.x;
|
||||
vertexData[0].Y = translation.y + right.y + up.y;
|
||||
vertexData[0].Z = translation.z + right.z + up.z;
|
||||
vertexData[0].U = 1.0f; vertexData[0].V = 1.0f;
|
||||
|
||||
vertexData[1].X = translation.x - right.x + up.x;
|
||||
vertexData[1].Y = translation.y - right.y + up.y;
|
||||
vertexData[1].Z = translation.z - right.z + up.z;
|
||||
vertexData[1].U = 0.0f; vertexData[1].V = 1.0f;
|
||||
|
||||
vertexData[2].X = translation.x - right.x - up.x;
|
||||
vertexData[2].Y = translation.y - right.y - up.y;
|
||||
vertexData[2].Z = translation.z - right.z - up.z;
|
||||
vertexData[2].U = 0.0f; vertexData[2].V = 0.0f;
|
||||
|
||||
vertexData[3].X = translation.x + right.x - up.x;
|
||||
vertexData[3].Y = translation.y + right.y - up.y;
|
||||
vertexData[3].Z = translation.z + right.z - up.z;
|
||||
vertexData[3].U = 1.0f; vertexData[3].V = 0.0f;
|
||||
}
|
||||
51
demo09/src/demo09/Resources/Billboard/BillboardBatch.h
Normal file
51
demo09/src/demo09/Resources/Billboard/BillboardBatch.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "IBillboard.h"
|
||||
#include "ICamera.h"
|
||||
#include "IRenderable.h"
|
||||
#include "../Renderable/Renderable.h"
|
||||
|
||||
|
||||
struct BillboardVertex
|
||||
{
|
||||
float X;
|
||||
float Y;
|
||||
float Z;
|
||||
float U;
|
||||
float V;
|
||||
};
|
||||
|
||||
|
||||
class BillboardBatch
|
||||
: public IBillboardBatch
|
||||
, public Renderable
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
BillboardBatch(IEngine* engine, unsigned int initialSizeInBillboards, IMaterial* material);
|
||||
|
||||
virtual void SetMaterial(IMaterial* value);
|
||||
virtual IMaterial* GetMaterial();
|
||||
|
||||
protected:
|
||||
// IRenderable
|
||||
virtual void RenderInternal(RenderStage::Enumeration stage);
|
||||
virtual void AddRenderable(IRenderable* value);
|
||||
|
||||
void Grow(unsigned int additionalSize);
|
||||
void FillVertexDataWithBillboard(IBillboard* billboard, BillboardVertex* vertexData, const Vector& right, const Vector& up);
|
||||
|
||||
bool SortParticles(IBillboard* a, IBillboard* b)
|
||||
{
|
||||
IRenderable* ra = dynamic_cast<IRenderable*>(a);
|
||||
IRenderable* rb = dynamic_cast<IRenderable*>(b);
|
||||
return ra->GetTranslation() > rb->GetTranslation();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::vector<IBillboard*> billboards;
|
||||
unsigned int maxSizeInBillboards;
|
||||
IMeshBuffer* batchMeshBuffer;
|
||||
};
|
||||
139
demo09/src/demo09/Resources/Bone/Bone.cpp
Normal file
139
demo09/src/demo09/Resources/Bone/Bone.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
#include "stdafx.h"
|
||||
#include "Bone.h"
|
||||
#include "ITransformationAnimation.h"
|
||||
|
||||
|
||||
Bone::Bone(IEngine* engine, const std::wstring& name, int index, const Vector& poseTranslation, const Vector& poseScale, const Quaternion& poseRotation)
|
||||
: engine(engine)
|
||||
, name(name)
|
||||
, parent(NULL)
|
||||
, transformationAnimation(NULL)
|
||||
, boneIndex(index)
|
||||
, lastAnimationTime(-1.0f)
|
||||
, matrixArray(NULL)
|
||||
{
|
||||
poseTransformation = Matrix::scale(poseScale) * Matrix::translate(poseTranslation) * Matrix(poseRotation);
|
||||
invPoseTransformation = poseTransformation;
|
||||
invPoseTransformation.inverse();
|
||||
}
|
||||
|
||||
|
||||
const Matrix& Bone::GetTransformationAtTime(float t, const Matrix& rootTransformationMatrix)
|
||||
{
|
||||
if (transformationAnimation != NULL)
|
||||
{
|
||||
if (t != lastAnimationTime)
|
||||
{
|
||||
if (parent != NULL)
|
||||
{
|
||||
transformation = (transformationAnimation->GetTransformationAtTime(t) * invPoseTransformation) * parent->GetTransformationAtTime(t, rootTransformationMatrix);
|
||||
transformation = invPoseTransformation * transformationAnimation->GetTransformationAtTime(t);
|
||||
//transformation = transformation * ( * invPoseTransformation);
|
||||
}
|
||||
else
|
||||
transformation = transformationAnimation->GetTransformationAtTime(t) * invPoseTransformation;
|
||||
}
|
||||
}
|
||||
return transformation;
|
||||
}
|
||||
|
||||
|
||||
const Matrix& Bone::GetPoseTransformation() const
|
||||
{
|
||||
return poseTransformation;
|
||||
}
|
||||
|
||||
|
||||
void Bone::SetParent(IBone* parent)
|
||||
{
|
||||
if (parent != NULL)
|
||||
{
|
||||
std::vector<IBone*>& children = parent->GetChildBones();
|
||||
for (__w64 unsigned int i = 0; i < children.size(); ++i)
|
||||
if (children[i] == this)
|
||||
{
|
||||
children.erase(children.begin() + (__w64 int)i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->parent = parent;
|
||||
if (this->parent != NULL)
|
||||
this->parent->GetChildBones().push_back(this);
|
||||
}
|
||||
|
||||
|
||||
IBone* Bone::GetParent() const
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
std::vector<IBone*>& Bone::GetChildBones()
|
||||
{
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
std::wstring Bone::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
int Bone::GetIndex() const
|
||||
{
|
||||
return boneIndex;
|
||||
}
|
||||
|
||||
|
||||
void Bone::SetTransformationAnimation(ITransformationAnimation* ta)
|
||||
{
|
||||
transformationAnimation = ta;
|
||||
lastAnimationTime = -1.0f;
|
||||
transformation = Matrix();
|
||||
}
|
||||
|
||||
|
||||
ITransformationAnimation* Bone::GetTransformationAnimation() const
|
||||
{
|
||||
return transformationAnimation;
|
||||
}
|
||||
|
||||
|
||||
std::map<int, IBone*>& Bone::GetBoneIndexList()
|
||||
{
|
||||
if (parent != NULL)
|
||||
return parent->GetBoneIndexList();
|
||||
|
||||
if (boneIndexList.empty())
|
||||
this->FillBoneIndexList(this, boneIndexList);
|
||||
|
||||
return boneIndexList;
|
||||
}
|
||||
|
||||
|
||||
Matrix* Bone::GetMatrixArray()
|
||||
{
|
||||
if (matrixArray == NULL)
|
||||
{
|
||||
matrixArraySize = this->GetBoneIndexList().size();
|
||||
matrixArray = new Matrix[matrixArraySize];
|
||||
}
|
||||
return matrixArray;
|
||||
}
|
||||
|
||||
|
||||
unsigned int Bone::GetMatrixArraySize()
|
||||
{
|
||||
if (matrixArray == NULL)
|
||||
this->GetMatrixArray();
|
||||
return matrixArraySize;
|
||||
}
|
||||
|
||||
|
||||
void Bone::FillBoneIndexList(IBone* currentBone, std::map<int, IBone*>& list)
|
||||
{
|
||||
list[currentBone->GetIndex()] = currentBone;
|
||||
for (unsigned int i = 0; i < currentBone->GetChildBones().size(); ++i)
|
||||
this->FillBoneIndexList(currentBone->GetChildBones()[i], list);
|
||||
}
|
||||
55
demo09/src/demo09/Resources/Bone/Bone.h
Normal file
55
demo09/src/demo09/Resources/Bone/Bone.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include "IBone.h"
|
||||
|
||||
|
||||
class Bone
|
||||
: public IBone
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
Bone(IEngine* engine, const std::wstring& name, int index, const Vector& poseTranslation, const Vector& poseScale, const Quaternion& poseRotation);
|
||||
|
||||
virtual const Matrix& GetTransformationAtTime(float t, const Matrix& rootTransformationMatrix);
|
||||
virtual const Matrix& GetPoseTransformation() const;
|
||||
|
||||
virtual void SetParent(IBone* parent);
|
||||
virtual IBone* GetParent() const;
|
||||
virtual std::vector<IBone*>& GetChildBones();
|
||||
|
||||
virtual std::wstring GetName() const;
|
||||
virtual int GetIndex() const;
|
||||
|
||||
virtual void SetTransformationAnimation(ITransformationAnimation* ta);
|
||||
virtual ITransformationAnimation* GetTransformationAnimation() const;
|
||||
|
||||
virtual std::map<int, IBone*>& GetBoneIndexList();
|
||||
|
||||
virtual Matrix* GetMatrixArray();
|
||||
virtual unsigned int GetMatrixArraySize();
|
||||
|
||||
private:
|
||||
void FillBoneIndexList(IBone* currentBone, std::map<int, IBone*>& list);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
|
||||
std::wstring name;
|
||||
int boneIndex;
|
||||
|
||||
Matrix poseTransformation;
|
||||
Matrix invPoseTransformation;
|
||||
|
||||
float lastAnimationTime;
|
||||
Matrix transformation;
|
||||
|
||||
std::vector<IBone*> children;
|
||||
IBone* parent;
|
||||
|
||||
ITransformationAnimation* transformationAnimation;
|
||||
|
||||
std::map<int, IBone*> boneIndexList;
|
||||
Matrix* matrixArray;
|
||||
unsigned int matrixArraySize;
|
||||
};
|
||||
109
demo09/src/demo09/Resources/Bone/BoneController.cpp
Normal file
109
demo09/src/demo09/Resources/Bone/BoneController.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "stdafx.h"
|
||||
#include "BoneController.h"
|
||||
#include "../../Interfaces/IBone.h"
|
||||
#include "../../Interfaces/IEngine.h"
|
||||
#include "../../Interfaces/ITimeLine.h"
|
||||
|
||||
BoneController::BoneController(IEngine* engine, IBone* rootBone)
|
||||
: engine(engine)
|
||||
, rootBone(rootBone)
|
||||
, startTime(0.0)
|
||||
{
|
||||
bones = rootBone->GetBoneIndexList();
|
||||
}
|
||||
|
||||
|
||||
BoneController::BoneController(const BoneController& other)
|
||||
: engine(other.engine)
|
||||
, rootBone(other.rootBone)
|
||||
, startTime(other.startTime)
|
||||
, currentSequence(other.currentSequence)
|
||||
, currentSequenceInfo(other.currentSequenceInfo)
|
||||
, sequences(other.sequences)
|
||||
, bones(other.bones)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BoneController::Apply(IRenderable&)
|
||||
{
|
||||
float time = 0.0f;
|
||||
if (!currentSequence.empty())
|
||||
time = GetCurrentTime();
|
||||
|
||||
int i = 0;
|
||||
Matrix* matrixArray = rootBone->GetMatrixArray();
|
||||
for (std::map<int, IBone*>::const_iterator iter = bones.begin(); iter != bones.end(); ++iter, ++i)
|
||||
{
|
||||
matrixArray[i] = iter->second->GetTransformationAtTime(time, Matrix());
|
||||
//matrix[i].transpose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BoneController::Revert(IRenderable&)
|
||||
{
|
||||
// nop
|
||||
}
|
||||
|
||||
|
||||
void BoneController::RegisterSequence(const std::wstring& name, float start, float end, bool loop)
|
||||
{
|
||||
Sequence newSequence;
|
||||
newSequence.start = start;
|
||||
newSequence.end = end;
|
||||
newSequence.loop = loop;
|
||||
sequences[name] = newSequence;
|
||||
}
|
||||
|
||||
|
||||
void BoneController::PlaySequence(const std::wstring& name)
|
||||
{
|
||||
startTime = engine->GetTimeline()->GetDemoTime();
|
||||
|
||||
std::map<std::wstring, Sequence >::iterator iter = sequences.find(name);
|
||||
if (iter != sequences.end())
|
||||
{
|
||||
currentSequenceInfo = iter->second;
|
||||
currentSequence = name;
|
||||
}
|
||||
else
|
||||
currentSequence = std::wstring();
|
||||
}
|
||||
|
||||
|
||||
const std::wstring& BoneController::GetCurrentSequence() const
|
||||
{
|
||||
return currentSequence;
|
||||
}
|
||||
|
||||
|
||||
float BoneController::GetCurrentTime()
|
||||
{
|
||||
float currentTime = static_cast<float>(engine->GetTimeline()->GetDemoTime() - startTime);
|
||||
currentTime = currentTime / (currentSequenceInfo.end - currentSequenceInfo.start);
|
||||
currentTime = (currentSequenceInfo.end - currentSequenceInfo.start) * currentTime + currentSequenceInfo.start;
|
||||
|
||||
if (currentTime >= currentSequenceInfo.end)
|
||||
{
|
||||
while (currentSequenceInfo.loop && currentTime >= currentSequenceInfo.end)
|
||||
{
|
||||
currentTime -= currentSequenceInfo.end;
|
||||
startTime += currentSequenceInfo.end;
|
||||
}
|
||||
if (!currentSequenceInfo.loop)
|
||||
currentTime = currentSequenceInfo.end;
|
||||
}
|
||||
else if (currentTime < currentSequenceInfo.start)
|
||||
{
|
||||
while (currentSequenceInfo.loop && currentTime < currentSequenceInfo.start)
|
||||
{
|
||||
currentTime += currentSequenceInfo.start;
|
||||
startTime -= currentSequenceInfo.start;
|
||||
}
|
||||
if (!currentSequenceInfo.loop)
|
||||
currentTime = currentSequenceInfo.start;
|
||||
}
|
||||
|
||||
return currentTime;
|
||||
}
|
||||
44
demo09/src/demo09/Resources/Bone/BoneController.h
Normal file
44
demo09/src/demo09/Resources/Bone/BoneController.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "../../Interfaces/IController.h"
|
||||
|
||||
struct IEngine;
|
||||
struct ITimeline;
|
||||
|
||||
class BoneController : public IController
|
||||
{
|
||||
public:
|
||||
BoneController(IEngine* engine, IBone* rootBone);
|
||||
BoneController(const BoneController& other);
|
||||
|
||||
virtual void Apply(IRenderable& renderable);
|
||||
virtual void Revert(IRenderable& renderable);
|
||||
|
||||
void RegisterSequence(const std::wstring& name, float start, float end, bool loop);
|
||||
void PlaySequence(const std::wstring& name);
|
||||
|
||||
const std::wstring& GetCurrentSequence() const;
|
||||
|
||||
private:
|
||||
|
||||
float GetCurrentTime();
|
||||
|
||||
struct Sequence
|
||||
{
|
||||
Sequence()
|
||||
: start(0.0f)
|
||||
, end(0.0f)
|
||||
, loop(false)
|
||||
{
|
||||
}
|
||||
float start;
|
||||
float end;
|
||||
bool loop;
|
||||
};
|
||||
|
||||
IEngine* engine;
|
||||
IBone* rootBone;
|
||||
double startTime;
|
||||
std::wstring currentSequence;
|
||||
Sequence currentSequenceInfo;
|
||||
std::map<std::wstring, Sequence > sequences;
|
||||
std::map<int, IBone*> bones;
|
||||
};
|
||||
32
demo09/src/demo09/Resources/Bone/BoneShaderCallback.cpp
Normal file
32
demo09/src/demo09/Resources/Bone/BoneShaderCallback.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "stdafx.h"
|
||||
#include "BoneShaderCallback.h"
|
||||
#include "ITimeLine.h"
|
||||
#include "IRenderer.h"
|
||||
#include "IWorld.h"
|
||||
#include "ICamera.h"
|
||||
#include "IBone.h"
|
||||
|
||||
|
||||
BoneShaderCallback::BoneShaderCallback(IEngine* engine)
|
||||
: engine(engine)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BoneShaderCallback::OnShaderProgramActivate(IShaderProgram& program, void* additionalData)
|
||||
{
|
||||
if (additionalData == NULL)
|
||||
return;
|
||||
|
||||
IBone* bone = reinterpret_cast<IBone*>(additionalData);
|
||||
if (bone == NULL)
|
||||
return;
|
||||
|
||||
program.SetParam("bonematrix", bone->GetMatrixArray(), (int)bone->GetMatrixArraySize());
|
||||
}
|
||||
|
||||
|
||||
bool BoneShaderCallback::IsFunctionalWithShaderProgram(IShaderProgram& program)
|
||||
{
|
||||
return program.GetUniformHandle("bonematrix") != (unsigned int)-1;
|
||||
}
|
||||
21
demo09/src/demo09/Resources/Bone/BoneShaderCallback.h
Normal file
21
demo09/src/demo09/Resources/Bone/BoneShaderCallback.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "IShader.h"
|
||||
|
||||
|
||||
class BoneShaderCallback
|
||||
: public IShaderCallback
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
BoneShaderCallback(IEngine* engine);
|
||||
virtual ~BoneShaderCallback() {};
|
||||
|
||||
virtual std::wstring GetName() const { return _T("bones"); }
|
||||
|
||||
virtual void OnShaderProgramActivate(IShaderProgram& program, void* additionalData);
|
||||
virtual bool IsFunctionalWithShaderProgram(IShaderProgram& program);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
};
|
||||
203
demo09/src/demo09/Resources/Camera/Camera.cpp
Normal file
203
demo09/src/demo09/Resources/Camera/Camera.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
#include "stdafx.h"
|
||||
#include "Camera.h"
|
||||
#include "IGraphics.h"
|
||||
|
||||
|
||||
Camera::Camera(IEngine* engine)
|
||||
: engine(engine)
|
||||
, type(CameraType::Perspective)
|
||||
, fOV(45.0f)
|
||||
, position(0.0f, 0.0f, -5.0f, 0.0f)
|
||||
, center(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
, direction(0.0f, 0.0f, -1.0f, 0.0f)
|
||||
, up(0.0f, 1.0f, 0.0f, 0.0f)
|
||||
, moon(0.0f, 1.0f, -5.0f, 0.0f)
|
||||
, right(1.0f, 0.0f, 0.0f, 0.0f)
|
||||
, changed(true)
|
||||
{
|
||||
frustum.SetCameraInternals(fOV, engine->GetGraphics()->GetAspectRatio(), 0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
|
||||
Camera::~Camera()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CameraType::Enumeration Camera::GetType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetType(CameraType::Enumeration value)
|
||||
{
|
||||
type = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetPosition(const Vector& value)
|
||||
{
|
||||
position = Vector(value);
|
||||
this->UpdateDirection();
|
||||
this->UpdateRight();
|
||||
this->UpdateUp();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetCenter(const Vector& value)
|
||||
{
|
||||
center = Vector(value);
|
||||
this->UpdateDirection();
|
||||
this->UpdateRight();
|
||||
this->UpdateUp();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetDirection(const Vector& value)
|
||||
{
|
||||
direction = Vector(value);
|
||||
center = position + direction;
|
||||
direction.normalize();
|
||||
this->UpdateRight();
|
||||
this->UpdateUp();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetUp(const Vector& value)
|
||||
{
|
||||
up = Vector(value);
|
||||
moon = position + up;
|
||||
up.normalize();
|
||||
this->UpdateRight();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::SetMoon(const Vector& value)
|
||||
{
|
||||
moon = Vector(value);
|
||||
up = moon - position;
|
||||
up.normalize();
|
||||
this->UpdateRight();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
Vector Camera::GetPosition()
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
Vector Camera::GetCenter()
|
||||
{
|
||||
return center;
|
||||
}
|
||||
|
||||
|
||||
Vector Camera::GetDirection()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
||||
Vector Camera::GetUp()
|
||||
{
|
||||
return up;
|
||||
}
|
||||
|
||||
|
||||
Vector Camera::GetMoon()
|
||||
{
|
||||
return moon;
|
||||
}
|
||||
|
||||
|
||||
Vector Camera::GetRight()
|
||||
{
|
||||
return right;
|
||||
}
|
||||
|
||||
|
||||
const Matrix& Camera::GetViewMatrix()
|
||||
{
|
||||
return viewMatrix;
|
||||
}
|
||||
|
||||
|
||||
void Camera::GetViewMatrix(const Matrix& value)
|
||||
{
|
||||
glLoadMatrixf(value.m);
|
||||
}
|
||||
|
||||
|
||||
void Camera::GetFOV(float value)
|
||||
{
|
||||
fOV = value;
|
||||
}
|
||||
|
||||
|
||||
float Camera::GetFOV()
|
||||
{
|
||||
return fOV;
|
||||
}
|
||||
|
||||
|
||||
void Camera::Apply()
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(fOV, engine->GetGraphics()->GetAspectRatio(), 0.1, 256.0);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
gluLookAt(
|
||||
position.x, position.y, position.z,
|
||||
center.x, center.y, center.z,
|
||||
up.x, up.y, up.z);
|
||||
|
||||
glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix.m);
|
||||
}
|
||||
|
||||
|
||||
void Camera::UpdateDirection()
|
||||
{
|
||||
direction = center - position;
|
||||
direction.normalize();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::UpdateRight()
|
||||
{
|
||||
right = direction.cross(up);
|
||||
right.normalize();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
void Camera::UpdateUp()
|
||||
{
|
||||
up = right.cross(direction);
|
||||
up.normalize();
|
||||
moon = position + up;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
IFrustum& Camera::GetFrustum()
|
||||
{
|
||||
// get view frustum
|
||||
if (changed)
|
||||
{
|
||||
changed = false;
|
||||
frustum.SetCameraDefinition(position, center, up);
|
||||
}
|
||||
|
||||
return frustum;
|
||||
}
|
||||
56
demo09/src/demo09/Resources/Camera/Camera.h
Normal file
56
demo09/src/demo09/Resources/Camera/Camera.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include "ICamera.h"
|
||||
#include "Frustum.h"
|
||||
|
||||
|
||||
class Camera
|
||||
: public ICamera
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
Camera(IEngine* engine);
|
||||
virtual ~Camera();
|
||||
|
||||
virtual CameraType::Enumeration GetType();
|
||||
virtual void SetType(CameraType::Enumeration value);
|
||||
virtual void SetPosition(const Vector& value);
|
||||
virtual void SetCenter(const Vector& value);
|
||||
virtual void SetDirection(const Vector& value);
|
||||
virtual void SetUp(const Vector& value);
|
||||
virtual void SetMoon(const Vector& value);
|
||||
virtual Vector GetPosition();
|
||||
virtual Vector GetCenter();
|
||||
virtual Vector GetDirection();
|
||||
virtual Vector GetUp();
|
||||
virtual Vector GetMoon();
|
||||
virtual Vector GetRight();
|
||||
virtual const Matrix& GetViewMatrix();
|
||||
virtual void GetViewMatrix(const Matrix& value);
|
||||
|
||||
virtual void GetFOV(float value);
|
||||
virtual float GetFOV();
|
||||
virtual void Apply();
|
||||
|
||||
virtual IFrustum& GetFrustum();
|
||||
|
||||
private:
|
||||
void UpdateDirection();
|
||||
void UpdateRight();
|
||||
void UpdateUp();
|
||||
|
||||
Vector position;
|
||||
Vector center;
|
||||
Vector direction;
|
||||
Vector right;
|
||||
Vector up;
|
||||
Vector moon;
|
||||
Matrix viewMatrix;
|
||||
IEngine* engine;
|
||||
CameraType::Enumeration type;
|
||||
float fOV;
|
||||
|
||||
Frustum frustum;
|
||||
bool changed;
|
||||
};
|
||||
93
demo09/src/demo09/Resources/Camera/Frustum.cpp
Normal file
93
demo09/src/demo09/Resources/Camera/Frustum.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "stdafx.h"
|
||||
#include "Frustum.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Frustum::Frustum()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Frustum::~Frustum()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Frustum::SetCameraInternals(float angle, float ratio, float nearD, float farD)
|
||||
{
|
||||
this->ratio = ratio;
|
||||
this->angle = angle;
|
||||
this->nearD = nearD;
|
||||
this->farD = farD;
|
||||
|
||||
tang = (float)tan(angle* ANG2RAD * 0.5);
|
||||
nh = nearD * tang;
|
||||
nw = nh * ratio;
|
||||
fh = farD * tang;
|
||||
fw = fh * ratio;
|
||||
}
|
||||
|
||||
|
||||
void Frustum::SetCameraDefinition(Vector &p, Vector &l, Vector &u)
|
||||
{
|
||||
Vector dir,nc,fc,X,Y,Z;
|
||||
|
||||
Z = p - l;
|
||||
Z.normalize();
|
||||
|
||||
X = u * Z;
|
||||
X.normalize();
|
||||
|
||||
Y = Z * X;
|
||||
|
||||
nc = p - Z * nearD;
|
||||
fc = p - Z * farD;
|
||||
|
||||
ntl = nc + Y * nh - X * nw;
|
||||
ntr = nc + Y * nh + X * nw;
|
||||
nbl = nc - Y * nh - X * nw;
|
||||
nbr = nc - Y * nh + X * nw;
|
||||
|
||||
ftl = fc + Y * fh - X * fw;
|
||||
ftr = fc + Y * fh + X * fw;
|
||||
fbl = fc - Y * fh - X * fw;
|
||||
fbr = fc - Y * fh + X * fw;
|
||||
|
||||
planes[0] = Plane(ntr,ntl,ftl);
|
||||
planes[1] = Plane(nbl,nbr,fbr);
|
||||
planes[2] = Plane(ntl,nbl,fbl);
|
||||
planes[3] = Plane(nbr,ntr,fbr);
|
||||
planes[4] = Plane(ntl,ntr,nbr);
|
||||
planes[5] = Plane(ftr,ftl,fbl);
|
||||
}
|
||||
|
||||
|
||||
ClipTestResult::Enumeration Frustum::TestPointInFrustum(Vector &p)
|
||||
{
|
||||
ClipTestResult::Enumeration result = ClipTestResult::Inside;
|
||||
for(int i=0; i < 6; i++)
|
||||
{
|
||||
if (planes[i].GetDistanceToPoint(p) < 0)
|
||||
return ClipTestResult::Outside;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ClipTestResult::Enumeration Frustum::TestSphereInFrustum(Vector &p, float raio)
|
||||
{
|
||||
ClipTestResult::Enumeration result = ClipTestResult::Inside;
|
||||
float distance;
|
||||
|
||||
for(int i=0; i < 6; i++)
|
||||
{
|
||||
distance = planes[i].GetDistanceToPoint(p);
|
||||
if (distance < -raio)
|
||||
return ClipTestResult::Outside;
|
||||
else if (distance < raio)
|
||||
result = ClipTestResult::Intersect;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
23
demo09/src/demo09/Resources/Camera/Frustum.h
Normal file
23
demo09/src/demo09/Resources/Camera/Frustum.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "ICamera.h"
|
||||
|
||||
|
||||
class Frustum
|
||||
: public IFrustum
|
||||
{
|
||||
public:
|
||||
Frustum();
|
||||
virtual ~Frustum();
|
||||
|
||||
virtual void SetCameraInternals(float angle, float ratio, float nearD, float farD);
|
||||
virtual void SetCameraDefinition(Vector &p, Vector &l, Vector &u);
|
||||
virtual ClipTestResult::Enumeration TestPointInFrustum(Vector &p);
|
||||
virtual ClipTestResult::Enumeration TestSphereInFrustum(Vector &p, float raio);
|
||||
|
||||
private:
|
||||
Plane planes[6];
|
||||
|
||||
Vector ntl,ntr,nbl,nbr,ftl,ftr,fbl,fbr;
|
||||
float nearD, farD, ratio, angle,tang;
|
||||
float nw,nh,fw,fh;
|
||||
};
|
||||
120
demo09/src/demo09/Resources/Light/Light.cpp
Normal file
120
demo09/src/demo09/Resources/Light/Light.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
#include "stdafx.h"
|
||||
#include "Light.h"
|
||||
|
||||
|
||||
Light::Light(IEngine* engine)
|
||||
: engine(engine)
|
||||
, ambient(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
, diffuse(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
, specular(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
, position(0.0f, 0.0f, 0.0f, 1.0f)
|
||||
, direction(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
, exponent(0.0f)
|
||||
, cutoff(180.0f)
|
||||
, constantAttenuation(1.0f)
|
||||
, linearAttenuation(0.0f)
|
||||
, quadraticAttenuation(0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Light::~Light()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Light::SetAmbient(const Vector& value)
|
||||
{
|
||||
ambient = value;
|
||||
}
|
||||
|
||||
|
||||
Vector Light::GetAmbient() const
|
||||
{
|
||||
return ambient;
|
||||
}
|
||||
|
||||
|
||||
void Light::SetDiffuse(const Vector& value)
|
||||
{
|
||||
diffuse = value;
|
||||
}
|
||||
|
||||
|
||||
Vector Light::GetDiffuse() const
|
||||
{
|
||||
return diffuse;
|
||||
}
|
||||
|
||||
|
||||
void Light::SetSpecular(const Vector& value)
|
||||
{
|
||||
specular = value;
|
||||
}
|
||||
|
||||
|
||||
Vector Light::GetSpecular() const
|
||||
{
|
||||
return specular;
|
||||
}
|
||||
|
||||
|
||||
void Light::SetPosition(const Vector& value)
|
||||
{
|
||||
position = value;
|
||||
}
|
||||
|
||||
|
||||
Vector Light::GetPosition() const
|
||||
{
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
void Light::SetSpotLightParameters(const Vector& direction, const float exponent, const float cutoff)
|
||||
{
|
||||
this->direction = direction;
|
||||
this->exponent = exponent;
|
||||
this->cutoff = cutoff;
|
||||
}
|
||||
|
||||
|
||||
void Light::GetSpotLightParameters(Vector& direction, float& exponent, float& cutoff) const
|
||||
{
|
||||
direction = this->direction;
|
||||
exponent = this->exponent;
|
||||
cutoff = this->cutoff;
|
||||
}
|
||||
|
||||
|
||||
void Light::SetAttenuation(const float constant, const float linear, const float quadratic)
|
||||
{
|
||||
this->constantAttenuation = constant;
|
||||
this->linearAttenuation = linear;
|
||||
this->quadraticAttenuation = quadratic;
|
||||
}
|
||||
|
||||
|
||||
void Light::GetAttenuation(float& constant, float& linear, float& quadratic) const
|
||||
{
|
||||
constant = this->constantAttenuation;
|
||||
linear = this->linearAttenuation;
|
||||
quadratic = this->quadraticAttenuation;
|
||||
}
|
||||
|
||||
|
||||
void Light::Bind(unsigned int unit)
|
||||
{
|
||||
GLenum light = GL_LIGHT0 + unit;
|
||||
glEnable(light);
|
||||
glLightfv(light, GL_AMBIENT, ambient);
|
||||
glLightfv(light, GL_DIFFUSE, diffuse);
|
||||
glLightfv(light, GL_SPECULAR, specular);
|
||||
glLightfv(light, GL_POSITION, position);
|
||||
glLightfv(light, GL_SPOT_DIRECTION, direction);
|
||||
glLightf(light, GL_SPOT_EXPONENT, exponent);
|
||||
glLightf(light, GL_SPOT_CUTOFF, cutoff);
|
||||
glLightf(light, GL_CONSTANT_ATTENUATION, constantAttenuation);
|
||||
glLightf(light, GL_LINEAR_ATTENUATION, linearAttenuation);
|
||||
glLightf(light, GL_QUADRATIC_ATTENUATION, quadraticAttenuation);
|
||||
}
|
||||
41
demo09/src/demo09/Resources/Light/Light.h
Normal file
41
demo09/src/demo09/Resources/Light/Light.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILight.h"
|
||||
|
||||
|
||||
class Light
|
||||
: public ILight
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
Light(IEngine* engine);
|
||||
virtual ~Light();
|
||||
|
||||
virtual void SetAmbient(const Vector& value);
|
||||
virtual Vector GetAmbient() const;
|
||||
virtual void SetDiffuse(const Vector& value);
|
||||
virtual Vector GetDiffuse() const;
|
||||
virtual void SetSpecular(const Vector& value);
|
||||
virtual Vector GetSpecular() const;
|
||||
virtual void SetPosition(const Vector& value);
|
||||
virtual Vector GetPosition() const;
|
||||
virtual void SetSpotLightParameters(const Vector& direction, const float exponent, const float cutoff);
|
||||
virtual void GetSpotLightParameters(Vector& direction, float& exponent, float& cutoff) const;
|
||||
virtual void SetAttenuation(const float constant, const float linear, const float quadratic);
|
||||
virtual void GetAttenuation(float& constant, float& linear, float& quadratic) const;
|
||||
virtual void Bind(unsigned int unit);
|
||||
|
||||
private:
|
||||
Vector ambient;
|
||||
Vector diffuse;
|
||||
Vector specular;
|
||||
Vector position;
|
||||
Vector direction;
|
||||
float exponent;
|
||||
float cutoff;
|
||||
float constantAttenuation;
|
||||
float linearAttenuation;
|
||||
float quadraticAttenuation;
|
||||
IEngine* engine;
|
||||
};
|
||||
161
demo09/src/demo09/Resources/Material/Material.cpp
Normal file
161
demo09/src/demo09/Resources/Material/Material.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include "stdafx.h"
|
||||
#include "Material.h"
|
||||
#include "ICamera.h"
|
||||
#include "ITexture.h"
|
||||
#include "IShader.h"
|
||||
#include "IRenderer.h"
|
||||
#include "IWorld.h"
|
||||
#include "IGraphics.h"
|
||||
#include "ITimeline.h"
|
||||
#include "MaterialLoader/MaterialLoader.h"
|
||||
|
||||
|
||||
Material::Material(IEngine* engine, LPCTSTR fileName)
|
||||
: engine(engine)
|
||||
{
|
||||
if (!std::basic_string<TCHAR>(fileName).empty())
|
||||
MaterialLoader(engine, *this, fileName);
|
||||
}
|
||||
|
||||
|
||||
Material::~Material()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Material::Bind()
|
||||
{
|
||||
SubMaterial* subMaterial = FindRelevantSubMaterial();
|
||||
if (subMaterial != NULL)
|
||||
BindInternal(*subMaterial);
|
||||
|
||||
return subMaterial != NULL;
|
||||
}
|
||||
|
||||
|
||||
void Material::AddSubMaterial(SubMaterial* subMaterial)
|
||||
{
|
||||
for (unsigned int i = 0; i < subMaterials.size(); ++i)
|
||||
if (subMaterials[i]->TargetWorldName == subMaterial->TargetWorldName)
|
||||
{
|
||||
subMaterials[i] = subMaterial;
|
||||
return;
|
||||
}
|
||||
|
||||
subMaterials.push_back(subMaterial);
|
||||
}
|
||||
|
||||
|
||||
const std::vector<SubMaterial*>& Material::GetSubMaterials() const
|
||||
{
|
||||
return subMaterials;
|
||||
}
|
||||
|
||||
|
||||
void Material::BindInternal(SubMaterial& subMaterial)
|
||||
{
|
||||
if (subMaterial.Culling != Culling::None)
|
||||
{
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace((GLenum)subMaterial.Culling);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glDepthMask((GLboolean)(subMaterial.DepthWrite ? GL_TRUE : GL_FALSE));
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, subMaterial.Ambient);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, subMaterial.Diffuse);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, subMaterial.Specular);
|
||||
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, subMaterial.Emissive);
|
||||
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, subMaterial.Shininess);
|
||||
glDepthFunc((GLenum)subMaterial.DepthFunction);
|
||||
|
||||
if (subMaterial.AlphaBlend)
|
||||
{
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc((GLenum)subMaterial.SrcBlendMode, (GLenum)subMaterial.DestBlendMode);
|
||||
}
|
||||
else
|
||||
glDisable(GL_BLEND);
|
||||
if (subMaterial.AlphaTestFunction == CompareFunc::Disabled)
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
else
|
||||
{
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc((GLenum)subMaterial.AlphaTestFunction, subMaterial.AlphaTestValue);
|
||||
}
|
||||
|
||||
int maxTextureUnits = 0;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &maxTextureUnits);
|
||||
|
||||
for (int i = 0; i < maxTextureUnits; ++i)
|
||||
{
|
||||
glActiveTexture((GLenum)(GL_TEXTURE0 + i));
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
if (subMaterial.ShaderProgram != NULL)
|
||||
subMaterial.ShaderProgram->Bind();
|
||||
|
||||
std::map<int, TextureInfo>::const_iterator iter = subMaterial.Textures.begin();
|
||||
for (int i = 0; iter != subMaterial.Textures.end(); ++iter, ++i)
|
||||
{
|
||||
const TextureInfo& info = iter->second;
|
||||
if (info.Texture == NULL)
|
||||
continue;
|
||||
info.Texture->Bind(iter->first);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, info.TextureWrapS);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, info.TextureWrapT);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, info.Texture->GetSupportsMipMaps() ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
if (subMaterial.ShaderProgram != NULL)
|
||||
{
|
||||
char paramName[9];
|
||||
char paramNameDdxy[13];
|
||||
sprintf_s(paramName, 9, "texture%d", i);
|
||||
sprintf_s(paramNameDdxy, 13, "texture%dDdxy", i);
|
||||
subMaterial.ShaderProgram->SetParam(paramName, iter->first);
|
||||
subMaterial.ShaderProgram->SetParam(paramNameDdxy, Vector(1.0f / info.Texture->GetWidth(), 1.0f / info.Texture->GetHeight(), (float)info.Texture->GetWidth(), (float)info.Texture->GetHeight()));
|
||||
}
|
||||
}
|
||||
IWorld* currentWorld = engine->GetRenderer()->GetCurrentWorld();
|
||||
if (currentWorld != NULL && subMaterial.ShaderProgram != NULL)
|
||||
{
|
||||
subMaterial.ShaderProgram->SetParam("numOfLights", (int)currentWorld->GetLights().size());
|
||||
subMaterial.ShaderProgram->SetParam("demoTime", (float)engine->GetTimeline()->GetDemoTime());
|
||||
subMaterial.ShaderProgram->SetParam("aspectRatio", engine->GetGraphics()->GetAspectRatio());
|
||||
ICamera* camera = currentWorld->GetCamera();
|
||||
if (camera != NULL)
|
||||
{
|
||||
subMaterial.ShaderProgram->SetParam("eyePosition", camera->GetPosition(), 3);
|
||||
subMaterial.ShaderProgram->SetParam("eyeDirection", camera->GetDirection(), 3);
|
||||
subMaterial.ShaderProgram->SetParam("viewMatrix", camera->GetViewMatrix());
|
||||
Matrix inverseViewMatrix = currentWorld->GetCamera()->GetViewMatrix();
|
||||
inverseViewMatrix.inverse();
|
||||
subMaterial.ShaderProgram->SetParam("viewMatrixInverse", inverseViewMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SubMaterial* Material::FindRelevantSubMaterial(IWorld* world)
|
||||
{
|
||||
if (world == NULL)
|
||||
world = engine->GetRenderer()->GetCurrentWorld();
|
||||
|
||||
SubMaterial* subMaterial = NULL;
|
||||
for (unsigned int i = 0; i < subMaterials.size(); ++i)
|
||||
if ((world!= NULL && subMaterials[i]->TargetWorldName == world->GetName()) ||
|
||||
(subMaterials[i]->TargetWorldName.empty() && subMaterial == NULL))
|
||||
{
|
||||
subMaterial = subMaterials[i];
|
||||
if (!subMaterials[i]->TargetWorldName.empty())
|
||||
break;
|
||||
}
|
||||
return subMaterial;
|
||||
}
|
||||
28
demo09/src/demo09/Resources/Material/Material.h
Normal file
28
demo09/src/demo09/Resources/Material/Material.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "IMaterial.h"
|
||||
|
||||
|
||||
class Material
|
||||
: public IMaterial
|
||||
{
|
||||
public:
|
||||
HEAP_ALIGNED_CLASS(16)
|
||||
|
||||
Material(IEngine* engine, LPCTSTR fileName = _T(""));
|
||||
virtual ~Material();
|
||||
|
||||
virtual bool Bind();
|
||||
|
||||
virtual void AddSubMaterial(SubMaterial* subMaterial);
|
||||
virtual const std::vector<SubMaterial*>& GetSubMaterials() const;
|
||||
|
||||
virtual SubMaterial* FindRelevantSubMaterial(IWorld* world = NULL);
|
||||
|
||||
private:
|
||||
void BindInternal(SubMaterial& subMaterial);
|
||||
|
||||
private:
|
||||
IEngine* engine;
|
||||
std::vector<SubMaterial*> subMaterials;
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user