/** * @file XTPOpenGLListPool.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "Common/XTPTypeId.h" #include "Common/XTPSynchro.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/Base/Diagnostic/XTPDisableAdvancedWarnings.h" #include "GraphicLibrary/OpenGL/GL.h" #include "Common/Base/Diagnostic/XTPEnableAdvancedWarnings.h" #include "GraphicLibrary/OpenGL/XTPOpenGLListPool.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif CXTPOpenGLListPool* AFX_CDECL XTPOpenGLListPool() { return &CXTPOpenGLListPool::Instance(); } CXTPOpenGLListPool::CXTPOpenGLListPool() : m_nMax(0) , m_bCommitExpected(FALSE) { } CXTPOpenGLListPool::~CXTPOpenGLListPool() { _ASSERTE(!m_bCommitExpected && "An OpenGL list has not been committed"); } GLuint CXTPOpenGLListPool::AllocateList(GLenum mode) { _ASSERTE(!m_bCommitExpected && "An OpenGL list has not been committed"); GLuint id = 0; BOOL bIsMax = FALSE; if (0 < m_reclaimed.GetCount()) { id = m_reclaimed.GetHead(); m_reclaimed.RemoveHead(); } else { _ASSERTE(m_nMax != ~GLuint(0) && "Too much lists generated. Consider resource optimization."); if (m_nMax != ~GLuint(0)) { bIsMax = TRUE; id = m_nMax + 1; } } if (0 < id) { glNewList(id, mode); if (GL_NO_ERROR == glGetError()) { m_allocated.AddTail(id); m_bCommitExpected = TRUE; if (bIsMax) { m_nMax = id; } } else { id = 0; } } return id; } void CXTPOpenGLListPool::CommitList() { _ASSERTE(m_bCommitExpected && "No OpenGL list is expected to be committed"); if (m_bCommitExpected) { glEndList(); m_bCommitExpected = FALSE; } } void CXTPOpenGLListPool::ReclaimList(GLuint id) { _ASSERTE(!m_bCommitExpected && "An OpenGL list has not been committed"); POSITION pos = m_allocated.Find(id); _ASSERTE(NULL != pos && "The list requested is not allocated and thus cannot be reclaimed"); if (NULL != pos) { m_allocated.RemoveAt(pos); m_reclaimed.AddTail(id); glDeleteLists(id, 1); } }