20 # include <android/log.h>
58 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &
_glMaxTexUnits);
66 glGetIntegerv(GL_NUM_EXTENSIONS, &n);
73 const GLubyte* ext = glGetString(GL_EXTENSIONS);
109 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
110 glPixelStorei(GL_PACK_ALIGNMENT, 1);
113 glEnable(GL_PROGRAM_POINT_SIZE);
126 SL_LOG(
"--------------------- Collected OpenGL Error: --------------------");
127 SL_LOG(
"Destructor : ~SLGLState");
128 for (
size_t i = 0; i <
errorTexts.size(); ++i)
131 SL_LOG(
"------------------------------------------------------------------");
143 glDepthFunc(GL_LESS);
144 glEnable(GL_DEPTH_TEST);
161 glClearColor(newColor.
r, newColor.
g, newColor.
b, newColor.
a);
177 glEnable(GL_DEPTH_TEST);
179 glDisable(GL_DEPTH_TEST);
194 glDepthMask(stateNew ? GL_TRUE : GL_FALSE);
224 glEnable(GL_CULL_FACE);
226 glDisable(GL_CULL_FACE);
251 SLenum newBlendFuncDFactor)
256 glBlendFunc(newBlendFuncSFactor, newBlendFuncDFactor);
275 glEnable(GL_MULTISAMPLE);
277 glDisable(GL_MULTISAMPLE);
296 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
298 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
318 glEnable(GL_POLYGON_OFFSET_POINT);
319 glPolygonOffset(factor, units);
322 glDisable(GL_POLYGON_OFFSET_POINT);
342 glEnable(GL_POLYGON_OFFSET_LINE);
343 glPolygonOffset(factor, units);
346 glDisable(GL_POLYGON_OFFSET_LINE);
365 glEnable(GL_POLYGON_OFFSET_FILL);
366 glPolygonOffset(factor, units);
369 glDisable(GL_POLYGON_OFFSET_FILL);
385 glViewport(x, y, width, height);
398 glColorMask(r, g, b, a);
414 glUseProgram(progID);
434 glBindTexture(target, textureID);
448 SL_LOG(
"******* To many texture units: %i used of %i",
449 (
SLint)textureUnit - GL_TEXTURE0,
453 "To many texture units!");
455 glActiveTexture(textureUnit);
488 GLenum err = glGetError();
489 if (err != GL_NO_ERROR)
494 case GL_INVALID_ENUM:
495 errStr =
"GL_INVALID_ENUM";
497 case GL_INVALID_VALUE:
498 errStr =
"GL_INVALID_VALUE";
500 case GL_INVALID_OPERATION:
501 errStr =
"GL_INVALID_OPERATION";
503 case GL_INVALID_FRAMEBUFFER_OPERATION:
504 errStr =
"GL_INVALID_FRAMEBUFFER_OPERATION";
506 case GL_OUT_OF_MEMORY:
507 errStr =
"GL_OUT_OF_MEMORY";
510 errStr =
"Unknown error";
514 string newErr(
"OpenGL Error in scene: ");
516 newErr +=
": file: ";
519 newErr += std::to_string(line);
525 auto foundErr = std::find(state->
errorTexts.begin(),
534 SL_LOG(
"**** %s ****", newErr.c_str());
538 long errorIndex = foundErr - state->
errorTexts.begin();
555 size_t dotPos = versionStr.find(
'.');
557 NO[0] = versionStr[dotPos - 1];
559 NO[2] = versionStr[dotPos + 1];
562 if (versionStr.find(
"OpenGL ES") != string::npos)
577 SLstring versionStr =
SLstring((
const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
578 size_t dotPos = versionStr.find(
'.');
580 NO[0] = versionStr[dotPos - 1];
581 NO[1] = versionStr[dotPos + 1];
631 default:
return false;
641 glPixelStorei(GL_PACK_ALIGNMENT, 4);
643 #ifndef SL_EMSCRIPTEN
644 glReadBuffer(GL_FRONT);
649 glGetIntegerv(GL_VIEWPORT, vp);
The AppCommon class holds the top-level instances of the app-demo.
Singleton class for global render state.
#define SL_READ_PIXELS_GL_FORMAT
static SLSceneID sceneID
ID of currently loaded scene.
Singleton class holding all OpenGL states.
void clearColor(const SLCol4f &c)
static void deleteInstance()
global destruction
static SLGLState * _instance
global singleton object
SLbool _depthMask
glDepthMask state
SLMat4f textureMatrix
matrix for the texture transform
SLVec4i _viewport
viewport size (x,y,w,h) of the framebuffer
void activeTexture(SLenum textureUnit)
SLuint _textureID
current texture id
SLMat4f modelMatrix
Init all states.
void polygonOffsetPoint(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
void depthMask(SLbool state)
SLCol4f _clearColor
clear color
SLbool _depthTest
GL_DEPTH_TEST state.
void multiSample(SLbool state)
static SLGLState * instance()
Public static instance getter for singleton pattern.
void polygonOffsetLine(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
~SLGLState()
destruction in ~SLScene
SLGLState()
private onetime constructor
SLbool _multisample
Multisampling state.
SLbool _isInitialized
flag for first init
SLbool _glIsES2
Flag if OpenGL ES2.
SLMat4f viewMatrix
matrix for the active cameras view transform
SLstring _glSLVersion
GLSL Version string.
void unbindAnythingAndFlush()
finishes all GL commands
SLVstring errorTexts
vector for error texts collected in getGLError
SLenum _textureTarget
current texture target
GLboolean _colorMaskA
current color mask for A
SLenum _blendFuncSfactor
blend function source factor enum
void blendFunc(SLenum blendFuncSFactor, SLenum blendFuncDFactor)
Sets new blend function source and destination factors.
void colorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
SLenum _blendFuncDfactor
blend function destination factor enum
SLstring getSLVersionNO()
Returns the OpenGL Shading Language version number as a string.
SLstring _glVendor
OpenGL Vendor string.
GLboolean _colorMaskR
current color mask for R
SLstring _glVersionNO
OpenGL Version number string.
SLstring _glSLVersionNO
GLSL Version number string.
SLstring _glExtensions
OpenGL extensions string.
SLbool _polygonOffsetFillEnabled
GL_POLYGON_OFFSET_FILL state enabled.
SLstring _glRenderer
OpenGL Renderer string.
SLbool _blend
blending default false;
SLbool _polygonOffsetLineEnabled
GL_POLYGON_OFFSET_LINE state enabled.
SLstring getGLVersionNO()
Returns the OpenGL version number as a string.
SLenum _textureUnit
current texture unit
SLint _glMaxTexUnits
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_glMaxTexUnits);
SLbool pixelFormatIsSupported(SLint pixelFormat)
Returns true if the according GL pixel format is valid in the GL context.
void depthFunc(SLenum func)
SLbool _polygonOffsetPointEnabled
GL_POLYGON_OFFSET_POINT state enabled.
SLenum _depthFunc
depth buffer comparison function
void bindTexture(SLenum target, SLuint textureID)
SLfloat _glVersionNOf
OpenGL Version number as float.
static void getGLError(const char *file, int line, bool quit)
Checks if an OpenGL error occurred.
void polygonOffsetFill(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
SLbool _glIsES3
Flag if OpenGL ES3.
void onInitialize(const SLCol4f &clearColor)
On init GL.
SLbool _polygonLine
Line polygon state.
SLMat4f projectionMatrix
matrix for projection transform
SLVlong errorCounts
vector for counts for the corresponding errorTexts
SLstring _glVersion
OpenGL Version string.
void useProgram(SLuint progID)
SLMaterial * _currentMaterial
void polygonLine(SLbool state)
SLint _glMaxTexSize
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_glMaxTexSize);
SLbool _cullFace
Face culling state.
SLint _multiSampleSamples
NO. of multisampling samples.
void readPixels(void *buffer)
Reads the front framebuffer pixels into the passed buffer.
GLboolean _colorMaskB
current color mask for B
GLboolean _colorMaskG
current color mask for G
void cullFace(SLbool state)
void depthTest(SLbool state)
SLuint _programID
current shader program id
void identity()
Sets the identity matrix.
void set(const T X, const T Y, const T Z, const T W=1)
string getFileName(const string &pathFilename)
Returns the filename of path-filename string.