Commit d46f1884 authored by Jan Möbius's avatar Jan Möbius
Browse files

Merge branch 'more_warnings' into 'master'

More warnings

A bunch of warnings fixed due to implicit conversions

See merge request !171
parents d677a929 dea303a7
Pipeline #3302 passed with stage
in 70 minutes and 56 seconds
......@@ -103,7 +103,7 @@ void ColorStack::initialize ()
//----------------------------------------------------------------------------
bool ColorStack::setMaximumIndex (unsigned int _idx)
bool ColorStack::setMaximumIndex (size_t _idx)
{
if (initialized_)
{
......@@ -117,7 +117,7 @@ bool ColorStack::setMaximumIndex (unsigned int _idx)
//----------------------------------------------------------------------------
void ColorStack::setIndex (unsigned int _idx)
void ColorStack::setIndex (size_t _idx)
{
if (initialized_)
{
......@@ -128,7 +128,7 @@ void ColorStack::setIndex (unsigned int _idx)
//----------------------------------------------------------------------------
Vec4uc ColorStack::getIndexColor (unsigned int _idx)
Vec4uc ColorStack::getIndexColor (size_t _idx)
{
if (initialized_)
{
......@@ -144,7 +144,7 @@ Vec4uc ColorStack::getIndexColor (unsigned int _idx)
//----------------------------------------------------------------------------
void ColorStack::pushIndex (unsigned int _idx)
void ColorStack::pushIndex (size_t _idx)
{
if (initialized_)
currentNode_ = currentNode_->pushIndex (_idx);
......@@ -160,12 +160,12 @@ void ColorStack::popIndex ()
//----------------------------------------------------------------------------
std::vector<unsigned int> ColorStack::colorToStack (Vec4uc _rgba) const
std::vector<size_t> ColorStack::colorToStack (Vec4uc _rgba) const
{
std::vector<unsigned int> rv(0);
std::vector<size_t> rv(0);
if (initialized_ && !error_)
{
unsigned int idx = translator_.color2index (_rgba);
const size_t idx = translator_.color2index (_rgba);
if (idx >= root_->startIndex () && idx < root_->endIndex ())
root_->colorToStack (rv, idx);
}
......@@ -174,7 +174,7 @@ std::vector<unsigned int> ColorStack::colorToStack (Vec4uc _rgba) const
//----------------------------------------------------------------------------
unsigned int ColorStack::freeIndicies() const
size_t ColorStack::freeIndicies() const
{
if (initialized_)
{
......@@ -186,7 +186,7 @@ unsigned int ColorStack::freeIndicies() const
//----------------------------------------------------------------------------
unsigned int ColorStack::currentIndex () const
size_t ColorStack::currentIndex () const
{
if (initialized_)
{
......@@ -198,7 +198,7 @@ unsigned int ColorStack::currentIndex () const
//----------------------------------------------------------------------------
ColorStack::Node::Node (unsigned int _idx, Node *_parent, ColorTranslator *_ct) :
ColorStack::Node::Node (size_t _idx, Node *_parent, ColorTranslator *_ct) :
parent_(_parent),
index_(_idx),
translator_(_ct),
......@@ -221,7 +221,7 @@ ColorStack::Node::~Node ()
//----------------------------------------------------------------------------
bool ColorStack::Node::setMaximumIndex (unsigned int _idx)
bool ColorStack::Node::setMaximumIndex (size_t _idx)
{
if (_idx == 0)
_idx = 1;
......@@ -237,7 +237,7 @@ bool ColorStack::Node::setMaximumIndex (unsigned int _idx)
//----------------------------------------------------------------------------
bool ColorStack::Node::setIndex (unsigned int _idx) const
bool ColorStack::Node::setIndex (size_t _idx) const
{
if (colorStartIdx_ && colorStartIdx_ + _idx < colorEndIdx_)
{
......@@ -249,7 +249,7 @@ bool ColorStack::Node::setIndex (unsigned int _idx) const
//----------------------------------------------------------------------------
bool ColorStack::Node::getIndexColor (unsigned int _idx, Vec4uc &_rgba) const
bool ColorStack::Node::getIndexColor (size_t _idx, Vec4uc &_rgba) const
{
if (colorStartIdx_ && colorStartIdx_ + _idx < colorEndIdx_)
{
......@@ -261,7 +261,7 @@ bool ColorStack::Node::getIndexColor (unsigned int _idx, Vec4uc &_rgba) const
//----------------------------------------------------------------------------
ColorStack::Node * ColorStack::Node::pushIndex (unsigned int _idx)
ColorStack::Node * ColorStack::Node::pushIndex (size_t _idx)
{
ColorStack::Node *n = new ColorStack::Node (_idx, this, translator_);
nodes_.push_back (n);
......@@ -278,7 +278,7 @@ ColorStack::Node * ColorStack::Node::popIndex ()
//----------------------------------------------------------------------------
void ColorStack::Node::colorToStack (std::vector<unsigned int> &_stack, unsigned int _index)
void ColorStack::Node::colorToStack (std::vector<size_t> &_stack, size_t _index)
{
if (_index >= colorStartIdx_ && _index < colorEndIdx_)
{
......
......@@ -95,31 +95,31 @@ public:
bool initialized() const { return initialized_; }
/// sets the maximum index number used in current node
bool setMaximumIndex (unsigned int _idx);
bool setMaximumIndex (size_t _idx);
/// sets the current color the given index (like glLoadName)
void setIndex (unsigned int _idx);
void setIndex (size_t _idx);
/// gets the color instead of setting it directly
Vec4uc getIndexColor (unsigned int _idx);
Vec4uc getIndexColor (size_t _idx);
/// creates a new node the stack (like glPushName)
void pushIndex (unsigned int _idx);
void pushIndex (size_t _idx);
/// pops the current node from the stack (like glPopName)
void popIndex ();
/// converts the given color to index values on the stack
std::vector<unsigned int> colorToStack (Vec4uc _rgba) const;
std::vector<size_t> colorToStack (Vec4uc _rgba) const;
/// returns maximal available index count
unsigned int freeIndicies () const;
size_t freeIndicies () const;
/// Did an error occur during picking
bool error () const { return error_ && initialized_; };
/// returns the current color index
unsigned int currentIndex () const;
size_t currentIndex () const;
private:
......@@ -127,40 +127,40 @@ private:
class Node {
public:
Node (unsigned int _idx, Node *_parent, ColorTranslator *_ct);
Node (size_t _idx, Node *_parent, ColorTranslator *_ct);
~Node ();
/// sets the maximum index number used in current node
bool setMaximumIndex (unsigned int _idx);
bool setMaximumIndex (size_t _idx);
/// sets the current color the given index (like glLoadName)
bool setIndex (unsigned int _idx) const;
bool setIndex (size_t _idx) const;
/// gets the color instead of setting it directly
bool getIndexColor (unsigned int _idx, Vec4uc &_rgba) const;
bool getIndexColor (size_t _idx, Vec4uc &_rgba) const;
/// creates a new node the stack (like glPushName)
Node * pushIndex (unsigned int _idx);
Node * pushIndex (size_t _idx);
/// pops the current node from the stack (like glPopName)
Node * popIndex ();
void colorToStack (std::vector<unsigned int> &_stack, unsigned int _index);
void colorToStack (std::vector<size_t> &_stack, size_t size_t);
unsigned int startIndex () { return startIdx_; };
unsigned int endIndex () { return endIdx_; };
unsigned int colorIndex () { return colorStartIdx_; };
size_t startIndex () const { return startIdx_; };
size_t endIndex () const { return endIdx_; };
size_t colorIndex () const { return colorStartIdx_; };
private:
Node *parent_;
unsigned int index_;
size_t index_;
ColorTranslator *translator_;
std::vector<Node *> nodes_;
unsigned int startIdx_;
unsigned int endIdx_;
unsigned int colorStartIdx_;
unsigned int colorEndIdx_;
size_t startIdx_;
size_t endIdx_;
size_t colorStartIdx_;
size_t colorEndIdx_;
};
......
......@@ -61,6 +61,7 @@
#include "ColorTranslator.hh"
#include <iostream>
#include <limits>
//== NAMESPACES ===============================================================
......@@ -81,21 +82,25 @@ initialize()
glGetIntegerv( GL_BLUE_BITS, &blue_bits_ );
glGetIntegerv( GL_ALPHA_BITS, &alpha_bits_ );
// We currently only support up to 8 bits per channel (
if (red_bits_ > 8) red_bits_ = 8;
if (green_bits_ > 8) green_bits_ = 8;
if (blue_bits_ > 8) blue_bits_ = 8;
if (alpha_bits_ > 8) alpha_bits_ = 8;
// Compute the mask to extract the component
red_mask_ = ((1 << red_bits_) - 1);
green_mask_ = ((1 << green_bits_) - 1);
blue_mask_ = ((1 << blue_bits_) - 1);
alpha_mask_ = ((1 << alpha_bits_) - 1);
// Shift required to move the component to the lowest bits
red_shift_ = 8 - red_bits_;
green_shift_ = 8 - green_bits_;
blue_shift_ = 8 - blue_bits_;
alpha_shift_ = 8 - alpha_bits_;
red_round_ = 1 << (red_shift_ - 1);
green_round_ = 1 << (green_shift_ - 1);
blue_round_ = 1 << (blue_shift_ - 1);
......@@ -110,12 +115,19 @@ initialize()
Vec4uc
ColorTranslator::
index2color(unsigned int _idx) const
index2color(const size_t _idx) const
{
assert(initialized());
unsigned char r, g, b, a;
unsigned int idx(_idx+1);
// Make sure that the number fits
if ( _idx > std::numeric_limits<unsigned int>::max() ) {
std::cerr << "Can't convert index " << _idx << " to RGBA. Number too large for unsigned int \n";
return Vec4uc(0, 0, 0, 0);
}
unsigned int idx = ( static_cast<unsigned int>(_idx) + 1);
b = ((idx & blue_mask_) << blue_shift_) | blue_round_;
idx >>= blue_bits_;
g = ((idx & green_mask_) << green_shift_) | green_round_;
......@@ -139,13 +151,18 @@ index2color(unsigned int _idx) const
//-----------------------------------------------------------------------------
int
size_t
ColorTranslator::
color2index(Vec4uc _rgba) const
color2index(const Vec4uc _rgba) const
{
assert(initialized());
// Work internally with#include <iostream> unsigned int for now
unsigned int result;
// Combine the single unsigned chars according to masks
result = _rgba[3] >> alpha_shift_;
result <<= red_bits_;
result = _rgba[0] >> red_shift_;
......@@ -154,14 +171,15 @@ color2index(Vec4uc _rgba) const
result <<= blue_bits_;
result |= _rgba[2] >> blue_shift_;
return (result-1);
// Return size_t Here
return ( static_cast<size_t>(result-1) );
}
//-----------------------------------------------------------------------------
unsigned int
size_t
ColorTranslator::max_index() const
{
assert(initialized());
......
......@@ -95,20 +95,23 @@ public:
~ColorTranslator() {};
/// init (takes current GL context)
/// init (takes current GL context to get the component sizes)
/// Can't use constructor as we might not have a context at this point.
void initialize();
/// has it been initialized?
bool initialized() const { return initialized_; }
/// index -> color (one buffer)
Vec4uc index2color(unsigned int _idx) const;
Vec4uc index2color(const size_t _idx) const;
/// color -> index (one buffer)
int color2index(Vec4uc _rgba) const;
size_t color2index(const Vec4uc _rgba) const;
/// returns maximal convertable index
unsigned int max_index() const;
/// returns maximal convertible index
size_t max_index() const;
private:
......
......@@ -474,7 +474,7 @@ public:
* @param _mvp model view projection transformation
* @param _pickOffset base picking id of the first vertex
*/
void drawPickingVertices_opt(const GLMatrixf& _mvp, int _pickOffset);
void drawPickingVertices_opt(const GLMatrixf& _mvp, size_t _pickOffset);
/** \brief Check if optimized vertex picking is supported
......@@ -559,7 +559,7 @@ public:
* @param _mvp model view projection transformation
* @param _pickOffset base picking id of the first edge
*/
void drawPickingEdges_opt(const GLMatrixf& _mvp, int _pickOffset);
void drawPickingEdges_opt(const GLMatrixf& _mvp, size_t _pickOffset);
/** \brief Check if optimized face picking is supported
......@@ -628,7 +628,7 @@ public:
* @param _mvp model view projection transformation
* @param _pickOffset base picking id of the first face
*/
void drawPickingFaces_opt(const GLMatrixf& _mvp, int _pickOffset);
void drawPickingFaces_opt(const GLMatrixf& _mvp, size_t _pickOffset);
/** \brief Check if optimized face picking is supported
......@@ -734,7 +734,7 @@ public:
* @param _mvp model view projection transformation
* @param _pickOffset base picking id of the first element
*/
void drawPickingAny_opt(const GLMatrixf& _mvp, int _pickOffset);
void drawPickingAny_opt(const GLMatrixf& _mvp, size_t _pickOffset);
/** \brief Check if optimized any picking is supported
*
......
......@@ -454,7 +454,7 @@ DrawMeshT<Mesh>::rebuild()
// read all vertices
for (size_t i = 0; i < numVerts_; ++i)
readVertex(i,
mesh_.vertex_handle(i),
mesh_.vertex_handle(static_cast<unsigned int>(i)),
(typename Mesh::HalfedgeHandle)(-1),
(typename Mesh::FaceHandle)(-1));
......@@ -1689,7 +1689,7 @@ bool ACG::DrawMeshT<Mesh>::supportsPickingVertices_opt()
template <class Mesh>
void ACG::DrawMeshT<Mesh>::drawPickingVertices_opt( const GLMatrixf& _mvp, int _pickOffset )
void ACG::DrawMeshT<Mesh>::drawPickingVertices_opt( const GLMatrixf& _mvp, size_t _pickOffset )
{
// optimized version which computes picking ids in the shader
......@@ -1724,7 +1724,7 @@ void ACG::DrawMeshT<Mesh>::drawPickingVertices_opt( const GLMatrixf& _mvp, int _
pickVertexShader_->use();
getVertexDeclaration()->activateShaderPipeline(pickVertexShader_);
pickVertexShader_->setUniform("pickVertexOffset", _pickOffset);
pickVertexShader_->setUniform("pickVertexOffset", static_cast<GLint>(_pickOffset) );
if (pickVertexMethod_ == 0)
{
......@@ -1960,7 +1960,7 @@ bool ACG::DrawMeshT<Mesh>::supportsPickingEdges_opt()
template <class Mesh>
void ACG::DrawMeshT<Mesh>::drawPickingEdges_opt( const GLMatrixf& _mvp, int _pickOffset )
void ACG::DrawMeshT<Mesh>::drawPickingEdges_opt( const GLMatrixf& _mvp, size_t _pickOffset )
{
// optimized version which computes picking ids in the shader
......@@ -1988,7 +1988,7 @@ void ACG::DrawMeshT<Mesh>::drawPickingEdges_opt( const GLMatrixf& _mvp, int _pic
pickEdgeShader_->use();
getVertexDeclaration()->activateShaderPipeline(pickEdgeShader_);
pickEdgeShader_->setUniform("pickVertexOffset", _pickOffset);
pickEdgeShader_->setUniform("pickVertexOffset", static_cast<GLint>(_pickOffset) );
pickEdgeShader_->setUniform("mWVP", _mvp);
// draw call
......@@ -2091,7 +2091,7 @@ bool ACG::DrawMeshT<Mesh>::supportsPickingFaces_opt()
template <class Mesh>
void ACG::DrawMeshT<Mesh>::drawPickingFaces_opt( const GLMatrixf& _mvp, int _pickOffset )
void ACG::DrawMeshT<Mesh>::drawPickingFaces_opt( const GLMatrixf& _mvp, size_t _pickOffset )
{
// optimized version which computes picking ids in the shader
......@@ -2137,7 +2137,7 @@ void ACG::DrawMeshT<Mesh>::drawPickingFaces_opt( const GLMatrixf& _mvp, int _pic
pickFaceShader_->use();
getVertexDeclaration()->activateShaderPipeline(pickFaceShader_);
pickFaceShader_->setUniform("pickFaceOffset", _pickOffset);
pickFaceShader_->setUniform("pickFaceOffset", static_cast<GLint>(_pickOffset));
pickFaceShader_->setUniform("triToFaceMap", 0);
#ifdef GL_ARB_texture_buffer_object
......@@ -2255,7 +2255,7 @@ bool ACG::DrawMeshT<Mesh>::supportsPickingAny_opt()
template <class Mesh>
void ACG::DrawMeshT<Mesh>::drawPickingAny_opt( const GLMatrixf& _mvp, int _pickOffset )
void ACG::DrawMeshT<Mesh>::drawPickingAny_opt( const GLMatrixf& _mvp, size_t _pickOffset )
{
// optimized version which computes picking ids in the shader
......
......@@ -1044,7 +1044,7 @@ void GLState::pick_init (bool _color)
//-----------------------------------------------------------------------------
bool GLState::pick_set_maximum (unsigned int _idx)
bool GLState::pick_set_maximum (size_t _idx)
{
bool rv = colorStack_.setMaximumIndex (_idx);
if (colorPicking_)
......@@ -1054,14 +1054,14 @@ bool GLState::pick_set_maximum (unsigned int _idx)
//-----------------------------------------------------------------------------
void GLState::pick_set_name (unsigned int _idx)
void GLState::pick_set_name (size_t _idx)
{
colorStack_.setIndex (_idx);
}
//-----------------------------------------------------------------------------
Vec4uc GLState::pick_get_name_color (unsigned int _idx)
Vec4uc GLState::pick_get_name_color (size_t _idx)
{
if (colorPicking_)
return colorStack_.getIndexColor (_idx);
......@@ -1070,7 +1070,7 @@ Vec4uc GLState::pick_get_name_color (unsigned int _idx)
//-----------------------------------------------------------------------------
void GLState::pick_push_name (unsigned int _idx)
void GLState::pick_push_name (size_t _idx)
{
colorStack_.pushIndex (_idx);
}
......@@ -1084,16 +1084,16 @@ void GLState::pick_pop_name ()
//-----------------------------------------------------------------------------
std::vector<unsigned int> GLState::pick_color_to_stack (Vec4uc _rgba) const
std::vector<size_t> GLState::pick_color_to_stack (Vec4uc _rgba) const
{
if (colorPicking_ && colorStack_.initialized ())
return colorStack_.colorToStack (_rgba);
return std::vector<unsigned int> ();
return std::vector<size_t> ();
}
//-----------------------------------------------------------------------------
unsigned int GLState::pick_free_indicies () const
size_t GLState::pick_free_indicies () const
{
if (colorPicking_ && colorStack_.initialized ())
return colorStack_.freeIndicies ();
......@@ -1111,7 +1111,7 @@ bool GLState::pick_error () const
//-----------------------------------------------------------------------------
unsigned int GLState::pick_current_index () const
size_t GLState::pick_current_index () const
{
if (colorPicking_)
return colorStack_.currentIndex ();
......
......@@ -1095,7 +1095,7 @@ public:
* If you create picking for your nodes, the values set with pick_set_name have to be between zero and
* this value.
*/
bool pick_set_maximum (unsigned int _idx);
bool pick_set_maximum (size_t _idx);
/** \brief sets the current name/color (like glLoadName(_idx))
*
......@@ -1107,25 +1107,25 @@ public:
* If you perform the picking and click on the second component, the returned index will be 1 as set in
* the node.
*/
void pick_set_name (unsigned int _idx);
void pick_set_name (size_t _idx);
/// returns the color that will be used for index _idx during color picking if this index will be set
/// with pick_set_name. This can be used to generate color arrays instead of using direct gl calls
/// for each primitive
Vec4uc pick_get_name_color (unsigned int _idx);
Vec4uc pick_get_name_color (size_t _idx);
/// creates a new name the stack (like glPushName())
void pick_push_name (unsigned int _idx);
void pick_push_name (size_t _idx);
/// pops the current name from the stack (like glPopName())
void pick_pop_name ();
/// converts the given color to index values on the stack (only used in color picking)
/// This can be compared to the results of the selection buffer results
std::vector<unsigned int> pick_color_to_stack (Vec4uc _rgba) const;
std::vector<size_t> pick_color_to_stack (Vec4uc _rgba) const;
/// returns the number of still available colors during color picking
unsigned int pick_free_indicies () const;
size_t pick_free_indicies () const;
/// Did an error occur during picking (only used in color picking)
/// Mostly to small color depth or wrong handling of pick_set_maximum
......@@ -1140,7 +1140,7 @@ public:
* of the object), not the name of the primitives/components in the object!
*
*/
unsigned int pick_current_index () const;
size_t pick_current_index () const;
/// Is color picking active?
bool color_picking () const;
......
......@@ -797,7 +797,7 @@ TextureBuffer::~TextureBuffer() {
}
void TextureBuffer::setBufferData(
int _size, const void* _data, GLenum _internalFormat, GLenum _usage) {
size_t _size, const void* _data, GLenum _internalFormat, GLenum _usage) {
#if defined(GL_ARB_texture_buffer_object)
if (supportsTextureBuffer()) {
// setup buffer object
......@@ -805,7 +805,7 @@ void TextureBuffer::setBufferData(
glGenBuffers(1, &buffer_);
glBindBuffer(GL_TEXTURE_BUFFER, buffer_);
glBufferData(GL_TEXTURE_BUFFER, _size, _data, _usage);
glBufferData(GL_TEXTURE_BUFFER, static_cast<GLsizei>(_size), _data, _usage);
usage_ = _usage;
fmt_ = _internalFormat;
......
......@@ -530,9 +530,9 @@ public:
// _data buffer data
// _internalFormat format of buffer - http://www.opengl.org/sdk/docs/man3/xhtml/glTexBuffer.xml
// _usage buffer usage hint - https://www.opengl.org/sdk/docs/man3/xhtml/glBufferData.xml
void setBufferData(int _size, const void* _data, GLenum _internalFormat, GLenum _usage = GL_STATIC_DRAW);
void setBufferData(size_t _size, const void* _data, GLenum _internalFormat, GLenum _usage = GL_STATIC_DRAW);
int getBufferSize() const {return bufferSize_;}
size_t getBufferSize() const {return bufferSize_;}
GLuint getBufferId() const {return buffer_;}
......@@ -547,7 +547,7 @@ public:
private:
int bufferSize_;
size_t bufferSize_;
GLuint buffer_;
GLenum usage_;
GLenum fmt_;
......
......@@ -186,27 +186,27 @@ rotate( Scalar angle, Scalar x, Scalar y, Scalar z,
xs = x * s;
ys = y * s;
zs = z * s;
one_c = 1.0F - c;
one_c = static_cast<Scalar>(1.0) - c;
m(0,0) = (one_c * xx) + c;
m(0,1) = (one_c * xy) - zs;
m(0,2) = (one_c * zx) + ys;
m(0,3) = 0.0F;
m(0,3) = static_cast<Scalar>(0.0);
m(1,0) = (one_c * xy) + zs;
m(1,1) = (one_c * yy) + c;
m(1,2) = (one_c * yz) - xs;
m(1,3) = 0.0F;
m(1,3) = static_cast<Scalar>(0.0);
m(2,0) = (one_c * zx) - ys;
m(2,1) = (one_c * yz) + xs;
m(2,2) = (one_c * zz) + c;