[DEV] continue integration

This commit is contained in:
Edouard DUPIN 2015-07-20 21:07:02 +02:00
parent b7286bda51
commit 79af104cfc
12 changed files with 321 additions and 187 deletions

View File

@ -0,0 +1,46 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __OPEN_GL_INCLUDE_H__
#define __OPEN_GL_INCLUDE_H__
extern "C" {
#if defined(__TARGET_OS__Linux)
// TO ENABLE THE SHADER api ...
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
// TODO : Check it it work
// This is to prevent the use of these element that is not allowed in the openGL ES
#undef glVertexPointer
#undef glTexCoordPointer
#undef glColorPointer
#undef glPopMatrix
#undef glPushMatrix
#undef glMatrixMode
#undef glLoadIdentity
#undef glTranslatef
#elif defined(__TARGET_OS__Android)
// Include openGL ES 2
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#elif defined(__TARGET_OS__Windows)
// TO ENABLE THE SHADER api ...
//#define GL_GLEXT_PROTOTYPES
#define GLEW_STATIC
#include <GL/glew.h>
#elif defined(__TARGET_OS__MacOs)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#elif defined(__TARGET_OS__IOs)
#include <OpenGLES/ES2/gl.h>
#else
#error you need to specify a __TAGET_OS__ ...
#endif
}
#endif

View File

