tidies changeset

This commit is contained in:
tosh 2013-04-16 14:06:03 +02:00
parent 1e388347dc
commit ac55c610be
6 changed files with 67 additions and 47 deletions

View file

@ -60,8 +60,10 @@ public:
*/
void activate() const {
if (_hndProg != 0u)
if (_hndProg != 0u) {
oGlLog( glUseProgram(_hndProg) );
}
}
/**
@ -77,16 +79,20 @@ public:
*/
bool addShader(GLenum type, GLsizei nStrings, GLchar const** strings) {
if (! _hndProg) { _hndProg = glCreateProgram(); }
if (! _hndProg && !! glCreateProgram) {
_hndProg = glCreateProgram();
}
if (! _hndProg) { return false; }
GLuint s = glCreateShader(type);
glShaderSource(s, nStrings, strings, 0l);
glCompileShader(s);
GLint status;
glGetShaderiv(s, GL_COMPILE_STATUS, & status);
if (!! status)
if (status != 0)
glAttachShader(_hndProg, s);
#ifdef NDEBUG
#ifdef NDEBUG // always fetch log in debug mode
else
#endif
fetchLog(s, glGetShaderiv, glGetShaderInfoLog);
@ -104,12 +110,21 @@ public:
glLinkProgram(_hndProg);
GLint status;
glGetProgramiv(_hndProg, GL_LINK_STATUS, & status);
#ifdef NDEBUG
if (status == 0)
#ifndef NDEBUG // always fetch log in debug mode
fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog);
#endif
if (status == 0) {
#ifdef NDEBUG // only on error in release mode
fetchLog(_hndProg, glGetProgramiv, glGetProgramInfoLog);
#endif
glDeleteProgram(_hndProg);
_hndProg = 0u;
return false;
return status != 0;
} else {
return true;
}
}
private:

View file

