本文整理汇总了C++中TextureUnit类的典型用法代码示例。如果您正苦于以下问题:C++ TextureUnit类的具体用法?C++ TextureUnit怎么用?C++ TextureUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TextureUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bindAndSetUniforms
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: bindAndSetUniforms
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: translate
//------------------------------------------------------------------------------//
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: setGlobalShaderParameters
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: Image
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();
}
示例6: preProcess
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());
}
示例7: depthTest
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();
}
示例8: setGlobalShaderParameters
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;
}
示例9: generateJitterTexture
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();
}
示例10: glClear
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;
}
示例11: bindTexture
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");
}
}
示例12: renderLayer
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();
}
示例13: bypass
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;
}
示例14: getTextureUnit
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);
}
}
示例15: glEnable
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);
}