Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Byron Heads
committed
Oct 30, 2011
1 parent
02ef9a2
commit 11aa42d
Showing
15 changed files
with
1,707 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef CMDFLAGS_H | ||
#define CMDFLAGS_H | ||
|
||
|
||
// include google flags | ||
#include <gflags/gflags.h> | ||
#include <glog/logging.h> | ||
|
||
DECLARE_bool(fullscreen); | ||
DECLARE_bool(fps); | ||
DECLARE_int32(width); | ||
DECLARE_int32(height); | ||
DECLARE_int32(interval); | ||
|
||
void parse_commandline(int *argc, char ***argv); | ||
|
||
#endif // CMDFLAGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
/** | ||
@file modules/cmdflags.cpp | ||
Contains the command line flags and procesing functions. | ||
*/ | ||
|
||
|
||
|
||
|
||
#include <cmdflags.h> | ||
|
||
// command line options | ||
DEFINE_int32( width, 640, "Set the screen width" ); | ||
DEFINE_int32( height, 480, "Set the screen height" ); | ||
DEFINE_bool( fullscreen, false, "Set the screen to fullscreen" ); | ||
DEFINE_bool( fps, true, "Show the frame rate in window mode" ); | ||
DEFINE_int32( interval, 0, "Screen refresh interval" ); | ||
|
||
/** | ||
parse_commandline parses the main functions command line options | ||
and sets up the logger | ||
@param argc number of command line arguments to parse | ||
@param argv list of command line arguments | ||
*/ | ||
void parse_commandline(int *argc, char ***argv) | ||
{ | ||
/// parse command line params | ||
google::SetUsageMessage( "rtrt [options]" ); | ||
FLAGS_logtostderr = true; | ||
google::ParseCommandLineFlags(argc, argv, true); | ||
|
||
/// setup logger | ||
google::InitGoogleLogging( *argv[0] ); | ||
/// setup term handler | ||
google::InstallFailureSignalHandler(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include "image.h" | ||
|
||
Image::Image() | ||
: _width(0), _height(0), _data(NULL), ready(false) | ||
{ | ||
} | ||
|
||
Image::Image(size_t w, size_t h) | ||
: _width(0), _height(0), _data(NULL), ready(false) | ||
{ | ||
create_image(w, h); | ||
} | ||
|
||
Image::~Image() | ||
{ | ||
destroy_image(); | ||
} | ||
|
||
|
||
void Image::create_image(size_t w, size_t h) | ||
{ | ||
destroy_image(); | ||
_width = w; | ||
_height = h; | ||
LOG(INFO) << "Creating new image: " << w << "x" << h; | ||
_data = new iColor[_width * _height]; | ||
ready = _data != NULL; | ||
fill_with_color(0); | ||
} | ||
|
||
void Image::destroy_image() | ||
{ | ||
if(ready || _data != NULL) | ||
{ | ||
delete[] _data; | ||
} | ||
ready = false; | ||
_data = NULL; | ||
} | ||
|
||
void Image::fill_with_color(boost::uint8_t r, boost::uint8_t g, boost::uint8_t b) | ||
{ | ||
if(!ready) return; | ||
for(size_t y = 0; y < _height; ++y) | ||
{ | ||
for(size_t x = 0; x < _width; ++x) | ||
{ | ||
_data[at(x,y)].r = r; | ||
_data[at(x,y)].g = g; | ||
_data[at(x,y)].b = b; | ||
_data[at(x,y)].a = 0; | ||
} | ||
} | ||
} | ||
|
||
void Image::fill_with_color(boost::uint32_t c) | ||
{ | ||
if(!ready) return; | ||
for(size_t y = 0; y < _height; ++y) | ||
{ | ||
for(size_t x = 0; x < _width; ++x) | ||
{ | ||
_data[at(x,y)].color = c; | ||
} | ||
} | ||
} | ||
|
||
|
||
void Image::fill_with_random() | ||
{ | ||
if(!ready) return; | ||
for(size_t y = 0; y < _height; ++y) | ||
{ | ||
for(size_t x = 0; x < _width; ++x) | ||
{ | ||
_data[at(x,y)].color = rand(); | ||
} | ||
} | ||
} | ||
|
||
void Image::set(size_t x, size_t y, color c) | ||
{ | ||
if(!ready) return; | ||
clamp(c); | ||
_data[at(x,y)].r = c.x*255; | ||
_data[at(x,y)].g = c.y*255; | ||
_data[at(x,y)].b = c.z*255; | ||
_data[at(x,y)].a = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef IMAGE_H | ||
#define IMAGE_H | ||
|
||
// C++ includes | ||
#include <boost/cstdint.hpp> | ||
#include <cstdlib> | ||
|
||
// Project includes | ||
#include <cmdflags.h> | ||
#include <modules/vec4.h> | ||
#include <modules/vec_func.h> | ||
|
||
union iColor | ||
{ | ||
boost::uint32_t color; | ||
struct { | ||
boost::uint8_t r, g, b, a; | ||
}; | ||
}; | ||
|
||
class Image | ||
{ | ||
public: | ||
Image(); | ||
Image(size_t, size_t); | ||
~Image(); | ||
|
||
void create_image(size_t, size_t); | ||
void destroy_image(); | ||
|
||
void fill_with_color(boost::uint8_t, boost::uint8_t, boost::uint8_t); | ||
void fill_with_color(boost::uint32_t); | ||
void fill_with_random(); | ||
|
||
|
||
inline boost::uint32_t width() { return(_width); } | ||
inline boost::uint32_t height() { return(_height); } | ||
inline iColor *data() { return(_data); } | ||
inline size_t at(size_t x, size_t y) { return((y * _width) + x); } | ||
|
||
void set(size_t , size_t, color); | ||
private: | ||
boost::uint32_t _width, _height; | ||
iColor *_data; | ||
bool ready; | ||
}; | ||
|
||
#endif // IMAGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* \file vec4.h | ||
* \brief Defines the base vector type | ||
* | ||
* Defines the single-precision 128 bit vector struct. This structure | ||
* is used to hold 4 floats, and is used to take advantage of SSE instructions. | ||
* Support functions are defined in vec_func.h | ||
* | ||
* \author Byron Heads <bheads@emich.edu> | ||
* \date July 14, 2011 | ||
*/ | ||
|
||
#ifndef VECT4_H | ||
#define VECT4_H | ||
|
||
/** | ||
* \struct vec4 | ||
* \brief Ray-tracers four float vector. | ||
* | ||
* Used in vec_func, and other parts if the ray-tracer. | ||
* Only has constructors, operators defined in vec_func.h | ||
* | ||
*/ | ||
struct vec4 | ||
{ | ||
float x, ///< x componant of vector. | ||
y, ///< y componant of vector. | ||
z, ///< z componant of vector. | ||
w; ///< w componant of vector, normally this should be zero. | ||
|
||
/** | ||
* \brief Default constructor | ||
* | ||
* Default constructor, all values are zero | ||
*/ | ||
vec4() | ||
: x(0), y(0), z(0), w(0) {} | ||
|
||
/** | ||
* \brief Destructor | ||
* | ||
* Destructor, does nothing here. | ||
*/ | ||
~vec4() {} | ||
|
||
/** | ||
* \brief Four float constructor | ||
* | ||
* Constructor taking 4 flosting point numbers. Defaults to 0. | ||
*/ | ||
vec4( float _x, float _y=0, float _z=0, float _w=0 ) | ||
: x(_x), y(_y), z(_z), w(_w) {} | ||
|
||
/** | ||
* \brief Array constructor | ||
* | ||
* Constructor taking an array of 4 floats. | ||
*/ | ||
vec4( float f[4] ) | ||
: x(f[0]), y(f[1]), z(f[2]), w(f[3]) {} | ||
|
||
/** | ||
* \brief Scalar constructor. | ||
* | ||
* Constructor taking a float, all elements except get set. If w2 | ||
* is true then w gets set as well, else it is set to zero. | ||
* | ||
* \param f Values to set x, y, z, and w if w2 is true. | ||
* \param w2 If true w is set to the value of f. | ||
*/ | ||
vec4( float f, bool w2 = false ) | ||
: x(f), y(f), z(f), w( w2 ? f: 0 ) {} | ||
|
||
/** | ||
* \brief Copy Constructor | ||
* | ||
* Constructor that copies the value of v. | ||
* | ||
* \param v Vector refrence to copy from. | ||
*/ | ||
vec4( const vec4 &v ) | ||
: x(v.x), y(v.y), z(v.z), w(v.w) {} | ||
|
||
|
||
/** | ||
* \brief Assignment operator. | ||
* | ||
* Assignment operator. Copies another vec4 object. | ||
* | ||
* \param o Object to copy; | ||
* \return Refrence to self, is a copy of o | ||
*/ | ||
vec4 &operator=( const vec4 &o ) | ||
{ | ||
if( this != &o ) | ||
{ | ||
x = o.x; | ||
y = o.y; | ||
z = o.z; | ||
w = o.w; | ||
} | ||
return *this; | ||
} | ||
|
||
/** | ||
* \brief Scalar assignment operator. | ||
* | ||
* Scalar assignment operator. Copies a scalar value. W is copied. | ||
* | ||
* \param v Scalar value to set vector to. | ||
* \return Refrence to self, is set to v. | ||
*/ | ||
vec4 &operator=( const float v ) | ||
{ | ||
x = y = z = w = v; | ||
return *this; | ||
} | ||
|
||
}__attribute__((aligned(16))); ///< Make sure this is 16 byte aligned. Can use movaps | ||
|
||
/** | ||
* \typedef vec4 color | ||
* rtrt Colors are also vectors | ||
*/ | ||
typedef vec4 color; | ||
|
||
#endif |
Oops, something went wrong.