[DEV] Add capability to use FBO (Frame Buffer Object)
This commit is contained in:
parent
bd0c899654
commit
9f4250cbdc
@ -38,6 +38,9 @@ void ewol::resource::Texture::init() {
|
|||||||
|
|
||||||
ewol::resource::Texture::Texture() :
|
ewol::resource::Texture::Texture() :
|
||||||
m_texId(0),
|
m_texId(0),
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
m_texPboId(0),
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
m_data(ivec2(32,32),egami::colorType::RGBA8),
|
m_data(ivec2(32,32),egami::colorType::RGBA8),
|
||||||
m_lastSize(1,1),
|
m_lastSize(1,1),
|
||||||
m_loaded(false),
|
m_loaded(false),
|
||||||
@ -68,22 +71,37 @@ bool ewol::resource::Texture::updateContext() {
|
|||||||
}
|
}
|
||||||
int32_t typeObject = GL_RGBA;
|
int32_t typeObject = GL_RGBA;
|
||||||
int32_t sizeObject = GL_UNSIGNED_BYTE;
|
int32_t sizeObject = GL_UNSIGNED_BYTE;
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
int32_t sizeByte = 1;
|
||||||
|
#endif
|
||||||
switch (m_data.getType()) {
|
switch (m_data.getType()) {
|
||||||
case egami::colorType::RGBA8:
|
case egami::colorType::RGBA8:
|
||||||
typeObject = GL_RGBA;
|
typeObject = GL_RGBA;
|
||||||
sizeObject = GL_UNSIGNED_BYTE;
|
sizeObject = GL_UNSIGNED_BYTE;
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
sizeByte = 4;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case egami::colorType::RGB8:
|
case egami::colorType::RGB8:
|
||||||
typeObject = GL_RGB;
|
typeObject = GL_RGB;
|
||||||
sizeObject = GL_UNSIGNED_BYTE;
|
sizeObject = GL_UNSIGNED_BYTE;
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
sizeByte = 3;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case egami::colorType::RGBAf:
|
case egami::colorType::RGBAf:
|
||||||
typeObject = GL_RGBA;
|
typeObject = GL_RGBA;
|
||||||
sizeObject = GL_FLOAT;
|
sizeObject = GL_FLOAT;
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
sizeByte = 16;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case egami::colorType::RGBf:
|
case egami::colorType::RGBf:
|
||||||
typeObject = GL_RGBA;
|
typeObject = GL_RGBA;
|
||||||
sizeObject = GL_FLOAT;
|
sizeObject = GL_FLOAT;
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
sizeByte = 12;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case egami::colorType::unsignedInt16:
|
case egami::colorType::unsignedInt16:
|
||||||
case egami::colorType::unsignedInt32:
|
case egami::colorType::unsignedInt32:
|
||||||
@ -104,6 +122,18 @@ bool ewol::resource::Texture::updateContext() {
|
|||||||
if (m_loaded == false) {
|
if (m_loaded == false) {
|
||||||
// Request a new texture at openGl :
|
// Request a new texture at openGl :
|
||||||
glGenTextures(1, &m_texId);
|
glGenTextures(1, &m_texId);
|
||||||
|
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
EWOL_ERROR("CREATE PBO");
|
||||||
|
glGenBuffers(1, &m_texPboId);
|
||||||
|
EWOL_ERROR("CREATE PBO 1");
|
||||||
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_texPboId);
|
||||||
|
EWOL_ERROR("CREATE PBO 2");
|
||||||
|
glBufferData(GL_PIXEL_UNPACK_BUFFER, m_data.getGPUSize().x()*m_data.getGPUSize().y()*sizeByte, 0, GL_STREAM_DRAW);
|
||||||
|
EWOL_ERROR("CREATE PBO 3");
|
||||||
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
|
EWOL_ERROR("CREATE PBO 4 (done)");
|
||||||
|
#endif
|
||||||
m_lastSize = m_data.getSize();
|
m_lastSize = m_data.getSize();
|
||||||
m_lastTypeObject = typeObject;
|
m_lastTypeObject = typeObject;
|
||||||
m_lastSizeObject = sizeObject;
|
m_lastSizeObject = sizeObject;
|
||||||
@ -142,28 +172,61 @@ bool ewol::resource::Texture::updateContext() {
|
|||||||
tmpData.resize(bufferSize, 0.0f);
|
tmpData.resize(bufferSize, 0.0f);
|
||||||
}
|
}
|
||||||
EWOL_DEBUG(" CREATE texture ==> " << m_data.getGPUSize());
|
EWOL_DEBUG(" CREATE texture ==> " << m_data.getGPUSize());
|
||||||
// 2 create a new emprty texture:
|
// 2 create a new empty texture:
|
||||||
glTexImage2D(GL_TEXTURE_2D, // Target
|
#ifdef EWOL_USE_FBO
|
||||||
0, // Level
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_texPboId);
|
||||||
typeObject, // Format internal
|
void* pBuff = ::glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, m_data.getGPUSize().x() * m_data.getGPUSize().y() * sizeByte, GL_MAP_WRITE_BIT);
|
||||||
m_data.getGPUSize().x(),
|
memcpy(pBuff, &tmpData[0], m_data.getGPUSize().x()*m_data.getGPUSize().y()*sizeByte);
|
||||||
m_data.getGPUSize().y(),
|
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||||
0, // Border
|
glTexImage2D(GL_TEXTURE_2D, // Target
|
||||||
typeObject, // format
|
0, // Level
|
||||||
sizeObject, // type
|
typeObject, // Format internal
|
||||||
&tmpData[0] );
|
m_data.getGPUSize().x(),
|
||||||
gale::openGL::flush();
|
m_data.getGPUSize().y(),
|
||||||
|
0, // Border
|
||||||
|
typeObject, // format
|
||||||
|
sizeObject, // type
|
||||||
|
(void*)0 );
|
||||||
|
#else
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, // Target
|
||||||
|
0, // Level
|
||||||
|
typeObject, // Format internal
|
||||||
|
m_data.getGPUSize().x(),
|
||||||
|
m_data.getGPUSize().y(),
|
||||||
|
0, // Border
|
||||||
|
typeObject, // format
|
||||||
|
sizeObject, // type
|
||||||
|
&tmpData[0] );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
//3 Flush all time the data:
|
#ifdef EWOL_USE_FBO
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, // Target
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_texPboId);
|
||||||
0, // Level
|
void* pBuff = ::glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, m_data.getGPUSize().x() * m_data.getGPUSize().y() * sizeByte, GL_MAP_WRITE_BIT);
|
||||||
0, // x offset
|
memcpy(pBuff, m_data.getTextureDataPointer(), m_data.getWidth()*m_data.getHeight()*sizeByte);
|
||||||
0, // y offset
|
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
|
||||||
m_data.getWidth(),
|
//3 Flush all time the data:
|
||||||
m_data.getHeight(),
|
glTexSubImage2D(GL_TEXTURE_2D, // Target
|
||||||
typeObject, // format
|
0, // Level
|
||||||
sizeObject, // type
|
0, // x offset
|
||||||
m_data.getTextureDataPointer() );
|
0, // y offset
|
||||||
|
m_data.getWidth(),
|
||||||
|
m_data.getHeight(),
|
||||||
|
typeObject, // format
|
||||||
|
sizeObject, // type
|
||||||
|
(void *)0 );
|
||||||
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
|
#else
|
||||||
|
//3 Flush all time the data:
|
||||||
|
glTexSubImage2D(GL_TEXTURE_2D, // Target
|
||||||
|
0, // Level
|
||||||
|
0, // x offset
|
||||||
|
0, // y offset
|
||||||
|
m_data.getWidth(),
|
||||||
|
m_data.getHeight(),
|
||||||
|
typeObject, // format
|
||||||
|
sizeObject, // type
|
||||||
|
m_data.getTextureDataPointer() );
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
// This is the normal case ==> set the image and after set just the update of the data
|
// This is the normal case ==> set the image and after set just the update of the data
|
||||||
if (m_loaded == false) {
|
if (m_loaded == false) {
|
||||||
|
@ -10,11 +10,16 @@
|
|||||||
#include <egami/Image.hpp>
|
#include <egami/Image.hpp>
|
||||||
#include <gale/resource/Texture.hpp>
|
#include <gale/resource/Texture.hpp>
|
||||||
|
|
||||||
|
//#define EWOL_USE_FBO 1
|
||||||
|
|
||||||
namespace ewol {
|
namespace ewol {
|
||||||
namespace resource {
|
namespace resource {
|
||||||
class Texture : public gale::Resource {
|
class Texture : public gale::Resource {
|
||||||
protected:
|
protected:
|
||||||
uint32_t m_texId; //!< openGl textureID.
|
uint32_t m_texId; //!< openGl textureID.
|
||||||
|
#ifdef EWOL_USE_FBO
|
||||||
|
uint32_t m_texPboId; //!< openGl textureID.
|
||||||
|
#endif
|
||||||
// openGl Context propoerties :
|
// openGl Context propoerties :
|
||||||
egami::Image m_data;
|
egami::Image m_data;
|
||||||
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 -> 1.0
|
// some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 -> 1.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user