Skip to content
10 changes: 10 additions & 0 deletions include/IECore/RefCounted.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ inline void intrusive_ptr_release( const IECore::RefCounted *r )
r->removeRef();
}

/// Implementation of tbb_hasher to allow intrusive_ptrs to be used
/// with tbb_concurrent_* containers.
template<typename T>
inline size_t tbb_hasher( const boost::intrusive_ptr<T> &ptr )
{
// This is the same as what tbb uses for raw pointers
const size_t h = reinterpret_cast<size_t>( ptr.get() );
return (h >> 3) ^ h;
}

} // namespace IECore


Expand Down
9 changes: 3 additions & 6 deletions include/IECoreGL/HitRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,15 @@ class HitRecord
/// for the OpenGL select buffer. Raises an exception if
/// more than one name is specified in the record.
HitRecord( const GLuint *hitRecord );
HitRecord( float dMin, float dMax, const IECore::InternedString &primName );
HitRecord( float dMin, float dMax, GLuint name );

/// The minimum and maximum depths of the hit, normalised
/// in the 0-1 range between the near and far clipping planes.
float depthMin;
float depthMax;

/// Unlike the gl hit record, the HitRecord stores
/// only one name - this is because the NameStateComponent
/// and the Renderer "name" attribute specify only a single
/// name for each primitive rendered.
IECore::InternedString name;
/// Identifier for the hit object.
GLuint name;

/// Performs comparison based on the depth.min member.
bool operator < ( const HitRecord &other ) const;
Expand Down
4 changes: 4 additions & 0 deletions include/IECoreGL/Selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class Selector : boost::noncopyable
/// If rendering a Scene, this will be called automatically
/// by the NameStateComponents within the Scene.
void loadName( GLuint name );
/// Generates a new name (by incrementing an internal counter) and
/// loads and returns it. No guarantee is made that generated names
/// will not clash with names loaded explicitly with the method above.
GLuint loadName();

/// A State that should be used as the base state for
/// selection drawing.
Expand Down
4 changes: 4 additions & 0 deletions include/IECoreGL/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ class State : public Bindable
/// new bindings. It is the caller's responsibility to keep both arguments
/// alive until after destruction of the ScopedBinding.
ScopedBinding( const State &s, State &currentState );
/// As above, but does nothing if bind is false.
ScopedBinding( const State &s, State &currentState, bool bind );
/// Reverts the state changes and modifications to currentState
/// made by the constructor.
~ScopedBinding();

private :

void init( const State &s, bool bind = true );

State &m_currentState;
std::vector<StateComponentPtr> m_savedComponents;

Expand Down
84 changes: 84 additions & 0 deletions include/IECoreGL/ToGLStateConverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECOREGL_TOGLSTATECONVERTER_H
#define IECOREGL_TOGLSTATECONVERTER_H

#include "IECoreGL/ToGLConverter.h"

namespace IECore
{

IE_CORE_FORWARDDECLARE( CompoundObject )
IE_CORE_FORWARDDECLARE( Data )

} // namespace IECore

namespace IECoreGL
{

IE_CORE_FORWARDDECLARE( State )
IE_CORE_FORWARDDECLARE( StateComponent )

/// Converts IECore::CompoundObject objects containing shaders and attributes
/// into IECoreGL::State objects.
/// \ingroup conversionGroup
class ToGLStateConverter : public ToGLConverter
{

public :

typedef IECore::CompoundObject InputType;
typedef IECoreGL::State ResultType;

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( IECoreGL::ToGLStateConverter, ToGLStateConverterTypeId, ToGLConverter );

ToGLStateConverter( IECore::ConstCompoundObjectPtr toConvert = NULL );
virtual ~ToGLStateConverter();

protected :

virtual IECore::RunTimeTypedPtr doConversion( IECore::ConstObjectPtr src, IECore::ConstCompoundObjectPtr operands ) const;

private :

static ConverterDescription<ToGLStateConverter> g_description;

};

IE_CORE_DECLAREPTR( ToGLStateConverter );

} // namespace IECoreGL

