Refactoring + new color map for bathymetry

parent f5435947
......@@ -55,8 +55,8 @@ else:
for i in sourceFiles:
env.src_files.append(env.Object(i))
# SWE_Block is used in every implementation
sourceFiles = ['SWE_Block.cpp']
# SWE_Block and Logger is used in every implementation
sourceFiles = ['SWE_Block.cpp', 'tools/Logger.cpp']
# OpenGL CPU-files
if env['openGL'] == True:
......@@ -66,7 +66,9 @@ if env['openGL'] == True:
sourceFiles.append( ['opengl/controller.cpp'] )
sourceFiles.append( ['opengl/shader.cpp'] )
sourceFiles.append( ['opengl/visualization.cpp'] )
sourceFiles.append( ['opengl/text.cpp'] )
sourceFiles.append( ['opengl/vbo.cpp'] )
if env['openGL_instr'] == True:
sourceFiles.append( ['opengl/text.cpp'] )
# Asagi scenario
if env['asagi'] == True:
......
......@@ -31,13 +31,9 @@
#include "SWE_WavePropagationBlockCuda_kernels.hh"
#include <cassert>
#ifndef STATICLOGGER
#define STATICLOGGER
#include "tools/Logger.hpp"
static tools::Logger s_sweLogger;
#endif
#include <cassert>
// CUDA-C includes
#include <cuda.h>
......@@ -146,7 +142,7 @@ SWE_WavePropagationBlockCuda::~SWE_WavePropagationBlockCuda() {
cudaFree(hvNetUpdatesAboveD);
// reset the cuda device
s_sweLogger.printString("Resetting the CUDA devices");
tools::Logger::logger.printString("Resetting the CUDA devices");
cudaDeviceReset();
}
......
......@@ -37,8 +37,8 @@
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
// Number of nodes (not cells) of grid
#define GRID_XSIZE 401
#define GRID_YSIZE 401
#define GRID_XSIZE 801
#define GRID_YSIZE 801
#define WINDOW_TITLE "Shallow Water Equations v1.2"
/**
......@@ -81,7 +81,6 @@ int main(int argc, char *argv[])
// Initialize scenario:
SWE_Scenario* scene = NULL;
SWE_VisInfo* visInfo = NULL;
SWE_BlockCUDA* splash = NULL;
// If input file specified, then read from VTK file:
......@@ -89,7 +88,6 @@ int main(int argc, char *argv[])
SWE_VtkScenarioVisInfo* newScene = SWE_VtkScenarioVisInfo::readVtkFile(argv[1]);
// NOTE: Simulation uses a fixed resolution (independent of VTK file)
scene = newScene;
visInfo = newScene;
printf("Scenario read from input file %s\n\n", argv[1]);
};
......@@ -113,9 +111,9 @@ int main(int argc, char *argv[])
// Initialize simulation
printf("Init simulation\n\n");
Simulation sim(nx,ny,dx,dy, scene, visInfo, splash);
Simulation sim(nx,ny,dx,dy, scene, splash);
printf("Init visualisation\n\n");
visualization.init(&sim);
visualization.init(sim);
// Initialize controller
Controller controller(&sim, &visualization);
......
......@@ -23,6 +23,7 @@
#include "../scenarios/SWE_simple_scenarios_vis.h"
#ifdef ASAGI
#include "../scenarios/SWE_AsagiScenario.hpp"
#include "../scenarios/SWE_AsagiScenario_vis.hpp"
#endif // ASAGI
/**
......@@ -172,6 +173,14 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
// Pause/Resume
paused = !paused;
break;
case SDLK_PLUS:
// Increase water scaling
visualization->modifyWaterScaling(1.5);
break;
case SDLK_MINUS:
// Decrease water scaling
visualization->modifyWaterScaling(1/1.5);
break;
case SDLK_1:
// Load scenario 1
{
......@@ -187,8 +196,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, NULL);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation);
}
break;
case SDLK_2:
......@@ -208,8 +217,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, visInfos[1]);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation, visInfos[1]);
}
break;
case SDLK_3:
......@@ -227,8 +236,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, NULL);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation);
}
break;
#ifdef ASAGI
......@@ -257,8 +266,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, NULL);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation);
}
break;
case SDLK_5:
......@@ -277,6 +286,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_bath.nc",
ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_displ.nc",
(float) 28800., simulationArea);
visInfos[4] = new SWE_AsagiJapanSmallVisInfo();
}
SWE_Scenario* newScene = scenarios[4];
......@@ -286,8 +297,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, NULL);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation, visInfos[4]);
}
break;
case SDLK_6:
......@@ -315,8 +326,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, NULL);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation);
}
break;
case SDLK_7:
......@@ -344,8 +355,8 @@ bool Controller::handleKeyPress( SDL_keysym *keysym) {
float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);
simulation->loadNewScenario(newScene, NULL);
visualization->updateBathymetryVBO(simulation);
simulation->loadNewScenario(newScene);
visualization->init(*simulation);
}
break;
#endif // ASAGI
......
......@@ -2,8 +2,9 @@
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
// Copyright (C) 2012 Sebastian Rettenberger
//
// SWE_CUDA is free software: you can redristribute it and/or modify
// SWE_CUDA is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
......@@ -19,6 +20,8 @@
#include "shader.h"
#include "../tools/Logger.hpp"
/**
Constructor.
Check whether shaders are supported. If yes, load vertex and fragment
......@@ -30,30 +33,43 @@
shader code
*/
Shader::Shader(char const * vertexShaderFile, char const * fragmentShaderFile) {
shdrSupport = isExtensionSupported("GL_ARB_vertex_shader")
&& isExtensionSupported("GL_ARB_shader_objects")
&& isExtensionSupported("GL_ARB_fragment_shader");
Shader::Shader(char const * vertexShaderFile, char const * fragmentShaderFile)
{
if (!shdrSupport) {
// Shaders are either not supported or we did not try yet
// This if-statement makes sure, we only load the extensions once
shdrSupport = isExtensionSupported("GL_ARB_vertex_shader")
&& isExtensionSupported("GL_ARB_shader_objects")
&& isExtensionSupported("GL_ARB_fragment_shader");
if (shdrSupport) {
tools::Logger::logger.printString("Shaders supported!");
// Load extensions
glCreateShader = (PFNGLCREATESHADERPROC) SDL_GL_GetProcAddress("glCreateShader");
glCreateProgram = (PFNGLCREATEPROGRAMPROC) SDL_GL_GetProcAddress("glCreateProgram");
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
glDetachShader = (PFNGLDETACHSHADERPROC)SDL_GL_GetProcAddress("glDetachShader");
glDeleteShader = (PFNGLDELETESHADERPROC) SDL_GL_GetProcAddress("glDeleteShader");
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram");
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) SDL_GL_GetProcAddress("glGetUniformLocation");
glUniform1f = (PFNGLUNIFORM1FPROC) SDL_GL_GetProcAddress("glUniform1f");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetShaderiv = (PFNGLGETSHADERIVPROC) SDL_GL_GetProcAddress("glGetShaderiv");
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) SDL_GL_GetProcAddress("glGetShaderInfoLog");
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) SDL_GL_GetProcAddress("glGetProgramInfoLog");
} else
tools::Logger::logger.printString("Shaders are NOT supported! Normal rendering mode");
}
shdrLoaded = false;
if (shdrSupport) {
// Load extensions
glCreateShader = (PFNGLCREATESHADERPROC) SDL_GL_GetProcAddress("glCreateShader");
glCreateProgram = (PFNGLCREATEPROGRAMPROC) SDL_GL_GetProcAddress("glCreateProgram");
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
glDetachShader = (PFNGLDETACHSHADERPROC)SDL_GL_GetProcAddress("glDetachShader");
glDeleteShader = (PFNGLDELETESHADERPROC) SDL_GL_GetProcAddress("glDeleteShader");
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetShaderiv = (PFNGLGETSHADERIVPROC) SDL_GL_GetProcAddress("glGetShaderiv");
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) SDL_GL_GetProcAddress("glGetShaderInfoLog");
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) SDL_GL_GetProcAddress("glGetProgramInfoLog");
// Read shader files
bool readSuccess = false;
vertexShaderSource = NULL;
......@@ -84,7 +100,6 @@ Shader::Shader(char const * vertexShaderFile, char const * fragmentShaderFile)
shdrLoaded = true;
} else {
// Errors while compiling shaders
shdrSupport = false;
glDeleteShader(vertexShader);
delete[] vertexShaderSource;
glDeleteShader(fragmentShader);
......@@ -135,13 +150,6 @@ void Shader::disableShader() {
}
}
/**
Returns, whether shaders are supported by graphics hardware
*/
bool Shader::shadersSupported() {
return shdrSupport;
}
/**
Returns, whether shaders could by loaded successfully
......@@ -333,3 +341,23 @@ bool Shader::isProgramLinked(GLuint program, char const * prefix)
return (linked != 0);
}
bool Shader::shdrSupport = false;
PFNGLCREATESHADERPROC Shader::glCreateShader;
PFNGLCREATEPROGRAMPROC Shader::glCreateProgram;
PFNGLATTACHSHADERPROC Shader::glAttachShader;
PFNGLCOMPILESHADERPROC Shader::glCompileShader;
PFNGLUSEPROGRAMPROC Shader::glUseProgram;
PFNGLDETACHSHADERPROC Shader::glDetachShader;
PFNGLDELETESHADERPROC Shader::glDeleteShader;
PFNGLLINKPROGRAMPROC Shader::glLinkProgram;
PFNGLSHADERSOURCEPROC Shader::glShaderSource;
PFNGLDELETEPROGRAMPROC Shader::glDeleteProgram;
PFNGLGETUNIFORMLOCATIONPROC Shader::glGetUniformLocation;
PFNGLUNIFORM1FPROC Shader::glUniform1f;
PFNGLGETOBJECTPARAMETERIVARBPROC Shader::glGetObjectParameterivARB;
PFNGLGETSHADERIVPROC Shader::glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC Shader::glGetShaderInfoLog;
PFNGLGETPROGRAMINFOLOGPROC Shader::glGetProgramInfoLog;
......@@ -4,8 +4,9 @@
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
// Copyright (C) 2012 Sebastian Rettenberger
//
// SWE_CUDA is free software: you can redristribute it and/or modify
// SWE_CUDA is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
......@@ -30,17 +31,35 @@ public:
Shader(char const * vertexShaderFile, char const * fragmentShaderFile) ;
~Shader();
// Check if shaders are supported
bool shadersSupported();
// Check if shaders are loaded
bool shadersLoaded();
// Shader control
void enableShader();
void disableShader();
/**
* @return Location of the uniform variable
*/
GLint getUniformLocation(const char* name)
{
if (!shdrLoaded)
return -1;
return glGetUniformLocation(program, name);
}
/**
* Set a uniform variable in the shader
*/
void setUniform(GLint location, GLfloat value)
{
if (location < 0)
return;
glUniform1f(location, value);
}
private:
// State flags
bool shdrSupport;
bool shdrLoaded;
// Helper functions
......@@ -62,23 +81,27 @@ private:
// Shaders id
GLuint program;
/** Are shaders supported */
static bool shdrSupport;
// Shader extension function pointers
PFNGLCREATESHADERPROC glCreateShader;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLDETACHSHADERPROC glDetachShader;
PFNGLDELETESHADERPROC glDeleteShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLDELETEPROGRAMPROC glDeleteProgram;
static PFNGLCREATESHADERPROC glCreateShader;
static PFNGLCREATEPROGRAMPROC glCreateProgram;
static PFNGLATTACHSHADERPROC glAttachShader;
static PFNGLCOMPILESHADERPROC glCompileShader;
static PFNGLUSEPROGRAMPROC glUseProgram;
static PFNGLDETACHSHADERPROC glDetachShader;
static PFNGLDELETESHADERPROC glDeleteShader;
static PFNGLLINKPROGRAMPROC glLinkProgram;
static PFNGLSHADERSOURCEPROC glShaderSource;
static PFNGLDELETEPROGRAMPROC glDeleteProgram;
static PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
static PFNGLUNIFORM1FPROC glUniform1f;
// Shader objects extension pointers
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
static PFNGLGETSHADERIVPROC glGetShaderiv;
static PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
static PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
};
#endif
......@@ -18,7 +18,7 @@
// along with SWE_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include "simulation.h"
#include <stdlib.h>
#include <cstring>
#include "../SWE_BlockCUDA.hh"
// Taken form FWaveCuda.h
......@@ -37,14 +37,13 @@ const float dryTol = 100.;
*/
Simulation::Simulation (int nx, int ny, float dx, float dy,
SWE_Scenario* scene, SWE_VisInfo* visInfo,
SWE_BlockCUDA* _splash)
SWE_Scenario* scene, SWE_BlockCUDA* _splash)
: maxDim( (nx > ny) ? nx : ny ),
maxCellSize( (dx > dy) ? dx : dy ),
splash(_splash),
fileNumber(0)
{
loadNewScenario(scene, visInfo);
loadNewScenario(scene);
}
/**
......@@ -53,19 +52,12 @@ Simulation::Simulation (int nx, int ny, float dx, float dy,
Simulation::~Simulation () {
}
void Simulation::loadNewScenario(SWE_Scenario* scene, SWE_VisInfo* visInfo) {
void Simulation::loadNewScenario(SWE_Scenario* scene) {
myScenario = scene;
curTime = 0.0f;
isFirstStep = 1;
useFileInput = false;
Simulation::initBoundaries(myScenario);
if (visInfo != NULL) {
wScale = visInfo->waterVerticalScaling();
bScale = visInfo->bathyVerticalScaling();
bOffset = visInfo->bathyVerticalOffset();
} else {
getScalingApproximation(splash->getWaterHeight(), splash->getBathymetry());
}
initBoundaries(myScenario);
}
/**
......@@ -79,7 +71,7 @@ void Simulation::runCuda(struct cudaGraphicsResource **vbo_resource, struct cuda
{
// map OpenGL buffer object for writing from CUDA
float3 *dptr, *dptr2;
size_t num_bytes, num_bytes2;
std::size_t num_bytes, num_bytes2;
cudaGraphicsMapResources(1, vbo_resource, 0);
cudaGraphicsResourceGetMappedPointer((void **)&dptr, &num_bytes,
......@@ -155,7 +147,7 @@ void Simulation::setBathBuffer(float* bath) {
for (int j=0; j<ny+1;j++) {
for (int i=0;i<nx+1;i++) {
bath[(j*(ny+1) + i)*6] = (float) i;
bath[(j*(ny+1) + i)*6 + 1]= bScale * 0.25f * (b[i][j]+b[i+1][j]+b[i][j+1]+b[i+1][j+1]) + bOffset;
bath[(j*(ny+1) + i)*6 + 1]= 0.25f * (b[i][j]+b[i+1][j]+b[i][j+1]+b[i+1][j+1]);
bath[(j*(ny+1) + i)*6 + 2] = (float) j;
bath[(j*(ny+1) + i)*6 + 3] = 0.0f;
bath[(j*(ny+1) + i)*6 + 4] = 0.0f;
......@@ -248,11 +240,12 @@ void Simulation::calculateWaterSurface(float3* destBuffer) {
Gets called before simulation starts and determines the average,
mininimum and maximum values of the bathymetry and water surface data.
Uses latter values to estimate the scaling factors.
@param h Fload2D array that holds water height
@param b Fload2D array that holds bathymetry data
*/
void Simulation::getScalingApproximation(const Float2D& h, const Float2D& b)
void Simulation::getScalingApproximation(float &bScale, float &bOffset, float &wScale)
{
const Float2D &h = splash->getWaterHeight();
const Float2D &b = splash->getBathymetry();
// Minimum values
float minB, minH;
// Maximum values
......@@ -282,7 +275,7 @@ void Simulation::getScalingApproximation(const Float2D& h, const Float2D& b)
}
}
bOffset = 0; // This should be !=0 only in some artificial scenarios
bScale = -50/minB;
bScale = -100/minB;
cout << "Scaling of bathymetry: " << bScale << endl;
if ((maxH - minH) < 0.0001f) {
......@@ -290,7 +283,7 @@ void Simulation::getScalingApproximation(const Float2D& h, const Float2D& b)
} else {
wScale = 1.0f;
}
wScale = (maxDim/40.0)*wScale;
wScale = (maxDim/50.0)*wScale;
cout << "Scaling of water level: " << wScale << endl;
}
......@@ -353,7 +346,7 @@ float scaleFunction(float val, float scale) {
*/
__global__
void kernelCalcVisBuffer(float3* visBuffer, const float* hd, const float* bd,
int nx, int ny, float scale)
int nx, int ny)
{
int i = TILE_SIZE*blockIdx.x + threadIdx.x;
int j = TILE_SIZE*blockIdx.y + threadIdx.y;
......@@ -368,7 +361,7 @@ void kernelCalcVisBuffer(float3* visBuffer, const float* hd, const float* bd,
else
visBuffer[j*(ny+1) + i] = make_float3(
i,
scale * 0.25 * (
0.25 * (
hd[index]+hd[index + 1]+ hd[index2] + hd[index2 + 1] +
bd[index]+bd[index + 1]+ bd[index2] + bd[index2 + 1]),
j);
......@@ -397,7 +390,7 @@ void Simulation::updateVisBuffer(float3* _visBuffer) {
// Interpolate cell centered h-values
dim3 dimBlock(TILE_SIZE,TILE_SIZE);
dim3 dimGrid((nx+TILE_SIZE)/TILE_SIZE,(ny+TILE_SIZE)/TILE_SIZE);
kernelCalcVisBuffer<<<dimGrid,dimBlock>>>(_visBuffer, hd, bd, nx, ny, wScale);
kernelCalcVisBuffer<<<dimGrid,dimBlock>>>(_visBuffer, hd, bd, nx, ny);
}
/**
Function used for debugging. Outputs the current visBuffer
......
......@@ -33,13 +33,13 @@ class Simulation {
public:
// Constructor + Destructor
Simulation (int nx, int ny, float dx, float dy,
SWE_Scenario* scene, SWE_VisInfo* visInfo, SWE_BlockCUDA* init_splash);
SWE_Scenario* scene, SWE_BlockCUDA* init_splash);
~Simulation();
// Restart simulation
void restart();
// Load new scenario after initialization
void loadNewScenario(SWE_Scenario* scene, SWE_VisInfo* visInfo);
void loadNewScenario(SWE_Scenario* scene);
// Save simulation state to file
void saveToFile();
// Return the bathymetry data
......@@ -51,6 +51,7 @@ class Simulation {
void writeDebugOutput(float3* destBuffer = NULL);
protected:
public:
// Instance of SWE_BlockCUDA
SWE_BlockCUDA* splash;
......@@ -63,8 +64,6 @@ class Simulation {
int isFirstStep;
// Maximum of cell sizes
float maxCellSize;
// Scaling factors used by visualization
float bScale, bOffset, wScale;
// Initialize boundaries defined by the scene
void initBoundaries(SWE_Scenario* scene);
// Initialize boundaries defined by an input file
......@@ -79,7 +78,7 @@ class Simulation {
// Compute normals of the water surface for shading
void calculateNormals(float3* vertexBuffer, float3* destBuffer);
void getScalingApproximation(const Float2D& h, const Float2D& b);
void getScalingApproximation(float &bScale, float &bOffset, float &wScale);
void updateVisBuffer(float3* _visBuffer);
void debugVisBuffer(float3* _visBuffer);
......
......@@ -89,7 +89,7 @@ public:
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, surf->w, surf->h, 0, GL_BGRA,
GL_UNSIGNED_BYTE, surf->pixels );
GL_UNSIGNED_BYTE, surf->pixels);
/* GL_NEAREST looks horrible, if scaled... */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
......
/**
* @file
* This file is part of SWE.
*
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
* SWE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWE. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vbo.h"
#include "visualization.h"
void VBO::init()
{
if (glGenBuffers == 0L) {
// Load vbo extension
// Check OpenGL extension(s)
if (!Visualization::isExtensionSupported("GL_ARB_vertex_buffer_object")) {
tools::Logger::logger.printString("Vertex Buffer Objects Extension not supported! Exit..\n");
SDL_Quit();
exit(1);
}
// Load Vertex Buffer Extension
glGenBuffers = (PFNGLGENBUFFERSARBPROC) SDL_GL_GetProcAddress("glGenBuffersARB");
glBindBuffer = (PFNGLBINDBUFFERARBPROC) SDL_GL_GetProcAddress("glBindBufferARB");
glBufferData = (PFNGLBUFFERDATAARBPROC) SDL_GL_GetProcAddress("glBufferDataARB");
glDeleteBuffers = (PFNGLDELETEBUFFERSARBPROC) SDL_GL_GetProcAddress("glDeleteBuffersARB");
}
glGenBuffers(1, &name);
}
PFNGLGENBUFFERSARBPROC VBO::glGenBuffers = 0L;
PFNGLBINDBUFFERARBPROC VBO::glBindBuffer = 0L;
PFNGLBUFFERDATAARBPROC VBO::glBufferData = 0L;
PFNGLDELETEBUFFERSARBPROC VBO::glDeleteBuffers = 0L;
/**
* @file
* This file is part of SWE.
*
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
* SWE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWE. If not, see <http://www.gnu.org/licenses/>.
*
*
* @section DESCRIPTION
*
* Handles a VertexBufferObject.
*/
#ifndef VBO_H
#define VBO_H
#include "../tools/Logger.hpp"
#include <SDL_opengl.h>
class VBO
{
private:
/** OpenGL name of the object */
GLuint name;
public:
VBO()
: name(0)
{}
/**
* Initializes the object
*/
void init();
/**
* @return The OpenGL name of the buffer
*/
GLuint getName()
{
return name;
}
void setBufferData(GLsizei size, const void* data,
GLenum target = GL_ARRAY_BUFFER,
GLenum usage = GL_STATIC_DRAW)
{
glBindBuffer(target, name);
glBufferData(target, size, data, usage);
glBindBuffer(target, 0);
}
void bindBuffer(GLenum target = GL_ARRAY_BUFFER)
{
glBindBuffer(target, name);
}
/**
* Frees all associated memory
*/
void finialize()
{
if (name) {
glDeleteBuffers(1, &name);
name = 0;
}
}
private:
// VBO Extension Function Pointers
static PFNGLGENBUFFERSARBPROC glGenBuffers; // VBO Name Generation Procedure
static PFNGLBINDBUFFERARBPROC glBindBuffer; // VBO Bind Procedure
static PFNGLBUFFERDATAARBPROC glBufferData; // VBO Data Loading Procedure
static PFNGLDELETEBUFFERSARBPROC glDeleteBuffers; // VBO Deletion Procedure
};
#endif // VBO_H
......@@ -18,6 +18,7 @@
// along with SWE_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
uniform float scale = 10;
varying vec3 N;
varying vec4 ambient;
varying vec4 worldCoordinates;
......@@ -34,7 +35,7 @@ void main()
N = normalize(gl_NormalMatrix * gl_Normal);
// Save world coordinates
worldCoordinates = gl_Vertex;
worldCoordinates = gl_Vertex * scale;
// Compute vertex position via internal transform function
gl_Position = ftransform();
......
This diff is collapsed.
......@@ -26,6 +26,8 @@
#include "camera.h"
#include "simulation.h"
#include "shader.h"
#include "vbo.h"
#include "../scenarios/SWE_VisInfo.h"
#ifdef USESDLTTF
#include "text.h"
#endif // USESDLTTF
......@@ -40,7 +42,8 @@ public:
// Constructor and Destructor
Visualization(int windowWidth, int windowHeight, const char* window_title, int _grid_xsize, int _grid_ysize);
~Visualization();
void init(Simulation* sim);
void init(Simulation &sim, SWE_VisInfo *visInfo = 0L);
void cleanUp();
Camera* camera;
......@@ -51,49 +54,60 @@ public:
// Main rendering function
void renderDisplay();
// Rescale water
void modifyWaterScaling(float factor);
// Helper functions
void setRenderingMode(RenderMode mode);
void updateBathymetryVBO(Simulation* sim);
void toggleRenderingMode();
int resizeWindow(int newWidth, int newHeight);
static bool isExtensionSupported(const char* szTargetExtension );
private:
// Init helper functions
void initSDL(int windowWidth, int windowHeight);
void initGLWindow(int width, int height);
void initGLDefaults();
void initCUDA();
bool IsExtensionSupported(const char* szTargetExtension );
void updateBathymetryVBO(Simulation &sim);
// Drawing functions
void DrawWaterSurface(GLuint vboID, GLuint vboNormals, GLuint verticesIndex);
void DrawBathymetry(GLuint vboID, GLuint verticesIndex);
void DrawWaterSurface();
void DrawBathymetry();
void DrawBottom();
int grid_xsize;
int grid_ysize;
// Vertex Buffer objects
GLuint vboBathymetry;
GLuint verticesIndex;
GLuint vboWaterSurface;
GLuint vboNormals;
VBO vboBathymetry;
VBO vboVerticesIndex;
VBO vboWaterSurface;
VBO vboNormals;
// Bathymetry color
VBO vboBathColor;
struct cudaGraphicsResource* cuda_vbo_watersurface;
struct cudaGraphicsResource* cuda_vbo_normals;
// VBO management functions
void createIndicesVBO(GLuint* vboID, int xsize, int ysize);
void createVertexVBO(GLuint* vboID, int size);
void createBathymetryVBO(GLuint* vboID, int size, Simulation* sim);
void createVertexVBO(GLuint* vboID, int size, struct cudaGraphicsResource **vbo_res,
void createIndicesVBO(int xsize, int ysize);
void createVertexVBO(VBO &vbo, struct cudaGraphicsResource *&vbo_res,
unsigned int vbo_res_flags);
void deleteVBO(GLuint* vbo);
void deleteVBO(GLuint* vbo, struct cudaGraphicsResource *vbo_res);
void deleteCudaResource(struct cudaGraphicsResource *&vbo_res);
// Rendering mode
RenderMode renderMode;
// Shader helper class
Shader* shaders;
// Water/Bathymetry scaling/offset
float wScale, bScale, bOffset;
/** Location of the water scaling in the shader */
GLint wScaleLocation;
// Shaders
Shader* waterShader;
#ifdef USESDLTTF
// Text helper class
......@@ -104,10 +118,10 @@ private:
// Helper function
int coord(int x, int y, int width = -1);
// VBO Extension Function Pointers
PFNGLGENBUFFERSARBPROC glGenBuffers; // VBO Name Generation Procedure
PFNGLBINDBUFFERARBPROC glBindBuffer; // VBO Bind Procedure
PFNGLBUFFERDATAARBPROC glBufferData; // VBO Data Loading Procedure
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers; // VBO Deletion Procedure
static void height2Color(float height, GLfloat *color);
static GLfloat mix(GLfloat a, GLfloat b, float factor)
{
return a * (1-factor) + b * factor;
}
};
#endif
/**
* @file
* This file is part of SWE.
*
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
* SWE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWE. If not, see <http://www.gnu.org/licenses/>.
*
*
* @section DESCRIPTION
*
* Rescale water height in small Japan scenario
*/
#ifndef SWEASAGISCENARIO_VIS_HPP_
#define SWEASAGISCENARIO_VIS_HPP_
#include "SWE_VisInfo.h"
class SWE_AsagiJapanSmallVisInfo : public SWE_VisInfo
{
public:
virtual float waterVerticalScaling() { return 4.0f; };
virtual float bathyVerticalScaling() { return 0.010313f; };
};
#endif // SWEASAGISCENARIO_VIS_HPP_
......@@ -28,7 +28,8 @@
* Set bathymetry offset hence it is visible in the screen
*/
class SWE_BathymetryDamBreakVisInfo : public SWE_VisInfo {
float bathyVerticalOffset() { return 2500.0f; };
public:
float bathyVerticalOffset() { return 2450.0f; };
};
#endif
/**
* @file
* This file is part of SWE.
*
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
* SWE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWE. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Logger.hpp"
tools::Logger tools::Logger::logger;
......@@ -3,6 +3,7 @@
* This file is part of SWE.
*
* @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer)
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
......@@ -152,7 +153,7 @@ class tools::Logger {
* @param i_largeDelimiter definition of the large delimiter.
* @param i_indentation definition of the indentation (used in all messages, except welcome, start and finish).
*/
Logger( const int i_processRank = 0,
Logger( const int i_processRank = -1,
const std::string i_programName = "SWE",
const std::string i_welcomeMessage = "Welcome to",
const std::string i_copyRights = "\n\nSWE Copyright (C) 2012\n"
......@@ -180,9 +181,13 @@ class tools::Logger {
//set time to zero
cpuTime = cpuCommTime = wallClockTime = 0.;
#ifndef USEMPI
printWelcomeMessage();
#endif
#ifdef USEMPI
// determine local MPI rank
MPI_Comm_rank(MPI_COMM_WORLD, &processRank);
#else
processRank = 0;
printWelcomeMessage();
#endif
}
/**
......@@ -503,6 +508,10 @@ class tools::Logger {
<< i_cpuCommunicationTimeMessage << ": "
<< cpuCommTime << " seconds"<< std::endl;
}
public:
/** The logger all classes shoud use */
static Logger logger;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment