]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
derzeitiger Stand
authorLockedLunatic <locked.lunatic@aon.at>
Thu, 21 Apr 2016 00:28:32 +0000 (02:28 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Thu, 21 Apr 2016 00:28:32 +0000 (02:28 +0200)
1  2 
CGUE2015_Weave.sln
Weave/Graphix/Graphix.cpp
Weave/Graphix/Shader.cpp
Weave/Graphix/Shader.h
Weave/Graphix/Textures/Texture.cpp
Weave/Graphix/ViewPort.cpp
Weave/Graphix/ViewPort.h
Weave/Scene/Scene.cpp
Weave/Scene/Scene.h

index 6e1ae8e364ffcb29039466e81b355d7838e80987,af72ee48921cdbbdb556e7bbe805b035a17af118..300f1ecae90a5436fda382b3cdcbf7cecc13e56f
@@@ -14,9 -15,6 +15,8 @@@ Project("{2150E333-8FDC-42A3-9474-1A395
                shader\blur_FS.hlsl = shader\blur_FS.hlsl
                shader\lightingTexture_FS.hlsl = shader\lightingTexture_FS.hlsl
                shader\perspective_VS.hlsl = shader\perspective_VS.hlsl
-               shader\skybox_VS.hlsl = shader\skybox_VS.hlsl
 +              shader\shadowmapDir_FS.hlsl = shader\shadowmapDir_FS.hlsl
 +              shader\shadowmapDir_VS.hlsl = shader\shadowmapDir_VS.hlsl
                shader\skyplane_color_FS.hlsl = shader\skyplane_color_FS.hlsl
                shader\skyplane_FS.hlsl = shader\skyplane_FS.hlsl
                shader\skyplane_VS.hlsl = shader\skyplane_VS.hlsl
index a3118c9b111dd99b851a3ba484b70d06ff52a421,90ba04c872394214d2f611b52e1028174e6a1172..d6d9e09aab6e0783679cc1f592ca4569622f7e04
@@@ -144,9 -148,7 +148,6 @@@ void Graphix::init(
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
        glClearAccum(0.f, 0.f, 0.f, 0.f);\r
        glClear(GL_ACCUM_BUFFER_BIT);\r
--\r
-       shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl");\r
-       shadow_dir = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl");\r
  }\r
  \r
  void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution)\r
index b084561a10c6489c3267a4602f766f0ffc897bf4,9285906e2d201f2925e9c0d2b9f64451a9925b18..1af65e0b4fce2d441ac44a02970c095e9779ed09
@@@ -141,3 -218,37 +218,38 @@@ GLuint Shader::loadProgram(GLuint _shad
        }
        return programHandle;
  }
+ void Shader::init()
+ {
+       if (!initShader)
+       {
+               shList[SH_BASIC] = new Shader("basic_VS.hlsl", "basic_FS.hlsl");
+               shList[SH_BASICTEXTURE] = new Shader("basic_VS.hlsl", "basicTexture_FS.hlsl");
+               shList[SH_LIGHTING] = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
+               shList[SH_BLUR] = new Shader("basic_VS.hlsl", "blur_FS.hlsl");
+               shList[SH_BLEND] = new Shader("basic_VS.hlsl", "blend_FS.hlsl");
++              shList[SH_SHADOWDIR] = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl");
+       }
+       initShader = true;
+ }
+ void Shader::cleanup()
+ {
+       if (initShader)
+       {
+               for (int i = 1; i < 6; i++)
+                       delete shList[i];
+       }
+       initShader = false;
+ }
+ const Shader* Shader::getShader(ShaderTarget _target)
+ {
+       return shList[_target];
+ }
+ bool Shader::initShader = false;
+ const Shader* Shader::shList[6];
index 027281aff7d851eeaa49122be3495b3e18816c29,f30a52de746e1edb4b19d9371e0bb1a3df6b5585..77ebd4619ef96642f5442fb68e82640ffd8c0073
@@@ -7,6 -9,15 +9,16 @@@ using std::string
  
  typedef unsigned int uint;
  
 -      SH_BLEND = 5
