[DEV] continue openGL abstraction

This commit is contained in:
Edouard DUPIN 2015-07-19 21:20:56 +02:00
parent 9ae89a2e4e
commit b7286bda51
2 changed files with 214 additions and 182 deletions

View File

@ -13,6 +13,42 @@
#include <mutex>
//#define DIRECT_MODE
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
static void checkGlError(const char* _op, int32_t _localLine) {
@ -146,6 +182,21 @@ void gale::openGL::swap() {
}
struct correspondenceTableClear {
enum gale::openGL::clearFlag curentFlag;
GLbitfield OGlFlag;
};
static struct correspondenceTableClear basicFlagClear[] = {
{gale::openGL::clearFlag_colorBuffer, GL_COLOR_BUFFER_BIT},
{gale::openGL::clearFlag_depthBuffer, GL_DEPTH_BUFFER_BIT},
{gale::openGL::clearFlag_stencilBuffer, GL_STENCIL_BUFFER_BIT}
};
static int32_t basicFlagClearCount = sizeof(basicFlagClear) / sizeof(struct correspondenceTableClear);
void gale::openGL::clearColor(const etk::Color<float>& _color) {
glClearColor(_color.r(), _color.g(), _color.b(), _color.a());
}
@ -158,40 +209,46 @@ void gale::openGL::clearStencil(int32_t _value) {
}
void gale::openGL::clear(uint32_t _flags) {
glClear(_flags);
GLbitfield field = 0;
for (int32_t iii=0; iii<basicFlagClearCount ; iii++) {
if ( (basicFlagClear[iii].curentFlag & _flagID) != 0) {
field |= basicFlagClear[iii].OGlFlag;
}
}
glClear(field);
}
std::ostream& gale::operator <<(std::ostream& _os, const enum openGL::openGlFlags& _obj) {
static std::vector<std::pair<enum openGL::openGlFlags, const char*>> list = {
std::make_pair(openGL::FLAG_BLEND, "FLAG_BLEND"),
std::make_pair(openGL::FLAG_CLIP_DISTANCE_I, "FLAG_CLIP_DISTANCE_I"),
std::make_pair(openGL::FLAG_COLOR_LOGIC_OP, "FLAG_COLOR_LOGIC_OP"),
std::make_pair(openGL::FLAG_CULL_FACE, "FLAG_CULL_FACE"),
std::make_pair(openGL::FLAG_DEBUG_OUTPUT, "FLAG_DEBUG_OUTPUT"),
std::make_pair(openGL::FLAG_DEBUG_OUTPUT_SYNCHRONOUS, "FLAG_DEBUG_OUTPUT_SYNCHRONOUS"),
std::make_pair(openGL::FLAG_DEPTH_CLAMP, "FLAG_DEPTH_CLAMP"),
std::make_pair(openGL::FLAG_DEPTH_TEST, "FLAG_DEPTH_TEST"),
std::make_pair(openGL::FLAG_DITHER, "FLAG_DITHER"),
std::make_pair(openGL::FLAG_FRAMEBUFFER_SRGB, "FLAG_FRAMEBUFFER_SRGB"),
std::make_pair(openGL::FLAG_LINE_SMOOTH, "FLAG_LINE_SMOOTH"),
std::make_pair(openGL::FLAG_MULTISAMPLE, "FLAG_MULTISAMPLE"),
std::make_pair(openGL::FLAG_POLYGON_OFFSET_FILL, "FLAG_POLYGON_OFFSET_FILL"),
std::make_pair(openGL::FLAG_POLYGON_OFFSET_LINE, "FLAG_POLYGON_OFFSET_LINE"),
std::make_pair(openGL::FLAG_POLYGON_OFFSET_POINT, "FLAG_POLYGON_OFFSET_POINT"),
std::make_pair(openGL::FLAG_POLYGON_SMOOTH, "FLAG_POLYGON_SMOOTH"),
std::make_pair(openGL::FLAG_PRIMITIVE_RESTART, "FLAG_PRIMITIVE_RESTART"),
std::make_pair(openGL::FLAG_PRIMITIVE_RESTART_FIXED_INDEX, "FLAG_PRIMITIVE_RESTART_FIXED_INDEX"),
std::make_pair(openGL::FLAG_SAMPLE_ALPHA_TO_COVERAGE, "FLAG_SAMPLE_ALPHA_TO_COVERAGE"),
std::make_pair(openGL::FLAG_SAMPLE_ALPHA_TO_ONE, "FLAG_SAMPLE_ALPHA_TO_ONE"),
std::make_pair(openGL::FLAG_SAMPLE_COVERAGE, "FLAG_SAMPLE_COVERAGE"),
std::make_pair(openGL::FLAG_SAMPLE_SHADING, "FLAG_SAMPLE_SHADING"),
std::make_pair(openGL::FLAG_SAMPLE_MASK, "FLAG_SAMPLE_MASK"),
std::make_pair(openGL::FLAG_SCISSOR_TEST, "FLAG_SCISSOR_TEST"),
std::make_pair(openGL::FLAG_STENCIL_TEST, "FLAG_STENCIL_TEST"),
std::make_pair(openGL::FLAG_PROGRAM_POINT_SIZE, "FLAG_PROGRAM_POINT_SIZE"),
std::make_pair(openGL::FLAG_TEXTURE_2D, "FLAG_TEXTURE_2D"),
std::make_pair(openGL::FLAG_ALPHA_TEST, "FLAG_ALPHA_TEST"),
std::make_pair(openGL::FLAG_FOG, "FLAG_FOG")
std::ostream& gale::operator <<(std::ostream& _os, const enum openGL::flag& _obj) {
static std::vector<std::pair<enum openGL::flag, const char*>> list = {
std::make_pair(openGL::flag_blend, "FLAG_BLEND"),
std::make_pair(openGL::flag_clipDistanceI, "FLAG_CLIP_DISTANCE_I"),
std::make_pair(openGL::flag_colorLogigOP, "FLAG_COLOR_LOGIC_OP"),
std::make_pair(openGL::flag_cullFace, "FLAG_CULL_FACE"),
std::make_pair(openGL::flag_debugOutput, "FLAG_DEBUG_OUTPUT"),
std::make_pair(openGL::flag_debugOutputSynchronous, "flag_debugOutput_SYNCHRONOUS"),
std::make_pair(openGL::flag_depthClamp, "FLAG_DEPTH_CLAMP"),
std::make_pair(openGL::flag_depthTest, "FLAG_DEPTH_TEST"),
std::make_pair(openGL::flag_dither, "FLAG_DITHER"),
std::make_pair(openGL::flag_framebufferSRGB, "FLAG_FRAMEBUFFER_SRGB"),
std::make_pair(openGL::flag_lineSmooth, "FLAG_LINE_SMOOTH"),
std::make_pair(openGL::flag_multisample, "FLAG_MULTISAMPLE"),
std::make_pair(openGL::flag_polygonOffsetFill, "FLAG_POLYGON_OFFSET_FILL"),
std::make_pair(openGL::flag_polygonOffsetLine, "FLAG_POLYGON_OFFSET_LINE"),
std::make_pair(openGL::flag_polygonOffsetPoint, "FLAG_POLYGON_OFFSET_POINT"),
std::make_pair(openGL::flag_polygonSmooth, "FLAG_POLYGON_SMOOTH"),
std::make_pair(openGL::flag_primitiveRestart, "FLAG_PRIMITIVE_RESTART"),
std::make_pair(openGL::flag_primitiveRestartFixedIndex, "flag_primitiveRestart_FIXED_INDEX"),
std::make_pair(openGL::flag_sampleAlphaToCoverage, "FLAG_SAMPLE_ALPHA_TO_COVERAGE"),
std::make_pair(openGL::flag_sampleAlphaToOne, "FLAG_SAMPLE_ALPHA_TO_ONE"),
std::make_pair(openGL::flag_sampleCoverage, "FLAG_SAMPLE_COVERAGE"),
std::make_pair(openGL::flag_sampleShading, "FLAG_SAMPLE_SHADING"),
std::make_pair(openGL::flag_sampleMask, "FLAG_SAMPLE_MASK"),
std::make_pair(openGL::flag_scissorTest, "FLAG_SCISSOR_TEST"),
std::make_pair(openGL::flag_stencilTest, "FLAG_STENCIL_TEST"),
std::make_pair(openGL::flag_programPointSize, "FLAG_PROGRAM_POINT_SIZE"),
std::make_pair(openGL::flag_texture2D, "FLAG_TEXTURE_2D"),
std::make_pair(openGL::flag_alphaTest, "FLAG_ALPHA_TEST"),
std::make_pair(openGL::flag_fog, "FLAG_FOG")
};
_os << "{";
bool hasOne = false;
@ -261,68 +318,68 @@ std::ostream& gale::operator <<(std::ostream& _os, const enum openGL::renderMode
}
typedef struct {
uint32_t curentFlag;
GLenum OGlFlag;
} correspondenceTable_ts;
struct correspondenceTable {
enum gale::openGL::flag curentFlag;
GLenum OGlFlag;
};
static correspondenceTable_ts basicFlag[] = {
{(uint32_t)gale::openGL::FLAG_BLEND, GL_BLEND},
{gale::openGL::flag_blend, GL_BLEND},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_CLIP_DISTANCE_I, GL_CLIP_DISTANCE0},
{(uint32_t)gale::openGL::FLAG_COLOR_LOGIC_OP, GL_COLOR_LOGIC_OP},
{gale::openGL::flag_clipDistanceI, GL_CLIP_DISTANCE0},
{gale::openGL::flag_colorLogigOP, GL_COLOR_LOGIC_OP},
#endif
{(uint32_t)gale::openGL::FLAG_CULL_FACE, GL_CULL_FACE},
{(uint32_t)gale::openGL::flag_cullFace, GL_CULL_FACE},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_DEBUG_OUTPUT, GL_DEBUG_OUTPUT},
{(uint32_t)gale::openGL::FLAG_DEBUG_OUTPUT_SYNCHRONOUS, GL_DEBUG_OUTPUT_SYNCHRONOUS},
{(uint32_t)gale::openGL::FLAG_DEPTH_CLAMP, GL_DEPTH_CLAMP},
{gale::openGL::flag_debugOutput, GL_DEBUG_OUTPUT},
{gale::openGL::flag_debugOutputSynchronous, GL_DEBUG_OUTPUT_SYNCHRONOUS},
{gale::openGL::flag_depthClamp, GL_DEPTH_CLAMP},
#endif
{(uint32_t)gale::openGL::FLAG_DEPTH_TEST, GL_DEPTH_TEST},
{(uint32_t)gale::openGL::FLAG_DITHER, GL_DITHER},
{gale::openGL::flag_depthTest, GL_DEPTH_TEST},
{gale::openGL::flag_dither, GL_DITHER},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_FRAMEBUFFER_SRGB, GL_FRAMEBUFFER_SRGB},
{(uint32_t)gale::openGL::FLAG_LINE_SMOOTH, GL_LINE_SMOOTH},
{(uint32_t)gale::openGL::FLAG_MULTISAMPLE, GL_MULTISAMPLE},
{gale::openGL::flag_framebufferSRGB, GL_FRAMEBUFFER_SRGB},
{gale::openGL::flag_lineSmooth, GL_LINE_SMOOTH},
{gale::openGL::flag_multisample, GL_MULTISAMPLE},
#endif
{(uint32_t)gale::openGL::FLAG_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_FILL},
{gale::openGL::flag_polygonOffsetFill, GL_POLYGON_OFFSET_FILL},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_POLYGON_OFFSET_LINE, GL_POLYGON_OFFSET_LINE},
{(uint32_t)gale::openGL::FLAG_POLYGON_OFFSET_POINT, GL_POLYGON_OFFSET_POINT},
{(uint32_t)gale::openGL::FLAG_POLYGON_SMOOTH, GL_POLYGON_SMOOTH},
{(uint32_t)gale::openGL::FLAG_PRIMITIVE_RESTART, GL_PRIMITIVE_RESTART},
{(uint32_t)gale::openGL::FLAG_PRIMITIVE_RESTART_FIXED_INDEX, GL_PRIMITIVE_RESTART_FIXED_INDEX},
{gale::openGL::flag_polygonOffsetLine, GL_POLYGON_OFFSET_LINE},
{gale::openGL::flag_polygonOffsetPoint, GL_POLYGON_OFFSET_POINT},
{gale::openGL::flag_polygonSmooth, GL_POLYGON_SMOOTH},
{gale::openGL::flag_primitiveRestart, GL_PRIMITIVE_RESTART},
{gale::openGL::flag_primitiveRestartFixedIndex, GL_PRIMITIVE_RESTART_FIXED_INDEX},
#endif
{(uint32_t)gale::openGL::FLAG_SAMPLE_ALPHA_TO_COVERAGE, GL_SAMPLE_ALPHA_TO_COVERAGE},
{gale::openGL::flag_sampleAlphaToCoverage, GL_SAMPLE_ALPHA_TO_COVERAGE},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_SAMPLE_ALPHA_TO_ONE, GL_SAMPLE_ALPHA_TO_ONE},
{gale::openGL::flag_sampleAlphaToOne, GL_SAMPLE_ALPHA_TO_ONE},
#endif
{(uint32_t)gale::openGL::FLAG_SAMPLE_COVERAGE, GL_SAMPLE_COVERAGE},
{gale::openGL::flag_sampleCoverage, GL_SAMPLE_COVERAGE},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_SAMPLE_SHADING, GL_SAMPLE_SHADING},
{(uint32_t)gale::openGL::FLAG_SAMPLE_MASK, GL_SAMPLE_MASK},
{gale::openGL::flag_sampleShading, GL_SAMPLE_SHADING},
{gale::openGL::flag_sampleMask, GL_SAMPLE_MASK},
#endif
{(uint32_t)gale::openGL::FLAG_SCISSOR_TEST, GL_SCISSOR_TEST},
{(uint32_t)gale::openGL::FLAG_STENCIL_TEST, GL_STENCIL_TEST},
{gale::openGL::flag_scissorTest, GL_SCISSOR_TEST},
{gale::openGL::flag_stencilTest, GL_STENCIL_TEST},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_PROGRAM_POINT_SIZE, GL_PROGRAM_POINT_SIZE},
{gale::openGL::flag_programPointSize, GL_PROGRAM_POINT_SIZE},
#endif
{(uint32_t)gale::openGL::FLAG_TEXTURE_2D, GL_TEXTURE_2D},
{gale::openGL::flag_texture2D, GL_TEXTURE_2D},
#if 0
!(defined(__TARGET_OS__Android) || defined(__TARGET_OS__MacOs))
{(uint32_t)gale::openGL::FLAG_ALPHA_TEST, GL_ALPHA_TEST},
{(uint32_t)gale::openGL::FLAG_FOG, GL_FOG}
{gale::openGL::flag_alphaTest, GL_ALPHA_TEST},
{gale::openGL::flag_fog, GL_FOG}
#endif
//{(uint32_t)gale::openGL::FLAG_, GL_}
};
static int32_t basicFlagCount = sizeof(basicFlag) / sizeof(correspondenceTable_ts);
static int32_t basicFlagCount = sizeof(basicFlag) / sizeof(struct correspondenceTable);
void gale::openGL::reset() {
#ifdef DIRECT_MODE
@ -335,7 +392,7 @@ void gale::openGL::reset() {
#endif
}
void gale::openGL::enable(enum gale::openGL::openGlFlags _flagID) {
void gale::openGL::enable(enum gale::openGL::flag _flagID) {
//GALE_INFO("Enable : " <GALE_ERROR< _flagID);
#ifdef DIRECT_MODE
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
@ -350,7 +407,7 @@ void gale::openGL::enable(enum gale::openGL::openGlFlags _flagID) {
#endif
}
void gale::openGL::disable(enum gale::openGL::openGlFlags _flagID) {
void gale::openGL::disable(enum gale::openGL::flag _flagID) {
//GALE_INFO("Disable : " << _flagID);
#ifdef DIRECT_MODE
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
@ -371,19 +428,19 @@ void gale::openGL::updateAllFlags() {
#endif
// check if fhags has change :
if (l_flagsMustBeSet == l_flagsCurrent ) {
OPENGL_INFO("OGL: current flag : " << (enum openGL::openGlFlags)l_flagsMustBeSet);
OPENGL_INFO("OGL: current flag : " << (enum openGL::flag)l_flagsMustBeSet);
return;
}
OPENGL_INFO("OGL: set new flag : " << (enum openGL::openGlFlags)l_flagsMustBeSet);
OPENGL_INFO("OGL: set new flag : " << (enum openGL::flag)l_flagsMustBeSet);
for (int32_t iii=0; iii<basicFlagCount ; iii++) {
uint32_t CurrentFlag = basicFlag[iii].curentFlag;
if ( (l_flagsMustBeSet&CurrentFlag)!=(l_flagsCurrent&CurrentFlag) ) {
if ( (l_flagsMustBeSet&CurrentFlag) != 0) {
glEnable(basicFlag[iii].OGlFlag);
OPENGL_INFO(" enable : " << (enum openGL::openGlFlags)basicFlag[iii].curentFlag);
OPENGL_INFO(" enable : " << (enum openGL::flag)basicFlag[iii].curentFlag);
} else {
glDisable(basicFlag[iii].OGlFlag);
OPENGL_INFO(" disable : " << (enum openGL::openGlFlags)basicFlag[iii].curentFlag);
OPENGL_INFO(" disable : " << (enum openGL::flag)basicFlag[iii].curentFlag);
}
}
}
@ -403,32 +460,51 @@ void gale::openGL::desActiveTexture(uint32_t _flagID) {
}
}
void gale::openGL::drawArrays(uint32_t _mode, int32_t _first, int32_t _count) {
const uint32_t convertRenderMode[] = {
GL_POINTS,
GL_LINES,
GL_LINE_STRIP,
GL_LINE_LOOP,
GL_TRIANGLES,
GL_TRIANGLE_STRIP,
GL_TRIANGLE_FAN,
#if (!defined(__TARGET_OS__IOs) && !defined(__TARGET_OS__Android))
GL_QUADS,
GL_QUAD_STRIP,
GL_POLYGON
#else
0,
0,
0
#endif
};
void gale::openGL::drawArrays(enum renderMode _mode, int32_t _first, int32_t _count) {
if (l_programId >= 0) {
updateAllFlags();
glDrawArrays(_mode, _first, _count);
glDrawArrays(convertRenderMode[_mode], _first, _count);
}
}
void gale::openGL::drawElements(uint32_t _mode, const std::vector<uint32_t>& _indices) {
void gale::openGL::drawElements(enum renderMode _mode, const std::vector<uint32_t>& _indices) {
if (l_programId >= 0) {
updateAllFlags();
//GALE_DEBUG("Request draw of " << indices.size() << "elements");
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_INT, &_indices[0]);
glDrawElements(convertRenderMode[_mode], _indices.size(), GL_UNSIGNED_INT, &_indices[0]);
}
}
void gale::openGL::drawElements16(uint32_t _mode, const std::vector<uint16_t>& _indices) {
void gale::openGL::drawElements16(enum renderMode _mode, const std::vector<uint16_t>& _indices) {
if (l_programId >= 0) {
updateAllFlags();
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
glDrawElements(convertRenderMode[_mode], _indices.size(), GL_UNSIGNED_SHORT, &_indices[0]);
}
}
void gale::openGL::drawElements8(uint32_t _mode, const std::vector<uint8_t>& _indices) {
void gale::openGL::drawElements8(enum renderMode _mode, const std::vector<uint8_t>& _indices) {
if (l_programId >= 0) {
updateAllFlags();
glDrawElements(_mode, _indices.size(), GL_UNSIGNED_BYTE, &_indices[0]);
glDrawElements(convertRenderMode[_mode], _indices.size(), GL_UNSIGNED_BYTE, &_indices[0]);
}
}
@ -459,7 +535,7 @@ void gale::openGL::useProgram(int32_t _id) {
bool gale::openGL::genBuffers(std::vector<GLuint>& _buffers) {
bool gale::openGL::genBuffers(std::vector<uint32_t>& _buffers) {
if (_buffers.size() == 0) {
GALE_WARNING("try to generate vector buffer with size 0");
return true;
@ -477,7 +553,7 @@ bool gale::openGL::genBuffers(std::vector<GLuint>& _buffers) {
return hasError;
}
bool gale::openGL::deleteBuffers(std::vector<GLuint>& _buffers) {
bool gale::openGL::deleteBuffers(std::vector<uint32_t>& _buffers) {
if (_buffers.size() == 0) {
GALE_WARNING("try to delete vector buffer with size 0");
return true;
@ -490,12 +566,14 @@ bool gale::openGL::deleteBuffers(std::vector<GLuint>& _buffers) {
return true;
}
bool gale::openGL::bindBuffer(GLuint _bufferId) {
bool gale::openGL::bindBuffer(uint32_t _bufferId) {
glBindBuffer(GL_ARRAY_BUFFER, _bufferId);
checkGlError("glBindBuffer", __LINE__);
return true;
}
GL_STREAM_DRAW, GL_STATIC_DRAW, or GL_DYNAMIC_DRAW
bool gale::openGL::bufferData(size_t _size, const void* _data, GLenum _usage) {
glBufferData(GL_ARRAY_BUFFER, _size, _data, _usage);
checkGlError("glBufferData", __LINE__);

View File

@ -14,46 +14,6 @@
#include <etk/math/Matrix4.h>
#include <etk/Color.h>
#ifdef __cplusplus
extern "C" {
#endif
#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
#ifdef __cplusplus
}
#endif
namespace gale {
namespace openGL {
/**
@ -128,9 +88,9 @@ namespace gale {
void clearStencil(int32_t _value);
enum clearFlag {
clearFlag_colorBuffer = GL_COLOR_BUFFER_BIT, //!< Indicates the buffers currently enabled for color writing.
clearFlag_depthBuffer = GL_DEPTH_BUFFER_BIT, //!< Indicates the depth buffer.
clearFlag_stencilBuffer = GL_STENCIL_BUFFER_BIT //!< Indicates the stencil buffer.
clearFlag_colorBuffer = 1<<0, //!< Indicates the buffers currently enabled for color writing.
clearFlag_depthBuffer = 1<<1, //!< Indicates the depth buffer.
clearFlag_stencilBuffer = 1<<2 //!< Indicates the stencil buffer.
};
/**
* @brief clear sets the bitplane area of the window to values previously selected by clearColor, clearDepth, and clearStencil. Multiple color buffers can be cleared simultaneously by selecting more than one buffer at a time using drawBuffer.
@ -139,66 +99,60 @@ namespace gale {
*/
void clear(uint32_t _flags);
enum openGlFlags {
FLAG_BLEND = 1<<0, //!< If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc.
FLAG_CLIP_DISTANCE_I = 1<<1, //!< If enabled, clip geometry against user-defined half space i.
FLAG_COLOR_LOGIC_OP = 1<<2, //!< If enabled, apply the currently selected logical operation to the computed fragment color and color buffer values. See glLogicOp.
FLAG_CULL_FACE = 1<<3, //!< If enabled, cull polygons based on their winding in window coordinates. See glCullFace.
FLAG_DEBUG_OUTPUT = 1<<4, //!< If enabled, debug messages are produced by a debug context. When disabled, the debug message log is silenced. Note that in a non-debug context, very few, if any messages might be produced, even when GL_DEBUG_OUTPUT is enabled.
FLAG_DEBUG_OUTPUT_SYNCHRONOUS = 1<<5, //!< If enabled, debug messages are produced synchronously by a debug context. If disabled, debug messages may be produced asynchronously. In particular, they may be delayed relative to the execution of GL commands, and the debug callback function may be called from a thread other than that in which the commands are executed. See glDebugMessageCallback.
FLAG_DEPTH_CLAMP = 1<<6, //!< If enabled, the -wc≤zc≤wc plane equation is ignored by view volume clipping (effectively, there is no near or far plane clipping). See glDepthRange.
FLAG_DEPTH_TEST = 1<<7, //!< If enabled, do depth comparisons and update the depth buffer. Note that even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. See glDepthFunc and glDepthRange.
FLAG_DITHER = 1<<8, //!< If enabled, dither color components or indices before they are written to the color buffer.
FLAG_FRAMEBUFFER_SRGB = 1<<9, //!< If enabled and the value of GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the framebuffer attachment corresponding to the destination buffer is GL_SRGB, the R, G, and B destination color values (after conversion from fixed-point to floating-point) are considered to be encoded for the sRGB color space and hence are linearized prior to their use in blending.
FLAG_LINE_SMOOTH = 1<<10, //!< If enabled, draw lines with correct filtering. Otherwise, draw aliased lines. See glLineWidth.
FLAG_MULTISAMPLE = 1<<11, //!< If enabled, use multiple fragment samples in computing the final color of a pixel. See glSampleCoverage.
FLAG_POLYGON_OFFSET_FILL = 1<<12, //!< If enabled, and if the polygon is rendered in GL_FILL mode, an offset is added to depth values of a polygon's fragments before the depth comparison is performed. See glPolygonOffset.
FLAG_POLYGON_OFFSET_LINE = 1<<13, //!< If enabled, and if the polygon is rendered in GL_LINE mode, an offset is added to depth values of a polygon's fragments before the depth comparison is performed. See glPolygonOffset.
FLAG_POLYGON_OFFSET_POINT = 1<<14, //!< If enabled, an offset is added to depth values of a polygon's fragments before the depth comparison is performed, if the polygon is rendered in GL_POINT mode. See glPolygonOffset.
FLAG_POLYGON_SMOOTH = 1<<15, //!< If enabled, draw polygons with proper filtering. Otherwise, draw aliased polygons. For correct antialiased polygons, an alpha buffer is needed and the polygons must be sorted front to back.
FLAG_PRIMITIVE_RESTART = 1<<16, //!< enables primitive restarting. If enabled, any one of the draw commands which transfers a set of generic attribute array elements to the GL will restart the primitive when the index of the vertex is equal to the primitive restart index. See glPrimitiveRestartIndex.
FLAG_PRIMITIVE_RESTART_FIXED_INDEX = 1<<17, //!< enables primitive restarting with a fixed index. If enabled, any one of the draw commands which transfers a set of generic attribute array elements to the GL will restart the primitive when the index of the vertex is equal to the fixed primitive index for the specified index type. The fixed index is equal to 2n1 where n is equal to 8 for GL_UNSIGNED_BYTE, 16 for GL_UNSIGNED_SHORT and 32 for GL_UNSIGNED_INT.
FLAG_SAMPLE_ALPHA_TO_COVERAGE = 1<<18, //!< If enabled, compute a temporary coverage value where each bit is determined by the alpha value at the corresponding sample location. The temporary coverage value is then ANDed with the fragment coverage value.
FLAG_SAMPLE_ALPHA_TO_ONE = 1<<19, //!< If enabled, each sample alpha value is replaced by the maximum representable alpha value.
FLAG_SAMPLE_COVERAGE = 1<<20, //!< If enabled, the fragment's coverage is ANDed with the temporary coverage value. If GL_SAMPLE_COVERAGE_INVERT is set to GL_TRUE, invert the coverage value. See glSampleCoverage.
FLAG_SAMPLE_SHADING = 1<<21, //!< If enabled, the active fragment shader is run once for each covered sample, or at fraction of this rate as determined by the current value of GL_MIN_SAMPLE_SHADING_VALUE. See glMinSampleShading.
FLAG_SAMPLE_MASK = 1<<22, //!< If enabled, the sample coverage mask generated for a fragment during rasterization will be ANDed with the value of GL_SAMPLE_MASK_VALUE before shading occurs. See glSampleMaski.
FLAG_SCISSOR_TEST = 1<<23, //!< If enabled, discard fragments that are outside the scissor rectangle. See glScissor.
FLAG_STENCIL_TEST = 1<<24, //!< If enabled, do stencil testing and update the stencil buffer. See glStencilFunc and glStencilOp. GL_TEXTURE_CUBE_MAP_SEAMLESS = 1<<0, //!< If enabled, cubemap textures are sampled such that when linearly sampling from the border between two adjacent faces, texels from both faces are used to generate the final sample value. When disabled, texels from only a single face are used to construct the final sample value.
FLAG_PROGRAM_POINT_SIZE = 1<<25, //!< If enabled and a vertex or geometry shader is active, then the derived point size is taken from the (potentially clipped) shader builtin gl_PointSize and clamped to the implementation-dependent point size range.
FLAG_TEXTURE_2D = 1<<26, //!<
FLAG_ALPHA_TEST = 1<<27, //!<
FLAG_FOG = 1<<28, //!<
enum flag {
flag_blend = 1<<0, //!< If enabled, blend the computed fragment color values with the values in the color buffers. See glBlendFunc.
flag_clipDistanceI = 1<<1, //!< If enabled, clip geometry against user-defined half space i.
flag_colorLogigOP = 1<<2, //!< If enabled, apply the currently selected logical operation to the computed fragment color and color buffer values. See glLogicOp.
flag_cullFace = 1<<3, //!< If enabled, cull polygons based on their winding in window coordinates. See glCullFace.
flag_debugOutput = 1<<4, //!< If enabled, debug messages are produced by a debug context. When disabled, the debug message log is silenced. Note that in a non-debug context, very few, if any messages might be produced, even when GL_DEBUG_OUTPUT is enabled.
flag_debugOutputSynchronous = 1<<5, //!< If enabled, debug messages are produced synchronously by a debug context. If disabled, debug messages may be produced asynchronously. In particular, they may be delayed relative to the execution of GL commands, and the debug callback function may be called from a thread other than that in which the commands are executed. See glDebugMessageCallback.
flag_depthClamp = 1<<6, //!< If enabled, the -wc≤zc≤wc plane equation is ignored by view volume clipping (effectively, there is no near or far plane clipping). See glDepthRange.
flag_depthTest = 1<<7, //!< If enabled, do depth comparisons and update the depth buffer. Note that even if the depth buffer exists and the depth mask is non-zero, the depth buffer is not updated if the depth test is disabled. See glDepthFunc and glDepthRange.
flag_dither = 1<<8, //!< If enabled, dither color components or indices before they are written to the color buffer.
flag_framebufferSRGB = 1<<9, //!< If enabled and the value of GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the framebuffer attachment corresponding to the destination buffer is GL_SRGB, the R, G, and B destination color values (after conversion from fixed-point to floating-point) are considered to be encoded for the sRGB color space and hence are linearized prior to their use in blending.
flag_lineSmooth = 1<<10, //!< If enabled, draw lines with correct filtering. Otherwise, draw aliased lines. See glLineWidth.
flag_multisample = 1<<11, //!< If enabled, use multiple fragment samples in computing the final color of a pixel. See glSampleCoverage.
flag_polygonOffsetFill = 1<<12, //!< If enabled, and if the polygon is rendered in GL_FILL mode, an offset is added to depth values of a polygon's fragments before the depth comparison is performed. See glPolygonOffset.
flag_polygonOffsetLine = 1<<13, //!< If enabled, and if the polygon is rendered in GL_LINE mode, an offset is added to depth values of a polygon's fragments before the depth comparison is performed. See glPolygonOffset.
flag_polygonOffsetPoint = 1<<14, //!< If enabled, an offset is added to depth values of a polygon's fragments before the depth comparison is performed, if the polygon is rendered in GL_POINT mode. See glPolygonOffset.
flag_polygonSmooth = 1<<15, //!< If enabled, draw polygons with proper filtering. Otherwise, draw aliased polygons. For correct antialiased polygons, an alpha buffer is needed and the polygons must be sorted front to back.
flag_primitiveRestart = 1<<16, //!< enables primitive restarting. If enabled, any one of the draw commands which transfers a set of generic attribute array elements to the GL will restart the primitive when the index of the vertex is equal to the primitive restart index. See glPrimitiveRestartIndex.
flag_primitiveRestartFixedIndex = 1<<17, //!< enables primitive restarting with a fixed index. If enabled, any one of the draw commands which transfers a set of generic attribute array elements to the GL will restart the primitive when the index of the vertex is equal to the fixed primitive index for the specified index type. The fixed index is equal to 2n1 where n is equal to 8 for GL_UNSIGNED_BYTE, 16 for GL_UNSIGNED_SHORT and 32 for GL_UNSIGNED_INT.
flag_sampleAlphaToCoverage = 1<<18, //!< If enabled, compute a temporary coverage value where each bit is determined by the alpha value at the corresponding sample location. The temporary coverage value is then ANDed with the fragment coverage value.
flag_sampleAlphaToOne = 1<<19, //!< If enabled, each sample alpha value is replaced by the maximum representable alpha value.
flag_sampleCoverage = 1<<20, //!< If enabled, the fragment's coverage is ANDed with the temporary coverage value. If GL_SAMPLE_COVERAGE_INVERT is set to GL_TRUE, invert the coverage value. See glSampleCoverage.
flag_sampleShading = 1<<21, //!< If enabled, the active fragment shader is run once for each covered sample, or at fraction of this rate as determined by the current value of GL_MIN_SAMPLE_SHADING_VALUE. See glMinSampleShading.
flag_sampleMask = 1<<22, //!< If enabled, the sample coverage mask generated for a fragment during rasterization will be ANDed with the value of GL_SAMPLE_MASK_VALUE before shading occurs. See glSampleMaski.
flag_scissorTest = 1<<23, //!< If enabled, discard fragments that are outside the scissor rectangle. See glScissor.
flag_stencilTest = 1<<24, //!< If enabled, do stencil testing and update the stencil buffer. See glStencilFunc and glStencilOp. GL_TEXTURE_CUBE_MAP_SEAMLESS = 1<<0, //!< If enabled, cubemap textures are sampled such that when linearly sampling from the border between two adjacent faces, texels from both faces are used to generate the final sample value. When disabled, texels from only a single face are used to construct the final sample value.
flag_programPointSize = 1<<25, //!< If enabled and a vertex or geometry shader is active, then the derived point size is taken from the (potentially clipped) shader builtin gl_PointSize and clamped to the implementation-dependent point size range.
flag_texture2D = 1<<26, //!<
flag_alphaTest = 1<<27, //!<
flag_fog = 1<<28, //!<
};
enum renderMode {
render_point = GL_POINTS,
render_line = GL_LINES,
render_lineStrip = GL_LINE_STRIP, //!< Not supported in GALE (TODO : Later)
render_lineLoop = GL_LINE_LOOP,
render_triangle = GL_TRIANGLES,
render_triangleStrip = GL_TRIANGLE_STRIP, //!< Not supported in GALE (TODO : Later)
render_triangleFan = GL_TRIANGLE_FAN, //!< Not supported in GALE (TODO : Later)
#if (!defined(__TARGET_OS__IOs) && !defined(__TARGET_OS__Android))
render_quad = GL_QUADS, //!< Not supported in OpenGL-ES2
render_quadStrip = GL_QUAD_STRIP, //!< Not supported in OpenGL-ES2
render_polygon = GL_POLYGON //!< Not supported in OpenGL-ES2
#else
renderQuad, //!< Not supported in OpenGL-ES2
renderQuadStrip, //!< Not supported in OpenGL-ES2
renderPolygon //!< Not supported in OpenGL-ES2
#endif
render_point,
render_line,
render_lineStrip, //!< Not supported in GALE (TODO : Later)
render_lineLoop,
render_triangle,
render_triangleStrip, //!< Not supported in GALE (TODO : Later)
render_triangleFan, //!< Not supported in GALE (TODO : Later)
renderQuad, //!< Not supported in OpenGL-ES2
renderQuadStrip, //!< Not supported in OpenGL-ES2
renderPolygon //!< Not supported in OpenGL-ES2
};
/**
* @brief enable a flag on the system
* @param[in] flagID The flag requested
*/
void enable(enum openGlFlags _flagID);
void enable(enum flag _flagID);
/**
* @brief disable a flag on the system
* @param[in] flagID The flag requested
*/
void disable(enum openGlFlags _flagID);
void disable(enum flag _flagID);
/**
* @brieg update all the internal flag needed to be set from tre previous element set ...
*/
@ -217,10 +171,10 @@ namespace gale {
/**
* @brief draw a specific array == > this enable mode difference ...
*/
void drawArrays(uint32_t _mode, int32_t _first, int32_t _count);
void drawElements (uint32_t _mode, const std::vector<uint32_t>& _indices);
void drawElements16(uint32_t _mode, const std::vector<uint16_t>& _indices);
void drawElements8 (uint32_t _mode, const std::vector<uint8_t>& _indices);
void drawArrays(enum renderMode _mode, int32_t _first, int32_t _count);
void drawElements (enum renderMode _mode, const std::vector<uint32_t>& _indices);
void drawElements16(enum renderMode _mode, const std::vector<uint16_t>& _indices);
void drawElements8 (enum renderMode _mode, const std::vector<uint8_t>& _indices);
/**
* @brief Use openGL program
* @param[in] id Id of the program that might be used
@ -229,13 +183,13 @@ namespace gale {
void reset();
bool genBuffers(std::vector<GLuint>& _buffers);
bool deleteBuffers(std::vector<GLuint>& _buffers);
bool bindBuffer(GLuint _bufferId);
bool genBuffers(std::vector<uint32_t>& _buffers);
bool deleteBuffers(std::vector<uint32_t>& _buffers);
bool bindBuffer(uint32_t _bufferId);
bool bufferData(size_t _size, const void* _data, GLenum _usage);
bool unbindBuffer();
};
std::ostream& operator <<(std::ostream& _os, const enum openGL::openGlFlags& _obj);
std::ostream& operator <<(std::ostream& _os, const enum openGL::flag& _obj);
std::ostream& operator <<(std::ostream& _os, const enum openGL::renderMode& _obj);
};