<commit_before>/**************************************************************************************/
/*                                                                                    */
/*  Visualization Library                                                             */
/*  http://www.visualizationlibrary.org                                               */
/*                                                                                    */
/*  Copyright (c) 2005-2010, <NAME>                                             */
/*  All rights reserved.                                                              */
/*                                                                                    */
/*  Redistribution and use in source and binary forms, with or without modification,  */
/*  are permitted provided that the following conditions are met:                     */
/*                                                                                    */
/*  - Redistributions of source code must retain the above copyright notice, this     */
/*  list of conditions and the following disclaimer.                                  */
/*                                                                                    */
/*  - Redistributions in binary form must reproduce the above copyright notice, this  */
/*  list of conditions and the following disclaimer in the documentation and/or       */
/*  other materials provided with the distribution.                                   */
/*                                                                                    */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
/*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
/*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
/*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
/*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
/*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
/*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
/*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
/*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
/*                                                                                    */
/**************************************************************************************/

#ifndef BufferObject_INCLUDE_ONCE
#define BufferObject_INCLUDE_ONCE

#include <vlCore/Vector2.hpp>
#include <vlCore/Vector3.hpp>
#include <vlCore/Vector4.hpp>
#include <vlCore/Buffer.hpp>
#include <vlGraphics/OpenGL.hpp>
#include <vlCore/vlnamespace.hpp>
#include <vlCore/Vector4.hpp>
#include <vlCore/Sphere.hpp>
#include <vlCore/AABB.hpp>

namespace vl
{
//-----------------------------------------------------------------------------
// BufferObject
//-----------------------------------------------------------------------------
  /**
   * The BufferObject class is a Buffer that can upload its data on the GPU memory. 
   * \remarks
   * BufferObject is the storage used by ArrayAbstract and subclasses like ArrayFloat3, ArrayUByte4 etc.
  */
  class BufferObject: public Buffer
  {
    VL_INSTRUMENT_CLASS(vl::BufferObject, Buffer)

  public:
    BufferObject()
    {
      VL_DEBUG_SET_OBJECT_NAME()
      mHandle = 0;
      mUsage = BU_STATIC_DRAW;
      mByteCountBufferObject = 0;
    }

    BufferObject(const BufferObject& other): Buffer(other)
    {
      VL_DEBUG_SET_OBJECT_NAME()
      mHandle = 0;
      mUsage = BU_STATIC_DRAW;
      mByteCountBufferObject = 0;
      // copy local data
      *this = other;
    }

    // deletes the BufferObject data and copyes only the local data
    BufferObject& operator=(const BufferObject& other) 
    { 
      deleteBufferObject();
      super::operator=(other); 
      return *this;
    }

    // swaps data with another BufferObject, including BufferObject handle, usage and local data.
    void swap(BufferObject& other)
    {
      // swap local data
      Buffer::swap(other);
      // tmp
      unsigned int tmp_handle = mHandle;
      EBufferObjectUsage tmp_usage = mUsage;
      GLsizeiptr tmp_bytes = mByteCountBufferObject;
      // this <- other
      mHandle = other.mHandle;
      mUsage = tmp_usage;
      mByteCountBufferObject = other.mByteCountBufferObject;
      // other <- this
      other.mHandle = tmp_handle;
      other.mUsage = tmp_usage;
      other.mByteCountBufferObject = tmp_bytes;
    }

    ~BufferObject()
    {
      deleteBufferObject();
    }

    void setHandle(unsigned int handle) { mHandle = handle; }

    unsigned int handle() const { return mHandle; }

    GLsizeiptr byteCountBufferObject() const { return mByteCountBufferObject; }

    void createBufferObject()
    {
      VL_CHECK_OGL();
      VL_CHECK(Has_BufferObject)
      if (Has_BufferObject && handle() == 0)
      {
        VL_CHECK(mByteCountBufferObject == 0)
        VL_glGenBuffers( 1, &mHandle ); VL_CHECK_OGL();
        mByteCountBufferObject = 0;
        VL_CHECK(handle())
      }
    }

