Added option to choose mirror or repeat texture on source

This commit is contained in:
brunoherbelin
2021-03-18 19:43:51 +01:00
parent 0de1b87028
commit dd9c8ac0b8
7 changed files with 36 additions and 8 deletions

View File

@@ -19,7 +19,7 @@
Surface::Surface(Shader *s) : Primitive(s), textureindex_(0)
Surface::Surface(Shader *s) : Primitive(s), textureindex_(0), mirror_(true)
{
// geometry for a trianglulated simple rectangle surface with UV
// (0,0) B +---+ D (1,0)
@@ -89,12 +89,8 @@ void Surface::draw(glm::mat4 modelview, glm::mat4 projection)
glActiveTexture(GL_TEXTURE0);
if ( textureindex_ ) {
glBindTexture(GL_TEXTURE_2D, textureindex_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // TODO add user input to select mode
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mirror_ ? GL_MIRRORED_REPEAT : GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mirror_ ? GL_MIRRORED_REPEAT : GL_REPEAT);
}
else
glBindTexture(GL_TEXTURE_2D, Resource::getTextureBlack());

View File

@@ -30,8 +30,12 @@ public:
inline void setTextureIndex(uint t) { textureindex_ = t; }
inline uint textureIndex() const { return textureindex_; }
inline void setMirrorTexture(bool m) { mirror_ = m; }
inline bool mirrorTexture() { return mirror_; }
protected:
uint textureindex_;
bool mirror_;
};

View File

@@ -521,7 +521,12 @@ void SessionLoader::visit (Source& s)
if (xmlCurrent_) s.groupNode(View::LAYER)->accept(*this);
xmlCurrent_ = sourceNode->FirstChildElement("Texture");
if (xmlCurrent_) s.groupNode(View::TEXTURE)->accept(*this);
if (xmlCurrent_) {
s.groupNode(View::TEXTURE)->accept(*this);
bool m = true;
xmlCurrent_->QueryBoolAttribute("mirrored", &m);
s.setTextureMirrored(m);
}
xmlCurrent_ = sourceNode->FirstChildElement("Blending");
if (xmlCurrent_) s.blendingShader()->accept(*this);

View File

@@ -345,6 +345,7 @@ void SessionVisitor::visit (Source& s)
s.groupNode(View::LAYER)->accept(*this);
xmlCurrent_ = xmlDoc_->NewElement( "Texture" );
xmlCurrent_->SetAttribute("mirrored", s.textureMirrored() );
sourceNode->InsertEndChild(xmlCurrent_);
s.groupNode(View::TEXTURE)->accept(*this);

View File

@@ -350,6 +350,16 @@ void Source::setImageProcessingEnabled (bool on)
texturesurface_->replaceShader(renderingshader_);
}
void Source::setTextureMirrored (bool on)
{
texturesurface_->setMirrorTexture(on);
}
bool Source::textureMirrored ()
{
return texturesurface_->mirrorTexture();
}
bool Source::imageProcessingEnabled()
{
return ( renderingshader_ == processingshader_ );

View File

@@ -119,6 +119,8 @@ public:
// a Source shall define a way to get a texture
virtual uint texture () const = 0;
void setTextureMirrored (bool on);
bool textureMirrored ();
// a Source shall define how to render into the frame buffer
virtual void render ();

View File

@@ -828,6 +828,16 @@ void TextureView::draw()
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.36f, 0.36f, 0.36f, 0.44f));
Source *s = Mixer::manager().currentSource();
if (s != nullptr) {
if (s->textureMirrored()) {
if (ImGui::Selectable( ICON_FA_TH " Repeat " ))
s->setTextureMirrored(false);
} else {
if (ImGui::Selectable( ICON_FA_TH " Mirror " ))
s->setTextureMirrored(true);
}
ImGui::Separator();
if (ImGui::Selectable( ICON_FA_VECTOR_SQUARE " Reset" )){
s->group(mode_)->scale_ = glm::vec3(1.f);
s->group(mode_)->rotation_.z = 0;