Commit 64a55ab3 authored by Frédéric Larue's avatar Frédéric Larue

Texture2DArray added to the GPU module.

parent 5b73c5ac
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#include "GPUdefs.h"
#include "Texture2DArray.h"
#include "FrameBuffer.h"
#include <iostream>
bool GPU::Texture2DArray::Allocate()
{
glGenTextures( 1, &m_Id );
return m_Id != 0;
}
bool GPU::Texture2DArray::Unallocate()
{
glDeleteTextures( 1, &m_Id );
m_Id = 0;
return true;
}
bool GPU::Texture2DArray::Create()
{
if( Instantiate() )
{
glBindTexture( m_Target, m_Id );
m_Width = m_Height = m_Depth = 0;
return true;
}
else
return false;
}
bool GPU::Texture2DArray::Create( GLenum internalFormats[],
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLenum format,
GLenum type,
const GLvoid* data,
GLsizei nMipMaps )
{
if( !Instantiate() )
return false;
glBindTexture( m_Target, m_Id );
int currentFormatId = -1;
GLint isSupported;
do
{
if( internalFormats[++currentFormatId] == GL_NONE )
{
m_Width = m_Height = m_Depth = 0;
std::cout << "Texture3D error - specified internal format(s) not supported." << std::endl;
for( int i=0; i<currentFormatId; ++i )
std::cout << internalFormats[i] << " ";
std::cout << std::endl;
Release();
return false;
}
if( glGetInternalformativ )
glGetInternalformativ( m_Target, internalFormats[currentFormatId], GL_INTERNALFORMAT_SUPPORTED, 1, &isSupported );
else
switch( internalFormats[currentFormatId] )
{
case GL_DEPTH_COMPONENT :
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT24:
case GL_DEPTH_COMPONENT32: isSupported = GL_TRUE; break;
default:
{
glGetError();
glTexStorage3D(
m_Target,
nMipMaps,
internalFormats[currentFormatId],
width,
height,
depth
);
isSupported = glGetError() == GL_NO_ERROR;
}
}
} while( !isSupported );
GLint validatedFormat;
GLint validatedType;
if( format == GL_NONE )
glGetInternalformativ( m_Target, internalFormats[currentFormatId], GL_TEXTURE_IMAGE_FORMAT, 1, &validatedFormat );
else
validatedFormat = (GLint) format;
if( type == GL_NONE )
glGetInternalformativ( m_Target, internalFormats[currentFormatId], GL_TEXTURE_IMAGE_TYPE , 1, &validatedType );
else
validatedType = (GLint) type;
glTexStorage3D(
m_Target,
nMipMaps,
internalFormats[currentFormatId],
width,
height,
depth
);
m_Width = width;
m_Height = height;
m_Depth = depth;
return true;
}
bool GPU::Texture2DArray::LoadSlice( GLsizei sliceDepth,
GLenum format,
GLenum type,
const GLvoid* data,
GLint level )
{
if( m_Id )
{
glBindTexture( m_Target, m_Id );
glTexSubImage3D(
m_Target,
level,
0,
0,
sliceDepth,
m_Width,
m_Height,
1,
format,
type,
data
);
return true;
}
return false;
}
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#ifndef __GPU__TEXTURE2DARRAY_H__
#define __GPU__TEXTURE2DARRAY_H__
#include "GPUdefs.h"
#include "InstantiatedObject.h"
#include <map>
#include <vector>
#include "Texture2D.h"
/*
*
* CLASS DECLARATION.
*
*/
namespace GPU
{
class Texture2DArray : public InstantiatedObject, public Texture
{
/********************\
| Member variable(s) |
\********************/
private:
unsigned int m_Width;
unsigned int m_Height;
unsigned int m_Depth;
/*****************************\
| Constructor(s) / destructor |
\*****************************/
public:
inline Texture2DArray() : InstantiatedObject(), Texture(GL_TEXTURE_2D_ARRAY), m_Width(0), m_Height(0), m_Depth(0) {}
inline ~Texture2DArray() { Release(); }
/********************\
| Member function(s) |
\********************/
protected:
bool Allocate();
bool Unallocate();
public:
bool Create();
inline bool Create( GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLenum format,
GLenum type,
const GLvoid* data,
GLsizei nMipMaps = 1 ) { GLenum f[] = {internalFormat,GL_NONE}; return Create(f,width,height,depth,border,format,type,data,nMipMaps); }
bool Create( GLenum internalFormats[],
GLsizei width,
GLsizei height,
GLsizei depth,
GLint border,
GLenum format,
GLenum type,
const GLvoid* data,
GLsizei nMipMaps = 1 );
inline bool Create( GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum format,
GLenum type,
const GLvoid* data,
GLsizei nMipMaps = 1 ) { return Create(internalFormat,width,height,depth,0,format,type,data,nMipMaps); }
inline bool Create( GLenum internalFormats[],
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum format,
GLenum type,
const GLvoid* data,
GLsizei nMipMaps = 1 ) { return Create(internalFormats,width,height,depth,0,format,type,data,nMipMaps); }
inline bool Create( GLenum internalFormat,
GLsizei width,
GLsizei height,
GLsizei depth,
GLsizei nMipMaps = 1 ) { return Create(internalFormat,width,height,depth,0,GL_RGB,GL_INT,NULL,nMipMaps); }
inline bool Create( GLenum internalFormats[],
GLsizei width,
GLsizei height,
GLsizei depth,
GLsizei nMipMaps = 1 ) { return Create(internalFormats,width,height,depth,0,GL_RGB,GL_INT,NULL,nMipMaps); };
bool LoadSlice( GLsizei sliceDepth,
GLenum format,
GLenum type,
const GLvoid* data,
GLint level = 0 );
inline unsigned int Width() const { return m_Width; }
inline unsigned int Height() const { return m_Height; }
inline unsigned int Depth() const { return m_Depth; }
};
};
#endif //__GPU__TEXTURE2DARRAY_H__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment