SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSGLTextureReader.cpp File Reference
#include "SENSGLTextureReader.h"
#include <SENS.h>
#include <Utils.h>
Include dependency graph for SENSGLTextureReader.cpp:

Go to the source code of this file.

Macros

#define GET_GL_ERROR
 

Functions

std::string glSLVersionNO ()
 Returns the OpenGL Shading Language version number as a string. More...
 
GLuint buildShaderFromSource (std::string source, GLenum shaderType, bool isGlExternalTexture)
 

Macro Definition Documentation

◆ GET_GL_ERROR

#define GET_GL_ERROR

Definition at line 31 of file SENSGLTextureReader.cpp.

Function Documentation

◆ buildShaderFromSource()

GLuint buildShaderFromSource ( std::string  source,
GLenum  shaderType,
bool  isGlExternalTexture 
)

Definition at line 57 of file SENSGLTextureReader.cpp.

58 {
59  // Compile Shader code
60  GLuint shaderHandle = glCreateShader(shaderType);
61  std::string version;
62 
63  std::string versionGLSL = glSLVersionNO();
64  std::string glVersion = std::string((const char*)glGetString(GL_VERSION));
65  bool glIsES3 = (glVersion.find("OpenGL ES 3") != string::npos);
66  std::string srcVersion = "#version " + versionGLSL;
67  if (glIsES3)
68  srcVersion += " es";
69  srcVersion += "\n";
70 
71  std::string completeSrc = srcVersion + source;
72 
73  if (isGlExternalTexture)
74  {
75  Utils::replaceString(completeSrc, "#include extension", "#extension GL_OES_EGL_image_external_essl3 : enable");
76  Utils::replaceString(completeSrc, "#include sampler", "uniform samplerExternalOES");
77  }
78  else
79  {
80  Utils::replaceString(completeSrc, "#include extension", "");
81  Utils::replaceString(completeSrc, "#include sampler", "uniform sampler2D");
82  }
83 
84  const char* src = completeSrc.c_str();
85 
86  glShaderSource(shaderHandle, 1, &src, nullptr);
87  glCompileShader(shaderHandle);
88 
89  // Check compile success
90  GLint compileSuccess;
91  glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &compileSuccess);
92 
93  if (!compileSuccess)
94  {
95  GLint logSize = 0;
96  glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, &logSize);
97 
98  GLchar* log = new GLchar[logSize];
99 
100  glGetShaderInfoLog(shaderHandle, logSize, nullptr, log);
101 
102  Utils::log("Application", "Cannot compile shader %s", log);
103  Utils::log("Application", "%s", src);
104  exit(1);
105  }
106  return shaderHandle;
107 }
std::string glSLVersionNO()
Returns the OpenGL Shading Language version number as a string.
void replaceString(string &source, const string &from, const string &to)
Replaces in the source string the from string by the to string.
Definition: Utils.cpp:170
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1100

◆ glSLVersionNO()

std::string glSLVersionNO ( )

Returns the OpenGL Shading Language version number as a string.

The string returned by glGetString can contain additional vendor information such as the build number and the brand name. For the shading language string "Nvidia GLSL 4.5" the function returns "450"

Definition at line 44 of file SENSGLTextureReader.cpp.

45 {
46  std::string versionStr = std::string((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
47  size_t dotPos = versionStr.find('.');
48  char NO[4];
49  NO[0] = versionStr[dotPos - 1];
50  NO[1] = versionStr[dotPos + 1];
51  NO[2] = '0';
52  NO[3] = 0;
53  return std::string(NO);
54 }