Commit 7006df5f3b680618a1597310683f8c334ca527fb

Authored by David Mayerich
1 parent 0174d823

reformat of directory structure

rts/biology/fibernet.h 0 → 100644
rts/cuda/glbind.h 0 → 100644
  1 +#ifndef RTS_GL_BIND_H
  2 +#define RTS_GL_BIND_H
  3 +
  4 +#include <GL/glew.h>
  5 +#include <GL/gl.h>
  6 +
  7 +#include <stdio.h>
  8 +#include <cstring>
  9 +
  10 +#include <cudaHandleError.h>
  11 +#include "cuda_gl_interop.h"
  12 +#include "rts/gl/error.h"
  13 +
  14 +
  15 +static void rtsInitGLEW()
  16 +{
  17 + //Initialize the GLEW toolkit
  18 +
  19 + GLenum err = glewInit();
  20 + if(GLEW_OK != err)
  21 + {
  22 + printf("Error starting GLEW.");
  23 + }
  24 + fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
  25 +}
  26 +
  27 +static void rts_cudaSetDevice(int major = 1, int minor = 3)
  28 +{
  29 + cudaDeviceProp prop;
  30 + int dev;
  31 +
  32 + //find a CUDA device that can handle an offscreen buffer
  33 + int num_gpu;
  34 + HANDLE_ERROR(cudaGetDeviceCount(&num_gpu));
  35 + printf("Number of CUDA devices detected: %d\n", num_gpu);
  36 + memset(&prop, 0, sizeof(cudaDeviceProp));
  37 + prop.major=major;
  38 + prop.minor=minor;
  39 + HANDLE_ERROR(cudaChooseDevice(&dev, &prop));
  40 + HANDLE_ERROR(cudaGetDeviceProperties(&prop, dev));
  41 + HANDLE_ERROR(cudaGLSetGLDevice(dev));
  42 +}
  43 +
  44 +static void* rts_cudaMapResource(cudaGraphicsResource* cudaBufferResource)
  45 +{
  46 + //this function takes a predefined CUDA resource and maps it to a pointer
  47 + void* buffer;
  48 + HANDLE_ERROR(cudaGraphicsMapResources(1, &cudaBufferResource, NULL));
  49 + size_t size;
  50 + HANDLE_ERROR(cudaGraphicsResourceGetMappedPointer( (void**)&buffer, &size, cudaBufferResource));
  51 + return buffer;
  52 +}
  53 +static void rts_cudaUnmapResource(cudaGraphicsResource* resource)
  54 +{
  55 + //this function unmaps the CUDA resource so it can be used by OpenGL
  56 + HANDLE_ERROR(cudaGraphicsUnmapResources(1, &resource, NULL));
  57 +}
  58 +
  59 +static void rts_cudaCreateRenderBuffer(GLuint &glBufferName, cudaGraphicsResource* &cudaBufferResource, int resX, int resY)
  60 +{
  61 + //delete the previous buffer name and resource
  62 + if(cudaBufferResource != 0)
  63 + HANDLE_ERROR(cudaGraphicsUnregisterResource(cudaBufferResource));
  64 + if(glBufferName != 0)
  65 + glDeleteBuffers(1, &glBufferName);
  66 +
  67 + //generate an OpenGL offscreen buffer
  68 + glGenBuffers(1, &glBufferName);
  69 +
  70 + //bind the buffer - directs all calls to this buffer
  71 + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, glBufferName);
  72 + glBufferData(GL_PIXEL_UNPACK_BUFFER, resX * resY * sizeof(uchar3), NULL, GL_DYNAMIC_DRAW_ARB);
  73 + CHECK_OPENGL_ERROR
  74 + HANDLE_ERROR(cudaGraphicsGLRegisterBuffer(&cudaBufferResource, glBufferName, cudaGraphicsMapFlagsNone));
  75 +}
  76 +
  77 +#endif
rts/cuda/memory.h 0 → 100644
  1 +#include <cuda.h>
  2 +
rts/cuda/threads.h 0 → 100644
  1 +#include "cuda_runtime.h"
  2 +#include "device_launch_parameters.h"
  3 +#include "rts/cuda/callable.h"
  4 +
  5 +#ifndef CUDA_THREADS_H
  6 +#define CUDA_THREADS_H
  7 +
  8 +#define MAX_GRID 65535
  9 +
  10 +__device__ unsigned int ThreadIndex1D()
  11 +{
  12 + return blockIdx.y * gridDim.x * blockDim.x + blockIdx.x * blockDim.x + threadIdx.x;
  13 +}
  14 +
  15 +dim3 GenGrid1D(unsigned int N, unsigned int blocksize = 128)
  16 +{
  17 + dim3 dimgrid;
  18 +
  19 + dimgrid.x = (N + blocksize - 1)/blocksize;
  20 + dimgrid.y = 1;
  21 + dimgrid.z = 1;
  22 +
  23 + if(dimgrid.x > MAX_GRID)
  24 + {
  25 + dimgrid.y = (dimgrid.x + MAX_GRID - 1) / MAX_GRID;
  26 + dimgrid.x = MAX_GRID;
  27 + }
  28 +
  29 + return dimgrid;
  30 +
  31 +}
  32 +
  33 +
  34 +#endif