@ -72,16 +72,17 @@ namespace starfield {
size_t _valLodNalloc;
size_t _valLodNrender;
BrightnessLevels _seqLodBrightness;
BrightnessLevel _valLodAllocBrightness;
#if STARFIELD_MULTITHREADING
atomic<BrightnessLevel> _valLodBrightness;
BrightnessLevel _valLodAllocBrightness;
atomic<Renderer*> _ptrRenderer;
typedef lock_guard<mutex> lock;
#else
BrightnessLevel _valLodBrightness;
BrightnessLevel _valLodAllocBrightness;
Renderer* _ptrRenderer;
@ -89,6 +90,10 @@ namespace starfield {
#define _(x)
#endif
static inline size_t toBufSize(double f) {
return size_t(floor(f + 0.5f));
}
public:
Controller() :
@ -99,8 +104,8 @@ namespace starfield {
_valLodOveralloc(1.2),
_valLodNalloc(0),
_valLodNrender(0),
_valLodAllocBrightness(0),
_valLodBrightness(0),
_valLodAllocBrightness(0),
_ptrRenderer(0l) {
}
@ -144,8 +149,8 @@ namespace starfield {
rcpChange = 1.0;
nRender = lrint(_valLodFraction * newLast);
n = min(newLast, size_t(lrint(_valLodOveralloc * nRender)));
nRender = toBufSize(_valLodFraction * newLast);
n = min(newLast, toBufSize(_valLodOveralloc * nRender));
} else {
@ -282,7 +287,7 @@ namespace starfield {
// calculate allocation size and corresponding brightness
// threshold
double oaFract = std::min(fraction * (1.0 + overalloc), 1.0);
n = lrint(oaFract * last);
n = toBufSize(oaFract * last);
bMin = _seqLodBrightness[n];
n = std::upper_bound(
_seqLodBrightness.begin() + n - 1,
@ -290,7 +295,7 @@ namespace starfield {
bMin, GreaterBrightness() ) - _seqLodBrightness.begin();
// also determine number of vertices to render and brightness
nRender = lrint(fraction * last);
nRender = toBufSize(fraction * last);
// Note: nRender does not have to be accurate
b = _seqLodBrightness[nRender];
// this setting controls the renderer, also keep b as the
@ -304,7 +309,7 @@ namespace starfield {
// fprintf(stderr, "Stars.cpp: "
// "fraction = %lf, oaFract = %lf, n = %d, n' = %d, bMin = %d, b = %d\n",
// fraction, oaFract, lrint(oaFract * last)), n, bMin, b);
// fraction, oaFract, toBufSize(oaFract * last)), n, bMin, b);
// will not have to reallocate? set new fraction right away
// (it is consistent with the rest of the state in this case)

View file

@ -50,8 +50,8 @@ namespace starfield {
return false;
}
fprintf(stderr, "Stars.cpp: read %d stars, rendering %ld\n",
_valRecordsRead, _ptrVertices->size());
fprintf(stderr, "Stars.cpp: read %u vertices, using %lu\n",
_valRecordsRead, _ptrVertices->size());
return true;
}

View file

@ -26,8 +26,8 @@ namespace starfield {
InputVertex(float azimuth, float altitude, unsigned color) {
_valColor = (color >> 16 & 0xffu) | (color & 0xff00u) |
(color << 16 & 0xff0000u) | 0xff000000u;
_valColor = ((color >> 16) & 0xffu) | (color & 0xff00u) |
((color << 16) & 0xff0000u) | 0xff000000u;
azimuth = angleConvert<Degrees,Radians>(azimuth);
altitude = angleConvert<Degrees,Radians>(altitude);

View file

@ -13,15 +13,8 @@
#error "This is an implementation file - not intended for direct inclusion."
#endif
#ifdef _WIN32
#include "../Config.h"
#define lrint(x) (floor(x + (x > 0) ? 0.5 : -0.5))
inline float remainder(float x, float y) { return std::fmod(x, y); }
inline int round(float x) { return (floor(x + 0.5)); }
double log2( double n ) { return log( n ) / log( 2 ); }
#else
#include "starfield/Config.h"
#endif
namespace starfield {
class Tiling {
@ -35,7 +28,7 @@ namespace starfield {
Tiling(unsigned k) :
_valK(k),
_valRcpSlice(k / Radians::twicePi()) {
_valBits = ceil(log2(getTileCount()));
_valBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2
}
unsigned getAzimuthalTiles() const { return _valK; }
@ -58,7 +51,7 @@ namespace starfield {
private:
unsigned discreteAngle(float unsigned_angle) const {
return unsigned(round(unsigned_angle * _valRcpSlice));
return unsigned(floor(unsigned_angle * _valRcpSlice + 0.5f));
}
unsigned discreteAzimuth(float a) const {

View file

@ -32,9 +32,9 @@ struct Rotations {
static float halfPi() { return 0.25f; }
};
/**
* Converts an angle from one unit to another.
*/
//
// Converts an angle from one unit to another.
//
template< class UnitFrom, class UnitTo >
float angleConvert(float a) {
@ -42,21 +42,28 @@ float angleConvert(float a) {
}
/**
* Clamps an angle to the range of [-180; 180) degrees.
*/
//
// Clamps an angle to the range of [-180; 180) degrees.
//
template< class Unit >
float angleSignedNormal(float a) {
float result = remainder(a, Unit::twicePi());
if (result == Unit::pi())
result = -Unit::pi();
// result is remainder(a, Unit::twicePi());
float result = fmod(a, Unit::twicePi());
if (result >= Unit::pi()) {
result -= Unit::twicePi();
} else if (result < -Unit::pi()) {
result += Unit::twicePi();
}
return result;
}
/**
* Clamps an angle to the range of [0; 360) degrees.
*/
//
// Clamps an angle to the range of [0; 360) degrees.
//
template< class Unit >
float angleUnsignedNormal(float a) {
@ -64,13 +71,13 @@ float angleUnsignedNormal(float a) {
}
/**
* Clamps a polar direction so that azimuth is in the range of [0; 360)
* degrees and altitude is in the range of [-90; 90] degrees.
*
* The so normalized angle still contains ambiguity due to gimbal lock:
* Both poles can be reached from any azimuthal direction.
*/
//
// Clamps a polar direction so that azimuth is in the range of [0; 360)
// degrees and altitude is in the range of [-90; 90] degrees.
//
// The so normalized angle still contains ambiguity due to gimbal lock:
// Both poles can be reached from any azimuthal direction.
//
template< class Unit >
void angleHorizontalPolar(float& azimuth, float& altitude) {