]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
dBuffer Object hinzugefügt
authorPeter Schaefer <schaeferpm@gmail.com>
Sun, 24 Apr 2016 19:28:18 +0000 (21:28 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Sun, 24 Apr 2016 19:28:18 +0000 (21:28 +0200)
Texture vereinfacht

aktuell wird der dBuffer + Bloom gezeichnet :)

14 files changed:
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Shader.cpp
Weave/Graphix/Shader.h
Weave/Graphix/Textures.h
Weave/Graphix/Textures/Texture.cpp
Weave/Graphix/Textures/Texture.h
Weave/Graphix/Textures/dBufferObject.cpp [new file with mode: 0644]
Weave/Graphix/Textures/dBufferObject.h [new file with mode: 0644]
Weave/Graphix/Textures/fBufferObject.cpp
Weave/Graphix/Textures/fBufferObject.h
Weave/Graphix/Textures/tImage.cpp
Weave/Scene/Scene.cpp
Weave/Weave.vcxproj
Weave/Weave.vcxproj.filters

index dd07243be0cf81845fcc1a343161cccfe0d781c0..8289d91ab9192f17d71ad57288f2c3084d16f255 100644 (file)
@@ -135,9 +135,9 @@ void Model::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color)
 \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
index 1af65e0b4fce2d441ac44a02970c095e9779ed09..d7e7d1d0c4ea46f23a925904fc7aa2e88e2b9eee 100644 (file)
@@ -6,6 +6,8 @@
 
 using namespace std;
 
+#define SHADER_NUM 7
+
 Shader::Shader(string _shader1, string _shader2)
 {
        GLuint handleS1 = loadShader("../shader/"+_shader1);
@@ -79,7 +81,7 @@ void Shader::bindBuffer(const uint &_buffer, const uint _target, const string& _
        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;
        }
 
@@ -238,7 +240,7 @@ void Shader::cleanup()
 {
        if (initShader)
        {
-               for (int i = 1; i < 6; i++)
+               for (int i = 1; i < SHADER_NUM; i++)
                        delete shList[i];
        }
 
@@ -252,4 +254,4 @@ const Shader* Shader::getShader(ShaderTarget _target)
 
 
 bool Shader::initShader = false;
-const Shader* Shader::shList[6];
+const Shader* Shader::shList[SHADER_NUM];
index 77ebd4619ef96642f5442fb68e82640ffd8c0073..9970b1680ad09a81c2ac25d57307a985ba25a477 100644 (file)
@@ -9,7 +9,7 @@ using std::string;
 
 typedef unsigned int uint;
 
-enum ShaderTarget {
+enum ShaderTarget { 
        SH_ACTIVE = 0,
        SH_BASIC = 1,
        SH_BASICTEXTURE = 2,
@@ -17,7 +17,7 @@ enum ShaderTarget {
        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
 {
index 9b981cd3bc9eb246447a2bbd20ab32141586d76e..0684d642ecf79798edefae0b60f41209bbea5c08 100644 (file)
@@ -3,4 +3,5 @@
 #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
index 32703c4c9e77eb7a9aa0e1e683590a7680b3a507..6c6b6b677769abcc746e28b470843890c9a8f1b8 100644 (file)
@@ -10,10 +10,31 @@ using std::string;
 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()
index ff15a825f7b74a51602f2835a16059491ac3160c..997e6bbf78441e9c3ae9bc35626e8b2f62edd7dd 100644 (file)
@@ -7,13 +7,19 @@
 
 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);
diff --git a/Weave/Graphix/Textures/dBufferObject.cpp b/Weave/Graphix/Textures/dBufferObject.cpp
new file mode 100644 (file)
index 0000000..9623602
--- /dev/null
@@ -0,0 +1,97 @@
+#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);
+//}
diff --git a/Weave/Graphix/Textures/dBufferObject.h b/Weave/Graphix/Textures/dBufferObject.h
new file mode 100644 (file)
index 0000000..8e764dd
--- /dev/null
@@ -0,0 +1,34 @@
+#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;
+       
+};
+
index ebef23240b99a9b0f4b35dd0d8515e94d9235b72..67a8ae3d4f2d5085f488a4e6e524f67c9c44a240 100644 (file)
@@ -18,7 +18,8 @@ fBufferObject::fBufferObject(unsigned int _dim, bool _rbo)
        
 
        /*gen Texture*/
-       textures = new Texture[_dim];
+       if(_dim > 0)
+               textures = new Texture[_dim];
 
        if (_rbo)
                rBO = new rBufferObject;
@@ -50,7 +51,7 @@ void fBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
 
        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++)
        {
index f8fbc0493f7279518c3a202b98714f0ef34ff45c..0f6242966bd40437827d5930504486e9d0a811eb 100644 (file)
@@ -19,10 +19,10 @@ public:
 
        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;
index 3e6a9dd3ddd1688687b28880aa8e60ee537f7579..6f4614bc4b5b32139a9380008f5120863cab92f7 100644 (file)
@@ -9,7 +9,7 @@
 
 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("."));
@@ -18,11 +18,7 @@ tImage::tImage(const string& _path, const vec4& _material) : path(_path), materi
        {
                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)");
        }
@@ -33,10 +29,6 @@ tImage::tImage(const string& _path, const vec4& _material) : path(_path), materi
                Message::error("Texture: Couldn't detect texture file format.");
        }
 
-       texture_internal = GL_RGBA8;
-       texture_format = GL_BGRA;
-       texture_type = GL_UNSIGNED_BYTE;
-
        loadImage(path);
 }
 
@@ -58,10 +50,7 @@ void tImage::useTexture(unsigned int _unit) const
 {
 
        /* 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);
index d89358d7c1bb1b3ee68bf9c6931f358fad0d6951..0ecfe891721072fd4f80def668b325bc99012e16 100644 (file)
@@ -18,6 +18,8 @@
 
 #include <btBulletDynamicsCommon.h>
 
+#define NELEMS(x)  (sizeof(x) / sizeof((x)[0]))
+
 
 using std::list;
 using std::set;
@@ -68,7 +70,7 @@ lookat(_lookat)
                blurPingPong[i]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
        }
 
-       shadowdir = new fBufferObject();
+       shadowdir = new dBufferObject();
        shadowdir->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
 
        postRender = new fBufferObject(2, false);
@@ -218,7 +220,7 @@ void Scene::draw() const
 
        //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();
 
@@ -290,7 +292,8 @@ void Scene::draw() const
                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));
        }
@@ -355,8 +358,8 @@ void Scene::setView(unsigned int x, unsigned int y, unsigned int width, unsigned
 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]));
@@ -369,4 +372,6 @@ void Scene::bindShader()
        for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i)
                (*i)->bindShaderCollision(Shader::getShader(SH_BASIC));
        
+
+       
 }
\ No newline at end of file
index c8cb897fad5148aa41e74cc5d6c99991cebe21df..82b6bd4876540b862158b86f8d16d7b6cd963abf 100644 (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
index 90fa55c172607fed0fc0308b54e24d081e06ecc4..e079ff4b89f8f373e8b2c3232e907ce19d863fa0 100644 (file)
     <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