Show framebuffertarget.cpp syntax highlighted
/***************************************************************************
framebuffertarget.cpp - Frame buffer render target
-------------------
begin : Fri Apr 25 2003
copyright : (C) 2003 by Reality Rift Studios
email : mattias@realityrift.com
***************************************************************************
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is the NeoEngine, NeoDevOpenGL, framebuffertarget.cpp
The Initial Developer of the Original Code is Mattias Jansson.
Portions created by Mattias Jansson are Copyright (C) 2003
Reality Rift Studios. All Rights Reserved.
***************************************************************************/
#define NEEDGDI
#include "framebuffertarget.h"
#include <neoengine/logstream.h>
using namespace std;
using namespace NeoEngine;
namespace NeoOGL
{
FrameBufferRenderTarget::FrameBufferRenderTarget( Device *pkDevice ) :
RenderTarget( pkDevice )
{
#ifdef WIN32
m_hDC = 0;
m_hRC = 0;
#elif __APPLE__
m_aglContext = 0;
m_aglPixelFormat = 0;
m_cglPixelFormat = 0;
m_cglContext = 0;
#elif POSIX
m_glxContext = 0;
#else
# error "Platform not implemented"
#endif
Deactivate();
}
FrameBufferRenderTarget::~FrameBufferRenderTarget()
{
Deactivate();
DeleteQueues();
#ifdef WIN32
if( m_hRC )
{
wglMakeCurrent( 0, 0 );
wglDeleteContext( (HGLRC)m_hRC );
}
if( m_hDC )
ReleaseDC( (HWND)m_pkDevice->m_kWindow.m_hWnd, m_hDC );
m_hDC = 0;
m_hRC = 0;
#elif __APPLE__
/*
if( m_pkDevice->m_kWindow.m_kCaps.IsSet( RenderCaps::FULLSCREEN ) )
{
CGLSetCurrentContext( 0 );
CGLClearDrawable( m_cglContext );
CGLDestroyContext( m_cglContext );
CGReleaseAllDisplays();
}
*/
if( m_aglContext )
{
glFinish();
aglSetCurrentContext( 0 );
aglSetDrawable( m_aglContext, 0 );
aglDestroyContext( m_aglContext );
}
if( m_aglPixelFormat )
aglDestroyPixelFormat( m_aglPixelFormat );
m_aglContext = 0;
m_aglPixelFormat = 0;
m_cglPixelFormat = 0;
m_cglContext = 0;
#elif POSIX
glXMakeCurrent( (Display*)m_pkDevice->m_kWindow.m_pDisplay, None, 0 );
glXDestroyContext( (Display*)m_pkDevice->m_kWindow.m_pDisplay, m_glxContext );
#else
# error "Platform not implemented"
#endif
}
void FrameBufferRenderTarget::Activate()
{
if( IsActive() )
return;
#ifdef WIN32
if( wglMakeCurrent( m_hDC, m_hRC ) == FALSE )
{
neolog << LogLevel( ERROR ) << "[FrameBufferRenderTarget::Activate] unable to set current GL context" << endl;
return;
}
#elif __APPLE__
if( m_pkDevice->m_kWindow.m_pWindow && !aglSetDrawable( m_aglContext, GetWindowPort( (WindowPtr)m_pkDevice->m_kWindow.m_pWindow ) ) )
{
neolog << LogLevel( ERROR ) << "[FrameBufferRenderTarget::Activate] Failed to bind AGLContext and window" << endl;
return;
}
if( !aglSetCurrentContext( m_aglContext ) )
{
neolog << LogLevel( ERROR ) << "[FrameBufferRenderTarget::Activate] Failed to set the current AGLContext active" << endl;
aglSetDrawable( m_aglContext, NULL );
return;
}
#elif defined( POSIX )
if( glXMakeCurrent( (Display*)m_pkDevice->m_kWindow.m_pDisplay, (Window)m_pkDevice->m_kWindow.m_Window, m_glxContext ) != True )
{
neolog << LogLevel( ERROR ) << "[FrameBufferRenderTarget::Activate] Unable to set current glx context" << endl;
return;
}
#else
# error "Platform not implemented"
#endif
m_pkDevice->SetViewport( 0, 0, m_pkDevice->GetWidth(), m_pkDevice->GetHeight() );
Activator::Activate();
}
void FrameBufferRenderTarget::Deactivate()
{
if( !IsActive() )
return;
Activator::Deactivate();
}
int FrameBufferRenderTarget::GetWidth()
{
return Core::Get()->GetRenderDevice()->GetWidth();
}
int FrameBufferRenderTarget::GetHeight()
{
return Core::Get()->GetRenderDevice()->GetHeight();
}
}; // namespace NeoOGL
See more files for this project here