51 glShaderSource(
handle, 1, &source, 0);
55 glGetShaderiv(
handle, GL_COMPILE_STATUS, &status);
56 if (status == GL_TRUE)
59 glGetShaderiv(
handle, GL_INFO_LOG_LENGTH, &logLength);
61 GLchar* log = (GLchar*)malloc(logLength);
62 glGetShaderInfoLog(
handle, logLength, &logLength, log);
63 std::string msg((
char*)log);
66 msg = msg +
"\n" + source;
79 std::string
src(source);
87 src =
"#version 100\n"
91 src =
"#version 300 es\n"
92 "#define attribute in\n"
93 "#define varying out\n"
98 src =
"#version 100\n"
102 src =
"#version 130\n"
103 "#define attribute in\n"
104 "#define varying out\n"
105 "#line 0\n" + source;
122 std::string
src(source);
130 bool mapToModernGlsl =
false;
134 src =
"#version 100\n";
137 src =
"#version 300 es\n";
138 mapToModernGlsl =
true;
143 src =
"#version 100\n";
146 src =
"#version 130\n";
147 mapToModernGlsl =
true;
153 src +=
"#ifdef GL_OES_EGL_image_external_essl3\n"
154 "#extension GL_OES_EGL_image_external_essl3 : require\n"
157 "#extension GL_OES_EGL_image_external : require\n"
158 "lowp vec4 " + std::string(
DIALECT_TEXTURE_SAMPLING_FUNC) +
"(samplerExternalOES sampler, mediump vec2 coord) { return texture2D(sampler, coord); }\n"
168 src +=
"#define varying in\n"
169 "#define texture2D(S, C) texture(S, C)\n"
170 "#define gl_FragColor beatmupFrgClrVar\n"
171 "out mediump vec4 beatmupFrgClrVar;\n";
174 src +=
"#line 0\n" + source;
179 throw GL::GLException(
"External texture extension is only supported with Beatmup dialect extension");
190 #ifndef BEATMUP_OPENGLVERSION_GLES20
193 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER,
handle);
194 glBufferData(GL_ATOMIC_COUNTER_BUFFER,
sizeof(GLuint),
nullptr, GL_STATIC_DRAW);
200 glDeleteBuffers(1, &
handle);
206 glBindBuffer(GL_ATOMIC_COUNTER_BUFFER,
handle);
207 data = (GLuint*)glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, 0,
sizeof(GLuint),
208 GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
210 glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
217 handle = glCreateProgram();
228 glGetProgramiv(
handle, GL_LINK_STATUS, &status);
229 if (status == GL_TRUE)
232 glGetProgramiv(
handle, GL_INFO_LOG_LENGTH, &logLength);
234 GLchar* log = (GLchar*)malloc(logLength);
235 glGetProgramInfoLog(
handle, logLength, &logLength, log);
256 #ifndef BEATMUP_OPENGLVERSION_GLES20
259 glGetProgramiv(
handle, GL_PROGRAM_BINARY_LENGTH, &length);
264 glGetProgramBinary(
handle, length,
nullptr,
result->ptr<GLenum>(0),
result->ptr<GLenum>(1));
272 glProgramBinary(
handle, binary.
at<GLenum>(0), binary.
ptr<GLenum>(1), binary.
size() -
sizeof(GLenum));
313 glUniform1i(location, (GLint)value);
328 #ifdef BEATMUP_OPENGLVERSION_GLES20
329 glUniform1i(location, (GLint)value);
331 glUniform1ui(location, (GLuint)value);
335 #ifdef BEATMUP_OPENGLVERSION_GLES20
352 glUniform1f(location, (GLfloat)value);
387 const float scale = outRange / 255;
393 GLfloat m[4] = { 1, 0, 0, 1 };
394 mat.getElements(m[0], m[2], m[1], m[3]);
403 GLfloat m[9] = { 1, 0, 0, 0, 1, 0, pos.
x, pos.
y, 1 };
404 mat.getElements(m[0], m[3], m[1], m[4]);
418 if (
sizeof(GLint) !=
sizeof(
int)) {
419 GLint* convValues =
new GLint[length];
420 for (
int i = 0; i < length; ++i)
421 convValues[i] = values[i];
435 static const int STORAGE_LEN = 8;
436 GLint storage[STORAGE_LEN];
437 const bool alloc = length > STORAGE_LEN;
438 GLint* values = alloc ?
new GLint[length] : storage;
439 for (
int i = 0; i < length; ++i)
440 values[i] = firstValue + i;
477 glGetUniformiv(
getHandle(), uniform, &unit);
479 gpu.
bind(image, unit, param);
486 glGetUniformiv(
getHandle(), uniform, &unit);
492 #ifndef BEATMUP_OPENGLVERSION_GLES20
494 glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, unit, counter.
handle);
555 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
2x3 affine mapping containing a 2x2 matrix and a 2D point
static const AffineMapping IDENTITY
Simply a piece of binary data of a specific size.
datatype * ptr(size_t offset=0)
datatype at(size_t offset) const
std::map< std::string, handle_t > uniformsCache
void setUnsignedInteger(const std::string &name, const unsigned int value, bool safe=false)
void setMatrix2(const std::string &name, const Matrix2 &mat)
void assertLinked() const
handle_t getAttribLocation(const std::string &name)
Retrieves attribute location by its name.
void setVec2Array(const std::string &name, const float *xy, const int length)
handle_t getHandle() const
handle_t findUniformLocation(const char *name)
Retrieves uniform variable location by its name.
void bindSampler(GraphicPipeline &gpu, GL::TextureHandler &image, const char *uniformId, TextureParam param)
void bindAtomicCounter(GraphicPipeline &gpu, AtomicCounter &counter, int unit)
void setInteger(const std::string &name, const int value, bool safe=false)
Assigns a value to a specific integer variable in the program.
Chunk * getBinary() const
void enable(const GraphicPipeline &gpu)
void loadBinary(const Chunk &binary)
void setIntegerArray(const std::string &name, const int *values, const int length)
void setFloatArray(const std::string &name, const float *values, const int length)
void setVec4Array(const std::string &name, const float *xyzw, const int length)
handle_t getUniformLocation(const std::string &name)
Retrieves uniform variable location by its name.
void setVector3(const std::string &name, const float x, const float y, const float z)
void setFloat(const std::string &name, const float value, bool safe=false)
Assigns a value to a specific floating point variable in the program.
void setVector4(const std::string &name, const float x, const float y, const float z, const float w)
std::map< std::string, handle_t > attribsCache
handle_t findAttribLocation(const char *name)
Retrieves attribute location by its name.
void bindImage(GraphicPipeline &gpu, GL::TextureHandler &image, const char *uniformId, bool read, bool write)
AbstractProgram(const AbstractProgram &)=delete
disabling copying constructor
void setMatrix3(const std::string &name, const Matrix2 &mat, const Point &pos)
void setVector2(const std::string &name, const float x, const float y)
void set(unsigned int value)
AtomicCounter(const GraphicPipeline &gpu)
static const char * DIALECT_SAMPLER_DECL_TYPE
glsl type name to declare a texture in Beatmup dialect
FragmentShader(const GraphicPipeline &gpu)
static const char * DIALECT_TEXTURE_SAMPLING_FUNC
glsl function name to sample a texture in Beatmup dialect
void compile(const GraphicPipeline &gpu, const std::string &source, Extensions extensions=Extensions::NONE)
static void check(const std::string &info)
Program(const GraphicPipeline &gpu)
void link(const VertexShader &, const FragmentShader &)
GLSL program to render images Makes use of default vertex attributes to pass the texture coordinates ...
void link(const GraphicPipeline &gpu, const FragmentShader &)
RenderingProgram(const GraphicPipeline &gpu, const FragmentShader &)
static const char * TEXTURE_COORD_ATTRIB_NAME
texture coordinate attribute name in vertex shaders
static const char * VERTEX_COORD_ATTRIB_NAME
vertex coordinate attribute name in vertex shaders
static const char * VERTICAL_FLIP_ID
Vertical flipping variable name in vertex shader.
static const char * MODELVIEW_MATRIX_ID
Modelview matrix (mapping input geometry to output) shader variable name in vertex shader.
Shader(const Shader &)=delete
disabling copying constructor
void compile(const GraphicPipeline &gpu, const char *source)
VertexShader(const GraphicPipeline &gpu)
void compile(const GraphicPipeline &gpu, const std::string &source, Extensions extensions=Extensions::NONE)
Internal low-level GPU control API.
const GL::VertexShader & getDefaultVertexShader() const
int getGlslVersion() const
Returns GLSL language version supported by the GPU context being used.
static const int ATTRIB_TEXTURE_COORD
texture coordinate attribute index in the VBO
void bind(GL::TextureHandler &texture, size_t texUnit, const TextureParam param)
static const int ATTRIB_VERTEX_COORD
vertex coordinate attribute index in the VBO
bool isGlEsCompliant() const
Returns true if the GPU context is OpenGL ES-compliant.
void write(Bitmap &bitmap, Args &&... args)
Calls a Func< WriterClass >::process(access, params) that writes to a bitmap of any kind,...
void read(Bitmap &bitmap, Args &&... args)
Calls a Func< ReaderClass >::process(access, params), where.
Extensions operator-=(Extensions &set, Extensions entry)
unsigned int handle_t
A reference to a GPU resource.
Extensions
Supported OpenGL estensions.
@ BEATMUP_DIALECT
pseudo-extension enabling Beatmup GLSL dialect
@ EXTERNAL_TEXTURE
GL_OES_EGL_image_external_essl3 if available or GL_OES_EGL_image_external.
Extensions operator+(Extensions lhs, Extensions rhs)
TextureParam
Parameters of binding a texture to a texture unit on GPU.
std::string to_string(Beatmup::NNets::ActivationFunction function)
JNIEnv jlong jint jint jint jint jfloat scale
JNIEnv jobject jint jint jint jfloat fragment
return(jlong) new Beatmup jlong jstring name
jlong jstring jint jint jint z
jobject jlong jint jint y
jlong jstring jint jint jint jint w
return(jlong) new Beatmup jlong jstring src
Beatmup::AffineMapping & mapping