Loaded all textures at the beginning of the application. Closes #7.
This commit is contained in:
parent
09282f51fd
commit
3680abfba4
@ -202,37 +202,40 @@ void Graphics::init(Level* level) {
|
|||||||
void Graphics::bindTextureUnits(){
|
void Graphics::bindTextureUnits(){
|
||||||
|
|
||||||
lightingShader->use();
|
lightingShader->use();
|
||||||
|
unsigned int textureCount = Material::getAllTextures()->size();
|
||||||
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
|
||||||
|
printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
|
||||||
|
// Exit if we need more texture units
|
||||||
|
if (number_of_texture_units < (int)textureCount + 18) {
|
||||||
|
printf("You need at least %d texture units to run this application. Exiting\n", textureCount + 18);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
for(unsigned int i = 0; i<Material::getAllTextures()->size(); i++) {
|
||||||
|
lightingShader->setTexture("uTexture", Material::getAllTextures()->at(i), i+2);
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
|
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
|
||||||
// start with texture unit 1 because the first is reserved for the texture
|
lightingShader->setTexture("shadowMap_directional" + std::to_string(i), depth_directionalMaps.at(i), textureCount + i + 2);
|
||||||
lightingShader->setTexture("shadowMap_directional" + std::to_string(i), depth_directionalMaps.at(i), i+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level->getLights()->size() > 0) {
|
if (level->getLights()->size() > 0) {
|
||||||
for(unsigned int i = 0; i<depth_cubeMaps.size(); i++){
|
for(unsigned int i = 0; i<depth_cubeMaps.size(); i++){
|
||||||
// start with texture unit 4 because the first four are used by the texture and the directional shadow map
|
lightingShader->setTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), textureCount + i + 5);
|
||||||
lightingShader->setTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), i+4);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flamePostShader->use();
|
flamePostShader->use();
|
||||||
flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 14);
|
flamePostShader->setTexture("light_fbo", light_fbo_color_texture, textureCount + 15);
|
||||||
|
|
||||||
skydomeShader->use();
|
skydomeShader->use();
|
||||||
skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), 15);
|
skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), textureCount + 16);
|
||||||
|
|
||||||
loadingShader->use();
|
loadingShader->use();
|
||||||
loadingShader->setTexture("screen", loadingScreen, 16);
|
loadingShader->setTexture("screen", loadingScreen, textureCount + 17);
|
||||||
loadingShader->setTexture("screenContinue", loadingContinueScreen, 17);
|
loadingShader->setTexture("screenContinue", loadingContinueScreen, textureCount + 18);
|
||||||
|
printf("This application used %d texture units.\n", textureCount + 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::renderLoadingScreen() {
|
void Graphics::renderLoadingScreen() {
|
||||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
|
|
||||||
printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
|
|
||||||
// Exit if we need more texture units
|
|
||||||
if (number_of_texture_units < 18) {
|
|
||||||
printf("You need at least 18 texture units to run this application. Exiting\n");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
loadingScreen = Texture2DFileManager::the()->get(Texture2DCreator(loadingScreenPath));
|
loadingScreen = Texture2DFileManager::the()->get(Texture2DCreator(loadingScreenPath));
|
||||||
loadingScreen->generateMipmaps();
|
loadingScreen->generateMipmaps();
|
||||||
loadingScreen->setMinFilter(GL_NEAREST_MIPMAP_LINEAR);
|
loadingScreen->setMinFilter(GL_NEAREST_MIPMAP_LINEAR);
|
||||||
@ -286,8 +289,8 @@ void Graphics::renderLoadingScreen() {
|
|||||||
.attributeLocations(fullscreen_quad_loading->getAttributeLocations()).create();
|
.attributeLocations(fullscreen_quad_loading->getAttributeLocations()).create();
|
||||||
loadingShader->use();
|
loadingShader->use();
|
||||||
loadingShader->setUniform("time", 0.0f);
|
loadingShader->setUniform("time", 0.0f);
|
||||||
loadingShader->setTexture("screen", loadingScreen, 16);
|
loadingShader->setTexture("screen", loadingScreen, 0);
|
||||||
loadingShader->setTexture("screenContinue", loadingContinueScreen, 17);
|
loadingShader->setTexture("screenContinue", loadingContinueScreen, 1);
|
||||||
fullscreen_quad_loading->render();
|
fullscreen_quad_loading->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "material.hh"
|
#include "material.hh"
|
||||||
|
|
||||||
|
std::set<SharedTexture2D> Material::allTexturesSet = std::set<SharedTexture2D>();
|
||||||
|
std::vector<SharedTexture2D> Material::allTexturesVector = std::vector<SharedTexture2D>();
|
||||||
|
|
||||||
Material::Material(std::string filePath, float ambientFactor, float diffuseFactor,
|
Material::Material(std::string filePath, float ambientFactor, float diffuseFactor,
|
||||||
float specularFactor, float shininess, bool movingTexture) {
|
float specularFactor, float shininess, bool movingTexture) {
|
||||||
reference = ACGL::OpenGL::Texture2DFileManager::the()->get(ACGL::OpenGL::Texture2DCreator(filePath));
|
reference = ACGL::OpenGL::Texture2DFileManager::the()->get(ACGL::OpenGL::Texture2DCreator(filePath));
|
||||||
@ -11,6 +14,11 @@ Material::Material(std::string filePath, float ambientFactor, float diffuseFacto
|
|||||||
this->specularFactor = specularFactor;
|
this->specularFactor = specularFactor;
|
||||||
this->shininess = shininess;
|
this->shininess = shininess;
|
||||||
this->movingTexture = movingTexture;
|
this->movingTexture = movingTexture;
|
||||||
|
unsigned int count = allTexturesSet.size();
|
||||||
|
allTexturesSet.insert(reference);
|
||||||
|
if (allTexturesSet.size() != count) {
|
||||||
|
allTexturesVector.push_back(reference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Material::Material() {
|
Material::Material() {
|
||||||
@ -42,3 +50,7 @@ float Material::getShininess() {
|
|||||||
bool Material::isMoving(){
|
bool Material::isMoving(){
|
||||||
return movingTexture;
|
return movingTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<SharedTexture2D>* Material::getAllTextures() {
|
||||||
|
return &allTexturesVector;
|
||||||
|
}
|
||||||
|
@ -2,22 +2,26 @@
|
|||||||
#define MATERIAL_HH_INCLUDED
|
#define MATERIAL_HH_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <set>
|
||||||
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
|
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
|
||||||
#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
|
#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
|
||||||
#include <ACGL/OpenGL/Managers.hh>
|
#include <ACGL/OpenGL/Managers.hh>
|
||||||
|
|
||||||
|
using namespace ACGL::OpenGL;
|
||||||
|
|
||||||
class Material{
|
class Material{
|
||||||
public:
|
public:
|
||||||
Material(std::string filePath, float ambientFactor,
|
Material(std::string filePath, float ambientFactor,
|
||||||
float diffuseFactor, float specularFactor, float shininess, bool movingTexture = false);
|
float diffuseFactor, float specularFactor, float shininess, bool movingTexture = false);
|
||||||
Material();
|
Material();
|
||||||
ACGL::OpenGL::SharedTexture2D getReference();
|
SharedTexture2D getReference();
|
||||||
~Material();
|
~Material();
|
||||||
float getAmbientFactor();
|
float getAmbientFactor();
|
||||||
float getDiffuseFactor();
|
float getDiffuseFactor();
|
||||||
float getSpecularFactor();
|
float getSpecularFactor();
|
||||||
float getShininess();
|
float getShininess();
|
||||||
bool isMoving();
|
bool isMoving();
|
||||||
|
static std::vector<SharedTexture2D>* getAllTextures();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ACGL::OpenGL::SharedTexture2D reference;
|
ACGL::OpenGL::SharedTexture2D reference;
|
||||||
@ -26,6 +30,8 @@ class Material{
|
|||||||
float specularFactor;
|
float specularFactor;
|
||||||
float shininess;
|
float shininess;
|
||||||
bool movingTexture;
|
bool movingTexture;
|
||||||
|
static std::set<SharedTexture2D> allTexturesSet;
|
||||||
|
static std::vector<SharedTexture2D> allTexturesVector;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "object.hh"
|
#include "object.hh"
|
||||||
|
//#include <iterator>
|
||||||
|
//#include <algorithm>
|
||||||
|
|
||||||
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, bool renderable) :
|
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, bool renderable) :
|
||||||
Entity(position, rotation) {
|
Entity(position, rotation) {
|
||||||
@ -27,7 +29,8 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
|||||||
else {
|
else {
|
||||||
shader->setUniform("movingTexture", false);
|
shader->setUniform("movingTexture", false);
|
||||||
}
|
}
|
||||||
shader->setTexture("uTexture", material.getReference(), 0);
|
auto textureUnit = std::distance(Material::getAllTextures()->begin(), std::find(std::begin(*Material::getAllTextures()), std::end(*Material::getAllTextures()), material.getReference()));
|
||||||
|
shader->setUniform("uTexture", (int)textureUnit + 2);
|
||||||
shader->setUniform("modelMatrix", modelMatrix);
|
shader->setUniform("modelMatrix", modelMatrix);
|
||||||
}
|
}
|
||||||
if (lightingPass) {
|
if (lightingPass) {
|
||||||
|
Loading…
Reference in New Issue
Block a user