#endif // IECOREGL_TOGLSTATECONVERTER_H
1 change: 1 addition & 0 deletions include/IECoreGL/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ enum TypeId
ToGLBufferConverterTypeId = 105078,
UIntTextureTypeId = 105079,
PrimitiveSelectableTypeId = 105080,
ToGLStateConverterTypeId = 105081,
LastCoreGLTypeId = 105999,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2007, Image Engine Design Inc. All rights reserved.
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -32,23 +32,14 @@
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECOREGL_TEXTUREUNITS_H
#define IECOREGL_TEXTUREUNITS_H

#include "IECoreGL/GL.h"

#include <vector>
#ifndef IECOREGL_CURVESPRIMITIVEBINDING_H
#define IECOREGL_CURVESPRIMITIVEBINDING_H

namespace IECoreGL
{

/// Returns a vector containing GL_TEXTURE0, GL_TEXTURE1, ...
/// GL_TEXTUREN for all texture unit enums up to
/// GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1. That way you can
/// actually program texture code like a grown up,
/// using like loops and stuff.
const std::vector<GLenum> &textureUnits();
void bindCurvesPrimitive();

} // namespace IECoreGL

#endif // IECOREGL_TEXTUREUNITS_H
#endif // IECOREGL_CURVESPRIMITIVEBINDING_H
45 changes: 45 additions & 0 deletions include/IECoreGL/bindings/ToGLStateConverterBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of Image Engine Design nor the names of any
// other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef IECOREGL_TOGLSTATECONVERTERBINDING_H
#define IECOREGL_TOGLSTATECONVERTERBINDING_H

namespace IECoreGL
{

void bindToGLStateConverter();

} // namespace IECoreGL

#endif // IECOREGL_TOGLSTATECONVERTERBINDING_H
6 changes: 3 additions & 3 deletions src/IECoreGL/HitRecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ using namespace IECoreGL;
HitRecord::HitRecord( const GLuint *hitRecord )
: depthMin( (float)hitRecord[1]/(float)Imath::limits<GLuint>::max() ),
depthMax( (float)hitRecord[2]/(float)Imath::limits<GLuint>::max() ),
name( NameStateComponent::nameFromGLName( hitRecord[3] ) )
name( hitRecord[3] )

{
if( hitRecord[0] != 1 )
Expand All @@ -55,8 +55,8 @@ HitRecord::HitRecord( const GLuint *hitRecord )
}
}

HitRecord::HitRecord( float dMin, float dMax, const IECore::InternedString &primName )
: depthMin( dMin ), depthMax( dMax ), name( primName )
HitRecord::HitRecord( float dMin, float dMax, GLuint name )
: depthMin( dMin ), depthMax( dMax ), name( name )
{
}

Expand Down
1 change: 0 additions & 1 deletion src/IECoreGL/Primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "IECoreGL/TypedStateComponent.h"
#include "IECoreGL/ShaderStateComponent.h"
#include "IECoreGL/Shader.h"
#include "IECoreGL/TextureUnits.h"
#include "IECoreGL/NumericTraits.h"
#include "IECoreGL/UniformFunctions.h"
#include "IECoreGL/CachedConverter.h"
Expand Down
19 changes: 16 additions & 3 deletions src/IECoreGL/Selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Selector::Implementation : public IECore::RefCounted
public :

Implementation( Selector *parent, const Imath::Box2f &region, Mode mode, std::vector<HitRecord> &hits )
: m_mode( mode ), m_hits( hits ), m_baseState( new State( true /* complete */ ) ), m_currentName( 0 ), m_currentIDShader( NULL )
: m_mode( mode ), m_hits( hits ), m_baseState( new State( true /* complete */ ) ), m_currentName( 0 ), m_nextGeneratedName( 1 ), m_currentIDShader( NULL )
{
// we don't want preexisting errors to trigger exceptions
// from error checking code in the begin*() methods, because
Expand Down Expand Up @@ -190,6 +190,13 @@ class Selector::Implementation : public IECore::RefCounted
m_currentName = name;
}

GLuint loadName()
{
const GLuint name = m_nextGeneratedName++;
loadName( name );
return name;
}

