ProgramBuilder (OpenGLShaderProgram& prog)
                {
                    prog.addShader ("attribute " JUCE_HIGHP " vec2 position;"
                                    "uniform " JUCE_HIGHP " vec2 screenSize;"
                                    "varying " JUCE_HIGHP " vec2 pixelPos;"
                                    "void main()"
                                    "{"
                                    "pixelPos = position;"
                                    JUCE_HIGHP " vec2 scaled = position / (0.5 * screenSize.xy);"
                                    "gl_Position = vec4 (scaled.x - 1.0, 1.0 - scaled.y, 0, 1.0);"
                                    "}",
                                    GL_VERTEX_SHADER);

                    prog.addShader ("uniform sampler2D imageTexture;"
                                    "uniform " JUCE_HIGHP " float textureBounds[4];"
                                    "varying " JUCE_HIGHP " vec2 pixelPos;"
                                    "void main()"
                                    "{"
                                     JUCE_HIGHP " vec2 texturePos = (pixelPos - vec2 (textureBounds[0], textureBounds[1]))"
                                                                      "/ vec2 (textureBounds[2], textureBounds[3]);"
                                     "gl_FragColor = texture2D (imageTexture, vec2 (texturePos.x, 1.0 - texturePos.y));"
                                    "}",
                                    GL_FRAGMENT_SHADER);
                    prog.link();
                }
Beispiel #2
0
void Graphics3D::render(const Matrix &view, const Matrix &proj, const Light *lighting, int flags)
{
    if (!getIsVisible()) return;
    if (!isValid()) return;
    if (lighting == nullptr) {
        lighting = defaultLight;
    }

    Matrix modl = referenceFrame->getModelMatrix();
    OpenGLShaderProgram *shaderProgram = shader->getShader();
    shaderProgram->use();
    
    OpenGLShaderProgram::Uniform modlMatrix(*shaderProgram, "M");
    OpenGLShaderProgram::Uniform viewMatrix(*shaderProgram, "V");
    OpenGLShaderProgram::Uniform projMatrix(*shaderProgram, "P");
    OpenGLShaderProgram::Uniform selectionHandle(*shaderProgram, "selectionHandle");


    modlMatrix.setMatrix4(modl.mat, 1, false);
    viewMatrix.setMatrix4(view.mat, 1, false);
    projMatrix.setMatrix4(proj.mat, 1, false);
    selectionHandle.set(flags ? uniqueHandle : 0);


    geometry->activate(shaderProgram);
    material->activate(shaderProgram);
    lighting->activate(shaderProgram);
    geometry->drawElements();
    geometry->deactivate(shaderProgram);
    material->deactivate(shaderProgram);
    lighting->deactivate(shaderProgram);
}
Beispiel #3
0
void OpenGLRenderer::setProgramBlockBinding(Renderer::ShaderProgram* p,
                                            const std::string& name,
                                            GLint point) {
    OpenGLShaderProgram* glsh = static_cast<OpenGLShaderProgram*>(p);

    auto ubi = glGetUniformBlockIndex(glsh->getName(), name.c_str());
    glUniformBlockBinding(glsh->getName(), ubi, point);
}
Beispiel #4
0
void process_vertex_attribute( 
    OpenGLContext&          openGLContext, 
    OpenGLShaderProgram&    shader, 
    std::string             name, 
    size_t                  stride_bytes, 
    size_t                  offset_bytes
    )
{
    // e.g. float[3] -> float and 3
    using Type = typename remove_extent<Tn>::type;
    static constexpr size_t  dim = extent<Tn>::value;

    GLint location = openGLContext.extensions.glGetAttribLocation(shader.getProgramID(), attributeName);
    if( location == -1 )
        return nullptr; // not found in shader
    
    OpenGLShaderProgram::Attribute gl_attribute =  new OpenGLShaderProgram::Attribute (shader, attributeName);
    
    if( gl_attribute == nullptr )
        return nullptr;
    
    generic_glVertexAttribPointer<Type>(
        attribNumber->attributeID,
        dim,
        vec_bytes,
        (const GLvoid *)offset_bytes
        );

    glEnableVertexAttribArray( attribNumber->attributeID );
}
OpenGLShaderProgram::Attribute::Attribute (const OpenGLShaderProgram& program, const char* name)
    : attributeID (program.context.extensions.glGetAttribLocation (program.getProgramID(), name))
{
    jassert (attributeID >= 0);
}
OpenGLShaderProgram::Uniform::Uniform (const OpenGLShaderProgram& program, const char* const name)
    : uniformID (program.context.extensions.glGetUniformLocation (program.getProgramID(), name)), context (program.context)
{
    jassert (uniformID >= 0);
}