Better texture handling.
This commit is contained in:
@@ -134,7 +134,7 @@ float IASSS_Robot::brss() {
|
||||
std::map<int, float> 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<double>::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;
|
||||
}
|
||||
|
@@ -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,26 +96,17 @@ 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<unsigned char>(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;
|
||||
}
|
||||
|
||||
|
@@ -78,7 +78,6 @@ private:
|
||||
unsigned m_height;
|
||||
unsigned char m_bpp;
|
||||
sem_t map_semaphore;
|
||||
bool tex_created;
|
||||
GLuint handle;
|
||||
clock_t then;
|
||||
|
||||
|
Reference in New Issue
Block a user