@ -12,42 +12,7 @@
#include <etk/stdTools.h> #include <etk/stdTools.h>
#include <mutex> #include <mutex>
//#define DIRECT_MODE //#define DIRECT_MODE
#include <gale/renderer/openGL/openGL-include.h>
extern "C" {
#if defined(__TARGET_OS__Linux)
// TO ENABLE THE SHADER api ...
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
// TODO : Check it it work
// This is to prevent the use of these element that is not allowed in the openGL ES
#undef glVertexPointer
#undef glTexCoordPointer
#undef glColorPointer
#undef glPopMatrix
#undef glPushMatrix
#undef glMatrixMode
#undef glLoadIdentity
#undef glTranslatef
#elif defined(__TARGET_OS__Android)
// Include openGL ES 2
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#elif defined(__TARGET_OS__Windows)
// TO ENABLE THE SHADER api ...
//#define GL_GLEXT_PROTOTYPES
#define GLEW_STATIC
#include <GL/glew.h>
#elif defined(__TARGET_OS__MacOs)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#elif defined(__TARGET_OS__IOs)
#include <OpenGLES/ES2/gl.h>
#else
#error you need to specify a __TAGET_OS__ ...
#endif
}
#define CHECK_ERROR_OPENGL #define CHECK_ERROR_OPENGL
@ -182,18 +147,24 @@ void gale::openGL::swap() {
} }
void gale::openGL::setViewPort(const ivec2& _start, const ivec2& _stop) {
glViewport(_start.x(), _start.y(), _stop.x(), _stop.y());
}
void gale::openGL::setViewPort(const vec2& _start, const vec2& _stop) {
glViewport(_start.x(), _start.y(), _stop.x(), _stop.y());
}
struct correspondenceTableClear { struct correspondenceTableClear {
enum gale::openGL::clearFlag curentFlag; enum gale::openGL::clearFlag curentFlag;
GLbitfield OGlFlag; GLbitfield OGlFlag;
}; };
static struct correspondenceTableClear basicFlagClear[] = { static struct correspondenceTableClear basicFlagClear[] = {
{gale::openGL::clearFlag_colorBuffer, GL_COLOR_BUFFER_BIT}, {gale::openGL::clearFlag_colorBuffer, GL_COLOR_BUFFER_BIT},
{gale::openGL::clearFlag_depthBuffer, GL_DEPTH_BUFFER_BIT}, {gale::openGL::clearFlag_depthBuffer, GL_DEPTH_BUFFER_BIT},
{gale::openGL::clearFlag_stencilBuffer, GL_STENCIL_BUFFER_BIT} {gale::openGL::clearFlag_stencilBuffer, GL_STENCIL_BUFFER_BIT}
}; };
static int32_t basicFlagClearCount = sizeof(basicFlagClear) / sizeof(struct correspondenceTableClear); static int32_t basicFlagClearCount = sizeof(basicFlagClear) / sizeof(struct correspondenceTableClear);
@ -211,7 +182,7 @@ void gale::openGL::clearStencil(int32_t _value) {
void gale::openGL::clear(uint32_t _flags) { void gale::openGL::clear(uint32_t _flags) {
GLbitfield field = 0; GLbitfield field = 0;
for (int32_t iii=0; iii<basicFlagClearCount ; iii++) { for (int32_t iii=0; iii<basicFlagClearCount ; iii++) {
if ( (basicFlagClear[iii].curentFlag & _flagID) != 0) { if ( (basicFlagClear[iii].curentFlag & _flags) != 0) {
field |= basicFlagClear[iii].OGlFlag; field |= basicFlagClear[iii].OGlFlag;
} }
} }
@ -323,14 +294,14 @@ struct correspondenceTable {
GLenum OGlFlag; GLenum OGlFlag;
}; };
static correspondenceTable_ts basicFlag[] = { static struct correspondenceTable basicFlag[] = {
{gale::openGL::flag_blend, GL_BLEND}, {gale::openGL::flag_blend, GL_BLEND},
#if 0 #if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs)) !(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{gale::openGL::flag_clipDistanceI, GL_CLIP_DISTANCE0}, {gale::openGL::flag_clipDistanceI, GL_CLIP_DISTANCE0},
{gale::openGL::flag_colorLogigOP, GL_COLOR_LOGIC_OP}, {gale::openGL::flag_colorLogigOP, GL_COLOR_LOGIC_OP},
#endif #endif
{(uint32_t)gale::openGL::flag_cullFace, GL_CULL_FACE}, {gale::openGL::flag_cullFace, GL_CULL_FACE},
#if 0 #if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs)) !(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{gale::openGL::flag_debugOutput, GL_DEBUG_OUTPUT}, {gale::openGL::flag_debugOutput, GL_DEBUG_OUTPUT},
@ -479,7 +450,7 @@ const uint32_t convertRenderMode[] = {
#endif #endif
}; };
void gale::openGL::drawArrays(enum renderMode _mode, int32_t _first, int32_t _count) { void gale::openGL::drawArrays(enum gale::openGL::renderMode _mode, int32_t _first, int32_t _count) {
if (l_programId >= 0) { if (l_programId >= 0) {
updateAllFlags(); updateAllFlags();
glDrawArrays(convertRenderMode[_mode], _first, _count); glDrawArrays(convertRenderMode[_mode], _first, _count);
@ -572,10 +543,14 @@ bool gale::openGL::bindBuffer(uint32_t _bufferId) {
return true; return true;
} }
GL_STREAM_DRAW, GL_STATIC_DRAW, or GL_DYNAMIC_DRAW static GLenum convertUsage[] = {
GL_STREAM_DRAW,
bool gale::openGL::bufferData(size_t _size, const void* _data, GLenum _usage) { GL_STATIC_DRAW,
glBufferData(GL_ARRAY_BUFFER, _size, _data, _usage); GL_DYNAMIC_DRAW
};
bool gale::openGL::bufferData(size_t _size, const void* _data, enum gale::openGL::usage _usage) {
glBufferData(GL_ARRAY_BUFFER, _size, _data, convertUsage[_usage]);
checkGlError("glBufferData", __LINE__); checkGlError("glBufferData", __LINE__);
return true; return true;
} }
@ -586,3 +561,166 @@ bool gale::openGL::unbindBuffer() {
return true; return true;
} }
static void checkGlError(const char* _op) {
for (GLint error = glGetError(); error; error = glGetError()) {
GALE_ERROR("after " << _op << "() glError (" << error << ")");
}
}
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
int64_t gale::openGL::shader::create(enum gale::openGL::shader::type _type) {
GLuint shader = 0;
if (_type == gale::openGL::shader::type_vertex) {
shader = glCreateShader(GL_VERTEX_SHADER);
} else if (_type == gale::openGL::shader::type_fragment) {
shader = glCreateShader(GL_FRAGMENT_SHADER);
} else {
GALE_ERROR("create shader with wrong type ...");
return -1;
}
if (shader == 0) {
GALE_ERROR("glCreateShader return error ...");
checkGlError("glCreateShader");
return -1;
}
return int64_t(shader);
}
void gale::openGL::shader::remove(int64_t& _shader) {
if (_shader < 0) {
return;
}
glDeleteShader(GLuint(_shader));
_shader = -1;
}
bool gale::openGL::shader::compile(int64_t _shader, const std::string& _data) {
const char* data = &_data[0];
glShaderSource(GLuint(_shader), 1, (const char**)&data, nullptr);
glCompileShader(GLuint(_shader));
GLint compiled = 0;
glGetShaderiv(GLuint(_shader), GL_COMPILE_STATUS, &compiled);
if (!compiled) {
GLint infoLen = 0;
l_bufferDisplayError[0] = '\0';
glGetShaderInfoLog(GLuint(_shader), LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
GALE_ERROR("Error " << l_bufferDisplayError);
std::vector<std::string> lines = etk::split(_data, '\n');
for (size_t iii=0; iii<lines.size(); iii++) {
GALE_ERROR("file " << (iii+1) << "|" << lines[iii]);
}
return false;
}
return true;
}
int64_t gale::openGL::program::create() {
GLuint program = glCreateProgram();
if (program == 0) {
GALE_ERROR("program creation return error ...");
checkGlError("glCreateProgram", __LINE__);
return -1;
}
GALE_DEBUG("Create program with oglID=" << program);
return int64_t(program);
}
void gale::openGL::program::remove(int64_t& _prog) {
if (_prog < 0) {
return;
}
glDeleteProgram(GLuint(_prog));
checkGlError("glDeleteProgram", __LINE__);
_prog = -1;
}
bool gale::openGL::program::attach(int64_t _prog, int64_t _shader) {
if (_prog < 0) {
GALE_ERROR("wrong program ID");
return false;
}
if (_shader < 0) {
GALE_ERROR("wrong shader ID");
return false;
}
glAttachShader(GLuint(_prog), GLuint(_shader));
checkGlError("glAttachShader", __LINE__);
return true;
}
bool gale::openGL::program::compile(int64_t _prog) {
if (_prog < 0) {
GALE_ERROR("wrong program ID");
return false;
}
glLinkProgram(GLuint(_prog));
checkGlError("glLinkProgram", __LINE__);
GLint linkStatus = GL_FALSE;
glGetProgramiv(GLuint(_prog), GL_LINK_STATUS, &linkStatus);
checkGlError("glGetProgramiv", __LINE__);
if (linkStatus != GL_TRUE) {
GLint bufLength = 0;
l_bufferDisplayError[0] = '\0';
glGetProgramInfoLog(GLuint(_prog), LOG_OGL_INTERNAL_BUFFER_LEN, &bufLength, l_bufferDisplayError);
char tmpLog[256];
int32_t idOut=0;
GALE_ERROR("Could not compile \"PROGRAM\":");
for (size_t iii=0; iii<LOG_OGL_INTERNAL_BUFFER_LEN ; iii++) {
tmpLog[idOut] = l_bufferDisplayError[iii];
if ( tmpLog[idOut] == '\n'
|| tmpLog[idOut] == '\0'
|| idOut >= 256) {
tmpLog[idOut] = '\0';
GALE_ERROR(" == > " << tmpLog);
idOut=0;
} else {
idOut++;
}
if (l_bufferDisplayError[iii] == '\0') {
break;
}
}
if (idOut != 0) {
tmpLog[idOut] = '\0';
GALE_ERROR(" == > " << tmpLog);
}
return false;
}
return true;
}
int32_t gale::openGL::program::getAttributeLocation(int64_t _prog, const std::string& _name) {
if (_prog < 0) {
GALE_ERROR("wrong program ID");
return -1;
}
if (_name.size() == 0) {
GALE_ERROR("wrong name of attribure");
return -1;
}
GLint val = glGetAttribLocation(GLuint(_prog), _name.c_str());
if (val < 0) {
checkGlError("glGetAttribLocation", __LINE__);
GALE_WARNING("glGetAttribLocation(\"" << _name << "\") = " << val);
}
return val;
}
int32_t gale::openGL::program::getUniformLocation(int64_t _prog, const std::string& _name) {
if (_prog < 0) {
GALE_ERROR("wrong program ID");
return -1;
}
if (_name.size() == 0) {
GALE_ERROR("wrong name of uniform");
return -1;
}
GLint val = glGetUniformLocation(GLuint(_prog), _name.c_str());
if (val < 0) {
checkGlError("glGetUniformLocation", __LINE__);
GALE_WARNING("glGetUniformLocation(\"" << _name << "\") = " << val);
}
return val;
}

View File

@ -12,6 +12,7 @@
#include <etk/types.h> #include <etk/types.h>
#include <vector> #include <vector>
#include <etk/math/Matrix4.h> #include <etk/math/Matrix4.h>
#include <etk/math/Vector2D.h>
#include <etk/Color.h> #include <etk/Color.h>
namespace gale { namespace gale {
@ -70,6 +71,8 @@ namespace gale {
* @brief * @brief
*/ */
void swap(); void swap();
void setViewPort(const ivec2& _start, const ivec2& _stop);
void setViewPort(const vec2& _start, const vec2& _stop);
/** /**
* @brief Specifies the clear color value When clear is requested * @brief Specifies the clear color value When clear is requested
@ -138,9 +141,9 @@ namespace gale {
render_triangle, render_triangle,
render_triangleStrip, //!< Not supported in GALE (TODO : Later) render_triangleStrip, //!< Not supported in GALE (TODO : Later)
render_triangleFan, //!< Not supported in GALE (TODO : Later) render_triangleFan, //!< Not supported in GALE (TODO : Later)
renderQuad, //!< Not supported in OpenGL-ES2 render_quad, //!< Not supported in OpenGL-ES2
renderQuadStrip, //!< Not supported in OpenGL-ES2 render_quadStrip, //!< Not supported in OpenGL-ES2
renderPolygon //!< Not supported in OpenGL-ES2 render_polygon //!< Not supported in OpenGL-ES2
}; };
/** /**
@ -186,8 +189,31 @@ namespace gale {
bool genBuffers(std::vector<uint32_t>& _buffers); bool genBuffers(std::vector<uint32_t>& _buffers);
bool deleteBuffers(std::vector<uint32_t>& _buffers); bool deleteBuffers(std::vector<uint32_t>& _buffers);
bool bindBuffer(uint32_t _bufferId); bool bindBuffer(uint32_t _bufferId);
bool bufferData(size_t _size, const void* _data, GLenum _usage); enum usage {
usage_streamDraw,
usage_staticDraw,
usage_dynamicDraw
};
bool bufferData(size_t _size, const void* _data, enum gale::openGL::usage _usage);
bool unbindBuffer(); bool unbindBuffer();
/* Shader wrapping : */
namespace shader {
enum type {
type_vertex,
type_fragment
};
int64_t create(enum gale::openGL::shader::type _type);
void remove(int64_t& _shader);
bool compile(int64_t _shader, const std::string& _data);
};
namespace program {
int64_t create();
void remove(int64_t& _prog);
bool attach(int64_t _prog, int64_t _shader);
bool compile(int64_t _prog);
int32_t getAttributeLocation(int64_t _prog, const std::string& _name);
int32_t getUniformLocation(int64_t _prog, const std::string& _name);
};
}; };
std::ostream& operator <<(std::ostream& _os, const enum openGL::flag& _obj); std::ostream& operator <<(std::ostream& _os, const enum openGL::flag& _obj);
std::ostream& operator <<(std::ostream& _os, const enum openGL::renderMode& _obj); std::ostream& operator <<(std::ostream& _os, const enum openGL::renderMode& _obj);

View File

@ -12,6 +12,7 @@
#include <gale/resource/Manager.h> #include <gale/resource/Manager.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
#include <gale/gale.h> #include <gale/gale.h>
#include <gale/renderer/openGL/openGL-include.h>
//#define LOCAL_DEBUG GALE_VERBOSE //#define LOCAL_DEBUG GALE_VERBOSE
#define LOCAL_DEBUG GALE_DEBUG #define LOCAL_DEBUG GALE_DEBUG
@ -153,6 +154,7 @@ void gale::resource::Program::checkGlError(const char* _op, int32_t _localLine,
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192) #define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = ""; static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
bool gale::resource::Program::checkIdValidity(int32_t _idElem) { bool gale::resource::Program::checkIdValidity(int32_t _idElem) {
if ( _idElem < 0 if ( _idElem < 0
|| (size_t)_idElem > m_elementList.size()) { || (size_t)_idElem > m_elementList.size()) {
@ -171,12 +173,11 @@ int32_t gale::resource::Program::getAttribute(std::string _elementName) {
progAttributeElement tmp; progAttributeElement tmp;
tmp.m_name = _elementName; tmp.m_name = _elementName;
tmp.m_isAttribute = true; tmp.m_isAttribute = true;
tmp.m_elementId = glGetAttribLocation(m_program, tmp.m_name.c_str()); tmp.m_elementId = gale::openGL::program::getAttributeLocation(m_program, tmp.m_name);
tmp.m_isLinked = true; tmp.m_isLinked = true;
if (tmp.m_elementId<0) { if (tmp.m_elementId<0) {
GALE_WARNING(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); GALE_WARNING(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
tmp.m_isLinked = false; tmp.m_isLinked = false;
checkGlError("glGetAttribLocation", __LINE__, tmp.m_elementId);
} else { } else {
GALE_INFO(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); GALE_INFO(" [" << m_elementList.size() << "] glGetAttribLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
} }
@ -194,12 +195,11 @@ int32_t gale::resource::Program::getUniform(std::string _elementName) {
progAttributeElement tmp; progAttributeElement tmp;
tmp.m_name = _elementName; tmp.m_name = _elementName;
tmp.m_isAttribute = false; tmp.m_isAttribute = false;
tmp.m_elementId = glGetUniformLocation(m_program, tmp.m_name.c_str()); tmp.m_elementId = gale::openGL::program::getUniformLocation(m_program, tmp.m_name);
tmp.m_isLinked = true; tmp.m_isLinked = true;
if (tmp.m_elementId<0) { if (tmp.m_elementId<0) {
GALE_WARNING(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); GALE_WARNING(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
tmp.m_isLinked = false; tmp.m_isLinked = false;
checkGlError("glGetUniformLocation", __LINE__, tmp.m_elementId);
} else { } else {
GALE_INFO(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId); GALE_INFO(" [" << m_elementList.size() << "] glGetUniformLocation(\"" << tmp.m_name << "\") = " << tmp.m_elementId);
} }
@ -213,82 +213,44 @@ void gale::resource::Program::updateContext() {
} else { } else {
// create the Shader // create the Shader
GALE_INFO("Create the Program ... \"" << m_name << "\""); GALE_INFO("Create the Program ... \"" << m_name << "\"");
m_program = glCreateProgram(); m_program = gale::openGL::program::create();
if (0 == m_program) { if (m_program < 0) {
GALE_ERROR("program creation return error ...");
checkGlError("glCreateProgram", __LINE__);
return; return;
} }
GALE_DEBUG("Create program with oglID=" << m_program);
// first attach vertex shader, and after fragment shader // first attach vertex shader, and after fragment shader
for (size_t iii=0; iii<m_shaderList.size(); iii++) { for (size_t iii=0; iii<m_shaderList.size(); iii++) {
if (nullptr != m_shaderList[iii]) { if (nullptr != m_shaderList[iii]) {
if (m_shaderList[iii]->getShaderType() == GL_VERTEX_SHADER) { if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type_vertex) {
glAttachShader(m_program, m_shaderList[iii]->getGL_ID()); gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
checkGlError("glAttachShader", __LINE__);
} }
} }
} }
for (size_t iii=0; iii<m_shaderList.size(); iii++) { for (size_t iii=0; iii<m_shaderList.size(); iii++) {
if (nullptr != m_shaderList[iii]) { if (nullptr != m_shaderList[iii]) {
if (m_shaderList[iii]->getShaderType() == GL_FRAGMENT_SHADER) { if (m_shaderList[iii]->getShaderType() == gale::openGL::shader::type_fragment) {
glAttachShader(m_program, m_shaderList[iii]->getGL_ID()); gale::openGL::program::attach(m_program, m_shaderList[iii]->getGL_ID());
checkGlError("glAttachShader", __LINE__);
} }
} }
} }
glLinkProgram(m_program); if (gale::openGL::program::compile(m_program) == false) {
checkGlError("glLinkProgram", __LINE__);
GLint linkStatus = GL_FALSE;
glGetProgramiv(m_program, GL_LINK_STATUS, &linkStatus);
checkGlError("glGetProgramiv", __LINE__);
if (linkStatus != GL_TRUE) {
GLint bufLength = 0;
l_bufferDisplayError[0] = '\0';
glGetProgramInfoLog(m_program, LOG_OGL_INTERNAL_BUFFER_LEN, &bufLength, l_bufferDisplayError);
char tmpLog[256];
int32_t idOut=0;
GALE_ERROR("Could not compile \"PROGRAM\": \"" << m_name << "\""); GALE_ERROR("Could not compile \"PROGRAM\": \"" << m_name << "\"");
for (size_t iii=0; iii<LOG_OGL_INTERNAL_BUFFER_LEN ; iii++) { gale::openGL::program::remove(m_program);
tmpLog[idOut] = l_bufferDisplayError[iii];
if (tmpLog[idOut] == '\n' || tmpLog[idOut] == '\0' || idOut >= 256) {
tmpLog[idOut] = '\0';
GALE_ERROR(" == > " << tmpLog);
idOut=0;
} else {
idOut++;
}
if (l_bufferDisplayError[iii] == '\0') {
break;
}
}
if (idOut != 0) {
tmpLog[idOut] = '\0';
GALE_ERROR(" == > " << tmpLog);
}
glDeleteProgram(m_program);
checkGlError("glDeleteProgram", __LINE__);
m_program = 0;
return; return;
} }
m_exist = true; m_exist = true;
// now get the old attribute requested priviously ... // now get the old attribute requested priviously ...
for(size_t iii=0; iii<m_elementList.size(); iii++) { for(size_t iii=0; iii<m_elementList.size(); iii++) {
if (true == m_elementList[iii].m_isAttribute) { if (m_elementList[iii].m_isAttribute == true) {
m_elementList[iii].m_elementId = glGetAttribLocation(m_program, m_elementList[iii].m_name.c_str()); m_elementList[iii].m_elementId = gale::openGL::program::getAttributeLocation(m_program, m_elementList[iii].m_name);
m_elementList[iii].m_isLinked = true; m_elementList[iii].m_isLinked = true;
if (m_elementList[iii].m_elementId<0) { if (m_elementList[iii].m_elementId < 0) {
m_elementList[iii].m_isLinked = false; m_elementList[iii].m_isLinked = false;
checkGlError("glGetAttribLocation", __LINE__);
GALE_WARNING("glGetAttribLocation(\"" << m_elementList[iii].m_name << "\") = " << m_elementList[iii].m_elementId);
} }
} else { } else {
m_elementList[iii].m_elementId = glGetUniformLocation(m_program, m_elementList[iii].m_name.c_str()); m_elementList[iii].m_elementId = gale::openGL::program::getUniformLocation(m_program, m_elementList[iii].m_name);
m_elementList[iii].m_isLinked = true; m_elementList[iii].m_isLinked = true;
if (m_elementList[iii].m_elementId<0) { if (m_elementList[iii].m_elementId < 0) {
m_elementList[iii].m_isLinked = false; m_elementList[iii].m_isLinked = false;
checkGlError("glGetUniformLocation", __LINE__);
GALE_WARNING("glGetUniformLocation(\"" << m_elementList[iii].m_name << "\") = " << m_elementList[iii].m_elementId);
} }
} }
} }
@ -296,8 +258,8 @@ void gale::resource::Program::updateContext() {
} }
void gale::resource::Program::removeContext() { void gale::resource::Program::removeContext() {
if (true == m_exist) { if (m_exist == true) {
glDeleteProgram(m_program); gale::openGL::program::remove(m_program);
m_program = 0; m_program = 0;
m_exist = false; m_exist = false;
for(size_t iii=0; iii<m_elementList.size(); iii++) { for(size_t iii=0; iii<m_elementList.size(); iii++) {
@ -764,7 +726,7 @@ void gale::resource::Program::use() {
} }
void gale::resource::Program::setTexture0(int32_t _idElem, GLint _textureOpenGlID) { void gale::resource::Program::setTexture0(int32_t _idElem, int64_t _textureOpenGlID) {
if (0 == m_program) { if (0 == m_program) {
return; return;
} }
@ -789,7 +751,7 @@ void gale::resource::Program::setTexture0(int32_t _idElem, GLint _textureOpenGlI
m_hasTexture = true; m_hasTexture = true;
} }
void gale::resource::Program::setTexture1(int32_t _idElem, GLint _textureOpenGlID) { void gale::resource::Program::setTexture1(int32_t _idElem, int64_t _textureOpenGlID) {
if (0 == m_program) { if (0 == m_program) {
return; return;
} }

View File

@ -29,7 +29,7 @@ namespace gale {
class progAttributeElement { class progAttributeElement {
public : public :
std::string m_name; //!< Name of the element std::string m_name; //!< Name of the element
GLint m_elementId; //!< openGl Id if this element == > can not exist ==> @ref m_isLinked int32_t m_elementId; //!< openGl Id if this element == > can not exist ==> @ref m_isLinked
bool m_isAttribute; //!< true if it was an attribute element, otherwite it was an uniform bool m_isAttribute; //!< true if it was an attribute element, otherwite it was an uniform
bool m_isLinked; //!< if this element does not exist this is false bool m_isLinked; //!< if this element does not exist this is false
}; };
@ -53,7 +53,7 @@ namespace gale {
class Program : public gale::Resource { class Program : public gale::Resource {
private : private :
bool m_exist; //!< the file existed bool m_exist; //!< the file existed
GLuint m_program; //!< openGL id of the current program int64_t m_program; //!< openGL id of the current program
std::vector<std::shared_ptr<gale::resource::Shader>> m_shaderList; //!< List of all the shader loaded std::vector<std::shared_ptr<gale::resource::Shader>> m_shaderList; //!< List of all the shader loaded
std::vector<gale::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user std::vector<gale::resource::progAttributeElement> m_elementList; //!< List of all the attribute requested by the user
bool m_hasTexture; //!< A texture has been set to the current shader bool m_hasTexture; //!< A texture has been set to the current shader
@ -280,8 +280,8 @@ namespace gale {
* @param[in] _idElem Id of the uniform that might be sended. * @param[in] _idElem Id of the uniform that might be sended.
* @param[in] _textureOpenGlID Real openGL texture ID * @param[in] _textureOpenGlID Real openGL texture ID
*/ */
void setTexture0(int32_t _idElem, GLint _textureOpenGlID); void setTexture0(int32_t _idElem, int64_t _textureOpenGlID);
void setTexture1(int32_t _idElem, GLint _textureOpenGlID); void setTexture1(int32_t _idElem, int64_t _textureOpenGlID);
/** /**
* @brief Stop the processing of this program * @brief Stop the processing of this program
*/ */

View File

@ -12,15 +12,17 @@
#include <gale/resource/Shader.h> #include <gale/resource/Shader.h>
#include <gale/resource/Manager.h> #include <gale/resource/Manager.h>
#include <gale/renderer/openGL/openGL-include.h>
#undef __class__ #undef __class__
#define __class__ "resource::Shader" #define __class__ "resource::Shader"
gale::resource::Shader::Shader() : gale::resource::Shader::Shader() :
gale::Resource(), gale::Resource(),
m_exist(false), m_exist(false),
m_fileData(nullptr), m_fileData(""),
m_shader(0), m_shader(-1),
m_type(0) { m_type(gale::openGL::shader::type_vertex) {
addResourceType("gale::Shader"); addResourceType("gale::Shader");
m_resourceLevel = 0; m_resourceLevel = 0;
} }
@ -31,9 +33,9 @@ void gale::resource::Shader::init(const std::string& _filename) {
// load data from file "all the time ..." // load data from file "all the time ..."
if (etk::end_with(m_name, ".frag") == true) { if (etk::end_with(m_name, ".frag") == true) {
m_type = GL_FRAGMENT_SHADER; m_type = gale::openGL::shader::type_fragment;
} else if (etk::end_with(m_name, ".vert") == true) { } else if (etk::end_with(m_name, ".vert") == true) {
m_type = GL_VERTEX_SHADER; m_type = gale::openGL::shader::type_vertex;
} else { } else {
GALE_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\""); GALE_ERROR("File does not have extention \".vert\" for Vertex Shader or \".frag\" for Fragment Shader. but : \"" << m_name << "\"");
return; return;
@ -42,62 +44,34 @@ void gale::resource::Shader::init(const std::string& _filename) {
} }
gale::resource::Shader::~Shader() { gale::resource::Shader::~Shader() {
if (nullptr != m_fileData) { m_fileData.clear();
delete [] m_fileData; gale::openGL::shader::remove(m_shader);
m_fileData = nullptr;
}
if (0!=m_shader) {
glDeleteShader(m_shader);
m_shader = 0;
}
m_exist = false; m_exist = false;
} }
static void checkGlError(const char* _op) {
for (GLint error = glGetError(); error; error = glGetError()) {
GALE_ERROR("after " << _op << "() glError (" << error << ")");
}
}
#define LOG_OGL_INTERNAL_BUFFER_LEN (8192)
static char l_bufferDisplayError[LOG_OGL_INTERNAL_BUFFER_LEN] = "";
void gale::resource::Shader::updateContext() { void gale::resource::Shader::updateContext() {
if (true == m_exist) { if (m_exist == true) {
// Do nothing == > too dangerous ... // Do nothing == > too dangerous ...
} else { } else {
// create the Shader // create the Shader
if (nullptr == m_fileData) { if (m_fileData.size() == 0) {
m_shader = 0; m_shader = -1;
return; return;
} }
GALE_INFO("Create Shader : '" << m_name << "'"); GALE_INFO("Create Shader : '" << m_name << "'");
m_shader = glCreateShader(m_type); m_shader = gale::openGL::shader::create(m_type);
if (!m_shader) { if (m_shader < 0) {
GALE_ERROR("glCreateShader return error ...");
checkGlError("glCreateShader");
GALE_CRITICAL(" can not load shader"); GALE_CRITICAL(" can not load shader");
return; return;
} else { } else {
GALE_INFO("Compile shader with GLID=" << m_shader); GALE_INFO("Compile shader with GLID=" << m_shader);
glShaderSource(m_shader, 1, (const char**)&m_fileData, nullptr); bool ret = gale::openGL::shader::compile(m_shader, m_fileData);
glCompileShader(m_shader); if (ret == false) {
GLint compiled = 0; const char * tmpShaderType = "FRAGMENT SHADER";
glGetShaderiv(m_shader, GL_COMPILE_STATUS, &compiled); if (m_type == gale::openGL::shader::type_vertex){
if (!compiled) { tmpShaderType = "VERTEX SHADER";
GLint infoLen = 0;
l_bufferDisplayError[0] = '\0';
glGetShaderInfoLog(m_shader, LOG_OGL_INTERNAL_BUFFER_LEN, &infoLen, l_bufferDisplayError);
const char * tmpShaderType = "GL_FRAGMENT_SHADER";
if (m_type == GL_VERTEX_SHADER){
tmpShaderType = "GL_VERTEX_SHADER";
} }
GALE_ERROR("Could not compile \"" << tmpShaderType << "\" name='" << m_name << "'"); GALE_CRITICAL("Could not compile \"" << tmpShaderType << "\" name='" << m_name << "'");
GALE_ERROR("Error " << l_bufferDisplayError);
std::vector<std::string> lines = etk::split(m_fileData, '\n');
for (size_t iii=0 ; iii<lines.size() ; iii++) {
GALE_ERROR("file " << (iii+1) << "|" << lines[iii]);
}
GALE_CRITICAL(" can not load shader");
return; return;
} }
} }
@ -107,9 +81,8 @@ void gale::resource::Shader::updateContext() {
void gale::resource::Shader::removeContext() { void gale::resource::Shader::removeContext() {
if (true == m_exist) { if (true == m_exist) {
glDeleteShader(m_shader); gale::openGL::shader::remove(m_shader);
m_exist = false; m_exist = false;
m_shader = 0;
} }
} }
@ -134,20 +107,7 @@ void gale::resource::Shader::reload() {
GALE_CRITICAL("Can not open the file : " << file); GALE_CRITICAL("Can not open the file : " << file);
return; return;
} }
// remove previous data ... m_fileData = file.fileReadAllString();
if (nullptr != m_fileData) {
delete[] m_fileData;
m_fileData = 0;
}
// allocate data
m_fileData = new char[fileSize+5];
if (nullptr == m_fileData) {
GALE_CRITICAL("Error Memory allocation size=" << fileSize);
return;
}
memset(m_fileData, 0, (fileSize+5)*sizeof(char));
// load data from the file :
file.fileRead(m_fileData, 1, fileSize);
// close the file: // close the file:
file.fileClose(); file.fileClose();

View File

@ -22,9 +22,9 @@ namespace gale {
class Shader : public gale::Resource { class Shader : public gale::Resource {
private : private :
bool m_exist; //!< The shader file existed and has been loaded bool m_exist; //!< The shader file existed and has been loaded
char* m_fileData; //!< A copy of the data loaded from the file (usefull only when opengl context is removed) std::string m_fileData; //!< A copy of the data loaded from the file (usefull only when opengl context is removed)
GLuint m_shader; //!< opengl id of this element int64_t m_shader; //!< opengl id of this element
GLenum m_type; //!< Type of the current shader(vertex/fragment) gale::openGL::shader::type m_type; //!< Type of the current shader(vertex/fragment)
protected: protected:
/** /**
* @brief Contructor of an opengl Shader * @brief Contructor of an opengl Shader
@ -43,14 +43,14 @@ namespace gale {
* @brief get the opengl reference id of this shader. * @brief get the opengl reference id of this shader.
* @return The opengl id. * @return The opengl id.
*/ */
GLuint getGL_ID() { int64_t getGL_ID() {
return m_shader; return m_shader;
}; };
/** /**
* @brief get the opengl type of this shader. * @brief get the opengl type of this shader.
* @return The type of this loaded shader. * @return The type of this loaded shader.
*/ */
GLenum getShaderType() { gale::openGL::shader::type getShaderType() {
return m_type; return m_type;
}; };
/** /**

View File

@ -15,6 +15,7 @@
#undef __class__ #undef __class__
#define __class__ "resource::Texture" #define __class__ "resource::Texture"
/** /**
* @brief get the next power 2 if the input * @brief get the next power 2 if the input
* @param[in] value Value that we want the next power of 2 * @param[in] value Value that we want the next power of 2

View File

@ -28,7 +28,7 @@ namespace gale {
dataType_float, //!< Image data are stored on flaoting point value on 32 bit for each element dataType_float, //!< Image data are stored on flaoting point value on 32 bit for each element
}; };
protected: protected:
GLuint m_texId; //!< openGl textureID. uint32_t m_texId; //!< openGl textureID.
vec2 m_endPointSize; //!< 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. vec2 m_endPointSize; //!< 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.
bool m_loaded; //!< internal state of the openGl system. bool m_loaded; //!< internal state of the openGl system.
// Gale internal API: // Gale internal API:
@ -38,7 +38,7 @@ namespace gale {
void removeContextToLate(); void removeContextToLate();
// middleware interface: // middleware interface:
public: public:
GLuint getRendererId() const { uint32_t getRendererId() const {
return m_texId; return m_texId;
}; };
const vec2& getUsableSize() const { const vec2& getUsableSize() const {

View File

@ -10,6 +10,7 @@
#include <gale/debug.h> #include <gale/debug.h>
#include <gale/resource/Manager.h> #include <gale/resource/Manager.h>
#include <gale/resource/VirtualBufferObject.h> #include <gale/resource/VirtualBufferObject.h>
#include <gale/renderer/openGL/openGL-include.h>
#undef __class__ #undef __class__
#define __class__ "resource::VirtualBufferObject" #define __class__ "resource::VirtualBufferObject"
@ -49,7 +50,7 @@ void gale::resource::VirtualBufferObject::updateContext() {
// select the buffer to set data inside it ... // select the buffer to set data inside it ...
if (m_buffer[iii].size()>0) { if (m_buffer[iii].size()>0) {
gale::openGL::bindBuffer(m_vbo[iii]); gale::openGL::bindBuffer(m_vbo[iii]);
gale::openGL::bufferData(sizeof(float)*m_buffer[iii].size(), &((m_buffer[iii])[0]), GL_STATIC_DRAW); gale::openGL::bufferData(sizeof(float)*m_buffer[iii].size(), &((m_buffer[iii])[0]), gale::openGL::usage_staticDraw);
} }
} }
} }

View File

@ -24,7 +24,7 @@ namespace gale {
class VirtualBufferObject : public gale::Resource { class VirtualBufferObject : public gale::Resource {
private : private :
bool m_exist; //!< This data is availlable in the Graphic card bool m_exist; //!< This data is availlable in the Graphic card
std::vector<GLuint> m_vbo; //!< openGl ID of this VBO std::vector<uint32_t> m_vbo; //!< openGl ID of this VBO
std::vector<bool> m_vboUsed; //!< true if the VBO is allocated or used ... std::vector<bool> m_vboUsed; //!< true if the VBO is allocated or used ...
std::vector<std::vector<float>> m_buffer; //!< data that is availlable in the VBO system ... std::vector<std::vector<float>> m_buffer; //!< data that is availlable in the VBO system ...
std::vector<int8_t> m_vboSizeDataOffset; //!< Internal size of the VBO (dynamicly set) std::vector<int8_t> m_vboSizeDataOffset; //!< Internal size of the VBO (dynamicly set)
@ -46,7 +46,7 @@ namespace gale {
* @brief get the real openGL ID. * @brief get the real openGL ID.
* @return the Ogl id reference of this VBO. * @return the Ogl id reference of this VBO.
*/ */
GLuint getGL_ID(int32_t _id) { int64_t getGL_ID(int32_t _id) {
return m_vbo[_id]; return m_vbo[_id];
}; };
/** /**

View File

@ -36,7 +36,7 @@ class MainApplication : public gale::Application {
void onDraw(gale::Context& _context) { void onDraw(gale::Context& _context) {
ivec2 size = getSize(); ivec2 size = getSize();
// set the basic openGL view port: (position drawed in the windows) // set the basic openGL view port: (position drawed in the windows)
glViewport(0,0,size.x(),size.y()); gale::openGL::setViewPort(ivec2(0,0),size);
// Clear all the stacked matrix ... // Clear all the stacked matrix ...
gale::openGL::setBasicMatrix(mat4()); gale::openGL::setBasicMatrix(mat4());
// clear background // clear background
@ -76,7 +76,7 @@ class MainApplication : public gale::Application {
// color : // color :
m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float)); m_GLprogram->sendAttribute(m_GLColor, 4/*r,g,b,a*/, color, 4*sizeof(float));
// Request the draw od the elements : // Request the draw od the elements :
gale::openGL::drawArrays(GL_TRIANGLES, 0, 3 /*number of points*/); gale::openGL::drawArrays(gale::openGL::render_triangle, 0, 3 /*number of points*/);
m_GLprogram->unUse(); m_GLprogram->unUse();
// Restore context of matrix // Restore context of matrix
gale::openGL::pop(); gale::openGL::pop();