コード例 #1
0
ファイル: textureutils.cpp プロジェクト: sarbi127/inviwo
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont,
    const Texture& texture, const std::string samplerID) {
    TextureUnit unit;
    bindTexture(texture, unit);
    shader.setUniform(samplerID, unit.getUnitNumber());
    cont.push_back(std::move(unit));
}
コード例 #2
0
ファイル: volumeutils.cpp プロジェクト: sunwj/inviwo
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont, VolumeInport& volumePort) {
    TextureUnit unit;
    utilgl::bindTexture(volumePort, unit);
    shader.setUniform(volumePort.getIdentifier(), unit.getUnitNumber());
    utilgl::setShaderUniforms(shader, volumePort, volumePort.getIdentifier() + "Parameters");
    cont.push_back(std::move(unit));
}
コード例 #3
0
ファイル: TiScriptTranslator.cpp プロジェクト: cty41/Titan
	//------------------------------------------------------------------------------//
	void TextureUnitTranslator::translate(ScriptNodePtr& pScriptNode, const String& group)
	{
		Pass* pass = any_cast<Pass*>(pScriptNode->parent->createObj);
		TextureUnit* tu = pass->createTextureUnit();
		pScriptNode->createObj = tu;

		//set TextureUnit setting
		StringKeyValueMap::iterator it = pScriptNode->keyValueMap.find("texture"), itend = pScriptNode->keyValueMap.end();
		if(it != itend)
		{
			tu->setTexture(it->second);
			pScriptNode->keyValueMap.erase(it);
		}
		else
		{
			it = pScriptNode->keyValueMap.find("cube_texture");
			if(it != itend)
			{
				tu->setTexture(it->second, TT_CUBEMAP);
				pScriptNode->keyValueMap.erase(it);
			}
		}
		
		tu->setParams(pScriptNode->keyValueMap);
	}
コード例 #4
0
ファイル: simpleraycaster.cpp プロジェクト: molsimmsu/3mview
void SimpleRaycaster::process() {
    // activate and clear output render target
    outport_.activateTarget();
    outport_.clearTarget();

    // retrieve shader from shader property
    tgt::Shader* shader = shader_.getShader();
    if (!shader || !shader->isLinked()) {
        outport_.deactivateTarget();
        return;
    }

    // activate shader and set common uniforms
    shader->activate();
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(shader, &cam);

    // bind entry and exit params and pass texture units to the shader
    TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit;
    entryPort_.bindTextures(entryUnit, entryDepthUnit);
    shader->setUniform("entryPoints_", entryUnit.getUnitNumber());
    shader->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber());
    entryPort_.setTextureParameters(shader, "entryParameters_");

    exitPort_.bindTextures(exitUnit, exitDepthUnit);
    shader->setUniform("exitPoints_", exitUnit.getUnitNumber());
    shader->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber());
    exitPort_.setTextureParameters(shader, "exitParameters_");

    // bind volume texture and pass it to the shader
    std::vector<VolumeStruct> volumeTextures;
    TextureUnit volUnit;
     volumeTextures.push_back(VolumeStruct(
        volumePort_.getData(),
        &volUnit,
        "volume_",
        "volumeStruct_",
        volumePort_.getTextureClampModeProperty().getValue(),
        tgt::vec4(volumePort_.getTextureBorderIntensityProperty().get()),
        volumePort_.getTextureFilterModeProperty().getValue())
    );
    bindVolumes(shader, volumeTextures, &cam, lightPosition_.get());

    // bind transfer function and pass it to the shader
    TextureUnit transferUnit;
    if (transferFunc_.get()) {
        transferUnit.activate();
        transferFunc_.get()->bind();
        transferFunc_.get()->setUniform(shader, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());
    }

    // render screen aligned quad
    renderQuad();

    // clean up
    shader->deactivate();
    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
コード例 #5
0
ファイル: textureutils.cpp プロジェクト: sarbi127/inviwo
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont,
    const TransferFunctionProperty& tf) {
    TextureUnit unit;
    bindTexture(tf, unit);
    shader.setUniform(tf.getIdentifier(), unit.getUnitNumber());
    cont.push_back(std::move(unit));
}
コード例 #6
0
ファイル: imageglprocessor.cpp プロジェクト: sunwj/inviwo
void ImageGLProcessor::process() {
    if (internalInvalid_) {
        internalInvalid_ = false;
        const DataFormatBase* format = inport_.getData()->getDataFormat();
        size2_t dimensions;
        if (outport_.isHandlingResizeEvents() || !inport_.isOutportDeterminingSize())
            dimensions  = outport_.getData()->getDimensions();
        else
            dimensions = inport_.getData()->getDimensions();
        if (!outport_.hasData() || format != outport_.getData()->getDataFormat()
            || dimensions != outport_.getData()->getDimensions()){
            Image *img = new Image(dimensions, format);
            img->copyMetaDataFrom(*inport_.getData());
            outport_.setData(img);
        }
    }

    TextureUnit imgUnit;    
    utilgl::bindColorTexture(inport_, imgUnit);

    utilgl::activateTargetAndCopySource(outport_, inport_, ImageType::ColorOnly);
    shader_.activate();

    utilgl::setShaderUniforms(shader_, outport_, "outportParameters_");
    shader_.setUniform("inport_", imgUnit.getUnitNumber());

    preProcess();

    utilgl::singleDrawImagePlaneRect();
    shader_.deactivate();
    utilgl::deactivateCurrentTarget();

    postProcess();
}
コード例 #7
0
ファイル: imagemapping.cpp プロジェクト: Ojaswi/inviwo
void ImageMapping::preProcess() {
    TextureUnit transFuncUnit;
    const Layer* tfLayer = transferFunction_.get().getData();
    const LayerGL* transferFunctionGL = tfLayer->getRepresentation<LayerGL>();

    transferFunctionGL->bindTexture(transFuncUnit.getEnum());
    shader_.setUniform("transferFunc_", transFuncUnit.getUnitNumber());
}
コード例 #8
0
ファイル: volumeutils.cpp プロジェクト: sunwj/inviwo
IVW_MODULE_OPENGL_API void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont,
                                              const Volume& volume, const std::string& samplerID) {
    TextureUnit unit;
    utilgl::bindTexture(volume, unit);
    shader.setUniform(samplerID, unit.getUnitNumber());
    utilgl::setShaderUniforms(shader, volume, samplerID + "Parameters");
    cont.push_back(std::move(unit));
}
void PCPUploadRenderer::renderParallelCoordinates() {
    std::shared_ptr<const ParallelCoordinatesPlotRawData> data = _inport.getData();
    int nDimensions = data->minMax.size();
    int nValues = data->data.size();

    utilgl::GlBoolState depthTest(GL_DEPTH_TEST, !_depthTesting);
    utilgl::BlendModeEquationState blendEquation(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);

    utilgl::GlBoolState lineSmooth(GL_LINE_SMOOTH, _lineSmoothing);
    if (_lineSmoothing)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

    _shader.activate();

    _shader.setUniform("_nDimensions", nDimensions);
    _shader.setUniform("_nData", nValues / nDimensions);
    _shader.setUniform("_horizontalBorder", _horizontalBorder);
    _shader.setUniform("_verticalBorder", _verticalBorder);
    _shader.setUniform("_depthTesting", !_depthTesting);
    _shader.setUniform("_alphaFactor", _alphaFactor);

    TextureUnit tfUnit;
    utilgl::bindTexture(_transFunc, tfUnit);
    _shader.setUniform("_transFunc", tfUnit.getUnitNumber());

    glBindVertexArray(_vao);

    bool hasColoringData = _coloringData.hasData() && _coloringData.getData()->hasData;
    _shader.setUniform("_hasColoringData", hasColoringData);
    if (hasColoringData) {
        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, _coloringData.getData()->ssboColor);
    }

    //glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data->ssboData);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, _dimensionOrderingBuffer);

    //for (int i = 0; i < nValues / nDimensions; ++i) {
    //    glDrawElements(GL_LINE_STRIP, nDimensions, )
    //}

    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex(PRIM_RESTART);

    glDrawElements(GL_LINE_STRIP, nValues / nDimensions, GL_UNSIGNED_INT, _drawElements);


    glDisable(GL_PRIMITIVE_RESTART);
    //glDrawArrays(GL_LINE_STRIP, 0, nValues);

    //glMultiDrawArrays(GL_LINE_STRIP, _multiDrawIndices, _multiDrawCount, nValues / nDimensions);

    //glDrawArraysInstanced(GL_LINE_STRIP, 0, data->nDimensions, data->nValues / data->nDimensions);

    glBindVertexArray(0);

    _shader.deactivate();
}
コード例 #10
0
void SimpleRaycaster::process() {
    // activate and clear output render target
    outport_.activateTarget();
    outport_.clearTarget();

    // activate shader and set common uniforms
    raycastPrg_->activate();
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(raycastPrg_, &cam);

    // bind entry and exit params and pass texture units to the shader
    TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit;
    entryPort_.bindTextures(entryUnit, entryDepthUnit);
    raycastPrg_->setUniform("entryPoints_", entryUnit.getUnitNumber());
    raycastPrg_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber());
    entryPort_.setTextureParameters(raycastPrg_, "entryParameters_");

    exitPort_.bindTextures(exitUnit, exitDepthUnit);
    raycastPrg_->setUniform("exitPoints_", exitUnit.getUnitNumber());
    raycastPrg_->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber());
    exitPort_.setTextureParameters(raycastPrg_, "exitParameters_");

    // bind volume texture and pass it to the shader
    std::vector<VolumeStruct> volumeTextures;
    TextureUnit volUnit;
     volumeTextures.push_back(VolumeStruct(
        volumePort_.getData()->getVolumeGL(),
        &volUnit,
        "volume_",
        "volumeParameters_",
        true)
    );
    bindVolumes(raycastPrg_, volumeTextures, &cam, lightPosition_.get());

    // bind transfer function and pass it to the shader
    TextureUnit transferUnit;
    if (transferFunc_.get()) {
        transferUnit.activate();
        transferFunc_.get()->bind();
        raycastPrg_->setUniform("transferFunc_", transferUnit.getUnitNumber());
    }

    // render screen aligned quad
    renderQuad();

    // clean up
    raycastPrg_->deactivate();
    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