State *baseState()
{
return m_baseState.get();
Expand Down Expand Up @@ -256,6 +263,7 @@ class Selector::Implementation : public IECore::RefCounted
std::vector<HitRecord> &m_hits;
StatePtr m_baseState;
GLuint m_currentName;
GLuint m_nextGeneratedName;

static Selector *g_currentSelector;

Expand Down Expand Up @@ -398,7 +406,7 @@ class Selector::Implementation : public IECore::RefCounted
std::map<unsigned int, HitRecord>::iterator it = idRecords.find( ids[i] );
if( it == idRecords.end() )
{
HitRecord r( Imath::limits<float>::max(), Imath::limits<float>::min(), NameStateComponent::nameFromGLName( ids[i] ) );
HitRecord r( Imath::limits<float>::max(), Imath::limits<float>::min(), ids[i] );
it = idRecords.insert( std::pair<unsigned int, HitRecord>( ids[i], r ) ).first;
}
it->second.depthMin = std::min( it->second.depthMin, z[i] );
Expand Down Expand Up @@ -461,7 +469,7 @@ class Selector::Implementation : public IECore::RefCounted
glGetQueryObjectuivARB( m_queries[i], GL_QUERY_RESULT_ARB, &samplesPassed );
if( samplesPassed )
{
m_hits.push_back( HitRecord( 0, 0, NameStateComponent::nameFromGLName( m_queryNames[i] ) ) );
m_hits.push_back( HitRecord( 0, 0, m_queryNames[i] ) );
}
}

Expand Down Expand Up @@ -501,6 +509,11 @@ void Selector::loadName( GLuint name )
m_implementation->loadName( name );
}

GLuint Selector::loadName()
{
return m_implementation->loadName();
}

State *Selector::baseState()
{
return m_implementation->baseState();
Expand Down
5 changes: 2 additions & 3 deletions src/IECoreGL/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "IECoreGL/Buffer.h"
#include "IECoreGL/NumericTraits.h"
#include "IECoreGL/CachedConverter.h"
#include "IECoreGL/TextureUnits.h"
#include "IECoreGL/Selector.h"

using namespace std;
Expand Down Expand Up @@ -517,7 +516,7 @@ class Shader::Setup::MemberData : public IECore::RefCounted

virtual void bind()
{
glActiveTexture( textureUnits()[m_textureUnit] );
glActiveTexture( GL_TEXTURE0 + m_textureUnit );
glGetIntegerv( GL_TEXTURE_BINDING_2D, &m_previousTexture );
if( m_texture )
{
Expand All @@ -532,7 +531,7 @@ class Shader::Setup::MemberData : public IECore::RefCounted

virtual void unbind()
{
glActiveTexture( textureUnits()[m_textureUnit] );
glActiveTexture( GL_TEXTURE0 + m_textureUnit );
glBindTexture( GL_TEXTURE_2D, m_previousTexture );
}

Expand Down
4 changes: 4 additions & 0 deletions src/IECoreGL/ShaderStateComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class ShaderStateComponent::Implementation : public IECore::RefCounted

void addParametersToShaderSetup( Shader::Setup *shaderSetup ) const
{
if( !m_parameterMap )
{
return;
}
const IECore::CompoundObject::ObjectMap &d = m_parameterMap->members();
for( IECore::CompoundObject::ObjectMap::const_iterator it = d.begin(), eIt = d.end(); it != eIt; it++ )
{
Expand Down
16 changes: 16 additions & 0 deletions src/IECoreGL/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,22 @@ class State::Implementation : public IECore::RefCounted
State::ScopedBinding::ScopedBinding( const State &s, State &currentState )
: m_currentState( currentState )
{
init( s );
}

State::ScopedBinding::ScopedBinding( const State &s, State &currentState, bool bind )
: m_currentState( currentState )
{
init( s, bind );
}

void State::ScopedBinding::init( const State &s, bool bind )
{
if( !bind )
{
return;
}

m_savedComponents.reserve( s.m_implementation->m_components.size() );

for( Implementation::ComponentMap::const_iterator it=s.m_implementation->m_components.begin(); it!=s.m_implementation->m_components.end(); it++ )
Expand Down
Loading