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
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
}
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];
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:
--- /dev/null
+ #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;
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){
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;
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();
}
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;
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)
{
btSequentialImpulseConstraintSolver* bt_solver;
btCollisionWorld* bt_collision_world;
btDiscreteDynamicsWorld* bt_dynamics_world;
+
+ fBufferObject* render;
+ fBufferObject* postRender;
+ fBufferObject** blurPingPong;
++ fBufferObject* shadowdir;
};