v01
This commit is contained in:
19
thirdparty/Pangolin/examples/VBODisplay/CMakeLists.txt
vendored
Normal file
19
thirdparty/Pangolin/examples/VBODisplay/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
|
||||
find_package(Pangolin 0.4 REQUIRED)
|
||||
include_directories(${Pangolin_INCLUDE_DIRS})
|
||||
link_directories(${Pangolin_LIBRARY_DIRS})
|
||||
link_libraries(${Pangolin_LIBRARIES})
|
||||
|
||||
find_package(CUDA QUIET)
|
||||
|
||||
# This example could be made to work with C++11, but the kernel code must be
|
||||
# compiled without it.
|
||||
if(CUDA_FOUND)
|
||||
cuda_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
cuda_add_executable(
|
||||
VBODisplay
|
||||
main.cpp kernal.cu
|
||||
)
|
||||
|
||||
endif()
|
||||
30
thirdparty/Pangolin/examples/VBODisplay/kernal.cu
vendored
Normal file
30
thirdparty/Pangolin/examples/VBODisplay/kernal.cu
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// Colour Sine wave Kernal
|
||||
// Based on kernal_colour in kernelVBO.cpp by Rob Farber
|
||||
__global__ void kernel(float4* dVertexArray, uchar4 *dColorArray,
|
||||
unsigned int width, unsigned int height, float time)
|
||||
{
|
||||
unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
|
||||
unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
|
||||
|
||||
// Each thread is unique point (u,v) in interval [-1,1],[-1,1]
|
||||
const float u = 2.0f* (x/(float)width) - 1.0f;
|
||||
const float v = 2.0f* (y/(float)height) - 1.0f;
|
||||
const float w = 0.5f * sinf(4.0f*u + time) * cosf(4.0f*v + time);
|
||||
|
||||
// Update vertex array for point
|
||||
dVertexArray[y*width+x] = make_float4(u, w, v, 1.0f);
|
||||
|
||||
// Update colour array for point
|
||||
dColorArray[y*width+x].w = 0.0f;
|
||||
dColorArray[y*width+x].x = 255.0f *0.5f*(1.f+sinf(w+x));
|
||||
dColorArray[y*width+x].y = 255.0f *0.5f*(1.f+sinf(x)*cosf(y));
|
||||
dColorArray[y*width+x].z = 255.0f *0.5f*(1.f+sinf(w+time/10.0f));
|
||||
}
|
||||
|
||||
extern "C" void launch_kernel(float4* dVertexArray, uchar4* dColourArray,
|
||||
unsigned int width, unsigned int height, float time)
|
||||
{
|
||||
dim3 block(8, 8, 1);
|
||||
dim3 grid(width / block.x, height / block.y, 1);
|
||||
kernel<<< grid, block>>>(dVertexArray, dColourArray, width, height, time);
|
||||
}
|
||||
84
thirdparty/Pangolin/examples/VBODisplay/main.cpp
vendored
Normal file
84
thirdparty/Pangolin/examples/VBODisplay/main.cpp
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <pangolin/pangolin.h>
|
||||
#include <pangolin/gl/glcuda.h>
|
||||
#include <pangolin/gl/glvbo.h>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <cuda_gl_interop.h>
|
||||
#include <vector_types.h>
|
||||
|
||||
using namespace pangolin;
|
||||
using namespace std;
|
||||
|
||||
// Mesh size
|
||||
const int mesh_width=256;
|
||||
const int mesh_height=256;
|
||||
|
||||
extern "C" void launch_kernel(float4* dVertexArray, uchar4* dColourArray, unsigned int width, unsigned int height, float time);
|
||||
|
||||
int main( int /*argc*/, char* argv[] )
|
||||
{
|
||||
// cudaGLSetGLDevice(0);
|
||||
|
||||
pangolin::CreateWindowAndBind("Main",640,480);
|
||||
glewInit();
|
||||
|
||||
// 3D Mouse handler requires depth testing to be enabled
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Create vertex and colour buffer objects and register them with CUDA
|
||||
GlBufferCudaPtr vertex_array(
|
||||
GlArrayBuffer, mesh_width*mesh_height, GL_FLOAT, 4,
|
||||
cudaGraphicsMapFlagsWriteDiscard, GL_STREAM_DRAW
|
||||
);
|
||||
GlBufferCudaPtr colour_array(
|
||||
GlArrayBuffer, mesh_width*mesh_height, GL_UNSIGNED_BYTE, 4,
|
||||
cudaGraphicsMapFlagsWriteDiscard, GL_STREAM_DRAW
|
||||
);
|
||||
|
||||
// Define Camera Render Object (for view / scene browsing)
|
||||
pangolin::OpenGlRenderState s_cam(
|
||||
ProjectionMatrix(640,480,420,420,320,240,0.1,1000),
|
||||
ModelViewLookAt(-0,2,-2, 0,0,0, AxisY)
|
||||
);
|
||||
const int UI_WIDTH = 180;
|
||||
|
||||
// Add named OpenGL viewport to window and provide 3D Handler
|
||||
View& d_cam = pangolin::Display("cam")
|
||||
.SetBounds(0.0, 1.0, Attach::Pix(UI_WIDTH), 1.0, -640.0f/480.0f)
|
||||
.SetHandler(new Handler3D(s_cam));
|
||||
|
||||
// Add named Panel and bind to variables beginning 'ui'
|
||||
// A Panel is just a View with a default layout and input handling
|
||||
View& d_panel = pangolin::CreatePanel("ui")
|
||||
.SetBounds(0.0, 1.0, 0.0, Attach::Pix(UI_WIDTH));
|
||||
|
||||
// Default hooks for exiting (Esc) and fullscreen (tab).
|
||||
for(int frame=0; !pangolin::ShouldQuit(); ++frame)
|
||||
{
|
||||
static double time = 0;
|
||||
static Var<double> delta("ui.time delta", 0.001, 0, 0.005);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
d_cam.Activate(s_cam);
|
||||
glColor3f(1.0,1.0,1.0);
|
||||
|
||||
{
|
||||
CudaScopedMappedPtr var(vertex_array);
|
||||
CudaScopedMappedPtr car(colour_array);
|
||||
launch_kernel((float4*)*var,(uchar4*)*car,mesh_width,mesh_height,time);
|
||||
time += delta;
|
||||
}
|
||||
|
||||
pangolin::RenderVboCbo(vertex_array, colour_array);
|
||||
|
||||
// Swap frames and Process Events
|
||||
pangolin::FinishFrame();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user