コード例 #11
0
void EntryExitPoints::jitterEntryPoints() {
    // if canvas resolution has changed, regenerate jitter texture
    if (!jitterTexture_ ||
        (jitterTexture_->getDimensions().x != entryPort_.getSize().x) ||
        (jitterTexture_->getDimensions().y != entryPort_.getSize().y))
    {
        generateJitterTexture();
    }

    shaderProgramJitter_->activate();
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(shaderProgramJitter_, &cam);

    // bind jitter texture
    TextureUnit jitterUnit;
    jitterUnit.activate();
    jitterTexture_->bind();
    jitterTexture_->uploadTexture();
    shaderProgramJitter_->setUniform("jitterTexture_", jitterUnit.getUnitNumber());
    shaderProgramJitter_->setIgnoreUniformLocationError(true);
    shaderProgramJitter_->setUniform("jitterParameters_.dimensions_",
                                     tgt::vec2(jitterTexture_->getDimensions().xy()));
    shaderProgramJitter_->setUniform("jitterParameters_.dimensionsRCP_",
                                     tgt::vec2(1.0f) / tgt::vec2(jitterTexture_->getDimensions().xy()));
    shaderProgramJitter_->setUniform("jitterParameters_.matrix_", tgt::mat4::identity);
    shaderProgramJitter_->setIgnoreUniformLocationError(false);

    // bind entry points texture and depth texture (have been rendered to temporary port)
    TextureUnit entryParams, exitParams, entryParamsDepth;
    tmpPort_.bindColorTexture(entryParams.getEnum());
    shaderProgramJitter_->setUniform("entryPoints_", entryParams.getUnitNumber());

    tmpPort_.bindDepthTexture(entryParamsDepth.getEnum());
    shaderProgramJitter_->setUniform("entryPointsDepth_", entryParamsDepth.getUnitNumber());
    tmpPort_.setTextureParameters(shaderProgramJitter_, "entryParameters_");

    // bind exit points texture
    exitPort_.bindColorTexture(exitParams.getEnum());
    shaderProgramJitter_->setUniform("exitPoints_", exitParams.getUnitNumber());
    exitPort_.setTextureParameters(shaderProgramJitter_, "exitParameters_");

    shaderProgramJitter_->setUniform("stepLength_", jitterStepLength_.get());

    entryPort_.activateTarget("jitteredEntryParams");
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // render screen aligned quad
    renderQuad();

    shaderProgramJitter_->deactivate();
}
コード例 #12
0
void DepthPeelingProcessor::process() {
    outport_.activateTarget();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // set modelview and projection matrices
    glMatrixMode(GL_PROJECTION);
    tgt::loadMatrix(camera_.get().getProjectionMatrix());
    glMatrixMode(GL_MODELVIEW);
    tgt::loadMatrix(camera_.get().getViewMatrix());
    LGL_ERROR;

    TextureUnit depthTexUnit;
    inport_.bindDepthTexture(depthTexUnit.getEnum());
    LGL_ERROR;

    // initialize shader
    shaderPrg_->activate();

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(shaderPrg_, &cam);

    // pass the remaining uniforms to the shader
    shaderPrg_->setUniform("depthTex_", depthTexUnit.getUnitNumber());
    inport_.setTextureParameters(shaderPrg_, "depthTexParameters_");

    std::vector<GeometryRendererBase*> portData = cpPort_.getConnectedProcessors();
    for (size_t i=0; i<portData.size(); i++) {
        GeometryRendererBase* pdcp = portData.at(i);
        if(pdcp->isReady()) {
            pdcp->setCamera(camera_.get());
            pdcp->setViewport(outport_.getSize());
            pdcp->render();
            LGL_ERROR;
        }
    }

    shaderPrg_->deactivate();
    outport_.deactivateTarget();

    // restore matrices
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    LGL_ERROR;
}
コード例 #13
0
ファイル: textureutils.cpp プロジェクト: sarbi127/inviwo
void bindTexture(const Volume& volume, const TextureUnit& texUnit) {
    if (auto volumeGL = volume.getRepresentation<VolumeGL>()) {
        volumeGL->bindTexture(texUnit.getEnum());
    } else {
        LogErrorCustom("TextureUtils", "Could not get a GL representation from volume");
    }
}
コード例 #14
0
ファイル: canvasgl.cpp プロジェクト: sarbi127/inviwo
void CanvasGL::renderLayer(size_t idx) {
    previousRenderedLayerIdx_ = idx;
    if (imageGL_) {
        const LayerGL* layerGL = imageGL_->getLayerGL(layerType_,idx);
        if (layerGL) {
            TextureUnit textureUnit;
            layerGL->bindTexture(textureUnit.getEnum());
            renderTexture(textureUnit.getUnitNumber());
            layerGL->unbindTexture();
            return;
        } else {
            renderNoise();
        }
    }
    if (!image_) renderNoise();
}
コード例 #15
0
    void configure() {
        s_textureUnit = -1;
        s_validGeneration++;
        VertexLayout::clearCache();

        blending.init(GL_FALSE);
        blendingFunc.init(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        culling.init(GL_TRUE);
        cullFace.init(GL_BACK);
        frontFace.init(GL_CCW);
        depthTest.init(GL_TRUE);
        depthWrite.init(GL_TRUE);

        glDisable(GL_STENCIL_TEST);
        glDepthFunc(GL_LEQUAL);
        glClearDepthf(1.0);
        glDepthRangef(0.0, 1.0);

        static size_t max = std::numeric_limits<size_t>::max();

        clearColor.init(0.0, 0.0, 0.0, 0.0);
        shaderProgram.init(max, false);
        vertexBuffer.init(max, false);
        indexBuffer.init(max, false);
        texture.init(GL_TEXTURE_2D, max, false);
        texture.init(GL_TEXTURE_CUBE_MAP, max, false);
        textureUnit.init(max, false);
    }
コード例 #16
0
ファイル: colordepth.cpp プロジェクト: emmaai/fractalM
void ColorDepth::process() {
    if (!enableSwitch_.get()) {
        bypass(&inport_, &outport_);
        return;
    }

    if (!chromaDepthTex_) {
        LERROR("No chroma depth texture");
        return;
    }

    //compute Depth Range
    tgt::vec2 depthRange = computeDepthRange(&inport_);

    outport_.activateTarget();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    TextureUnit colorUnit, depthUnit;
    inport_.bindTextures(colorUnit.getEnum(), depthUnit.getEnum());

    // bind chroma depth texture
    TextureUnit chromaDepthUnit;
    chromaDepthUnit.activate();
    //chromaDepthTex_ is 0 here
    chromaDepthTex_->bind();
    LGL_ERROR;

    // initialize shader
    program_->activate();
    setGlobalShaderParameters(program_);
    program_->setUniform("colorTex_", colorUnit.getUnitNumber());
    program_->setUniform("depthTex_", depthUnit.getUnitNumber());
    inport_.setTextureParameters(program_, "texParams_");
    program_->setUniform("chromadepthTex_", chromaDepthUnit.getUnitNumber());
    program_->setUniform("minDepth_", depthRange.x);
    program_->setUniform("maxDepth_", depthRange.y);
    program_->setUniform("colorMode_", colorMode_.getValue());
    program_->setUniform("colorDepthFactor_", factor_.get());

    renderQuad();

    program_->deactivate();
    TextureUnit::setZeroUnit();
    outport_.deactivateTarget();
    LGL_ERROR;
}
コード例 #17
0
ファイル: textureutils.cpp プロジェクト: sarbi127/inviwo
void bindAndSetUniforms(Shader& shader, TextureUnitContainer& cont, const Image& image,
                        const std::string& id, ImageType type) {
    switch (type) {
        case COLOR_ONLY: {
            TextureUnit unit;
            bindColorTexture(image, unit);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit.getUnitNumber());
            cont.push_back(std::move(unit));
            break;
        }
        case COLOR_DEPTH: {
            TextureUnit unit1, unit2;
            bindTextures(image, unit1, unit2);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit1.getUnitNumber());
            shader.setUniform(id + "Depth", unit2.getUnitNumber());
            cont.push_back(std::move(unit1));
            cont.push_back(std::move(unit2));
            break;
        }
        case COLOR_PICKING: {
            TextureUnit unit1, unit2;
            bindColorTexture(image, unit1);
            bindPickingTexture(image, unit2);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit1.getUnitNumber());
            shader.setUniform(id + "Picking", unit2.getUnitNumber());
            cont.push_back(std::move(unit1));
            cont.push_back(std::move(unit2));
            break;
        }
        case COLOR_DEPTH_PICKING: {
            TextureUnit unit1, unit2, unit3;
            bindTextures(image, unit1, unit2, unit3);
            utilgl::setShaderUniforms(shader, image, id + "Parameters");
            shader.setUniform(id + "Color", unit1.getUnitNumber());
            shader.setUniform(id + "Depth", unit2.getUnitNumber());
            shader.setUniform(id + "Picking", unit3.getUnitNumber());
            cont.push_back(std::move(unit1));
            cont.push_back(std::move(unit2));
            cont.push_back(std::move(unit3));
            break;
        }
    }
}
コード例 #18
0
namespace RenderState {

