Commit 31e76d0f authored by Jan Möbius's avatar Jan Möbius

Merge branch 'texcontrol_update' into 'master'

update texture control plugin

fixed issue #36 
- change object drawmode instead of the global viewer mode upon texture assignment


fixed issues #1 and #13 
- integrate bspline surface into texture control plugin
- I've tested this just now on linux

can be merged now

See merge request !110
parents 964898ed 90c5d13d
Pipeline #2164 passed with stage
in 82 minutes and 58 seconds
......@@ -555,7 +555,10 @@ void TextureNode::leavePick(GLState& /*_state*/, PickTarget /*_target*/, const D
GLuint TextureNode::activeTexture()
{
return textures_[activeTexture_].tex->id();
if (0 <= activeTexture_ && activeTexture_ < int(textures_.size()))
return textures_[activeTexture_].tex->id();
return 0;
}
//----------------------------------------------------------------------------
......
......@@ -144,6 +144,9 @@ getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMod
// because normals aren't available in the vertex shader
ro.shaderDesc.texGenPerFragment = true;
if ( props->textured() && arb_texture_idx_)
ro.addTexture(ACG::RenderObject::Texture(arb_texture_idx_), 0);
if (props->primitive() == DrawModes::PRIMITIVE_POLYGON || props->primitive() == DrawModes::PRIMITIVE_WIREFRAME)
{
updateSurfaceMesh();
......@@ -414,8 +417,8 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
if ((_drawMode & DrawModes::SOLID_TEXTURED) || (_drawMode & DrawModes::SOLID_ENV_MAPPED)) {
ACG::GLState::enable(GL_AUTO_NORMAL);
ACG::GLState::enable(GL_NORMALIZE);
ACG::GLState::enable (GL_BLEND);
ACG::GLState::blendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// ACG::GLState::enable (GL_BLEND);
// ACG::GLState::blendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ACG::GLState::enable(GL_LIGHTING);
ACG::GLState::shadeModel(GL_SMOOTH);
ACG::GLState::depthRange(0.01, 1.0);
......@@ -425,7 +428,7 @@ draw(GLState& _state, const DrawModes::DrawMode& _drawMode)
arb_texture_used_ = false;
ACG::GLState::depthRange(0.0, 1.0);
ACG::GLState::disable(GL_BLEND);
// ACG::GLState::disable(GL_BLEND);
}
glPopAttrib();
......@@ -490,8 +493,8 @@ BSplineSurfaceNodeT<BSplineSurfaceType>::
drawTexturedSurface(GLState& _state, GLuint _texture_idx)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
ACG::GLState::enable( GL_COLOR_MATERIAL );
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
// ACG::GLState::enable( GL_COLOR_MATERIAL );
// glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
ACG::GLState::enable(GL_TEXTURE_2D);
......@@ -518,7 +521,7 @@ drawTexturedSurface(GLState& _state, GLuint _texture_idx)
ACG::GLState::bindTexture( GL_TEXTURE_2D, 0);
ACG::GLState::disable(GL_TEXTURE_2D);
ACG::GLState::disable( GL_COLOR_MATERIAL );
// ACG::GLState::disable( GL_COLOR_MATERIAL );
glPopAttrib( );
}
......
......@@ -212,10 +212,12 @@ class BSplineSurfaceNodeT : public BaseNode
/// use arbitrary texture (in SOLID_TEXTURED mode)
void set_arb_texture( const QImage& _texture, bool _repeat = false, float _u_repeat = 1.0f, float _v_repeat = 1.0f);
void set_repeat_arb_texture( bool _repeat = true, float _urep = 5.0f, float _vrep = 5.0f) { arb_texture_repeat_ = _repeat; arb_texture_repeat_u_ = _urep; arb_texture_repeat_v_ = _vrep; }
void set_arb_texture(const GLuint _texture) { arb_texture_idx_ = _texture; }
void set_repeat_arb_texture(bool _repeat = true, float _urep = 5.0f, float _vrep = 5.0f) { arb_texture_repeat_ = _repeat; arb_texture_repeat_u_ = _urep; arb_texture_repeat_v_ = _vrep; }
bool get_repeat_arb_texture( ) { return arb_texture_repeat_; }
private:
void pick_vertices( GLState& _state );
......
......@@ -246,6 +246,9 @@ update(UpdateType _type)
splineSurfaceNode()->knotSelectionTextureValid(false);
splineSurfaceNode()->updateGeometry();
if (textureNode())
splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
}
else
{
......@@ -262,6 +265,9 @@ update(UpdateType _type)
splineSurfaceNode()->cpSelectionTextureValid(false);
else if (_type.contains(UPDATE_SELECTION_KNOTS))
splineSurfaceNode()->knotSelectionTextureValid(false);
if (_type.contains(UPDATE_TEXTURE) && textureNode())
splineSurfaceNode()->set_arb_texture(textureNode()->activeTexture());
}
}
......
......@@ -16,6 +16,10 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/HexahedralMesh)
list( APPEND CURRENT_PLUGIN_DEPS OpenVolumeMesh )
endif()
if (EXISTS ${CMAKE_SOURCE_DIR}/ObjectTypes/BSplineSurface)
add_definitions (-DENABLE_BSPLINESURFACE_SUPPORT)
endif()
list(REMOVE_DUPLICATES CURRENT_PLUGIN_DEPS )
# use Qwt6 for QT5
......
......@@ -127,6 +127,11 @@ void TextureControlPlugin::slotTextureAdded( QString _textureName , QString _fil
glName = PluginFunctions::polyhedralMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newId,0));
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
if (obj->dataType(DATA_BSPLINE_SURFACE))
glName = PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->add_texture(imageStore().getImage(newId, 0));
#endif
// ================================================================================
// Store texture information in objects metadata
// ================================================================================
......@@ -244,6 +249,9 @@ void TextureControlPlugin::addedEmptyObject( int _id ) {
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
&& !obj->dataType(DATA_POLYHEDRAL_MESH)
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
&& !obj->dataType(DATA_BSPLINE_SURFACE)
#endif
)
{
......@@ -288,6 +296,11 @@ void TextureControlPlugin::addedEmptyObject( int _id ) {
if ( obj->dataType( DATA_POLYHEDRAL_MESH ) )
glName = PluginFunctions::polyhedralMeshObject(obj)->textureNode()->add_texture(imageStore().getImage(newImageId,0));
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
if (obj->dataType(DATA_BSPLINE_SURFACE))
glName = PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->add_texture(imageStore().getImage(newImageId, 0));
#endif
// ================================================================================
// Store texture information in objects metadata
......@@ -458,6 +471,12 @@ void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if (obj->dataType(DATA_BSPLINE_SURFACE)) {
PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->set_texture(_image, texData->texture(_textureName).glName());
}
#endif
emit updateView();
}
......@@ -508,6 +527,11 @@ void TextureControlPlugin::slotTextureChangeImage( QString _textureName , QImage
else if ( o_it->dataType( DATA_POLYHEDRAL_MESH ) ) {
PluginFunctions::polyhedralMeshObject(o_it)->textureNode()->set_texture( _image , texData->texture(_textureName).glName());
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if (o_it->dataType(DATA_BSPLINE_SURFACE)) {
PluginFunctions::bsplineSurfaceObject(o_it)->textureNode()->set_texture(_image, texData->texture(_textureName).glName());
}
#endif
}
}
......@@ -765,6 +789,9 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
&& !obj->dataType( DATA_POLYHEDRAL_MESH )
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
&& !obj->dataType(DATA_BSPLINE_SURFACE)
#endif
)
return;
......@@ -834,6 +861,15 @@ void TextureControlPlugin::slotTextureUpdated( QString _textureName , int _ident
PluginFunctions::polyhedralMeshObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if (obj->dataType(DATA_BSPLINE_SURFACE)) {
// texcoords are parametric so nothing to update in the bspline surface mesh
// Texture has been bound to that object by slotAddTexture.. directly or by fileOpened from global texture
// Just activate it
PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName());
PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->set_repeat(texData->texture(_textureName).parameters.repeat);
}
#endif
// ================================================================================
// Mark texture as not dirty
......@@ -1030,6 +1066,9 @@ void TextureControlPlugin::slotObjectUpdated(int _identifier, const UpdateType&
#endif
#ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
&& !obj->dataType( DATA_POLYHEDRAL_MESH )
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
&& !obj->dataType(DATA_BSPLINE_SURFACE)
#endif
)
return;
......@@ -1366,6 +1405,10 @@ void TextureControlPlugin::pluginsInitialized() {
emit addContextMenuItem(contextMenu_->menuAction() ,DATA_POLYHEDRAL_MESH , CONTEXTOBJECTMENU );
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
emit addContextMenuItem(contextMenu_->menuAction(), DATA_BSPLINE_SURFACE, CONTEXTOBJECTMENU);
#endif
slotTextureAdded("Reflection Lines","reflection_map.png",2);
slotSetTextureMode("Reflection Lines","type=environmentmap");
}
......@@ -1409,6 +1452,12 @@ void TextureControlPlugin::applyDialogSettings(TextureData* _texData, QString _t
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if (obj->dataType(DATA_BSPLINE_SURFACE)) {
PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->set_texture(imageStore().getImage(texture.textureImageId(), 0), texture.glName());
}
#endif
// Always mark texture as dirty
_texData->texture( _textureName ).setDirty();
......@@ -1500,7 +1549,7 @@ void TextureControlPlugin::slotTextureMenu(QAction* _action) {
TextureData* texData = dynamic_cast< TextureData* > ( o_it->objectData(TEXTUREDATA) );
if (texData != 0) {
switchDrawMode(texData->texture(_action->text()).type());
switchDrawMode(texData->texture(_action->text()).type(), o_it->id());
}
}
......@@ -1678,6 +1727,12 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
// Activate the requested texture in texture node
PluginFunctions::polyhedralMeshObject(obj)->textureNode()->activateTexture( texData->texture( _textureName ).glName() );
}
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
else if (obj->dataType(DATA_BSPLINE_SURFACE)){
// Activate the requested texture in texture node
PluginFunctions::bsplineSurfaceObject(obj)->textureNode()->activateTexture(texData->texture(_textureName).glName());
}
#endif
else {
emit log(LOGERR, "doSwitchTexture: Texture Error ( mesh required) for Texture: " + _textureName );
......@@ -1688,46 +1743,28 @@ void TextureControlPlugin::doSwitchTexture( QString _textureName , int _id ) {
}
void TextureControlPlugin::switchDrawMode( TextureType _type ) {
bool textureMode = false;
for ( int j = 0 ; j < PluginFunctions::viewers() ; ++j ) {
switch (_type) {
case MULTITEXTURE:
case HALFEDGEBASED:
textureMode |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE );
textureMode |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE_SHADED );
break;
case VERTEXBASED:
textureMode |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED );
textureMode |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED );
break;
case ENVIRONMENT:
textureMode |= ( PluginFunctions::drawMode(j) == ACG::SceneGraph::DrawModes::SOLID_ENV_MAPPED );
break;
case UNSET:
emit log(LOGERR,"doSwitchTexture: Switching drawmode for unknown Texture Type!");
break;
}
}
void TextureControlPlugin::switchDrawMode( TextureType _type, int _id ) {
if ( !textureMode ) {
switch (_type) {
case MULTITEXTURE:
case HALFEDGEBASED:
PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE_SHADED, PluginFunctions::ALL_VIEWERS );
break;
case VERTEXBASED:
PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED , PluginFunctions::ALL_VIEWERS);
break;
case ENVIRONMENT:
PluginFunctions::setDrawMode( ACG::SceneGraph::DrawModes::SOLID_ENV_MAPPED , PluginFunctions::ALL_VIEWERS);
break;
case UNSET:
emit log(LOGERR,"doSwitchTexture: Switching drawmode for unknonw Texture Type!");
break;
}
// Get the new object
BaseObjectData* obj;
if (!PluginFunctions::getObject(_id, obj)) {
emit log(LOGERR, "doSwitchTexture: Unable to get Object for id " + QString::number(_id));
}
switch (_type) {
case MULTITEXTURE:
case HALFEDGEBASED:
obj->setObjectDrawMode(ACG::SceneGraph::DrawModes::SOLID_2DTEXTURED_FACE_SHADED, PluginFunctions::ALL_VIEWERS);
break;
case VERTEXBASED:
obj->setObjectDrawMode(ACG::SceneGraph::DrawModes::SOLID_TEXTURED_SHADED, PluginFunctions::ALL_VIEWERS);
break;
case ENVIRONMENT:
obj->setObjectDrawMode(ACG::SceneGraph::DrawModes::SOLID_ENV_MAPPED, PluginFunctions::ALL_VIEWERS);
break;
case UNSET:
emit log(LOGERR, "doSwitchTexture: Switching drawmode for unknonw Texture Type!");
break;
}
emit updateView();
......@@ -1770,6 +1807,9 @@ void TextureControlPlugin::slotUpdateContextMenu( int _objectId ) {
#endif
#ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
&& !obj->dataType( DATA_POLYHEDRAL_MESH )
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
&& !obj->dataType(DATA_BSPLINE_SURFACE)
#endif
)
{
......@@ -1855,7 +1895,7 @@ void TextureControlPlugin::slotTextureContextMenu( QAction * _action ) {
slotSwitchTexture( _action->text() , id );
// Switch to a texture drawMode
switchDrawMode(texData->texture( _action->text() ).type());
switchDrawMode(texData->texture( _action->text() ).type(), id);
}
}
......
......@@ -75,6 +75,10 @@
#include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
#endif
#ifdef ENABLE_BSPLINESURFACE_SUPPORT
#include <ObjectTypes/BSplineSurface/BSplineSurface.hh>
#endif
#include <OpenFlipper/common/Types.hh>
#include "textureProperties.hh"
......@@ -178,7 +182,7 @@ class TextureControlPlugin : public QObject, BaseInterface, BackupInterface, Tex
bool StringToBool(QString _value);
/// Checks for a correct drawmode and changes if necessary
void switchDrawMode( TextureType _type );
void switchDrawMode( TextureType _type, int _id );
TextureData globalTextures_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment