From a2d0da24044725064bbd92a38ea66d5efd82401c Mon Sep 17 00:00:00 2001 From: Miguel Angel Astor Romero Date: Tue, 21 Feb 2017 17:17:35 -0400 Subject: [PATCH] Better texture handling. --- ias_robot.cpp | 12 ++++++------ pheromone.cpp | 32 +++++++++++--------------------- pheromone.hpp | 1 - 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/ias_robot.cpp b/ias_robot.cpp index aae3552..2bd1d79 100644 --- a/ias_robot.cpp +++ b/ias_robot.cpp @@ -134,7 +134,7 @@ float IASSS_Robot::brss() { std::map U, V; unsigned int i_min, i_max; float min, sample, prob, max, sum_uv = 0.0f, steer; - std::ostringstream oss; + // std::ostringstream oss; while(U.size() < (U_RATIO * NUM_PHERO_SAMPLES)) { min = std::numeric_limits::max(); @@ -221,12 +221,12 @@ float IASSS_Robot::brss() { steer = (NUM_PHERO_SAMPLES / 2.0f) - i_max; - oss << "samples: " << std::endl; - for(unsigned int i = 0; i < NUM_PHERO_SAMPLES; i++) - oss << "\tSAMPLE[" << i << "]: " << _phero_sensor[i] << " - " << _phero_sensor.sample_amnt[i] << " - " << _phero_sensor.probs[i] << std::endl; - oss << "\ti_max: " << i_max << " | Steer: " << steer; + // oss << "samples: " << std::endl; + // for(unsigned int i = 0; i < NUM_PHERO_SAMPLES; i++) + // oss << "\tSAMPLE[" << i << "]: " << _phero_sensor[i] << " - " << _phero_sensor.sample_amnt[i] << " - " << _phero_sensor.probs[i] << std::endl; + // oss << "\ti_max: " << i_max << " | Steer: " << steer; - log(oss.str()); + // log(oss.str()); return steer; } diff --git a/pheromone.cpp b/pheromone.cpp index ce8e710..9fa3658 100644 --- a/pheromone.cpp +++ b/pheromone.cpp @@ -55,8 +55,9 @@ static inline float random_n(float r) { PheromoneMap::PheromoneMap(const char * file_name) { load_map(file_name); sem_init(&map_semaphore, 0, 1); - tex_created = false; then = 0; + + glGenTextures(1, &handle); } PheromoneMap::~PheromoneMap() { @@ -64,11 +65,9 @@ PheromoneMap::~PheromoneMap() { delete tex_data; sem_destroy(&map_semaphore); - if(tex_created) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, handle); - glDeleteTextures(1, &handle); - } + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, handle); + glDeleteTextures(1, &handle); } void PheromoneMap::load_map(const char * file_name) { @@ -97,25 +96,16 @@ void PheromoneMap::load_map(const char * file_name) { GLuint PheromoneMap::s_build_texture() { sem_wait(&map_semaphore); { - if(tex_created) { - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, handle); - glDeleteTextures(1, &handle); - } - for(unsigned int i = 0; i < (m_width * m_height * m_bpp); i++) { tex_data[i] = static_cast(data[i]); } - - glGenTextures(1, &handle); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, handle); - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_width, m_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, tex_data); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - tex_created = true; } sem_post(&map_semaphore); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, handle); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, m_width, m_height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, tex_data); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); return handle; } diff --git a/pheromone.hpp b/pheromone.hpp index d9ca139..72a6e70 100644 --- a/pheromone.hpp +++ b/pheromone.hpp @@ -78,7 +78,6 @@ private: unsigned m_height; unsigned char m_bpp; sem_t map_semaphore; - bool tex_created; GLuint handle; clock_t then;