+ enum ShaderTarget {
+       SH_ACTIVE = 0,
+       SH_BASIC = 1,
+       SH_BASICTEXTURE = 2,
+       SH_LIGHTING = 3,
+       SH_BLUR = 4,
++      SH_BLEND = 5,
++      SH_SHADOWDIR = 6
+ };
  class Shader
  {
  public:
index 0000000000000000000000000000000000000000,d016d5a6f5660bca924f32113d41dcc46b0fb3a9..32703c4c9e77eb7a9aa0e1e683590a7680b3a507
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,131 +1,149 @@@
+ #include "Texture.h"
+ #include <GL\glew.h>
+ #include "../../Message.h"
+ #include "../Shader.h"
+ #include "tImage.h"
+ 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)
+ {
+       glGenTextures(1, &handle);
+ }
+ Texture::~Texture()
+ {
+       glDeleteTextures(1, &handle);
+ }
+ Texture* Texture::newTImage(const string& _path, const vec4& _material)
+ {
+       texHandle& t_ptr = texture_Map[_path];
+       if (t_ptr.ptr == nullptr)
+       {
+               t_ptr.ptr = new tImage(_path, _material);
+               handle_Map[t_ptr.ptr->handle] = &t_ptr;
+       }
+       ++t_ptr.count;
+       return t_ptr.ptr;
+ }
+ void Texture::deleteTImage(unsigned int _handle)
+ {
+       texHandle& t_ptr = *handle_Map[_handle];
+       if (t_ptr.ptr == nullptr)
+       {
+               Message::warning("deleteTexture: Image doesn't exist.");
+               return;
+       }
+               
+       --t_ptr.count;
+       if (!t_ptr.count)
+       {
+               texture_Map.erase(*t_ptr.ptr);
+               //delete t_ptr.ptr;
+       }
+ }
+ unsigned int Texture::getTTarget() const
+ {
+       return texture_target;
+ }
+ Texture::operator unsigned int() const
+ {
+       return handle;
+ }
+ void Texture::bindTexture(unsigned int _width, unsigned int _height)
+ {
+       if (_width != 0 && _height != 0)
+       {
+               width = _width;
+               height = _height;
+       }
+       glBindTexture(texture_target, handle);
+       if(data!=nullptr)
+               glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+       else
+               glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+       glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+       glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+       glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+       //glTexParameteri(texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+       glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
+ }
+ void Texture::unbindTexture()
+ {
+       glDeleteTextures(1, &handle);
+       glGenTextures(1, &handle);
+ }
+ void Texture::useTexture(unsigned int _unit) const
+ {
+       /* bind Texture*/
+       glActiveTexture(GL_TEXTURE0 + _unit);
+       glBindTexture(texture_target, handle);
+       
+       switch (_unit)
+       {
+       case 1:
+               Shader::getShader()->setUniformLocation("uBlendTexture", _unit);
+               break;
++      case 2:
++              Shader::getShader()->setUniformLocation("upointLightxp", _unit);
++              break;
++      case 3:
++              Shader::getShader()->setUniformLocation("upointLightxm", _unit);
++              break;
++      case 4:
++              Shader::getShader()->setUniformLocation("upointLightyp", _unit);
++              break;
++      case 5:
++              Shader::getShader()->setUniformLocation("upointLightym", _unit);
++              break;
++      case 6:
++              Shader::getShader()->setUniformLocation("upointLightzp", _unit);
++              break;
++      case 7:
++              Shader::getShader()->setUniformLocation("upointLightzm", _unit);
++              break;
+       default:
+               Shader::getShader()->setUniformLocation("uColorTexture", _unit);
+               break;
+       }
+ }
+ void Texture::updateSize(unsigned int _width, unsigned int _height)
+ {
+       if (_width == 0 || _height == 0)
+               return;
+       width = _width;
+       height = _height;
+       glBindTexture(texture_target, handle);
+       glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
+ }
+ unordered_map<string, Texture::texHandle> Texture::texture_Map;
+ unordered_map<unsigned int, Texture::texHandle*> Texture::handle_Map;
index 9f05ecb907c906390a5e233f4270db18d653d584,c7a5d2e53f16f09cc4b2f62bafdf14efd230e9ad..8b9350684871089a44ded2ce400a39d1c906b25b
@@@ -37,58 -36,23 +37,32 @@@ void ViewPort::useViewPort() cons
        glViewport(xpos, ypos, width, height);
  }
  
- void ViewPort::bindView(Shader* shader) const{
+ void ViewPort::bindView(const Shader* shader) const{
        shader->useShader();
-       int tmp = -1;
  
-       tmp = shader->getUniformLocation("uProjection");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(projection));
+       shader->setUniformLocation("uProjection", projection);
+       shader->setUniformLocation("uInvProjection", glm::inverse(projection));
+       shader->setUniformLocation("uView", view);
  
-       tmp = shader->getUniformLocation("uInvProjection");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::inverse(projection)));
-       tmp = shader->getUniformLocation("uView");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(view));
  }
  
- void ViewPort::bindView(Shader* shader, vec3 pos) const{
+ void ViewPort::bindView(const Shader* shader, vec3 pos) const{
        shader->useShader();
-       int tmp = -1;
-       tmp = shader->getUniformLocation("uProjection");
-       if (tmp>=0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(projection));
-       tmp = shader->getUniformLocation("uInvProjection");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::inverse(projection)));
  
-       tmp = shader->getUniformLocation("uView");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(translate(view,-pos)));
+       shader->setUniformLocation("uProjection", projection);
+       shader->setUniformLocation("uInvProjection", glm::inverse(projection));
+       shader->setUniformLocation("uView", translate(view, -pos));
  }
  
