Render_GL_Win32_Device.cpp
Go to the documentation of this file.
00001 /************************************************************************************
00002 
00003 Filename    :   Render_GL_Win32 Device.cpp
00004 Content     :   Win32 OpenGL Device implementation
00005 Created     :   September 10, 2012
00006 Authors     :   Andrew Reisse, Michael Antonov
00007 
00008 Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.
00009 
00010 Licensed under the Apache License, Version 2.0 (the "License");
00011 you may not use this file except in compliance with the License.
00012 You may obtain a copy of the License at
00013 
00014 http://www.apache.org/licenses/LICENSE-2.0
00015 
00016 Unless required by applicable law or agreed to in writing, software
00017 distributed under the License is distributed on an "AS IS" BASIS,
00018 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019 See the License for the specific language governing permissions and
00020 limitations under the License.
00021 
00022 ************************************************************************************/
00023 
00024 #include "Render_GL_Win32_Device.h"
00025 
00026 namespace OVR { namespace Render { namespace GL { namespace Win32 {
00027 
00028 
00029 // ***** GL::Win32::RenderDevice
00030 
00031 // Implement static initializer function to create this class.
00032 Render::RenderDevice* RenderDevice::CreateDevice(const RendererParams&, void* oswnd)
00033 {
00034     HWND hwnd = (HWND)oswnd;
00035 
00036     PIXELFORMATDESCRIPTOR pfd;
00037     memset(&pfd, 0, sizeof(pfd));
00038 
00039     pfd.nSize       = sizeof(pfd);
00040     pfd.nVersion    = 1;
00041     pfd.iPixelType  = PFD_TYPE_RGBA;
00042     pfd.dwFlags     = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
00043     pfd.cColorBits  = 32;
00044     pfd.cDepthBits  = 16;
00045 
00046     HDC dc = GetDC(hwnd);
00047     int pf = ChoosePixelFormat(dc, &pfd);
00048     if (!pf)
00049     {
00050         ReleaseDC(hwnd, dc);
00051         return NULL;
00052     }
00053     if (!SetPixelFormat(dc, pf, &pfd))
00054     {
00055         ReleaseDC(hwnd, dc);
00056         return NULL;
00057     }
00058     HGLRC context = wglCreateContext(dc);
00059     if (!wglMakeCurrent(dc, context))
00060     {
00061         wglDeleteContext(context);
00062         ReleaseDC(hwnd, dc);
00063         return NULL;
00064     }
00065 
00066    // return new RenderDevice(rp, hwnd, dc, context);
00067     return 0;
00068 }
00069 
00070 
00071 void RenderDevice::Present()
00072 {
00073     SwapBuffers(GdiDc);
00074 }
00075 
00076 void RenderDevice::Shutdown()
00077 {
00078     if (WglContext)
00079     {
00080         wglMakeCurrent(NULL,NULL);
00081         wglDeleteContext(WglContext);
00082         ReleaseDC(Window, GdiDc);
00083         WglContext = NULL;
00084         GdiDc = NULL;
00085         Window = NULL;
00086     }
00087 }
00088 
00089 }}}}
00090 


oculus_sdk
Author(s): Tully Foote
autogenerated on Thu Jun 6 2019 20:13:49