@@ -173,7 +173,7 @@ class EnviFile @@ -173,7 +173,7 @@ class EnviFile
173 exit(1); 173 exit(1);
174 } 174 }
175 175
176 - float r, v0, v1; 176 + float v0, v1;
177 for(int n=0; n<N; n++) 177 for(int n=0; n<N; n++)
178 { 178 {
179 v0 = ((float*)A)[n]; 179 v0 = ((float*)A)[n];
rts/envi/envi_header.h
@@ -72,7 +72,7 @@ struct EnviHeader @@ -72,7 +72,7 @@ struct EnviHeader
72 std::string trim(std::string line) 72 std::string trim(std::string line)
73 { 73 {
74 //trims whitespace from the beginning and end of line 74 //trims whitespace from the beginning and end of line
75 - int start_i, end_i; 75 + unsigned int start_i, end_i;
76 for(start_i=0; start_i < line.length(); start_i++) 76 for(start_i=0; start_i < line.length(); start_i++)
77 if(line[start_i] != 32) 77 if(line[start_i] != 32)
78 { 78 {
@@ -188,16 +188,12 @@ struct EnviHeader @@ -188,16 +188,12 @@ struct EnviHeader
188 { 188 {
189 //this function returns a sequence of comma-delimited strings 189 //this function returns a sequence of comma-delimited strings
190 std::vector<double> result; 190 std::vector<double> result;
191 -  
192 - double fentry;  
193 -  
194 std::string entry; 191 std::string entry;
195 size_t i; 192 size_t i;
196 do 193 do
197 { 194 {
198 i = sequence.find_first_of(','); 195 i = sequence.find_first_of(',');
199 entry = sequence.substr(0, i); 196 entry = sequence.substr(0, i);
200 - fentry = atof(entry.c_str());  
201 sequence = sequence.substr(i+1); 197 sequence = sequence.substr(i+1);
202 result.push_back(atof(entry.c_str())); 198 result.push_back(atof(entry.c_str()));
203 //std::cout<<entry<<" "; 199 //std::cout<<entry<<" ";
@@ -356,7 +352,7 @@ struct EnviHeader @@ -356,7 +352,7 @@ struct EnviHeader
356 if(band_names.size() > 0) 352 if(band_names.size() > 0)
357 { 353 {
358 outfile<<"band names = {"<<std::endl; 354 outfile<<"band names = {"<<std::endl;
359 - for(int i=0; i<band_names.size(); i++) 355 + for(unsigned int i=0; i<band_names.size(); i++)
360 { 356 {
361 outfile<<band_names[i]; 357 outfile<<band_names[i];
362 if(i < band_names.size() - 1) 358 if(i < band_names.size() - 1)
@@ -365,7 +361,7 @@ struct EnviHeader @@ -365,7 +361,7 @@ struct EnviHeader
365 outfile<<"}"<<std::endl; 361 outfile<<"}"<<std::endl;
366 } 362 }
367 outfile<<"wavelength = {"<<std::endl; 363 outfile<<"wavelength = {"<<std::endl;
368 - for(int i=0; i<wavelength.size()-1; i++) 364 + for(unsigned int i=0; i<wavelength.size()-1; i++)
369 outfile<<wavelength[i]<<", "; 365 outfile<<wavelength[i]<<", ";
370 outfile<<wavelength.back()<<"}"<<std::endl; 366 outfile<<wavelength.back()<<"}"<<std::endl;
371 367
rts/gl/error.h 0 → 100755
  1 +#ifndef RTS_OPENGL_ERROR
  2 +#define RTS_OPENGL_ERROR
  3 +
  4 +#include <stdio.h>
  5 +#include <GL/gl.h>
  6 +#include <GL/glu.h>
  7 +
  8 +#define CHECK_OPENGL_ERROR \
  9 +{ GLenum error; \
  10 + while ( (error = glGetError()) != GL_NO_ERROR) { \
  11 + printf( "OpenGL ERROR: %s\nCHECK POINT: %s (line %d)\n", gluErrorString(error), __FILE__, __LINE__ ); \
  12 + } \
  13 +}
  14 +
  15 +#endif
0 \ No newline at end of file 16 \ No newline at end of file
rts/gl/rtsSourceCode.h 0 → 100755
  1 +#ifndef RTSSOURCECODE_H
  2 +#define RTSSOURCECODE_H
  3 +
  4 +#include <string>
  5 +#include <fstream>
  6 +#include <vector>
  7 +#include <iostream>
  8 +
  9 +using namespace std;
  10 +
  11 +///This class defines generic source code that can be loaded from text files. It is primarily used by the rts_glShaderProgram class for GLSL programming.
  12 +
  13 +class rtsSourceCode
  14 +{
  15 +public:
  16 + vector<string> source; //the actual source code
  17 + void clear() ///<Clears any current source code from the class.
  18 + {
  19 + source.clear();
  20 + }
  21 + void LoadSource(const char* filename) ///<Loads source code from a specified file.
  22 + {
  23 + ifstream infile; //create an input file
  24 + infile.open(filename); //load the specified file
  25 +
  26 + if(!infile.is_open()) //if the file is not open, exit
  27 + {
  28 + return;
  29 + }
  30 + source.clear(); //remove any previous code
  31 +
  32 + while(!infile.eof())
  33 + {
  34 + string current_line;
  35 + getline(infile, current_line);
  36 + current_line += '\n';
  37 + source.push_back(current_line);
  38 + }
  39 + }
  40 + rtsSourceCode(const char* filename) ///<Constructor creates the class and loads source code from the specified file.
  41 + {
  42 + LoadSource(filename);
  43 + }
  44 + rtsSourceCode(){} ///<Constructor creates a blank class.
  45 + rtsSourceCode& operator+=(const rtsSourceCode& rhs)
  46 + {
  47 + int lines = rhs.source.size();
  48 + for(int l=0; l<lines; l++)
  49 + source.push_back(rhs.source[l]);
  50 + return *this;
  51 + }
  52 + rtsSourceCode& operator+=(const string& rhs)
  53 + {
  54 + source.push_back(rhs);
  55 + return *this;
  56 + }
  57 + void ConsoleOut() ///<Sends the source code to the standard output.
  58 + {
  59 + unsigned int lines = source.size();
  60 + for(unsigned int l = 0; l<lines; l++)
  61 + cout<<l<<": "<<source[l];
  62 + }
  63 +};
  64 +
  65 +#endif
0 \ No newline at end of file 66 \ No newline at end of file
rts/gl/rts_glShaderObject.h 0 → 100755
  1 +#ifndef RTS_GLSHADERS
  2 +#define RTS_GLSHADERS
  3 +
  4 +#include <GL/glew.h>
  5 +//#include "windows.h"
  6 +#include <GL/gl.h>
  7 +#include "rtsSourceCode.h"
  8 +
  9 +class rts_glShaderObject
  10 +{
  11 +private:
  12 + void init()
  13 + {
  14 + id = 0;
  15 + compiled = false;
  16 + type = GL_FRAGMENT_SHADER;
  17 + }
  18 +public:
  19 + bool compiled;
  20 + GLenum type;
  21 + rtsSourceCode source;
  22 + GLuint id;
  23 + string log;
  24 +
  25 + rts_glShaderObject(GLenum type, const char* filename)
  26 + {
  27 + init(); //initialize the shader
  28 + SetType(type); //set the shader type
  29 + LoadSource(filename); //load the source code
  30 + }
  31 + rts_glShaderObject(GLenum type, rtsSourceCode sourceCode)
  32 + {
  33 + init(); //initialize the shader
  34 + SetType(type); //set the shader type
  35 + source = sourceCode;
  36 + }
  37 + rts_glShaderObject()
  38 + {
  39 + init();
  40 + }
  41 + rts_glShaderObject(GLenum type)
  42 + {
  43 + init();
  44 + SetType(type);
  45 + }
  46 + void LoadSource(const char* filename)
  47 + {
  48 + source = rtsSourceCode(filename); //get the shader source code
  49 +
  50 + }
  51 + void SetType(GLenum type)
  52 + {
  53 + if(id != 0) //if a shader currently exists, delete it
  54 + {
  55 + glDeleteShader(id);
  56 + id = 0;
  57 + }
  58 + type = type;
  59 + id = glCreateShader(type); //create a shader object
  60 + if(id == 0) //if a shader was not created, log an error
  61 + {
  62 + log = "Error getting shader ID from OpenGL";
  63 + return;
  64 + }
  65 + }
  66 + void UploadSource()
  67 + {
  68 + //create the structure for the shader source code
  69 + GLsizei count = source.source.size();
  70 + GLchar** code_string = new GLchar*[count];
  71 + GLint* length = new GLint[count];
  72 + for(int l = 0; l<count; l++) //for each line of code
  73 + {
  74 + length[l] = source.source[l].size();
  75 + code_string[l] = new GLchar[length[l]]; //copy the string into a new structure
  76 + source.source[l].copy(code_string[l], (unsigned int)length[l]);
  77 +
  78 + }
  79 + glShaderSource(id, count, (const GLchar**)code_string, length); //attach the shader source
  80 + }
  81 + void Compile()
  82 + {
  83 + /*
  84 + This function compiles the shader source code, records any errors to a log, and sets the compiled flag.
  85 + */
  86 + //send the source code to the GPU
  87 + UploadSource();
  88 +
  89 + //compile the shader
  90 + glCompileShader(id); //compile the shader
  91 + GLint compile_status;
  92 + glGetShaderiv(id, GL_COMPILE_STATUS, &compile_status); //get the compile status
  93 + if(compile_status != GL_TRUE) //if there was an error
  94 + {
  95 + GLchar buffer[1000]; //create a log buffer
  96 + GLsizei length;
  97 + glGetShaderInfoLog(id, 1000, &length, buffer); //get the log
  98 + log = buffer;
  99 + compiled = false;
  100 + }
  101 + else
  102 + compiled = true;
  103 +
  104 + }
  105 + void PrintLog()
  106 + {
  107 + cout<<log;
  108 + if(log.size() != 0) cout<<endl;
  109 + }
  110 + void Clean(){if(id != 0) glDeleteShader(id);}
  111 +};
  112 +
  113 +
  114 +
  115 +#endif
rts/gl/rts_glShaderProgram.h 0 → 100755
  1 +#ifndef RTS_GLSHADERPROGRAM_H
  2 +#define RTS_GLSHADERPROGRAM_H
  3 +
  4 +/*********************************************************
  5 +//create a shader program
  6 + rts_glShaderProgram myProgram;
  7 +//initialize
  8 + myProgram.Init();
  9 +//Attach shaders
  10 + myProgram.AttachShader(GL_FRAGMENT_SHADER, "filename.glsl");
  11 +//Compile and link
  12 + myProgram.Compile();
  13 + myProgram.Link();
  14 + myProgram.PrintLog();
  15 +//attach uniform variables
  16 + myProgram.AttachTextureMap("texture", texture);
  17 + myProgram.AttachGlobalUniform("light_intensity", &intensity);
  18 +
  19 +//use the program
  20 + myProgram.BeginProgram();
  21 + //render
  22 + myProgram.EndProgram();
  23 +**********************************************************/
  24 +
  25 +
  26 +#include "rts_glShaderObject.h"
  27 +#include "rts_glShaderUniform.h"
  28 +#include "rts_glTextureMap.h"
  29 +#include <algorithm>
  30 +
  31 +using namespace std;
  32 +
  33 +class rts_glShaderProgram
  34 +{
  35 +private:
  36 + void get_uniforms()
  37 + {
  38 + GLint num_uniforms;
  39 + glGetProgramiv(id, GL_ACTIVE_UNIFORMS, &num_uniforms); //get the number of uniform variables
  40 + GLint max_name_length;
  41 + glGetProgramiv(id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); //get the maximum uniform name length
  42 + GLchar* name_buffer = new GLchar[max_name_length]; //create a buffer to store the name
  43 + GLsizei length; //I'm not using these yet
  44 + GLint size;
  45 + GLenum type; //variable's data type
  46 + GLint location; //GPU location of the variable
  47 + for(int i=0; i<num_uniforms; i++) //create an rts_glShaderUniform structure for each variable
  48 + {
  49 + glGetActiveUniform(id, i, max_name_length, &length, &size, &type, name_buffer); //get the uniform information
  50 + location = glGetUniformLocation(id, name_buffer); //get the GPU location of the variable
  51 + //create the rts_glShaderUniform structure
  52 + rts_glShaderUniform current;
  53 + current.location = location;
  54 + current.name = name_buffer;
  55 + current.type = type;
  56 + current.p_value = NULL;
  57 +
  58 +
  59 + uniform_list.push_back(current);
  60 + }
  61 +
  62 + }
  63 + int get_index(const char* name)
  64 + {
  65 + unsigned int size = uniform_list.size();
  66 + for(unsigned int i=0; i<size; i++)
  67 + {
  68 + if(uniform_list[i].name == name)
  69 + return i;
  70 + }
  71 + return -1;
  72 + }
  73 + string log;
  74 +public:
  75 + GLuint id;
  76 + bool linked;
  77 + vector<rts_glShaderObject> shader_list; //list of opengl shaders
  78 + vector<rts_glShaderUniform> uniform_list; //list of active uniform variables
  79 + vector<rts_glTextureMap> texture_list; //list of texture maps
  80 +
  81 + rts_glShaderProgram()
  82 + {
  83 + linked = false;
  84 + id = 0;
  85 + }
  86 + void AttachShader(rts_glShaderObject shader)
  87 + {
  88 + if(id == 0)
  89 + {
  90 + Init();
  91 + }
  92 + if(shader.id == 0) //if the shader is invalid
  93 + {
  94 + log = "Shader is invalid";
  95 + return;
  96 + }
  97 +
  98 + //attach the shader to the program
  99 + glAttachShader(id, shader.id); //attach the shader to the program in OpenGL
  100 + CHECK_OPENGL_ERROR
  101 + shader_list.push_back(shader); //push the shader onto our list for later access
  102 + }
  103 + //type = GL_FRAGMENT_SHADER or GL_VERTEX_SHADER
  104 + void AttachShader(GLenum type, const char* filename)
  105 + {
  106 + rts_glShaderObject shader(type, filename);
  107 + AttachShader(shader);
  108 + }
  109 + void AttachShader(GLenum type, rtsSourceCode source)
  110 + {
  111 + rts_glShaderObject shader(type, source);
  112 + AttachShader(shader);
  113 + }
  114 + void PrintLog()
  115 + {
  116 + cout<<log;
  117 +
  118 + if(log.size() != 0) cout<<endl;
  119 + }
  120 + void Compile()
  121 + {
  122 + if(shader_list.size() == 0)
  123 + {
  124 + log = "No shaders to compile";
  125 + return;
  126 + }
  127 +
  128 + vector<rts_glShaderObject>::iterator iter;
  129 + for(iter = shader_list.begin(); iter != shader_list.end(); iter++)
  130 + {
  131 + (*iter).Compile();
  132 + //(*iter).PrintLog();
  133 + }
  134 + }
  135 + void Link()
  136 + {
  137 + glLinkProgram(id); //link the current shader program
  138 + GLint link_status; //test to see if the link went alright
  139 + glGetProgramiv(id, GL_LINK_STATUS, &link_status);
  140 + if(link_status != GL_TRUE)
  141 + {
  142 + linked = false;
  143 + }
  144 + else
  145 + linked = true;
  146 +
  147 + GLsizei length;
  148 + GLchar buffer[1000];
  149 + glGetProgramInfoLog(id, 1000, &length, buffer);
  150 + log = buffer;
  151 +
  152 + get_uniforms(); //create the list of active uniform variables
  153 + }
  154 + void BeginProgram()
  155 + {
  156 + CHECK_OPENGL_ERROR
  157 + if(id == 0) //if the program is invalid, return
  158 + {
  159 + log = "Invalid program, cannot use.";
  160 + return;
  161 + }
  162 + if(!linked)
  163 + {
  164 + cout<<"Shader Program used without being linked."<<endl;
  165 + //exit(1);
  166 + }
  167 +
  168 + //set up all of the texture maps
  169 + int num_textures = texture_list.size();
  170 +
  171 + for(int t=0; t<num_textures; t++)
  172 + {
  173 + glActiveTexture(GL_TEXTURE0 + t);
  174 + CHECK_OPENGL_ERROR
  175 + //glEnable(texture_list[t].texture_type);
  176 + //CHECK_OPENGL_ERROR
  177 + glBindTexture(texture_list[t].texture_type, texture_list[t].name);
  178 + CHECK_OPENGL_ERROR
  179 + }
  180 +
  181 + glUseProgram(id);
  182 + CHECK_OPENGL_ERROR
  183 + }
  184 + void EndProgram()
  185 + {
  186 + CHECK_OPENGL_ERROR
  187 + //return standard functionality
  188 + int num_textures = texture_list.size();
  189 +
  190 + //disable all texture units
  191 + for(int t=0; t<num_textures; t++)
  192 + {
  193 + glActiveTexture(GL_TEXTURE0 + t);
  194 + glDisable(texture_list[t].texture_type);
  195 + CHECK_OPENGL_ERROR
  196 + }
  197 + //make sure that the single default texture unit is active
  198 + if(num_textures > 0)
  199 + glActiveTexture(GL_TEXTURE0);
  200 + CHECK_OPENGL_ERROR
  201 +
  202 + //return to OpenGL default shading
  203 + glUseProgram(0);
  204 + CHECK_OPENGL_ERROR
  205 + }
  206 + void PrintUniforms()
  207 + {
  208 + cout<<"Shader Uniforms: "<<endl;
  209 + unsigned int i;
  210 + for(i=0; i<uniform_list.size(); i++)
  211 + {
  212 + cout<<i<<": "<<uniform_list[i].name<<" "<<uniform_list[i].location<<endl;
  213 + }
  214 + }
  215 + void AttachGlobalUniform(unsigned int index, void* param) //attaches a global variable to the indexed uniform parameter
  216 + {
  217 + uniform_list[index].p_value = param;
  218 + }
  219 + void AttachGlobalUniform(const char* name, void* param)
  220 + {
  221 + //find the index of the shader
  222 + int index = get_index(name);
  223 + if(index != -1)
  224 + AttachGlobalUniform(index, param);
  225 + else
  226 + {
  227 + string strError = "Error finding uniform variable: ";
  228 + strError += name;
  229 + cout<<strError<<endl;
  230 + }
  231 + }
  232 + void AttachTextureMap(unsigned int index, rts_glTextureMap texture) //attaches a texture map to the program
  233 + {
  234 + //if there is not a texture map assigned to the variable
  235 + if(uniform_list[index].p_value == NULL)
  236 + {
  237 + uniform_list[index].p_value = new unsigned int[1];
  238 + ((unsigned int*)uniform_list[index].p_value)[0] = texture_list.size(); //set the parameter value to the index of the texture
  239 + texture_list.push_back(texture); //add the texture to the texture list
  240 + }
  241 + //if there is a texture map assigned, replace it
  242 + else
  243 + {
  244 + texture_list[((unsigned int*)(uniform_list[index].p_value))[0]] = texture;
  245 + }
  246 +
  247 + }
  248 + void AttachTextureMap(const char* name, rts_glTextureMap texture)
  249 + {
  250 + int index = get_index(name);
  251 + if(index != -1) //make sure that the uniform index is valid
  252 + AttachTextureMap(index, texture);
  253 + else
  254 + cout<<"Error finding texture index. Try linking."<<endl;
  255 + }
  256 + void UpdateGlobalUniforms() //sends updated uniform information to the GPU
  257 + {
  258 + CHECK_OPENGL_ERROR
  259 + BeginProgram();
  260 + CHECK_OPENGL_ERROR
  261 + unsigned int num = uniform_list.size();
  262 + for(unsigned int i=0; i<num; i++)
  263 + uniform_list[i].submit_to_gpu();
  264 + EndProgram();
  265 + }
  266 + void Init() //Initialize the shader program
  267 + {
  268 + CHECK_OPENGL_ERROR
  269 + if(id != 0)
  270 + Clean();
  271 + id = glCreateProgram();
  272 + if(id == 0)
  273 + log = "Error getting program ID from OpenGL";
  274 + CHECK_OPENGL_ERROR
  275 + }
  276 + void Clean()
  277 + {
  278 + if(id != 0)
  279 + glDeleteProgram(id);
  280 + id = 0;
  281 +
  282 + //these are allocated outside the object and can just be cleared
  283 + uniform_list.clear();
  284 + texture_list.clear();
  285 +
  286 + //delete each shader from OpenGL
  287 + int num_shad = shader_list.size();
  288 + for(int i=0; i<num_shad; i++)
  289 + shader_list[i].Clean();
  290 + //clear the list
  291 + shader_list.clear();
  292 + }
  293 +};
  294 +
  295 +#endif
rts/gl/rts_glShaderUniform.h 0 → 100755
  1 +#ifndef RTS_GLSHADERUNIFORM_H
  2 +#define RTS_GLSHADERUNIFORM_H
  3 +
  4 +#include "CHECK_OPENGL_ERROR.h"
  5 +#include <GL/glew.h>
  6 +#include <string>
  7 +
  8 +using namespace std;
  9 +
  10 +enum rtsUniformEnum {RTS_FLOAT, RTS_INT, RTS_BOOL, RTS_FLOAT_MATRIX};
  11 +
  12 +///This class stores a single uniform variable for GLSL and is designed to be used by the rts_glShaderProgram class.
  13 +struct rts_glShaderUniform
  14 +{
  15 +public:
  16 + string name; //the name of the variable
  17 + GLint location; //the location in the program
  18 + void* p_value; //pointer to the global data representing the value in main memory
  19 + GLenum type; //variable type (float, int, vec2, etc.)
  20 + //rtsUniformEnum rts_type; //type of variable in rts format
  21 + //unsigned int num; //the number of values required by the variable (1 for float, 2 for vec2, etc.)
  22 + string log;
  23 +
  24 + //void convert_type(GLenum gl_type); //converts the OpenGL data type to something useful for rts
  25 + void submit_to_gpu()
  26 + {
  27 + if(location < 0)
  28 + return;
  29 + if(p_value == NULL)
  30 + {
  31 + cout<<"Error in uniform address: "<<name<<endl;
  32 + return;
  33 + }
  34 +
  35 +
  36 + CHECK_OPENGL_ERROR
  37 + switch(type)
  38 + {
  39 + case GL_FLOAT:
  40 + glUniform1fv(location, 1, (float*)p_value);
  41 + break;
  42 + case GL_FLOAT_VEC2:
  43 + glUniform2fv(location, 1, (float*)p_value);
  44 + break;
  45 + case GL_FLOAT_VEC3:
  46 + glUniform3fv(location, 1, (float*)p_value);
  47 + break;
  48 + case GL_FLOAT_VEC4:
  49 + glUniform4fv(location, 1, (float*)p_value);
  50 + break;
  51 + case GL_INT:
  52 + glUniform1iv(location, 1, (int*)p_value);
  53 + break;
  54 + case GL_INT_VEC2:
  55 + glUniform2iv(location, 1, (int*)p_value);
  56 + break;
  57 + case GL_INT_VEC3:
  58 + glUniform3iv(location, 1, (int*)p_value);
  59 + break;
  60 + case GL_INT_VEC4:
  61 + glUniform4iv(location, 1, (int*)p_value);
  62 + break;
  63 + case GL_BOOL:
  64 + glUniform1iv(location, 1, (int*)p_value);
  65 + break;
  66 + case GL_BOOL_VEC2:
  67 + glUniform2iv(location, 1, (int*)p_value);
  68 + break;
  69 + case GL_BOOL_VEC3:
  70 + glUniform3iv(location, 1, (int*)p_value);
  71 + break;
  72 + case GL_BOOL_VEC4:
  73 + glUniform4iv(location, 1, (int*)p_value);
  74 + break;
  75 + case GL_FLOAT_MAT2:
  76 + glUniformMatrix2fv(location, 1, GL_FALSE, (float*)p_value);
  77 + break;
  78 + case GL_FLOAT_MAT3:
  79 + glUniformMatrix3fv(location, 1, GL_FALSE, (float*)p_value);
  80 + break;
  81 + case GL_FLOAT_MAT4:
  82 + glUniformMatrix4fv(location, 1, GL_FALSE, (float*)p_value);
  83 + break;
  84 + case GL_SAMPLER_1D:
  85 + case GL_SAMPLER_2D:
  86 + case GL_SAMPLER_3D:
  87 + case GL_SAMPLER_CUBE:
  88 + case GL_SAMPLER_1D_SHADOW:
  89 + case GL_SAMPLER_2D_SHADOW:
  90 + default:
  91 + glUniform1iv(location, 1, (int*)p_value);
  92 + break;
  93 + }
  94 + CHECK_OPENGL_ERROR
  95 + }
  96 + rts_glShaderUniform()
  97 + {
  98 + location = -1;
  99 + p_value = NULL;
  100 + }
  101 +};
  102 +
  103 +
  104 +
  105 +#endif
0 \ No newline at end of file 106 \ No newline at end of file
rts/gl/rts_glUtilities.h 0 → 100755
  1 +#ifndef RTS_GLUTILITIES_H
  2 +#define RTS_GLUTILITIES_H
  3 +
  4 +
  5 +#define CHECK_OPENGL_ERROR \
  6 +{ GLenum error; \
  7 + while ( (error = glGetError()) != GL_NO_ERROR) { \
  8 + printf( "OpenGL ERROR: %s\nCHECK POINT: %s (line %d)\n", gluErrorString(error), __FILE__, __LINE__ ); \
  9 + } \
  10 +}
  11 +
  12 +#endif
0 \ No newline at end of file 13 \ No newline at end of file
rts/gl/texture.h 0 → 100755
  1 +#ifndef RTS_GLTEXTUREMAP_H
  2 +#define RTS_GLTEXTUREMAP_H
  3 +
  4 +//#include <GL/glew.h>
  5 +#include "rts/math/vector.h"
  6 +#include "rts/gl/error.h"
  7 +#include <stdlib.h>
  8 +
  9 +namespace rts{
  10 +
  11 +///This class stores an OpenGL texture map and is used by rts_glShaderProgram.
  12 +class glTexture
  13 +{
  14 +private:
  15 + void get_type() //guesses the texture type based on the size
  16 + {
  17 + if(size[1] == 0)
  18 + texture_type = GL_TEXTURE_1D;
  19 + else if(size[2] == 0)
  20 + texture_type = GL_TEXTURE_2D;
  21 + else
  22 + texture_type = GL_TEXTURE_3D;
  23 + }
  24 + void set_wrapping() //set the texture wrapping based on the dimensions
  25 + {
  26 + CHECK_OPENGL_ERROR
  27 + switch(texture_type)
  28 + {
  29 + case GL_TEXTURE_3D:
  30 + glTexParameteri(texture_type, GL_TEXTURE_WRAP_R_EXT, GL_REPEAT);
  31 + case GL_TEXTURE_2D:
  32 + glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
  33 + case GL_TEXTURE_1D:
  34 + glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_REPEAT);
  35 + break;
  36 + case GL_TEXTURE_RECTANGLE_ARB:
  37 + glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  38 + glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  39 + break;
  40 +
  41 + default:
  42 + break;
  43 + }
  44 + CHECK_OPENGL_ERROR
  45 + }
  46 + //void set_bits(GLvoid* bits);
  47 +public:
  48 + vector<GLsizei, 3> size; //vector representing the size of the texture
  49 + GLuint name; //texture name assigned by OpenGL
  50 + GLenum texture_type; //1D, 2D, 3D
  51 + GLint internal_format; //number of components (ex. 4 for RGBA)
  52 + GLenum pixel_format; //type of data (RGBA, LUMINANCE)
  53 + GLenum data_type; //data type of the bits (float, int, etc.)
  54 +
  55 + //constructor
  56 + glTexture()
  57 + {
  58 + name = 0;
  59 + }
  60 + glTexture(GLvoid *bits,
  61 + GLenum type = GL_TEXTURE_2D,
  62 + GLsizei width = 256,
  63 + GLsizei height = 256,
  64 + GLsizei depth = 0,
  65 + GLint internalformat = 1,
  66 + GLenum format = GL_LUMINANCE,
  67 + GLenum datatype = GL_UNSIGNED_BYTE,
  68 + GLint interpolation = GL_LINEAR)
  69 + {
  70 + init(bits, type, width, height, depth, internalformat, format, datatype, interpolation);
  71 + }
  72 +
  73 + void begin()
  74 + {
  75 + glEnable(texture_type);
  76 + CHECK_OPENGL_ERROR
  77 + glBindTexture(texture_type, name);
  78 + CHECK_OPENGL_ERROR
  79 + }
  80 + void end()
  81 + {
  82 + glDisable(texture_type);
  83 + CHECK_OPENGL_ERROR
  84 + }
  85 +
  86 + ///Creates an OpenGL texture map. This function requires basic information about the texture map as well as a pointer to the bit data describing the texture.
  87 + void init(GLvoid *bits,
  88 + GLenum type = GL_TEXTURE_2D,
  89 + GLsizei width = 256,
  90 + GLsizei height = 256,
  91 + GLsizei depth = 0,
  92 + GLint internalformat = 1,
  93 + GLenum format = GL_LUMINANCE,
  94 + GLenum datatype = GL_UNSIGNED_BYTE,
  95 + GLint interpolation = GL_LINEAR)
  96 + {
  97 + CHECK_OPENGL_ERROR
  98 + if(name != 0)
  99 + glDeleteTextures(1, &name);
  100 +
  101 +
  102 + CHECK_OPENGL_ERROR
  103 + if(datatype == GL_FLOAT)
  104 + {
  105 + glPixelStorei(GL_PACK_ALIGNMENT, 4);
  106 + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); //I honestly don't know what this does but it fixes problems
  107 + }
  108 + else if(datatype == GL_UNSIGNED_BYTE)
  109 + {
  110 + //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  111 + //glPixelStorei(GL_PACK_ALIGNMENT, 1);
  112 + }
  113 + else if(datatype == GL_UNSIGNED_SHORT)
  114 + {
  115 + //glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
  116 + //glPixelStorei(GL_PACK_ALIGNMENT, 2);
  117 + }
  118 + CHECK_OPENGL_ERROR
  119 + glGenTextures(1, &name); //get the texture name from OpenGL
  120 + //cout<<"OpenGL Name: "<<name<<endl;
  121 + CHECK_OPENGL_ERROR
  122 + size = vector<GLsizei, 3>(width, height, depth); //assign the texture size
  123 + //get_type(); //guess the type based on the size
  124 + texture_type = type; //set the type of texture
  125 + glEnable(texture_type); //enable the texture map
  126 + CHECK_OPENGL_ERROR
  127 + glBindTexture(texture_type, name); //bind the texture for editing
  128 + CHECK_OPENGL_ERROR
  129 + set_wrapping(); //set the texture wrapping parameters
  130 + CHECK_OPENGL_ERROR
  131 + glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, interpolation); //set filtering
  132 + CHECK_OPENGL_ERROR
  133 + glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, interpolation);
  134 + CHECK_OPENGL_ERROR
  135 + internal_format = internalformat; //set the number of components per pixel
  136 + pixel_format = format; //set the pixel format
  137 + data_type = datatype; //set the data type
  138 + SetBits(bits); //send the bits to the OpenGL driver
  139 + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); //replace the specified vertex color
  140 + CHECK_OPENGL_ERROR
  141 + glDisable(texture_type);
  142 +
  143 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  144 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  145 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
  146 + }
  147 + void Clean()
  148 + {
  149 + if(name != 0)
  150 + {
  151 + glDeleteTextures(1, &name);
  152 + CHECK_OPENGL_ERROR
  153 + name = 0;
  154 + }
  155 + }
  156 + void SetBits(GLvoid *bits)
  157 + {
  158 + glEnable(texture_type); //enable the texture map
  159 + CHECK_OPENGL_ERROR
  160 + glBindTexture(texture_type, name);
  161 + CHECK_OPENGL_ERROR
  162 +
  163 + switch(texture_type)
  164 + {
  165 + case GL_TEXTURE_3D:
  166 + glTexImage3D(texture_type, 0, internal_format, size[0], size[1], size[2], 0, pixel_format, data_type, bits);
  167 + CHECK_OPENGL_ERROR
  168 + break;
  169 + case GL_TEXTURE_2D:
  170 + case GL_TEXTURE_RECTANGLE_ARB:
  171 + glTexImage2D(texture_type, 0, internal_format, size[0], size[1], 0, pixel_format, data_type, bits);
  172 + CHECK_OPENGL_ERROR
  173 + break;
  174 + case GL_TEXTURE_1D:
  175 + glTexImage1D(texture_type, 0, internal_format, size[0], 0, pixel_format, data_type, bits);
  176 + CHECK_OPENGL_ERROR
  177 + break;
  178 + default:
  179 + //glTexImage2D(texture_type, 0, internal_format, size.x, size.y, 0, pixel_format, data_type, bits);
  180 + break;
  181 + }
  182 + CHECK_OPENGL_ERROR
  183 + }
  184 + void ResetBits(GLvoid *bits)
  185 + {
  186 + glEnable(texture_type); //enable the texture map
  187 + CHECK_OPENGL_ERROR
  188 + glBindTexture(texture_type, name);
  189 + CHECK_OPENGL_ERROR
  190 +
  191 + switch(texture_type)
  192 + {
  193 + case GL_TEXTURE_3D:
  194 + //glTexImage3D(texture_type, 0, internal_format, size.x, size.y, size.z, 0, pixel_format, data_type, bits);
  195 + break;
  196 + case GL_TEXTURE_2D:
  197 + case GL_TEXTURE_RECTANGLE_ARB:
  198 + glTexSubImage2D(texture_type, 0, 0, 0, size[0], size[1], pixel_format, data_type, bits);
  199 + CHECK_OPENGL_ERROR
  200 + break;
  201 + case GL_TEXTURE_1D:
  202 + //glTexImage1D(texture_type, 0, internal_format, size.x, 0, pixel_format, data_type, bits);
  203 + break;
  204 + default:
  205 + //glTexImage2D(texture_type, 0, internal_format, size.x, size.y, 0, pixel_format, data_type, bits);
  206 + break;
  207 + }
  208 + glDisable(texture_type);
  209 + CHECK_OPENGL_ERROR
  210 + }
  211 + void* GetBits(GLenum format, GLenum type)
  212 + {
  213 + //returns the texture data
  214 +
  215 + int components;
  216 + switch(format)
  217 + {
  218 + case GL_RED:
  219 + case GL_GREEN:
  220 + case GL_BLUE:
  221 + case GL_ALPHA:
  222 + case GL_LUMINANCE:
  223 + components = 1;
  224 + break;
  225 + case GL_LUMINANCE_ALPHA:
  226 + components = 2;
  227 + break;
  228 + case GL_RGB:
  229 + case GL_BGR:
  230 + components = 3;
  231 + break;
  232 + case GL_RGBA:
  233 + case GL_BGRA:
  234 + components = 4;
  235 + break;
  236 + }
  237 +
  238 + int type_size;
  239 + switch(type)
  240 + {
  241 + case GL_UNSIGNED_BYTE:
  242 + case GL_BYTE:
  243 + type_size = sizeof(char);
  244 + break;
  245 + case GL_UNSIGNED_SHORT:
  246 + case GL_SHORT:
  247 + type_size = sizeof(short);
  248 + break;
  249 + case GL_UNSIGNED_INT:
  250 + case GL_INT:
  251 + type_size = sizeof(int);
  252 + break;
  253 + case GL_FLOAT:
  254 + type_size = sizeof(float);
  255 + break;
  256 + }
  257 +
  258 + //allocate memory for the texture
  259 + void* result = malloc(components*type_size * size[0] * size[1]);
  260 +
  261 + begin();
  262 + glGetTexImage(texture_type, 0, format, type, result);
  263 +
  264 + CHECK_OPENGL_ERROR
  265 + end();
  266 +
  267 +
  268 + return result;
  269 +
  270 + }
  271 +};
  272 +
  273 +}
  274 +
  275 +#define RTS_UNKNOWN 0
  276 +
  277 +#endif
rts/math/complex.h
@@ -15,12 +15,12 @@ namespace rts @@ -15,12 +15,12 @@ namespace rts
15 { 15 {
16 16
17 template <class T> 17 template <class T>
18 -struct rtsComplex 18 +struct complex
19 { 19 {
20 T r, i; 20 T r, i;
21 21
22 //default constructor 22 //default constructor
23 - CUDA_CALLABLE rtsComplex() 23 + CUDA_CALLABLE complex()
24 { 24 {
25 r = 0.0; 25 r = 0.0;
26 i = 0.0; 26 i = 0.0;
@@ -49,16 +49,16 @@ struct rtsComplex @@ -49,16 +49,16 @@ struct rtsComplex
49 } 49 }
50 50
51 //constructor when given real and imaginary values 51 //constructor when given real and imaginary values
52 - CUDA_CALLABLE rtsComplex(T r, T i) 52 + CUDA_CALLABLE complex(T r, T i)
53 { 53 {
54 this->r = r; 54 this->r = r;
55 this->i = i; 55 this->i = i;
56 } 56 }
57 57
58 //return the current value multiplied by i 58 //return the current value multiplied by i
59 - CUDA_CALLABLE rtsComplex<T> imul() 59 + CUDA_CALLABLE complex<T> imul()
60 { 60 {
61 - rtsComplex<T> result; 61 + complex<T> result;
62 result.r = -i; 62 result.r = -i;
63 result.i = r; 63 result.i = r;
64 64
@@ -68,70 +68,70 @@ struct rtsComplex @@ -68,70 +68,70 @@ struct rtsComplex
68 //ARITHMETIC OPERATORS-------------------- 68 //ARITHMETIC OPERATORS--------------------
69 69
70 //binary + operator (returns the result of adding two complex values) 70 //binary + operator (returns the result of adding two complex values)
71 - CUDA_CALLABLE rtsComplex<T> operator+ (const rtsComplex<T> rhs) 71 + CUDA_CALLABLE complex<T> operator+ (const complex<T> rhs)
72 { 72 {
73 - rtsComplex<T> result; 73 + complex<T> result;
74 result.r = r + rhs.r; 74 result.r = r + rhs.r;
75 result.i = i + rhs.i; 75 result.i = i + rhs.i;
76 return result; 76 return result;
77 } 77 }
78 78
79 - CUDA_CALLABLE rtsComplex<T> operator+ (const T rhs) 79 + CUDA_CALLABLE complex<T> operator+ (const T rhs)
80 { 80 {
81 - rtsComplex<T> result; 81 + complex<T> result;
82 result.r = r + rhs; 82 result.r = r + rhs;
83 result.i = i; 83 result.i = i;
84 return result; 84 return result;
85 } 85 }
86 86
87 //binary - operator (returns the result of adding two complex values) 87 //binary - operator (returns the result of adding two complex values)
88 - CUDA_CALLABLE rtsComplex<T> operator- (const rtsComplex<T> rhs) 88 + CUDA_CALLABLE complex<T> operator- (const complex<T> rhs)
89 { 89 {
90 - rtsComplex<T> result; 90 + complex<T> result;
91 result.r = r - rhs.r; 91 result.r = r - rhs.r;
92 result.i = i - rhs.i; 92 result.i = i - rhs.i;
93 return result; 93 return result;
94 } 94 }
95 95
96 //binary - operator (returns the result of adding two complex values) 96 //binary - operator (returns the result of adding two complex values)
97 - CUDA_CALLABLE rtsComplex<T> operator- (const T rhs) 97 + CUDA_CALLABLE complex<T> operator- (const T rhs)
98 { 98 {
99 - rtsComplex<T> result; 99 + complex<T> result;
100 result.r = r - rhs; 100 result.r = r - rhs;
101 result.i = i; 101 result.i = i;
102 return result; 102 return result;
103 } 103 }
104 104
105 //binary MULTIPLICATION operators (returns the result of multiplying complex values) 105 //binary MULTIPLICATION operators (returns the result of multiplying complex values)
106 - CUDA_CALLABLE rtsComplex<T> operator* (const rtsComplex<T> rhs) 106 + CUDA_CALLABLE complex<T> operator* (const complex<T> rhs)
107 { 107 {
108 - rtsComplex<T> result; 108 + complex<T> result;
109 result.r = r * rhs.r - i * rhs.i; 109 result.r = r * rhs.r - i * rhs.i;
110 result.i = r * rhs.i + i * rhs.r; 110 result.i = r * rhs.i + i * rhs.r;
111 return result; 111 return result;
112 } 112 }
113 - CUDA_CALLABLE rtsComplex<T> operator* (const T rhs) 113 + CUDA_CALLABLE complex<T> operator* (const T rhs)
114 { 114 {
115 - return rtsComplex<T>(r * rhs, i * rhs); 115 + return complex<T>(r * rhs, i * rhs);
116 } 116 }
117 117
118 //binary DIVISION operators (returns the result of dividing complex values) 118 //binary DIVISION operators (returns the result of dividing complex values)
119 - CUDA_CALLABLE rtsComplex<T> operator/ (const rtsComplex<T> rhs) 119 + CUDA_CALLABLE complex<T> operator/ (const complex<T> rhs)
120 { 120 {
121 - rtsComplex<T> result; 121 + complex<T> result;
122 T denom = rhs.r * rhs.r + rhs.i * rhs.i; 122 T denom = rhs.r * rhs.r + rhs.i * rhs.i;
123 result.r = (r * rhs.r + i * rhs.i) / denom; 123 result.r = (r * rhs.r + i * rhs.i) / denom;
124 result.i = (- r * rhs.i + i * rhs.r) / denom; 124 result.i = (- r * rhs.i + i * rhs.r) / denom;
125 125
126 return result; 126 return result;
127 } 127 }
128 - CUDA_CALLABLE rtsComplex<T> operator/ (const T rhs) 128 + CUDA_CALLABLE complex<T> operator/ (const T rhs)
129 { 129 {
130 - return rtsComplex<T>(r / rhs, i / rhs); 130 + return complex<T>(r / rhs, i / rhs);
131 } 131 }
132 132
133 //ASSIGNMENT operators----------------------------------- 133 //ASSIGNMENT operators-----------------------------------
134 - CUDA_CALLABLE rtsComplex<T> & operator=(const rtsComplex<T> &rhs) 134 + CUDA_CALLABLE complex<T> & operator=(const complex<T> &rhs)
135 { 135 {
136 //check for self-assignment 136 //check for self-assignment
137 if(this != &rhs) 137 if(this != &rhs)
@@ -141,7 +141,7 @@ struct rtsComplex @@ -141,7 +141,7 @@ struct rtsComplex
141 } 141 }
142 return *this; 142 return *this;
143 } 143 }
144 - CUDA_CALLABLE rtsComplex<T> & operator=(const T &rhs) 144 + CUDA_CALLABLE complex<T> & operator=(const T &rhs)
145 { 145 {
146 this->r = rhs; 146 this->r = rhs;
147 this->i = 0; 147 this->i = 0;
@@ -150,34 +150,34 @@ struct rtsComplex @@ -150,34 +150,34 @@ struct rtsComplex
150 } 150 }
151 151
152 //arithmetic assignment operators 152 //arithmetic assignment operators
153 - CUDA_CALLABLE rtsComplex<T> operator+=(const rtsComplex<T> &rhs) 153 + CUDA_CALLABLE complex<T> operator+=(const complex<T> &rhs)
154 { 154 {
155 *this = *this + rhs; 155 *this = *this + rhs;
156 return *this; 156 return *this;
157 } 157 }
158 - CUDA_CALLABLE rtsComplex<T> operator+=(const T &rhs) 158 + CUDA_CALLABLE complex<T> operator+=(const T &rhs)
159 { 159 {
160 *this = *this + rhs; 160 *this = *this + rhs;
161 return *this; 161 return *this;
162 } 162 }
163 163
164 - CUDA_CALLABLE rtsComplex<T> operator*=(const rtsComplex<T> &rhs) 164 + CUDA_CALLABLE complex<T> operator*=(const complex<T> &rhs)
165 { 165 {
166 *this = *this * rhs; 166 *this = *this * rhs;
167 return *this; 167 return *this;
168 } 168 }
169 - CUDA_CALLABLE rtsComplex<T> operator*=(const T &rhs) 169 + CUDA_CALLABLE complex<T> operator*=(const T &rhs)
170 { 170 {
171 *this = *this * rhs; 171 *this = *this * rhs;
172 return *this; 172 return *this;
173 } 173 }
174 //divide and assign 174 //divide and assign
175 - CUDA_CALLABLE rtsComplex<T> operator/=(const rtsComplex<T> &rhs) 175 + CUDA_CALLABLE complex<T> operator/=(const complex<T> &rhs)
176 { 176 {
177 *this = *this / rhs; 177 *this = *this / rhs;
178 return *this; 178 return *this;
179 } 179 }
180 - CUDA_CALLABLE rtsComplex<T> operator/=(const T &rhs) 180 + CUDA_CALLABLE complex<T> operator/=(const T &rhs)
181 { 181 {
182 *this = *this / rhs; 182 *this = *this / rhs;
183 return *this; 183 return *this;
@@ -189,9 +189,9 @@ struct rtsComplex @@ -189,9 +189,9 @@ struct rtsComplex
189 return std::sqrt(r * r + i * i); 189 return std::sqrt(r * r + i * i);
190 } 190 }
191 191
192 - CUDA_CALLABLE rtsComplex<T> log() 192 + CUDA_CALLABLE complex<T> log()
193 { 193 {
194 - rtsComplex<T> result; 194 + complex<T> result;
195 result.r = std::log(std::sqrt(r * r + i * i)); 195 result.r = std::log(std::sqrt(r * r + i * i));
196 result.i = std::atan2(i, r); 196 result.i = std::atan2(i, r);
197 197
@@ -199,9 +199,9 @@ struct rtsComplex @@ -199,9 +199,9 @@ struct rtsComplex
199 return result; 199 return result;
200 } 200 }
201 201
202 - CUDA_CALLABLE rtsComplex<T> exp() 202 + CUDA_CALLABLE complex<T> exp()
203 { 203 {
204 - rtsComplex<T> result; 204 + complex<T> result;
205 205
206 T e_r = std::exp(r); 206 T e_r = std::exp(r);
207 result.r = e_r * std::cos(i); 207 result.r = e_r * std::cos(i);
@@ -216,18 +216,18 @@ struct rtsComplex @@ -216,18 +216,18 @@ struct rtsComplex
216 return pow((double)y); 216 return pow((double)y);
217 }*/ 217 }*/
218 218
219 - CUDA_CALLABLE rtsComplex<T> pow(T y) 219 + CUDA_CALLABLE complex<T> pow(T y)
220 { 220 {
221 - rtsComplex<T> result; 221 + complex<T> result;
222 222
223 result = log() * y; 223 result = log() * y;
224 224
225 return result.exp(); 225 return result.exp();
226 } 226 }
227 227
228 - CUDA_CALLABLE rtsComplex<T> sqrt() 228 + CUDA_CALLABLE complex<T> sqrt()
229 { 229 {
230 - rtsComplex<T> result; 230 + complex<T> result;
231 231
232 //convert to polar coordinates 232 //convert to polar coordinates
233 T a = std::sqrt(r*r + i*i); 233 T a = std::sqrt(r*r + i*i);
@@ -253,7 +253,7 @@ struct rtsComplex @@ -253,7 +253,7 @@ struct rtsComplex
253 } 253 }
254 254
255 //COMPARISON operators 255 //COMPARISON operators
256 - CUDA_CALLABLE bool operator==(rtsComplex<T> rhs) 256 + CUDA_CALLABLE bool operator==(complex<T> rhs)
257 { 257 {
258 if(r == rhs.r && i == rhs.i) 258 if(r == rhs.r && i == rhs.i)
259 return true; 259 return true;
@@ -267,72 +267,44 @@ struct rtsComplex @@ -267,72 +267,44 @@ struct rtsComplex
267 return false; 267 return false;
268 } 268 }
269 269
270 - /*//FRIEND functions  
271 - //unary minus operator (for negating the complex number)  
272 - template<class A> CUDA_CALLABLE friend complex<A> operator-(const complex<A> &rhs);  
273 -  
274 - //multiplication by T values when the complex number isn't on the left hand side  
275 - template<class A> CUDA_CALLABLE friend complex<A> operator*(const A a, const complex<A> b);  
276 -  
277 - //division by T values when the complex number isn't on the left hand side  
278 - template<class A> CUDA_CALLABLE friend complex<A> operator/(const A a, const complex<A> b);  
279 -  
280 - //POW function  
281 - //template<class A> CUDA_CALLABLE friend complex<A> pow(const complex<A> x, T y);  
282 - template<class A> CUDA_CALLABLE friend complex<A> pow(const complex<A> x, int y);  
283 -  
284 - //log function  
285 - template<class A> CUDA_CALLABLE friend complex<A> log(complex<A> x);  
286 -  
287 - //exp function  
288 - template<class A> CUDA_CALLABLE friend complex<A> exp(complex<A> x);  
289 -  
290 - //sqrt function  
291 - template<class A> CUDA_CALLABLE friend complex<A> sqrt(complex<A> x);  
292 -