- void ViewPort::bindViewShadowDir(Shader* shader) const {
++void ViewPort::bindViewShadowDir(const Shader* shader) const {
 +      shader->useShader();
-       int tmp = -1;
-       tmp = shader->getUniformLocation("uProjection");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::mat4(1 / shadow_dist)));
-       tmp = shader->getUniformLocation("uInvProjection");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::mat4(shadow_dist)));
 +
-       tmp = shader->getUniformLocation("uView");
-       if (tmp >= 0)
-               //TODO the real thing
-               glUniformMatrix4fv(tmp, 1, false, value_ptr(view));
++      shader->setUniformLocation("uProjection", glm::mat4(1 / shadow_dist));
++      shader->setUniformLocation("uInvProjection", glm::mat4(shadow_dist));
++      //TODO the real thing
++      shader->setUniformLocation("uView", view);
 +}
 +
  void ViewPort::rotateView(float angle_x, float angle_y){
  
        if (angle_y || angle_x){
index fdf8bdff2eecd80f330082c2930b1bab7412c86d,4770d2e1c3b986faceedaf946459bab6eb6afaa4..62c02a60ef2c512277bf57b4cd7e5bf68d965137
@@@ -15,9 -15,8 +15,9 @@@ public
  
        void setView(unsigned int x, unsigned int y, unsigned int width, unsigned int height, bool updateProjection = true);
  
-       void bindView(Shader* shader) const;
-       void bindView(Shader* shader, vec3 lookat) const;
-       void bindViewShadowDir(Shader* shader) const;
+       void bindView(const Shader* shader) const;
+       void bindView(const Shader* shader, vec3 lookat) const;
++      void bindViewShadowDir(const Shader* shader) const;
  
        void rotateView(float angle_x, float angle_y);
        vec3 rotateDirection(const vec3 & direction) const;
index 848be43ec1e5a2688eae50e78eb81023385e4a21,3c7f60d9c30d1ba14db97f8c5fcb81f947184829..e1fd1ac1086347bcbbdd0729c5ef56709eea266a
@@@ -54,6 -56,26 +56,30 @@@ lookat(_lookat
  
  
        bt_dynamics_world->setGravity(btVector3(0, YFALL_SPEED, 0));
+       render = new fBufferObject();
+       render->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+       blurPingPong = new fBufferObject*[2];
+       blurPingPong[0] = new fBufferObject(1, false);
+       blurPingPong[1] = new fBufferObject(1, false);
+       blurPingPong[0]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+       blurPingPong[1]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
++      shadowdir = new fBufferObject();
++
++      shadowdir->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
++
+       
+       postRender = new fBufferObject(2, false);
+       postRender->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+       render->clearBuffer();
  }
  
  
@@@ -74,6 -96,12 +100,15 @@@ Scene::~Scene(
        delete bt_dispatcher;
        delete bt_collision_configuration;
  
+       //fBO
+       delete render;
+       delete blurPingPong[0];
+       delete blurPingPong[1];
+       delete blurPingPong;
++      delete shadowdir;
++      delete postRender;
++
  
        //if (viewPort != nullptr)
        //      delete viewPort;
@@@ -163,14 -191,19 +198,28 @@@ void Scene::update(float deltaT
  
  void Scene::draw() const
  {
++      //Directional Light Shadow
++      shadowdir->useBuffer();
++      viewPort.bindViewShadowDir(Shader::getShader(SH_SHADOWDIR));
++      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
++
++
++
++
++
+       /* DRAW SCENE */
+       if (Graphix::testEffect(EF_BLOOM))
+       {
+               render->useBuffer();
+               glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+       }
        viewPort.useViewPort();
  
-       //Directional Light Shadow
-       viewPort.bindViewShadowDir(Graphix::shadow_dir);
        //Skybox
-       viewPort.bindView(SkyBox.getShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
+       viewPort.bindView(SkyBox.gShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
        //BBox
-       viewPort.bindView(Graphix::shader_BBox, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
+       viewPort.bindView(Shader::getShader(SH_BASIC), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
  
        for (auto i = ShaderSet.cbegin(); i != ShaderSet.cend(); ++i)
        {
index baddcb265c441b414fdb73c6cb716f5a84b2acdc,82d09a411c14ff3d2a30c02ed4d2e6acc0faa3ca..ebe02e58b466bf82f848d31f03549cd773ea2b09
@@@ -61,4 -64,8 +64,9 @@@ protected
        btSequentialImpulseConstraintSolver* bt_solver;
        btCollisionWorld* bt_collision_world;
        btDiscreteDynamicsWorld* bt_dynamics_world;
+       fBufferObject* render;
+       fBufferObject* postRender;
+       fBufferObject** blurPingPong;
++      fBufferObject* shadowdir;
  };