    void deleteBufferObject()
    {
      // mic fixme: it would be nice to re-enable these
      // VL_CHECK_OGL();
      VL_CHECK(Has_BufferObject)
      if (Has_BufferObject && handle() != 0)
      {
        VL_glDeleteBuffers( 1, &mHandle ); // VL_CHECK_OGL();
        mHandle = 0;
        mByteCountBufferObject = 0;<commit_msg>fixed BufferObject destructor to be more loose when no GL context is present and no BufferObject was created.<commit_after>/**************************************************************************************/
/*                                                                                    */
/*  Visualization Library                                                             */
/*  http://www.visualizationlibrary.org                                               */
/*                                                                                    */
/*  Copyright (c) 2005-2010, <NAME>                                             */
/*  All rights reserved.                                                              */
/*                                                                                    */
/*  Redistribution and use in source and binary forms, with or without modification,  */
/*  are permitted provided that the following conditions are met:                     */
/*                                                                                    */
/*  - Redistributions of source code must retain the above copyright notice, this     */
/*  list of conditions and the following disclaimer.                                  */
/*                                                                                    */
/*  - Redistributions in binary form must reproduce the above copyright notice, this  */
/*  list of conditions and the following disclaimer in the documentation and/or       */
/*  other materials provided with the distribution.                                   */
/*                                                                                    */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND   */
/*  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED     */
/*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE            */
/*  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR  */
/*  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    */
/*  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;      */
/*  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON    */
/*  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT           */
/*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS     */
/*  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                      */
/*                                                                                    */
/**************************************************************************************/

#ifndef BufferObject_INCLUDE_ONCE
#define BufferObject_INCLUDE_ONCE

#include <vlCore/Vector2.hpp>
#include <vlCore/Vector3.hpp>
#include <vlCore/Vector4.hpp>
#include <vlCore/Buffer.hpp>
#include <vlGraphics/OpenGL.hpp>
#include <vlCore/vlnamespace.hpp>
#include <vlCore/Vector4.hpp>
#include <vlCore/Sphere.hpp>
#include <vlCore/AABB.hpp>

namespace vl
{
//-----------------------------------------------------------------------------
// BufferObject
//-----------------------------------------------------------------------------
  /**
   * The BufferObject class is a Buffer that can upload its data on the GPU memory. 
   * \remarks
   * BufferObject is the storage used by ArrayAbstract and subclasses like ArrayFloat3, ArrayUByte4 etc.
  */
  class BufferObject: public Buffer
  {
    VL_INSTRUMENT_CLASS(vl::BufferObject, Buffer)

  public:
    BufferObject()
    {
      VL_DEBUG_SET_OBJECT_NAME()
      mHandle = 0;
      mUsage = BU_STATIC_DRAW;
      mByteCountBufferObject = 0;
    }

    BufferObject(const BufferObject& other): Buffer(other)
    {
      VL_DEBUG_SET_OBJECT_NAME()
      mHandle = 0;
      mUsage = BU_STATIC_DRAW;
      mByteCountBufferObject = 0;
      // copy local data
      *this = other;
    }

    // deletes the BufferObject data and copyes only the local data
    BufferObject& operator=(const BufferObject& other) 
    { 
      deleteBufferObject();
      super::operator=(other); 
      return *this;
    }

    // swaps data with another BufferObject, including BufferObject handle, usage and local data.
    void swap(BufferObject& other)
    {
      // swap local data
      Buffer::swap(other);
      // tmp
      unsigned int tmp_handle = mHandle;
      EBufferObjectUsage tmp_usage = mUsage;
      GLsizeiptr tmp_bytes = mByteCountBufferObject;
      // this <- other
      mHandle = other.mHandle;
      mUsage = tmp_usage;
      mByteCountBufferObject = other.mByteCountBufferObject;
      // other <- this
      other.mHandle = tmp_handle;
      other.mUsage = tmp_usage;
      other.mByteCountBufferObject = tmp_bytes;
    }

    ~BufferObject()
    {
      deleteBufferObject();
    }

    void setHandle(unsigned int handle) { mHandle = handle; }

    unsigned int handle() const { return mHandle; }

    GLsizeiptr byteCountBufferObject() const { return mByteCountBufferObject; }

    void createBufferObject()
    {
      VL_CHECK_OGL();
      VL_CHECK(Has_BufferObject)
      if (Has_BufferObject && handle() == 0)
      {
        VL_CHECK(mByteCountBufferObject == 0)
        VL_glGenBuffers( 1, &mHandle ); VL_CHECK_OGL();
        mByteCountBufferObject = 0;
        VL_CHECK(handle())
      }
    }

    void deleteBufferObject()
    {
      // mic fixme: it would be nice to re-enable these
      // VL_CHECK_OGL();
      VL_CHECK(Has_BufferObject || handle() == 0)
      if (Has_BufferObject && handle() != 0)
      {
        VL_glDeleteBuffers( 1, &mHandle ); // VL_CHECK_OGL();
        mHandle = 0;
        mByteCountBufferObject = 0;
{'fraction_non_alphanumeric': 0.1346304859959864, 'fraction_numerical': 0.00462437832649856, 'mean_word_length': 1.5705315093070196, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7534827', 'n_tokens_mistral': 2811, 'n_tokens_neox': 2600, 'n_words': 826}