\r
switch (_type)\r
{\r
- default:
- case dr_Model:
- drawModel();
+ default:\r
+ case dr_Model:\r
+ drawModel();\r
break;\r
\r
case dr_WireC:\r
using namespace std;
+#define SHADER_NUM 7
+
Shader::Shader(string _shader1, string _shader2)
{
GLuint handleS1 = loadShader("../shader/"+_shader1);
int ind = glGetAttribLocation(handle, _name.c_str());
if (ind == (uint)-1)
{
- Message::error("Model: BindBuffer wird ausgelassen da index fuer [" + _name + "] fehlerhaft ist.");
+ //Message::error("Model: BindBuffer wird ausgelassen da index fuer [" + _name + "] fehlerhaft ist.");
return;
}
{
if (initShader)
{
- for (int i = 1; i < 6; i++)
+ for (int i = 1; i < SHADER_NUM; i++)
delete shList[i];
}
bool Shader::initShader = false;
-const Shader* Shader::shList[6];
+const Shader* Shader::shList[SHADER_NUM];
typedef unsigned int uint;
-enum ShaderTarget {
+enum ShaderTarget {
SH_ACTIVE = 0,
SH_BASIC = 1,
SH_BASICTEXTURE = 2,
SH_BLUR = 4,
SH_BLEND = 5,
SH_SHADOWDIR = 6
-};
+}; //Don't forget to resize the shList Array at the begining of shader.cpp!
class Shader
{
#include "Textures/Texture.h"
//#include "Textures\tImage.h"
#include "Textures\fBufferObject.h"
-#include "Textures\rBufferObject.h"
\ No newline at end of file
+#include "Textures\rBufferObject.h"
+#include "Textures\dBufferObject.h"
\ No newline at end of file
using std::unordered_map;
-Texture::Texture()
- : texture_internal(GL_RGB16F), texture_format(GL_RGB),texture_target(GL_TEXTURE_2D),texture_type(GL_UNSIGNED_BYTE)
+Texture::Texture(texTarget _target)
+ : texture_target(GL_TEXTURE_2D)
{
glGenTextures(1, &handle);
+
+ switch (_target)
+ {
+ default:
+ case texT_COLORBUFFER:
+ texture_internal = GL_RGB16F;
+ texture_format = GL_RGB;
+ texture_type = GL_UNSIGNED_BYTE;
+ break;
+ case texT_IMAGE:
+ texture_internal = GL_RGBA8;
+ texture_format = GL_BGRA;
+ texture_type = GL_UNSIGNED_BYTE;
+ break;
+ case texT_DEPTHBUFFER:
+ texture_internal = GL_DEPTH_COMPONENT;
+ texture_format = GL_DEPTH_COMPONENT;
+ texture_type = GL_FLOAT;
+ break;
+ }
+
}
Texture::~Texture()
class tImage;
+enum texTarget {
+ texT_COLORBUFFER,
+ texT_DEPTHBUFFER,
+ texT_IMAGE
+};
+
class Texture
{
public:
static Texture* newTImage(const std::string& path, const vec4& material);
static void deleteTImage(const unsigned int handle);
- Texture();
+ Texture(texTarget target = texT_COLORBUFFER);
~Texture();
virtual void bindTexture(unsigned int width = 0, unsigned int height = 0);
--- /dev/null
+#include "dBufferObject.h"
+
+#include <GL\glew.h>
+#include "../Shader.h"
+#include "../../Message.h"
+
+#include "Texture.h"
+#include "rBufferObject.h"
+
+
+dBufferObject::dBufferObject() : fBufferObject(0, false)
+{
+ //buffer_target = GL_FRAMEBUFFER;
+
+ /*gen Buffer*/
+ //glGenFramebuffers(1, &handle);
+
+
+ /*gen Texture*/
+ textures = new Texture(texT_DEPTHBUFFER);
+}
+
+
+dBufferObject::~dBufferObject()
+{
+// delete textures;
+
+ //if (rBO != nullptr)
+ // delete rBO;
+
+ glDeleteFramebuffers(1, &handle);
+}
+
+//unsigned int dBufferObject::getDim() const
+//{
+// return dim;
+//}
+//
+//Texture* dBufferObject::getTexture(unsigned int i) const
+//{
+// return &textures[i];
+//}
+
+void dBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
+{
+
+ glBindFramebuffer(buffer_target, handle);
+
+ /*Bind Texture Buffers (RENDER)*/
+ textures->bindTexture(_width, _height);
+ glFramebufferTexture2D(buffer_target, GL_DEPTH_ATTACHMENT, textures->getTTarget(), *textures, 0);
+
+ glDrawBuffer(GL_NONE);
+ glReadBuffer(GL_NONE);
+ if (glCheckFramebufferStatus(buffer_target) != GL_FRAMEBUFFER_COMPLETE)
+ Message::error("dBufferObject: Framebuffer not complete!");
+
+}
+
+//void dBufferObject::unbindBuffer()
+//{
+// for (unsigned int i = 0; i < dim; i++)
+// {
+// textures[i].unbindTexture();
+// }
+//
+// if (rBO != nullptr)
+// rBO->unbindBuffer();
+//
+// glDeleteFramebuffers(1, &handle);
+// glGenFramebuffers(1, &handle);
+//
+//}
+//
+//void dBufferObject::useBuffer() const
+//{
+// glBindFramebuffer(buffer_target, handle);
+//
+//}
+//
+//void dBufferObject::clearBuffer() const
+//{
+// glBindFramebuffer(buffer_target, 0);
+//}
+//
+//void dBufferObject::updateSize(unsigned int _width, unsigned int _height)
+//{
+//
+// for (unsigned int i = 0; i < dim; i++)
+// {
+// textures[i].updateSize(_width, _height);
+//
+// }
+//
+// if (rBO != nullptr)
+// rBO->updateSize(_width, _height);
+//}
--- /dev/null
+#pragma once
+
+#include "fBufferObject.h"
+
+class Texture;
+//class rBufferObject;
+
+class dBufferObject
+ : public fBufferObject
+{
+public:
+ dBufferObject();
+ virtual ~dBufferObject();
+
+ virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) override;
+// virtual void unbindBuffer() override;
+
+// virtual void useBuffer() const override;
+
+// virtual void clearBuffer() const override;
+
+// void updateSize(unsigned int _width, unsigned int _height);
+
+// unsigned int getDim() const;
+// Texture* getTexture(unsigned int i = 0) const;
+
+protected:
+// unsigned int dim;
+// Texture* textures = nullptr;
+
+// rBufferObject* rBO = nullptr;
+
+};
+
/*gen Texture*/
- textures = new Texture[_dim];
+ if(_dim > 0)
+ textures = new Texture[_dim];
if (_rbo)
rBO = new rBufferObject;
glBindFramebuffer(buffer_target, handle);
- /*Bind Texture Buffers*/
+ /*Bind Texture Buffers (COLOR)*/
unsigned int* attachments = new unsigned int[dim];
for (unsigned int i = 0; i < dim; i++)
{
virtual void clearBuffer() const override;
- void updateSize(unsigned int _width, unsigned int _height);
+ virtual void updateSize(unsigned int _width, unsigned int _height) override;
- unsigned int getDim() const;
- Texture* getTexture(unsigned int i = 0) const;
+ virtual unsigned int getDim() const;
+ virtual Texture* getTexture(unsigned int i = 0) const;
protected:
unsigned int dim;
using std::string;
-tImage::tImage(const string& _path, const vec4& _material) : path(_path), material(_material)
+tImage::tImage(const string& _path, const vec4& _material) : Texture(texT_IMAGE), path(_path), material(_material)
{
auto path_type = _path.substr(_path.find_last_of("_") + 1);
path_type = path_type.substr(0, path_type.find_first_of("."));
{
texture_target = GL_TEXTURE_CUBE_MAP;
}
- else if (path_type == "2D")
- {
- texture_target = GL_TEXTURE_2D;
- }
- else
+ else if(path_type != "2D")
{
Message::info("Texture : Undefined Type, was set to default (2D)");
}
Message::error("Texture: Couldn't detect texture file format.");
}
- texture_internal = GL_RGBA8;
- texture_format = GL_BGRA;
- texture_type = GL_UNSIGNED_BYTE;
-
loadImage(path);
}
{
/* bind Texture*/
- glActiveTexture(GL_TEXTURE0 + _unit);
- glBindTexture(texture_target, handle);
-
- Shader::getShader()->setUniformLocation("uColorTexture", _unit);
+ Texture::useTexture(_unit);
/* bind Material*/
Shader::getShader()->setUniformLocation("material", material);
#include <btBulletDynamicsCommon.h>
+#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
+
using std::list;
using std::set;
blurPingPong[i]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
}
- shadowdir = new fBufferObject();
+ shadowdir = new dBufferObject();
shadowdir->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
postRender = new fBufferObject(2, false);
//Directional Light Shadow
shadowdir->useBuffer();
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClear(GL_DEPTH_BUFFER_BIT);
Shader::getShader(SH_SHADOWDIR)->useShader();
drawSceneObjects();
render->clearBuffer();
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//SceneObjects.front()->gTexture()->useTexture();
- render->getTexture(0)->useTexture();
+ shadowdir->getTexture()->useTexture();
+ //render->getTexture(0)->useTexture();
blurPingPong[!horizontal]->getTexture()->useTexture(1);
Model::getPlaneModel()->drawModel(mat4(1.f));
}
void Scene::bindShader()
{
/*SceneObject*/
- ShaderTarget shader[] = {SH_BASIC,SH_BASICTEXTURE,SH_LIGHTING };
- for (int s = 0; s < 3; s++)
+ ShaderTarget shader[] = {SH_BASIC,SH_BASICTEXTURE,SH_LIGHTING, SH_SHADOWDIR};
+ for (int s = 0; s < NELEMS(shader); s++)
{
for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i)
(*i)->bindShader(Shader::getShader(shader[s]));
for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i)
(*i)->bindShaderCollision(Shader::getShader(SH_BASIC));
+
+
}
\ No newline at end of file
<ClCompile Include="Graphix\Model\Plane.cpp" />\r
<ClCompile Include="Graphix\Model\SkyBox.cpp" />\r
<ClCompile Include="Graphix\PointLight.cpp" />\r
+ <ClCompile Include="Graphix\Textures\dBufferObject.cpp" />\r
<ClCompile Include="Graphix\Textures\fBufferObject.cpp" />\r
<ClCompile Include="Graphix\Textures\rBufferObject.cpp" />\r
<ClCompile Include="Graphix\Textures\Texture.cpp" />\r
<ClInclude Include="Graphix\Model\SkyBox.h" />\r
<ClInclude Include="Graphix\PointLight.h" />\r
<ClInclude Include="Graphix\Textures.h" />\r
+ <ClInclude Include="Graphix\Textures\dBufferObject.h" />\r
<ClInclude Include="Graphix\Textures\fBufferObject.h" />\r
<ClInclude Include="Graphix\Textures\rBufferObject.h" />\r
<ClInclude Include="Graphix\Textures\Texture.h" />\r
<ClCompile Include="Graphix\Textures\rBufferObject.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
+ <ClCompile Include="Graphix\Textures\dBufferObject.cpp">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="Fps.h">\r
<ClInclude Include="Graphix\Textures\rBufferObject.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
+ <ClInclude Include="Graphix\Textures\dBufferObject.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
</Project>
\ No newline at end of file