#include <mitkGPGPU.h>
Classes | |
class | Shader |
class | Texture |
Public Types | |
enum | TextureFormat { FLOAT32_LUMINANCE, FLOAT32_LUMINANCE_ALPHA, FLOAT32_RGBA, UINT8_RGBA } |
Public Member Functions | |
GPGPU () | |
~GPGPU () | |
void | Activate () |
void | Deactivate () |
void | Run () |
void | Run (float start, float end) |
Definition at line 54 of file mitkGPGPU.h.
Definition at line 58 of file mitkGPGPU.h.
mitk::GPGPU::GPGPU | ( | ) |
Definition at line 418 of file mitkGPGPU.cpp.
References Activate(), GL_CULL_FACE, GL_DEPTH_TEST, GL_MODELVIEW, GL_NICEST, GL_PERSPECTIVE_CORRECTION_HINT, GL_PROJECTION, GL_SMOOTH, GL_TEXTURE_COMPRESSION_HINT, glClearColor(), glClearDepth(), glDepthMask(), glDisable(), GLEW_OK, glewGetErrorString(), glewInit(), glHint(), glLoadIdentity(), glMatrixMode(), glOrtho(), glShadeModel(), GLX_BLUE_SIZE, GLX_DOUBLEBUFFER, GLX_GREEN_SIZE, GLX_RED_SIZE, GLX_RGBA, glXChooseVisual(), glXCreateContext(), GPGPU_CHECKGLERR, GPGPU_ERROR, and GPGPU_INFO.
{ #ifdef _WIN32 /* WNDCLASSEX wcx; // Fill in the window class structure with parameters // that describe the main window. wcx.cbSize = sizeof(wcx); // size of structure wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes wcx.lpfnWndProc = MainWndProc; // points to window procedure wcx.cbClsExtra = 0; // no extra class memory wcx.cbWndExtra = 0; // no extra window memory wcx.hInstance = GetModuleHandle(NULL); // handle to inst ance wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); // predefined app. icon wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // predefined arrow wcx.hbrBackground = NULL; // white background brush wcx.lpszMenuName = (LPCSTR) "MainMenu"; // name of menu resource wcx.lpszClassName = (LPCSTR) "MainWClass"; // name of window class wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // Register the window class. if(!RegisterClassEx(&wcx)) std::cout << "failed registering window class\n"; HWND desktopWindow=CreateWindowEx( WS_EX_CLIENTEDGE, (LPCSTR)"MainWClass", (LPCSTR)"Anatomy of a Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, GetModuleHandle(NULL), NULL); windowHandle = desktopWindow; ShowWindow(desktopWindow, SW_RESTORE); if(desktopWindow==0) std::cout << "failed creating window\n"; */ HWND desktopWindow=QApplication::topLevelWidgets().at(0)->winId(); windowsContext = GetDC(desktopWindow); if(windowsContext==0) std::cout << "failed getting window device context\n"; static PIXELFORMATDESCRIPTOR pfd =// pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER | PFD_SWAP_EXCHANGE , // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 24, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored if(openGLContext==0) 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 0, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; // Sonstiges einstellen int iFormat = ChoosePixelFormat(windowsContext,&pfd); SetPixelFormat(windowsContext,iFormat,&pfd); openGLContext = wglCreateContext(windowsContext); int errw=GetLastError(); if(openGLContext==0) std::cout << "failed creating openGL context "<<errw<<"\n"; #else X_display = XOpenDisplay(NULL); GPGPU_ERROR( !X_display ) << "cant open X display"; GLX_drawable = QApplication::topLevelWidgets().at(0)->winId(); GPGPU_ERROR( !GLX_drawable ) << "cant get toplevel widget from QT"; static int visAttributes[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DOUBLEBUFFER, None }; XVisualInfo *visinfo = glXChooseVisual(X_display, 0, visAttributes); GPGPU_ERROR(!visinfo) << "Unable to choose specified visual!"; openGLContext = glXCreateContext(X_display, visinfo, 0, true); if(visinfo) XFree(visinfo); GPGPU_ERROR(!openGLContext) << "cant create GLX context"; #endif Activate(); GPGPU_INFO << "initializing glew"; int err=glewInit(); GPGPU_CHECKGLERR << "initializing glew"; GPGPU_ERROR(GLEW_OK != err) << "glewInit() fails with " << err << " as text: " << glewGetErrorString(err); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,1,0,1,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); GPGPU_CHECKGLERR << "intializing projection&modelview matrix"; glDisable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); // Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background glClearDepth(1.0f); // Depth Buffer Setup glDisable(GL_DEPTH_TEST); // Enables Depth Testing glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST); glDepthMask(false); GPGPU_CHECKGLERR << "setting up openGL context"; }
mitk::GPGPU::~GPGPU | ( | ) |
Definition at line 570 of file mitkGPGPU.cpp.
References glXDestroyContext().
{ #ifdef _WIN32 wglDeleteContext( openGLContext ); #else if(openGLContext) glXDestroyContext(X_display,openGLContext); if(X_display) XCloseDisplay(X_display); #endif }
void mitk::GPGPU::Activate | ( | ) |
Definition at line 588 of file mitkGPGPU.cpp.
References glXMakeCurrent(), and GPGPU_CHECKGLERR.
Referenced by GPGPU().
{ #ifdef _WIN32 wglMakeCurrent(windowsContext,openGLContext); #else glXMakeCurrent(X_display, GLX_drawable, openGLContext); #endif GPGPU_CHECKGLERR << "activating openGL context"; }
void mitk::GPGPU::Deactivate | ( | ) |
Definition at line 600 of file mitkGPGPU.cpp.
{ }
void mitk::GPGPU::Run | ( | ) |
Definition at line 604 of file mitkGPGPU.cpp.
References GL_TRIANGLE_STRIP, glBegin(), glEnd(), glVertex2f(), and GPGPU_CHECKGLERR.
{ glBegin( GL_TRIANGLE_STRIP ); glVertex2f( 0,0 ); glVertex2f( 0,1 ); glVertex2f( 1,0 ); glVertex2f( 1,1 ); glEnd(); GPGPU_CHECKGLERR << "running a shader"; }
void mitk::GPGPU::Run | ( | float | start, |
float | end | ||
) |
Definition at line 616 of file mitkGPGPU.cpp.
References GL_TRIANGLE_STRIP, glBegin(), glEnd(), glVertex2f(), and GPGPU_CHECKGLERR.
{ glBegin( GL_TRIANGLE_STRIP ); glVertex2f( 0,start ); glVertex2f( 0,end ); glVertex2f( 1,start ); glVertex2f( 1,end ); glEnd(); GPGPU_CHECKGLERR << "running a shader"; }