    Blending blending;
    DepthTest depthTest;
    StencilTest stencilTest;
    Culling culling;
    DepthWrite depthWrite;
    BlendingFunc blendingFunc;
    StencilWrite stencilWrite;
    StencilFunc stencilFunc;
    StencilOp stencilOp;
    ColorWrite colorWrite;
    FrontFace frontFace;
    CullFace cullFace;

    VertexBuffer vertexBuffer;
    IndexBuffer indexBuffer;

    TextureUnit textureUnit;
    Texture texture;

    GLuint getTextureUnit(GLuint _unit) {
        if (_unit >= TANGRAM_MAX_TEXTURE_UNIT) {
            logMsg("Warning: trying to access unavailable texture unit");
        }

        return GL_TEXTURE0 + _unit;
    }

    void bindVertexBuffer(GLuint _id) { glBindBuffer(GL_ARRAY_BUFFER, _id); }
    void bindIndexBuffer(GLuint _id) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _id); }
    void activeTextureUnit(GLuint _unit) { glActiveTexture(getTextureUnit(_unit)); }
    void bindTexture(GLenum _target, GLuint _textureId) { glBindTexture(_target, _textureId); }

    void configure() {
        blending.init(GL_FALSE);
        blendingFunc.init(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        culling.init(GL_TRUE);
        cullFace.init(GL_BACK);
        frontFace.init(GL_CCW);
        depthTest.init(GL_TRUE);
        depthWrite.init(GL_TRUE);

        glDisable(GL_STENCIL_TEST);
        glDepthFunc(GL_LEQUAL);
        glClearDepthf(1.0);
        glDepthRangef(0.0, 1.0);
        glClearColor(0.3, 0.3, 0.3, 1.0);

        vertexBuffer.init(std::numeric_limits<unsigned int>::max(), false);
        indexBuffer.init(std::numeric_limits<unsigned int>::max(), false);
        texture.init(GL_TEXTURE_2D, std::numeric_limits<unsigned int>::max(), false);
        texture.init(GL_TEXTURE_CUBE_MAP, std::numeric_limits<unsigned int>::max(), false);
        textureUnit.init(std::numeric_limits<unsigned int>::max(), false);
    }

}
コード例 #19
0
ファイル: renderer.cpp プロジェクト: belindabernfort/PUMlab3
void Renderer::drawParticles() {
    // We want to be able to set the point size from the shader
    // and let OpenGL generate texture coordinates for each point
    glEnable(GL_PROGRAM_POINT_SIZE);
    glEnable(GL_POINT_SPRITE); // Deprecated in OpenGL 3.2, but necessary

    // Activate the ProgramObject
    _particleProgram->activate();

    // Bind the only one texture that is used as the color and normal texture
    TextureUnit textureUnit;
    textureUnit.activate();
    _particleTexture->enable();
    _particleTexture->bind();

    // We are using 'fragColor' as the output variable from the FragmentShader
    _particleProgram->bindFragDataLocation("fragColor", 0);

    // Enable and bind the VBO holding the vertices for the ground and assign them a location
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, _particleVBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_TRUE, 0, 0);
    _particleProgram->bindAttributeLocation("in_position", _particleVBO);

    // Set the rest of the uniforms
    // It would be faster to cache the uniform location and reuse that, but this is more readable
    _particleProgram->setUniform("_viewProjectionMatrix", _viewProjectionMatrix);
    _particleProgram->setUniform("_cameraPosition", _position);
    _particleProgram->setUniform("_lightPosition", _lightPosition);
    _particleProgram->setUniform("_texture", textureUnit.unitNumber());

    // _particleData holds the xyz coordinates, so it has thrice the amount of data
    // than it has points. And since we test for the correct amount of data elsewhere,
    // it is safe to assume that everything is fine
    glDrawArrays(GL_POINTS, 0, _numberOfParticles);

    // Be a good citizen and disable everything again
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    _particleTexture->disable();
    _particleProgram->deactivate();
    glDisable(GL_POINT_SPRITE);
    glDisable(GL_PROGRAM_POINT_SIZE);
}
コード例 #20
0
TextureUnit TextureUnitManager::requestTextureUnit()
{
   if(!TextureUnitManager::initted)
   {
      init();
   }
   if(!unitQueue.empty())
   {
      TextureUnit ret = unitQueue.top();
      unitQueue.pop();
      ret.active = true;
      LOG(INFO) << "Leasing unit " + std::to_string(ret.getTexUnit());
      return ret;
   }
   else
   {
      LOG(ERROR) << "Out of texture untis!";
      exit(-1);
   }
}
void PCPRenderer::renderParallelCoordinates() {
    std::shared_ptr<const ParallelCoordinatesPlotData> data = _inport.getData();
    utilgl::GlBoolState depthTest(GL_DEPTH_TEST, !_depthTesting);

    //utilgl::GlBoolState alpha(GL_ALPHA, _alphaFactor != 1.f);
    utilgl::BlendModeEquationState blendEquation(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_FUNC_ADD);

    utilgl::GlBoolState lineSmooth(GL_LINE_SMOOTH, _lineSmoothing);
    if (_lineSmoothing)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

    _shader.activate();

    _shader.setUniform("_nDimensions", data->nDimensions);
    _shader.setUniform("_nData", data->nValues / data->nDimensions);
    _shader.setUniform("_horizontalBorder", _horizontalBorder);
    _shader.setUniform("_verticalBorder", _verticalBorder);
    _shader.setUniform("_depthTesting", _depthTesting);
    _shader.setUniform("_alphaFactor", _alphaFactor);

    TextureUnit tfUnit;
    utilgl::bindTexture(_transFunc, tfUnit);
    _shader.setUniform("_transFunc", tfUnit.getUnitNumber());

    glBindVertexArray(_vao);

    bool hasColoringData = _coloringData.hasData() && _coloringData.getData()->hasData;
    _shader.setUniform("_hasColoringData", hasColoringData);
    if (hasColoringData) {
        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, _coloringData.getData()->ssboColor);
    }

    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, data->ssboData);
    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, _dimensionOrderingBuffer);

    glDrawArraysInstanced(GL_LINE_STRIP, 0, data->nDimensions, data->nValues / data->nDimensions);

    glBindVertexArray(0);

    _shader.deactivate();
}
コード例 #22
0
ファイル: renderer.cpp プロジェクト: belindabernfort/PUMlab3
void Renderer::drawSkybox() {
    // Active the ProgramObject
    _skyboxProgram->activate();

    // Bind the cube map texture into the first texture unit
    TextureUnit cubeMapTextureUnit;
    cubeMapTextureUnit.activate();
    glEnable(GL_TEXTURE_CUBE_MAP);
    glBindTexture(GL_TEXTURE_CUBE_MAP, _skyboxTexture);

    // We are using 'fragColor' as the output variable from the FragmentShader
    _skyboxProgram->bindFragDataLocation("fragColor", 0);

    // Enable and bind the VBO holding the vertices for the ground and assign them a location
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, _skyboxVBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    _skyboxProgram->bindAttributeLocation("in_position", _skyboxVBO);

    // Use _skyboxIBO as our element array buffer to handle the indexed rendering
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _skyboxIBO);

    // Set the rest of the uniforms
    // It would be faster to cache the uniform location and reuse that, but this is more readable
    _skyboxProgram->setUniform("_viewProjectionMatrix", _viewProjectionMatrix);
    _skyboxProgram->setUniform("_texture", cubeMapTextureUnit.unitNumber());

    // Render the 4 quads
    glDrawElements(GL_QUADS, _numSkyboxIndices, GL_UNSIGNED_SHORT, 0);

    // And disable everything again to be a good citizen
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    glDisable(GL_TEXTURE_CUBE_MAP);
    _skyboxProgram->deactivate();
}
コード例 #23
0
    void configure() {
        blending.init(GL_FALSE);
        blendingFunc.init(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        culling.init(GL_TRUE);
        cullFace.init(GL_BACK);
        frontFace.init(GL_CCW);
        depthTest.init(GL_TRUE);
        depthWrite.init(GL_TRUE);

        glDisable(GL_STENCIL_TEST);
        glDepthFunc(GL_LEQUAL);
        glClearDepthf(1.0);
        glDepthRangef(0.0, 1.0);
        glClearColor(0.3, 0.3, 0.3, 1.0);

        vertexBuffer.init(std::numeric_limits<unsigned int>::max(), false);
        indexBuffer.init(std::numeric_limits<unsigned int>::max(), false);
        texture.init(GL_TEXTURE_2D, std::numeric_limits<unsigned int>::max(), false);
        texture.init(GL_TEXTURE_CUBE_MAP, std::numeric_limits<unsigned int>::max(), false);
        textureUnit.init(std::numeric_limits<unsigned int>::max(), false);
    }
コード例 #24
0
ファイル: renderer.cpp プロジェクト: belindabernfort/PUMlab3
void Renderer::drawGround() {
    // Active the ProgramObject
    _groundProgram->activate();

    // Bind the ground texture in the first available texture unit
    TextureUnit groundTextureUnit;
    groundTextureUnit.activate();
    _groundTexture->enable();
    _groundTexture->bind();

    // Bind the normal texture in the next free texture unit
    TextureUnit groundTextureNormalUnit;
    groundTextureNormalUnit.activate();
    _groundTextureNormal->enable();
    _groundTextureNormal->bind();

    // We are using 'fragColor' as the output variable from the FragmentShader
    _groundProgram->bindFragDataLocation("fragColor", 0);

    // Enable and bind the VBO holding the vertices for the ground and assign them a location
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, _groundVBO);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
    _groundProgram->bindAttributeLocation("in_position", _groundVBO);
    
    // Set the rest of the uniforms
    // It would be faster to cache the uniform location and reuse that, but this is more readable
    _groundProgram->setUniform("_viewProjectionMatrix", _viewProjectionMatrix);
    _groundProgram->setUniform("_cameraPosition", _position);
    _groundProgram->setUniform("_lightPosition", _lightPosition);
    _groundProgram->setUniform("_texture", groundTextureUnit.unitNumber());
    _groundProgram->setUniform("_textureNormal", groundTextureNormalUnit.unitNumber());

    // Draw one quad 
    glDrawArrays(GL_QUADS, 0, 4);

    // And disable everything again to be a good citizen
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    _groundTexture->disable();
    _groundTextureNormal->disable();
    _groundProgram->deactivate();
}
コード例 #25
0
ファイル: occlusionslicer.cpp プロジェクト: molsimmsu/3mview
void OcclusionSlicer::process() {

    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    occlusionbuffer0_.activateTarget();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    occlusionbuffer1_.activateTarget();
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    outport_.activateTarget();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volume_","volumeStruct_")
    );

    // initialize slicing shader
    tgt::Shader* slicingPrg = shaderProp_.getShader();
    slicingPrg->activate();

    // fragment shader uniforms
    TextureUnit occlusionUnit;
    transferFunc_.get()->setUniform(slicingPrg, "transferFunc_", "transferFuncTex_", transferUnit.getUnitNumber());
    slicingPrg->setUniform("occlusion_", occlusionUnit.getUnitNumber());
    occlusionbuffer1_.setTextureParameters(slicingPrg, "occlusionParams_");

    //clipping uniforms
    setupUniforms(slicingPrg);

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(slicingPrg, &cam);

    slicingPrg->setUniform("sigma_", sigma_.get());
    slicingPrg->setUniform("radius_", radius_.get());
    slicingPrg->setUniform("lightPos_", lightPosition_.get().xyz());

    // bind the volumes and pass the necessary information to the shader
    bindVolumes(slicingPrg, volumeTextures, &cam, lightPosition_.get());

    glDisable(GL_DEPTH_TEST);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getProjectionMatrix(outport_.getSize()));

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    tgt::loadMatrix(camera_.get().getViewMatrix());

    unsigned int numSlices = static_cast<unsigned int>(maxLength_ / sliceDistance_);

    slicingPrg->activate();

    for (unsigned int curSlice=0; curSlice<numSlices; curSlice++) {
        // first pass
        slicingPrg->setUniform("secondPass_", false);
        outport_.activateTarget();
        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);

        occlusionbuffer0_.bindColorTexture(occlusionUnit.getEnum());

        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();
        glDisable(GL_BLEND);

        outport_.deactivateTarget();

        // second pass
        slicingPrg->setUniform("secondPass_", true);

        occlusionbuffer1_.activateTarget();

        slicingPrg->setUniform("blurDirection_", tgt::vec2(1.f, 0.f));
        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();

        occlusionbuffer1_.deactivateTarget();
        occlusionbuffer0_.activateTarget();
        occlusionbuffer1_.bindColorTexture(occlusionUnit.getEnum());

        slicingPrg->setUniform("blurDirection_", tgt::vec2(0.f, 1.f));
        glBegin(GL_POLYGON);
        for (unsigned int curPoint=0; curPoint<6; curPoint++)
            glVertex2i(curPoint, curSlice);
        glEnd();

        occlusionbuffer0_.deactivateTarget();
    }

    slicingPrg->deactivate();

    glEnable(GL_DEPTH_TEST);

    glPopMatrix();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    glBlendFunc(GL_ONE, GL_ZERO);
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
コード例 #26
0
ファイル: imagegl.cpp プロジェクト: ResearchDaniel/inviwo
bool ImageGL::copyRepresentationsTo(ImageGL* target) const {
    const ImageGL* source = this;

    auto singleChannel = source->getColorLayerGL()->getDataFormat()->getComponents() == 1;

    // Set shader to copy all color layers
    if (!shader_.isReady() || singleChanelCopy_ != singleChannel ||
        colorLayerCopyCount_ != colorLayersGL_.size()) {
        std::stringstream ssUniform;
        for (size_t i = 1; i < colorLayersGL_.size(); ++i) {
            ssUniform << "layout(location = " << i + 1 << ") out vec4 FragData" << i << ";";
        }
        for (size_t i = 1; i < colorLayersGL_.size(); ++i) {
            ssUniform << "uniform sampler2D color" << i << ";";
        }
        shader_.getFragmentShaderObject()->addShaderDefine("ADDITIONAL_COLOR_LAYER_OUT_UNIFORMS",
                                                           ssUniform.str());

        std::stringstream ssWrite;
        for (size_t i = 1; i < colorLayersGL_.size(); ++i) {
            if (singleChannel) {
                ssWrite << "FragData" << i << " = vec4(texture(color" << i << ", texCoord_.xy).r);";
            } else {
                ssWrite << "FragData" << i << " = texture(color" << i << ", texCoord_.xy);";
            }
        }
        shader_.getFragmentShaderObject()->addShaderDefine("ADDITIONAL_COLOR_LAYER_WRITE",
                                                           ssWrite.str());

        if (colorLayersGL_.size() > 1) {
            shader_.getFragmentShaderObject()->addShaderDefine("ADDITIONAL_COLOR_LAYERS");
        } else {
            shader_.getFragmentShaderObject()->removeShaderDefine("ADDITIONAL_COLOR_LAYERS");
        }

        if (singleChannel) {
            shader_.getFragmentShaderObject()->addShaderDefine("SINGLE_CHANNEL");
        } else {
            shader_.getFragmentShaderObject()->removeShaderDefine("SINGLE_CHANNEL");
        }

        colorLayerCopyCount_ = colorLayersGL_.size();
        singleChanelCopy_ = singleChannel;

        shader_.build();
    }

    TextureUnit colorUnit, depthUnit, pickingUnit;
    source->getColorLayerGL()->bindTexture(colorUnit.getEnum());
    if (source->getDepthLayerGL()) {
        source->getDepthLayerGL()->bindTexture(depthUnit.getEnum());
    }
    if (source->getPickingLayerGL()) {
        source->getPickingLayerGL()->bindTexture(pickingUnit.getEnum());
    }
    TextureUnitContainer additionalColorUnits;
    for (size_t i = 0; i < colorLayersGL_.size(); ++i) {
        TextureUnit unit;
        source->getColorLayerGL(i)->bindTexture(unit.getEnum());
        additionalColorUnits.push_back(std::move(unit));
    }

    // Render to FBO, with correct scaling
    target->activateBuffer(ImageType::AllLayers);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    float ratioSource = (float)source->getDimensions().x / (float)source->getDimensions().y;
    float ratioTarget = (float)target->getDimensions().x / (float)target->getDimensions().y;
    glm::mat4 scale;

    if (ratioTarget < ratioSource)
        scale = glm::scale(glm::vec3(1.0f, ratioTarget / ratioSource, 1.0f));
    else
        scale = glm::scale(glm::vec3(ratioSource / ratioTarget, 1.0f, 1.0f));

    GLint prog;
    glGetIntegerv(GL_CURRENT_PROGRAM, &prog);

    shader_.activate();
    shader_.setUniform("color_", colorUnit.getUnitNumber());
    if (source->getDepthLayerGL()) {
        shader_.setUniform("depth_", depthUnit.getUnitNumber());
    }
    if (source->getPickingLayerGL()) {
        shader_.setUniform("picking_", pickingUnit.getUnitNumber());
    }
    for (size_t i = 0; i < additionalColorUnits.size(); ++i) {
        shader_.setUniform("color" + toString<size_t>(i + 1),
                           additionalColorUnits[i].getUnitNumber());
    }
    shader_.setUniform("dataToClip", scale);

    LGL_ERROR;
    target->renderImagePlaneRect();
    LGL_ERROR;
    shader_.deactivate();
    target->deactivateBuffer();
    LGL_ERROR;

    glUseProgram(prog);

    return true;
}
コード例 #27
0
void CurvatureRaycaster::process() {
    // compile program if needed
    if (getInvalidationLevel() >= Processor::INVALID_PROGRAM)
        compile();
    LGL_ERROR;

    // bind transfer function
    TextureUnit transferUnit;
    transferUnit.activate();
    if (transferFunc_.get())
        transferFunc_.get()->bind();

    portGroup_.activateTargets();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    LGL_ERROR;

    transferFunc_.setVolumeHandle(volumeInport_.getData());

    TextureUnit entryUnit, entryDepthUnit, exitUnit, exitDepthUnit;
    // bind entry params
    entryPort_.bindTextures(entryUnit.getEnum(), entryDepthUnit.getEnum());
    LGL_ERROR;

    // bind exit params
    exitPort_.bindTextures(exitUnit.getEnum(), exitDepthUnit.getEnum());
    LGL_ERROR;

    // vector containing the volumes to bind; is passed to bindVolumes()
    std::vector<VolumeStruct> volumeTextures;

    // add main volume
    TextureUnit volUnit, volUnit2;
    volumeTextures.push_back(VolumeStruct(
        volumeInport_.getData(),
        &volUnit,
        "volumeStruct_")
        );
    volumeTextures.push_back(VolumeStruct(
        gradientInport_.getData(),
        &volUnit2,
        "gradientVolumeParameters_")
        );

    // segmentation volume
    //VolumeHandle* volumeSeg = volumeInport_.getData()->getRelatedVolumeHandle(Modality::MODALITY_SEGMENTATION);
    VolumeHandle* volumeSeg = 0;

    bool usingSegmentation = (maskingMode_.get() == "Segmentation") && volumeSeg;
    TextureUnit segUnit;
    if (usingSegmentation) {
        // Important to set the correct texture unit before getRepresentation<VolumeGL>() is called or
        // glTexParameter() might influence the wrong texture.
        segUnit.activate();

        volumeTextures.push_back(VolumeStruct(volumeSeg,
                                              &segUnit,
                                              "segmentationParameters_"));

        // set texture filtering for this texture unit
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    }

    // initialize shader
    raycastPrg_->activate();

    // set common uniforms used by all shaders
    tgt::Camera cam = camera_.get();
    setGlobalShaderParameters(raycastPrg_, &cam);
    // bind the volumes and pass the necessary information to the shader
    bindVolumes(raycastPrg_, volumeTextures, &cam, lightPosition_.get());

    // pass the remaining uniforms to the shader
    raycastPrg_->setUniform("entryPoints_", entryUnit.getUnitNumber());
    raycastPrg_->setUniform("entryPointsDepth_", entryDepthUnit.getUnitNumber());
    entryPort_.setTextureParameters(raycastPrg_, "entryParameters_");
    raycastPrg_->setUniform("exitPoints_", exitUnit.getUnitNumber());
    raycastPrg_->setUniform("exitPointsDepth_", exitDepthUnit.getUnitNumber());
    exitPort_.setTextureParameters(raycastPrg_, "exitParameters_");

    if (compositingMode_.get() ==  "iso" ||
        compositingMode1_.get() == "iso" ||
        compositingMode2_.get() == "iso")
        raycastPrg_->setUniform("isoValue_", isoValue_.get());

    if (classificationMode_.get() == "transfer-function")
        transferFunc_.get()->setUniform(raycastPrg_, "transferFunc_", transferUnit.getUnitNumber());

    // curvature uniforms
    GLint curvatureType = -1;
    if (curvatureType_.get() == "first") curvatureType = 0;
    else if (curvatureType_.get() == "second") curvatureType = 1;
    else if (curvatureType_.get() == "mean") curvatureType = 2;
    else if (curvatureType_.get() == "gauss") curvatureType = 3;
    raycastPrg_->setUniform("curvatureType_", curvatureType);
    raycastPrg_->setUniform("curvatureFactor_", curvatureFactor_.get());
    raycastPrg_->setUniform("silhouetteWidth_", silhouetteWidth_.get());
    raycastPrg_->setUniform("minGradientLength_", minGradientLength_.get());

    LGL_ERROR;

    renderQuad();

    raycastPrg_->deactivate();

    if (usingSegmentation) {
        // restore default texture filtering mode
        segUnit.activate();
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }

    LGL_ERROR;
}
コード例 #28
0
ファイル: transfuncoverlay.cpp プロジェクト: molsimmsu/3mview
void TransFuncOverlay::process() {
    #ifndef VRN_MODULE_FONTRENDERING
    LWARNING("Empty output, enable module 'fontrendering'.");
    return;
    #endif

    tgtAssert(outport_.isReady(), "Outport not ready");
    tgtAssert(imageInport_.isReady(), "Inport not ready");
    tgtAssert(program_ && copyShader_, "Shader missing");

    if(dynamic_cast<TransFunc1DKeys*>(transferFunc_.get()) == 0){
        LWARNING("No transfer function of class TransFuncIntensity is given!!!");
        return;
    }
    TransFunc1DKeys* tfi = dynamic_cast<TransFunc1DKeys*>(transferFunc_.get());

    //render overlay
    privatePort_.activateTarget();
        glPushAttrib(GL_ALL_ATTRIB_BITS);
            glClearColor(fontColor_.get().r,fontColor_.get().g,fontColor_.get().b,0.0f);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            //render the transfer function texture
            const tgt::Texture* tfTex = 0;
            if(renderPreIntegrationTable_.get())
                tfTex = tfi->getPreIntegrationTable(1.0f / (41.0f * 2.0f))->getTexture();
            else
                tfTex = tfi->getTexture();

            tgtAssert(tfTex, "No transfer function texture");
            tfTex->bind();
            glColor4f(1.f,1.f,1.f,1.f);
            glDisable(GL_DEPTH_TEST);
                glBegin(GL_QUADS);
                    glVertex2f(-0.8f,-0.9f);
                    glVertex2f(-0.5f,-0.9f);
                    glVertex2f(-0.5f,0.7f);
                    glVertex2f(-0.8f,0.7f);
                glEnd();
                glColor4f(0.8f,0.8f,0.8f,1.f);
                glBegin(GL_QUADS);
                    glVertex2f(-0.8f,-0.9f);
                    glVertex2f(-0.65f,-0.9f);
                    glVertex2f(-0.65f,-0.58f);
                    glVertex2f(-0.8f,-0.58f);

                    glVertex2f(-0.65f,-0.58f);
                    glVertex2f(-0.5f,-0.58f);
                    glVertex2f(-0.5f,-0.26f);
                    glVertex2f(-0.65f,-0.26f);

                    glVertex2f(-0.8f,-0.26f);
                    glVertex2f(-0.65f,-0.26f);
                    glVertex2f(-0.65f,0.06f);
                    glVertex2f(-0.8f,0.06f);

                    glVertex2f(-0.65f,0.06f);
                    glVertex2f(-0.5f,0.06f);
                    glVertex2f(-0.5f,0.38f);
                    glVertex2f(-0.65f,0.38f);

                    glVertex2f(-0.8f,0.38f);
                    glVertex2f(-0.65f,0.38f);
                    glVertex2f(-0.65f,0.7f);
                    glVertex2f(-0.8f,0.7f);
                glEnd();
                glColor4f(1.f,1.f,1.f,1.f);

                if(renderPreIntegrationTable_.get())
                    glEnable(GL_TEXTURE_2D);
                else
                    glEnable(GL_TEXTURE_1D);
                
                glEnable(GL_BLEND);
                    glBlendColor(0.0f,0.0f,0.0f,overlayOpacity_.get());
                    glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ZERO,GL_CONSTANT_ALPHA);
                    glBegin(GL_QUADS);
                    if(renderPreIntegrationTable_.get()) {
                        glTexCoord2f(0.f, 0.f); glVertex2f(-0.8f,-0.9f);
                        glTexCoord2f(1.f, 0.f); glVertex2f(-0.5f,-0.9f);
                        glTexCoord2f(1.f, 1.f); glVertex2f(-0.5f,0.7f);
                        glTexCoord2f(0.f, 1.f); glVertex2f(-0.8f,0.7f);
                    }
                    else {
                        glTexCoord1f(0.f); glVertex2f(-0.8f,-0.9f);
                        glTexCoord1f(0.f); glVertex2f(-0.5f,-0.9f);
                        glTexCoord1f(1.f); glVertex2f(-0.5f,0.7f);
                        glTexCoord1f(1.f); glVertex2f(-0.8f,0.7f);
                    }
                    glEnd();
                glDisable(GL_BLEND);
                glDisable(GL_TEXTURE_1D);
            glEnable(GL_DEPTH_TEST);
            //render fonts
            glPushMatrix();
                glTranslatef(-1.f,-1.f,0.f);
                float scaleFactorX = 2.0f / (float)privatePort_.getSize().x;
                float scaleFactorY = 2.0f / (float)privatePort_.getSize().y;
                glScalef(scaleFactorX, scaleFactorY, 1.f);
                glColor4f(fontColor_.get().r,fontColor_.get().g,fontColor_.get().b,fontColor_.get().a*overlayOpacity_.get());
                fontProp_.get()->setSize(privatePort_.getSize().y/12);
                fontProp_.get()->setVerticalTextAlignment(tgt::Font::Middle);
                fontProp_.get()->setFontType(tgt::Font::BitmapFont);
                fontProp_.get()->setLineWidth(privatePort_.getSize().x*0.35f);
                fontProp_.get()->setTextAlignment(tgt::Font::Center);
                fontProp_.get()->render(tgt::vec3(0,privatePort_.getSize().y*0.925f,0), tfUnit_.get());
                fontProp_.get()->setLineWidth((float)privatePort_.getSize().x);
                fontProp_.get()->setTextAlignment(tgt::Font::Left);
                std::stringstream strstr;
                strstr << tfi->getDomain(0).x * scalingProp_.get();
                fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.05f,0), strstr.str());
                strstr.clear();
                strstr.str("");
                strstr << (tfi->getDomain(0).x+((tfi->getDomain(0).y-tfi->getDomain(0).x)/2)) * scalingProp_.get();
                fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.45f,0), strstr.str());
                strstr.clear();
                strstr.str("");
                strstr << tfi->getDomain(0).y * scalingProp_.get();
                fontProp_.get()->render(tgt::vec3(privatePort_.getSize().x*0.3f,privatePort_.getSize().y*0.85f,0), strstr.str());
            glPopMatrix();
        glPopAttrib();
         // render border around overlay
        if (renderBorder_.get()) {
            glPushAttrib(GL_ALL_ATTRIB_BITS);
                glColor4f(borderColor_.get().r,borderColor_.get().g,borderColor_.get().b,borderColor_.get().a*overlayOpacity_.get());
                glLineWidth(borderWidth_.get());
                glDepthFunc(GL_ALWAYS);
                glBegin(GL_LINE_STRIP);
                    glVertex2f(-0.8f,-0.9f);
                    glVertex2f(-0.5f,-0.9f);
                    glVertex2f(-0.5f,0.7f);
                    glVertex2f(-0.8f,0.7f);
                    glVertex2f(-0.8f,-0.9f);
                glEnd();
            glPopAttrib();
        }
        LGL_ERROR;
    privatePort_.deactivateTarget();

    //same code as in ImageOverlay
    //          |
    //          v
    outport_.activateTarget();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // bind input image to tex unit
    TextureUnit imageUnit, imageUnitDepth;
    imageInport_.bindTextures(imageUnit.getEnum(), imageUnitDepth.getEnum());

    // 1. copy input image to outport
    copyShader_->activate();
    setGlobalShaderParameters(copyShader_);
    imageInport_.setTextureParameters(copyShader_, "texParams_");
    copyShader_->setUniform("colorTex_", imageUnit.getUnitNumber());
    copyShader_->setUniform("depthTex_", imageUnitDepth.getUnitNumber());
    renderQuad();
    copyShader_->deactivate();
    LGL_ERROR;

    // 2. render overlay over copied input image (using compositor shader)
    // check, if overlay dims are greater zero
    bool dimensionsValid = ( (usePixelCoordinates_.getValue()  && tgt::hand(tgt::greaterThan(overlayDimensions_.get(), tgt::ivec2(0)))) ||
                             (!usePixelCoordinates_.getValue() && tgt::hand(tgt::greaterThan(overlayDimensionsRelative_.get(), tgt::vec2(0.f)))) );
    if (renderOverlay_.get() && /*overlayInport_.isReady() &&*/ dimensionsValid) {
        // bind overlay to tex unit
        TextureUnit overlayUnit;
        tgt::Texture* overlayTex = privatePort_.getColorTexture();//overlayInport_.getColorTexture();
        tgtAssert(overlayTex, "No overlay texture");
        overlayUnit.activate();
        overlayTex->bind();

        program_->activate();
        setGlobalShaderParameters(program_);

        // image texture parameters
        imageInport_.setTextureParameters(program_, "textureParameters0_");
        program_->setUniform("colorTex0_", imageUnit.getUnitNumber());
        program_->setUniform("depthTex0_", imageUnitDepth.getUnitNumber());
        program_->setUniform("colorTex1_", overlayUnit.getUnitNumber());
        //program_->setUniform("weightingFactor_", 1.f-overlayOpacity_.get());

        // determine overlay dimensions and bottom-left in float pixel coords
        tgt::vec2 outportDim = tgt::vec2(outport_.getSize());
        tgt::vec2 overlayDim, overlayBL;
        if (usePixelCoordinates_.getValue()) {
            overlayDim = tgt::vec2(overlayDimensions_.get());
            overlayBL = tgt::vec2(overlayBottomLeft_.get());
        }
        else {
            overlayDim = overlayDimensionsRelative_.get() * outportDim;
            overlayBL = overlayBottomLeftRelative_.get() * outportDim;
        }

        // overlay texture matrix mapping from normalized frag coords (outport) to overlay tex coords
        tgt::mat4 overlayTexCoordMatrix = tgt::mat4::identity;
        overlayTexCoordMatrix *= tgt::mat4::createScale(tgt::vec3(outportDim / overlayDim, 0.f));
        overlayTexCoordMatrix *= tgt::mat4::createTranslation(-tgt::vec3(overlayBL / outportDim, 1.f));

        // overlay texture parameters
        bool oldIgnoreError = program_->getIgnoreUniformLocationError();
        program_->setIgnoreUniformLocationError(true);
        program_->setUniform("textureParameters1_.dimensions_",    overlayDim);
        program_->setUniform("textureParameters1_.dimensionsRCP_", tgt::vec2(1.f) / overlayDim);
        program_->setUniform("textureParameters1_.matrix_", overlayTexCoordMatrix);
        program_->setIgnoreUniformLocationError(oldIgnoreError);
        LGL_ERROR;

        // render overlay at specified position and size
        tgt::vec2 bl = 2.f*overlayBL / outportDim - 1.f;
        tgt::vec2 dim = 2.f*overlayDim / outportDim;
        glDepthFunc(GL_ALWAYS);
        glBegin(GL_QUADS);
            glVertex2f(bl.x, bl.y);
            glVertex2f(bl.x + dim.x, bl.y);
            glVertex2f(bl.x + dim.x, bl.y + dim.y);
            glVertex2f(bl.x, bl.y + dim.y);
        glEnd();
        glDepthFunc(GL_LESS);
        program_->deactivate();
        LGL_ERROR;
    }

    outport_.deactivateTarget();
    TextureUnit::setZeroUnit();
    LGL_ERROR;
}
コード例 #29
0
ファイル: lightvolumegl.cpp プロジェクト: Ojaswi/inviwo
void LightVolumeGL::process() {
    bool lightColorChanged = false;

    if (lightSource_.isChanged()) {
        lightColorChanged = lightSourceChanged();
    }

    bool reattach = false;

    if (internalVolumesInvalid_ || lightColorChanged || inport_.isChanged()) {
        reattach = volumeChanged(lightColorChanged);
    }

    VolumeGL* outVolumeGL = volume_->getEditableRepresentation<VolumeGL>();
    TextureUnit volUnit;
    const VolumeGL* inVolumeGL = inport_.getData()->getRepresentation<VolumeGL>();
    inVolumeGL->bindTexture(volUnit.getEnum());
    TextureUnit transFuncUnit;
    const Layer* tfLayer = transferFunction_.get().getData();
    const LayerGL* transferFunctionGL = tfLayer->getRepresentation<LayerGL>();
    transferFunctionGL->bindTexture(transFuncUnit.getEnum());
    TextureUnit lightVolUnit[2];
    propParams_[0].vol->bindTexture(lightVolUnit[0].getEnum());
    propParams_[1].vol->bindTexture(lightVolUnit[1].getEnum());
    propagationShader_.activate();
    propagationShader_.setUniform("volume_", volUnit.getUnitNumber());
    utilgl::setShaderUniforms(propagationShader_, *inport_.getData(), "volumeParameters_");
    propagationShader_.setUniform("transferFunc_", transFuncUnit.getUnitNumber());
    propagationShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    propagationShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);

    BufferObjectArray* rectArray = utilgl::enableImagePlaneRect();

    //Perform propagation passes
    for (int i=0; i<2; ++i) {
        propParams_[i].fbo->activate();
        glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

        if (reattach)
            propParams_[i].fbo->attachColorTexture(propParams_[i].vol->getTexture().get(), 0);

        propagationShader_.setUniform("lightVolume_", lightVolUnit[i].getUnitNumber());
        propagationShader_.setUniform("permutationMatrix_", propParams_[i].axisPermutation);

        if (lightSource_.getData()->getLightSourceType() == LightSourceType::LIGHT_POINT) {
            propagationShader_.setUniform("lightPos_", lightPos_);
            propagationShader_.setUniform("permutedLightMatrix_", propParams_[i].axisPermutationLight);
        }
        else {
            propagationShader_.setUniform("permutedLightDirection_", propParams_[i].permutedLightDirection);
        }

        for (unsigned int z=0; z<volumeDimOut_.z; ++z) {
            glFramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_3D, propParams_[i].vol->getTexture()->getID(), 0, z);
            propagationShader_.setUniform("sliceNum_", static_cast<GLint>(z));
            glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
            glFlush();
        }

        propParams_[i].fbo->deactivate();
    }

    utilgl::disableImagePlaneRect(rectArray);

    propagationShader_.deactivate();
    mergeShader_.activate();
    mergeShader_.setUniform("lightVolume_", lightVolUnit[0].getUnitNumber());
    mergeShader_.setUniform("lightVolumeSec_", lightVolUnit[1].getUnitNumber());
    mergeShader_.setUniform("lightVolumeParameters_.dimensions", volumeDimOutF_);
    mergeShader_.setUniform("lightVolumeParameters_.reciprocalDimensions", volumeDimOutFRCP_);
    mergeShader_.setUniform("permMatInv_", propParams_[0].axisPermutationINV);
    mergeShader_.setUniform("permMatInvSec_", propParams_[1].axisPermutationINV);
    mergeShader_.setUniform("blendingFactor_", blendingFactor_);
    //Perform merge pass
    mergeFBO_->activate();
    glViewport(0, 0, static_cast<GLsizei>(volumeDimOut_.x), static_cast<GLsizei>(volumeDimOut_.y));

    if (reattach)
        mergeFBO_->attachColorTexture(outVolumeGL->getTexture().get(), 0);

    utilgl::multiDrawImagePlaneRect(static_cast<int>(volumeDimOut_.z));
    mergeShader_.deactivate();
    mergeFBO_->deactivate();
}
コード例 #30
0
ファイル: textureutils.cpp プロジェクト: sarbi127/inviwo
void bindTexture(const TransferFunctionProperty& tfp, const TextureUnit& texUnit) { 
    if (auto tfLayer = tfp.get().getData()) {
        auto transferFunctionGL = tfLayer->getRepresentation<LayerGL>();
        transferFunctionGL->bindTexture(texUnit.getEnum());
    }
}