Fixed blending function for OpenGL compositing. Corrected documentation, removed unnecessary functions.
This commit is contained in:
parent
67c0cd2205
commit
27113348b9
|
@ -1,4 +1,4 @@
|
|||
/*i
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2013 CERN
|
||||
|
@ -103,58 +103,56 @@ unsigned int OPENGL_COMPOSITOR::GetBuffer()
|
|||
{
|
||||
wxASSERT( m_initialized );
|
||||
|
||||
if( m_buffers.size() < m_maxBuffers )
|
||||
{
|
||||
// GL_COLOR_ATTACHMENTn are consecutive integers
|
||||
GLuint attachmentPoint = GL_COLOR_ATTACHMENT0 + usedBuffers();
|
||||
GLuint textureTarget;
|
||||
if( m_buffers.size() >= m_maxBuffers )
|
||||
return 0; // Unfortunately we have no more free buffers left
|
||||
|
||||
// Generate the texture for the pixel storage
|
||||
glGenTextures( 1, &textureTarget );
|
||||
glBindTexture( GL_TEXTURE_2D, textureTarget );
|
||||
// GL_COLOR_ATTACHMENTn are consecutive integers
|
||||
GLuint attachmentPoint = GL_COLOR_ATTACHMENT0 + usedBuffers();
|
||||
GLuint textureTarget;
|
||||
|
||||
// Set texture parameters
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, NULL );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
// Generate the texture for the pixel storage
|
||||
glGenTextures( 1, &textureTarget );
|
||||
glBindTexture( GL_TEXTURE_2D, textureTarget );
|
||||
|
||||
// Bind the texture to the specific attachment point, clear and rebind the screen
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, m_framebuffer );
|
||||
m_currentFbo = m_framebuffer;
|
||||
glFramebufferTexture2D( GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, textureTarget, 0 );
|
||||
ClearBuffer();
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
m_currentFbo = 0;
|
||||
// Set texture parameters
|
||||
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, NULL );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
|
||||
// Store the new buffer
|
||||
BUFFER_ITEM buffer = { textureTarget, attachmentPoint };
|
||||
m_buffers.push_back( buffer );
|
||||
// Bind the texture to the specific attachment point, clear and rebind the screen
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, m_framebuffer );
|
||||
m_currentFbo = m_framebuffer;
|
||||
glFramebufferTexture2D( GL_FRAMEBUFFER, attachmentPoint, GL_TEXTURE_2D, textureTarget, 0 );
|
||||
ClearBuffer();
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
m_currentFbo = 0;
|
||||
|
||||
return usedBuffers();
|
||||
}
|
||||
// Store the new buffer
|
||||
OPENGL_BUFFER buffer = { textureTarget, attachmentPoint };
|
||||
m_buffers.push_back( buffer );
|
||||
|
||||
// Unfortunately we have no more buffers left
|
||||
return 0;
|
||||
return usedBuffers();
|
||||
}
|
||||
|
||||
|
||||
void OPENGL_COMPOSITOR::SetBuffer( unsigned int aBufferHandle )
|
||||
{
|
||||
if( aBufferHandle <= usedBuffers() )
|
||||
{
|
||||
// Change the rendering destination to the selected attachment point
|
||||
if( m_currentFbo != m_framebuffer )
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, m_framebuffer );
|
||||
m_currentFbo = m_framebuffer;
|
||||
}
|
||||
if( aBufferHandle > usedBuffers() )
|
||||
return;
|
||||
|
||||
if( m_current != aBufferHandle - 1 )
|
||||
{
|
||||
glDrawBuffer( m_buffers[m_current].attachmentPoint );
|
||||
m_current = aBufferHandle - 1;
|
||||
}
|
||||
// Change the rendering destination to the selected attachment point
|
||||
if( m_currentFbo != m_framebuffer )
|
||||
{
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, m_framebuffer );
|
||||
m_currentFbo = m_framebuffer;
|
||||
}
|
||||
|
||||
if( m_current != aBufferHandle - 1 )
|
||||
{
|
||||
m_current = aBufferHandle - 1;
|
||||
glDrawBuffer( m_buffers[m_current].attachmentPoint );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,15 +166,7 @@ void OPENGL_COMPOSITOR::ClearBuffer()
|
|||
}
|
||||
|
||||
|
||||
void OPENGL_COMPOSITOR::BlitBuffer( unsigned int aBufferHandle )
|
||||
{
|
||||
wxASSERT( m_initialized );
|
||||
|
||||
wxASSERT_MSG( false, wxT( "Not implemented yet" ) );
|
||||
}
|
||||
|
||||
|
||||
void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle, double aDepth )
|
||||
void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle )
|
||||
{
|
||||
wxASSERT( m_initialized );
|
||||
|
||||
|
@ -202,18 +192,18 @@ void OPENGL_COMPOSITOR::DrawBuffer( unsigned int aBufferHandle, double aDepth )
|
|||
|
||||
glBegin( GL_TRIANGLES );
|
||||
glTexCoord2f( 0.0f, 1.0f );
|
||||
glVertex3f( -1.0f, -1.0f, aDepth );
|
||||
glVertex2f( -1.0f, -1.0f );
|
||||
glTexCoord2f( 1.0f, 1.0f );
|
||||
glVertex3f( 1.0f, -1.0f, aDepth );
|
||||
glVertex2f( 1.0f, -1.0f );
|
||||
glTexCoord2f( 1.0f, 0.0f );
|
||||
glVertex3f( 1.0f, 1.0f, aDepth );
|
||||
glVertex2f( 1.0f, 1.0f );
|
||||
|
||||
glTexCoord2f( 0.0f, 1.0f );
|
||||
glVertex3f( -1.0f, -1.0f, aDepth );
|
||||
glVertex2f( -1.0f, -1.0f );
|
||||
glTexCoord2f( 1.0f, 0.0f );
|
||||
glVertex3f( 1.0f, 1.0f, aDepth );
|
||||
glVertex2f( 1.0f, 1.0f );
|
||||
glTexCoord2f( 0.0f, 0.0f );
|
||||
glVertex3f( -1.0f, 1.0f, aDepth );
|
||||
glVertex2f( -1.0f, 1.0f );
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
@ -229,7 +219,7 @@ void OPENGL_COMPOSITOR::clean()
|
|||
glDeleteFramebuffers( 1, &m_framebuffer );
|
||||
glDeleteRenderbuffers( 1, &m_depthBuffer );
|
||||
|
||||
Buffers::const_iterator it;
|
||||
OPENGL_BUFFERS::const_iterator it;
|
||||
for( it = m_buffers.begin(); it != m_buffers.end(); ++it )
|
||||
{
|
||||
glDeleteTextures( 1, &it->textureTarget );
|
||||
|
|
|
@ -333,8 +333,8 @@ void OPENGL_GAL::EndDrawing()
|
|||
|
||||
// Draw the remaining contents, blit the rendering targets to the screen, swap the buffers
|
||||
glFlush();
|
||||
compositor.DrawBuffer( mainBuffer, -1.0 );
|
||||
compositor.DrawBuffer( overlayBuffer, 0.0 );
|
||||
compositor.DrawBuffer( mainBuffer );
|
||||
compositor.DrawBuffer( overlayBuffer );
|
||||
SwapBuffers();
|
||||
|
||||
delete clientDC;
|
||||
|
|
|
@ -80,22 +80,13 @@ public:
|
|||
*/
|
||||
virtual void ClearBuffer() = 0;
|
||||
|
||||
/**
|
||||
* Function BlitBuffer()
|
||||
* pastes the content of the buffer to the current buffer (set by SetBuffer() function).
|
||||
*
|
||||
* @param aBufferHandle is the handle to the buffer that is going to be pasted.
|
||||
*/
|
||||
virtual void BlitBuffer( unsigned int aBufferHandle ) = 0;
|
||||
|
||||
/**
|
||||
* Function DrawBuffer()
|
||||
* draws the selected buffer on the screen.
|
||||
*
|
||||
* @param aBufferHandle is the handle of the buffer to be drawn.
|
||||
* @param aDepth is the depth on which the buffer should be drawn. // TODO mention if higher depth value means close to the screen or is it opposite
|
||||
*/
|
||||
virtual void DrawBuffer( unsigned int aBufferHandle, double aDepth ) = 0;
|
||||
virtual void DrawBuffer( unsigned int aBufferHandle ) = 0;
|
||||
|
||||
protected:
|
||||
unsigned int m_width; ///< Width of the buffer (in pixels)
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <gal/compositor.h>
|
||||
#include <GL/glew.h>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
namespace KiGfx
|
||||
{
|
||||
|
@ -44,41 +44,40 @@ public:
|
|||
OPENGL_COMPOSITOR();
|
||||
virtual ~OPENGL_COMPOSITOR();
|
||||
|
||||
///< @copydoc COMPOSITOR::Initialize()
|
||||
/// @copydoc COMPOSITOR::Initialize()
|
||||
virtual void Initialize();
|
||||
|
||||
///< @copydoc COMPOSITOR::Resize()
|
||||
/// @copydoc COMPOSITOR::Resize()
|
||||
virtual void Resize( unsigned int aWidth, unsigned int aHeight );
|
||||
|
||||
///< @copydoc COMPOSITOR::GetBuffer()
|
||||
/// @copydoc COMPOSITOR::GetBuffer()
|
||||
virtual unsigned int GetBuffer();
|
||||
|
||||
///< @copydoc COMPOSITOR::SetBuffer()
|
||||
/// @copydoc COMPOSITOR::SetBuffer()
|
||||
virtual void SetBuffer( unsigned int aBufferHandle );
|
||||
|
||||
///< @copydoc COMPOSITOR::ClearBuffer()
|
||||
/// @copydoc COMPOSITOR::ClearBuffer()
|
||||
virtual void ClearBuffer();
|
||||
|
||||
///< @copydoc COMPOSITOR::BlitBuffer()
|
||||
virtual void BlitBuffer( unsigned int aBufferHandle );
|
||||
|
||||
///< @copydoc COMPOSITOR::DrawBuffer()
|
||||
virtual void DrawBuffer( unsigned int aBufferHandle, double aDepth );
|
||||
/// @copydoc COMPOSITOR::DrawBuffer()
|
||||
virtual void DrawBuffer( unsigned int aBufferHandle );
|
||||
|
||||
protected:
|
||||
typedef struct
|
||||
{
|
||||
GLuint textureTarget; ///< Main texture handle
|
||||
GLuint attachmentPoint;
|
||||
} BUFFER_ITEM;
|
||||
GLuint attachmentPoint; ///< Point to which an image from texture is attached
|
||||
} OPENGL_BUFFER;
|
||||
|
||||
bool m_initialized;
|
||||
unsigned int m_current;
|
||||
bool m_initialized; ///< Initialization status flag
|
||||
unsigned int m_current; ///< Currently used buffer handle
|
||||
GLuint m_framebuffer; ///< Main FBO handle
|
||||
GLuint m_depthBuffer; ///< Depth buffer handle
|
||||
unsigned int m_maxBuffers; ///< Maximal amount of buffers
|
||||
typedef std::vector<BUFFER_ITEM> Buffers;
|
||||
Buffers m_buffers;
|
||||
typedef std::deque<OPENGL_BUFFER> OPENGL_BUFFERS;
|
||||
|
||||
/// Stores information about initialized buffers
|
||||
OPENGL_BUFFERS m_buffers;
|
||||
|
||||
/// Store the currently used FBO name in case there was more than one compositor used
|
||||
static GLuint m_currentFbo;
|
||||
|
@ -89,7 +88,7 @@ protected:
|
|||
*/
|
||||
void clean();
|
||||
|
||||
///< Returns number of used buffers
|
||||
/// Returns number of used buffers
|
||||
unsigned int usedBuffers()
|
||||
{
|
||||
return m_buffers.size();
|
||||
|
|
Loading…
Reference in New Issue