Skip to content

Commit

Permalink
Replace Array1DView and Array2DView with read and write views.
Browse files Browse the repository at this point in the history
- Added readViewOf(string).
- TODO: 3D.
  • Loading branch information
Jiawen Chen committed Nov 28, 2016
1 parent 1d25b8b commit 8c5721e
Show file tree
Hide file tree
Showing 94 changed files with 1,458 additions and 684 deletions.
16 changes: 6 additions & 10 deletions GL/src/GL_45/GLBufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

#include "GLBufferObject.h"

//////////////////////////////////////////////////////////////////////////
// Public
//////////////////////////////////////////////////////////////////////////

// static
bool GLBufferObject::copy( GLBufferObject* pSource,
GLBufferObject* pDestination, GLintptr sourceOffsetBytes,
Expand Down Expand Up @@ -36,7 +32,7 @@ GLBufferObject::GLBufferObject( GLsizeiptr nBytes,
glNamedBufferStorage( m_id, nBytes, nullptr, glStorageFlags() );
}

GLBufferObject::GLBufferObject( Array1DView< uint8_t > data,
GLBufferObject::GLBufferObject( Array1DReadView< uint8_t > data,
GLBufferObject::StorageFlags flags ) :
m_id( 0 ),
m_nBytes( data.size() ),
Expand Down Expand Up @@ -73,10 +69,10 @@ GLbitfield GLBufferObject::glStorageFlags() const
return ::glStorageFlags( m_storageFlags );
}

Array1DView< uint8_t > GLBufferObject::mapRange( GLintptr offsetBytes,
Array1DWriteView< uint8_t > GLBufferObject::mapRange( GLintptr offsetBytes,
GLsizeiptr sizeBytes, GLBufferObject::MapRangeAccess access )
{
return Array1DView< uint8_t >(
return Array1DWriteView< uint8_t >(
glMapNamedBufferRange( m_id, offsetBytes, sizeBytes,
glBufferMapRangeAccess( access ) ),
sizeBytes
Expand All @@ -103,7 +99,7 @@ void GLBufferObject::unmap()
glUnmapNamedBuffer( m_id );
}

bool GLBufferObject::get( GLintptr srcOffset, Array1DView< uint8_t > dst )
bool GLBufferObject::get( GLintptr srcOffset, Array1DWriteView< uint8_t > dst )
{
if( srcOffset + dst.size() > m_nBytes )
{
Expand All @@ -114,7 +110,7 @@ bool GLBufferObject::get( GLintptr srcOffset, Array1DView< uint8_t > dst )
return true;
}

bool GLBufferObject::set( Array1DView< const uint8_t > src, GLintptr dstOffset )
bool GLBufferObject::set( Array1DReadView< uint8_t > src, GLintptr dstOffset )
{
if( !( src.packed() ) )
{
Expand Down Expand Up @@ -200,4 +196,4 @@ GLBufferObject::MapRangeAccess& operator |= (
static_cast< GLbitfield >( lhs ) | static_cast< GLbitfield >( rhs )
);
return lhs;
}
}
21 changes: 11 additions & 10 deletions GL/src/GL_45/GLBufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include <GL/glew.h>

#include <common/ArrayView.h>
#include <common/BasicTypes.h>
#include <common/Array1DView.h>

#include "GLImageFormat.h"
#include "GLImageInternalFormat.h"
Expand Down Expand Up @@ -70,6 +70,7 @@ class GLBufferObject
COHERENT_BIT = GL_MAP_COHERENT_BIT
};

// TODO: make this a free function
// Direct copy between two buffer objects.
// Returns false if either range is out of bounds.
static bool copy( GLBufferObject* pSource, GLBufferObject* pDestination,
Expand Down Expand Up @@ -105,7 +106,7 @@ class GLBufferObject
// data must be packed().
// flags is a bitfield, which is an OR combination of elements from
// StorageFlags.
GLBufferObject( Array1DView< uint8_t > data, StorageFlags flags );
GLBufferObject( Array1DReadView< uint8_t > data, StorageFlags flags );

virtual ~GLBufferObject();

Expand All @@ -125,8 +126,8 @@ class GLBufferObject
// GL_MAP_INVALIDATE_BUFFER_BIT, GL_MAP_FLUSH_EXPLICIT_BIT,
// and/or GL_MAP_UNSYNCHRONIZED_BIT.
// TODO: make a Range1l class for 64-bit ranges (and use it here).
Array1DView< uint8_t > mapRange( GLintptr offsetBytes, GLsizeiptr sizeBytes,
GLBufferObject::MapRangeAccess access );
Array1DWriteView< uint8_t > mapRange( GLintptr offsetBytes,
GLsizeiptr sizeBytes, GLBufferObject::MapRangeAccess access );

// Maps a range of this buffer as a pointer into client memory.
// access is a bitfield, which is an | combination of elements of
Expand All @@ -137,8 +138,8 @@ class GLBufferObject
// and/or GL_MAP_UNSYNCHRONIZED_BIT.
// TODO: make a Range1l class for 64-bit ranges (and use it here).
template< typename T >
Array1DView< T > mapRangeAs( GLintptr offsetBytes, GLsizeiptr sizeBytes,
GLBufferObject::MapRangeAccess access );
Array1DWriteView< T > mapRangeAs( GLintptr offsetBytes,
GLsizeiptr sizeBytes, GLBufferObject::MapRangeAccess access );

// If the buffer was mapped with GL_MAP_FLUSH_EXPLICIT_BIT, flushRange()
// tells OpenGL that this range should now be visible to calls after this.
Expand All @@ -158,13 +159,13 @@ class GLBufferObject

// Copies the data in a subset of this buffer to dst.
// Returns false if srcOffset + dst.length() > numBytes().
bool get( GLintptr srcOffset, Array1DView< uint8_t > dst );
bool get( GLintptr srcOffset, Array1DWriteView< uint8_t > dst );

// Copies the data from src into this buffer.
// Returns false if:
// The source buffer is not packed(), or
// if dstOffset + src.length() > numBytes().
bool set( Array1DView< const uint8_t > src, GLintptr dstOffset );
bool set( Array1DReadView< uint8_t > src, GLintptr dstOffset );

// Fills the entire buffer with 0.
void clear();
Expand Down Expand Up @@ -213,10 +214,10 @@ GLBufferObject::MapRangeAccess& operator |= (
GLBufferObject::MapRangeAccess& lhs, GLBufferObject::MapRangeAccess rhs );

template< typename T >
Array1DView< T > GLBufferObject::mapRangeAs( GLintptr offsetBytes,
Array1DWriteView< T > GLBufferObject::mapRangeAs( GLintptr offsetBytes,
GLsizeiptr sizeBytes, GLBufferObject::MapRangeAccess access )
{
return Array1DView< T >(
return Array1DWriteView< T >(
glMapNamedBufferRange( m_id, offsetBytes, sizeBytes,
glBufferMapRangeAccess( access ) ),
static_cast< size_t >( sizeBytes / sizeof( T ) ) );
Expand Down
3 changes: 2 additions & 1 deletion GL/src/GL_45/GLFramebufferObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ void GLFramebufferObject::setDrawBuffer( GLenum attachment )
glNamedFramebufferDrawBuffer( m_id, attachment );
}

void GLFramebufferObject::setDrawBuffers( Array1DView< const GLenum > attachments )
void GLFramebufferObject::setDrawBuffers(
Array1DReadView< GLenum > attachments )
{
assert( attachments.packed() );
glNamedFramebufferDrawBuffers( m_id,
Expand Down
5 changes: 2 additions & 3 deletions GL/src/GL_45/GLFramebufferObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

#include <GL/glew.h>

#include <common/Array1D.h>
#include <common/Array1DView.h>
#include <common/ArrayView.h>
#include <common/BasicTypes.h>
#include <vecmath/Vector4f.h>

Expand Down Expand Up @@ -107,7 +106,7 @@ class GLFramebufferObject
// Set the fraembuffer's draw buffers [0, 1, ... attachments.size())
// to [attachments[0], attachments[1], ...)
// attachments must be packed.
void setDrawBuffers( Array1DView< const GLenum > attachments );
void setDrawBuffers( Array1DReadView< GLenum > attachments );

void setReadBuffer( GLenum attachment );

Expand Down
16 changes: 8 additions & 8 deletions GL/src/GL_45/GLTexture1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int GLTexture1D::size() const
return m_width;
}

bool GLTexture1D::set( Array1DView< const uint8_t > srcData,
bool GLTexture1D::set( Array1DReadView< uint8_t > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -81,7 +81,7 @@ bool GLTexture1D::set( Array1DView< const uint8_t > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const uint8x2 > srcData,
bool GLTexture1D::set( Array1DReadView< uint8x2 > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -98,7 +98,7 @@ bool GLTexture1D::set( Array1DView< const uint8x2 > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const uint8x3 > srcData,
bool GLTexture1D::set( Array1DReadView< uint8x3 > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -116,7 +116,7 @@ bool GLTexture1D::set( Array1DView< const uint8x3 > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const uint8x4 > srcData,
bool GLTexture1D::set( Array1DReadView< uint8x4 > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -133,7 +133,7 @@ bool GLTexture1D::set( Array1DView< const uint8x4 > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const float > srcData,
bool GLTexture1D::set( Array1DReadView< float > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -153,7 +153,7 @@ bool GLTexture1D::set( Array1DView< const float > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const Vector2f > srcData,
bool GLTexture1D::set( Array1DReadView< Vector2f > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -170,7 +170,7 @@ bool GLTexture1D::set( Array1DView< const Vector2f > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const Vector3f > srcData,
bool GLTexture1D::set( Array1DReadView< Vector3f > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand All @@ -187,7 +187,7 @@ bool GLTexture1D::set( Array1DView< const Vector3f > srcData,
dstOffset );
}

bool GLTexture1D::set( Array1DView< const Vector4f > srcData,
bool GLTexture1D::set( Array1DReadView< Vector4f > srcData,
GLImageFormat srcFormat,
int dstOffset )
{
Expand Down
18 changes: 9 additions & 9 deletions GL/src/GL_45/GLTexture1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <GL/glew.h>

#include <common/Array1DView.h>
#include <common/ArrayView.h>
#include <common/BasicTypes.h>
#include <vecmath/Vector2f.h>
#include <vecmath/Vector3f.h>
Expand Down Expand Up @@ -45,28 +45,28 @@ class GLTexture1D : public GLTexture

// srcFormat must be compatible with the texture's internal format.
// srcData must be packed().
bool set( Array1DView< const uint8_t > srcData,
bool set( Array1DReadView< uint8_t > srcData,
GLImageFormat srcFormat = GLImageFormat::RED,
int dstOffset = 0 );
bool set( Array1DView< const uint8x2 > srcData,
bool set( Array1DReadView< uint8x2 > srcData,
GLImageFormat srcFormat = GLImageFormat::RG,
int dstOffset = 0 );
bool set( Array1DView< const uint8x3 > srcData,
bool set( Array1DReadView< uint8x3 > srcData,
GLImageFormat srcFormat = GLImageFormat::RGB,
int dstOffset = 0 );
bool set( Array1DView< const uint8x4 > srcData,
bool set( Array1DReadView< uint8x4 > srcData,
GLImageFormat srcFormat = GLImageFormat::RGBA,
int dstOffset = 0 );
bool set( Array1DView< const float > srcData,
bool set( Array1DReadView< float > srcData,
GLImageFormat srcFormat = GLImageFormat::RED,
int dstOffset = 0 );
bool set( Array1DView< const Vector2f > srcData,
bool set( Array1DReadView< Vector2f > srcData,
GLImageFormat srcFormat = GLImageFormat::RG,
int dstOffset = 0 );
bool set( Array1DView< const Vector3f > srcData,
bool set( Array1DReadView< Vector3f > srcData,
GLImageFormat srcFormat = GLImageFormat::RGB,
int dstOffset = 0 );
bool set( Array1DView< const Vector4f > srcData,
bool set( Array1DReadView< Vector4f > srcData,
GLImageFormat srcFormat = GLImageFormat::RGBA,
int dstOffset = 0 );

Expand Down
Loading

0 comments on commit 8c5721e

Please sign in to comment.