Skip to content

Commit 9e39ecd

Browse files
committed
Merge pull request #357 from johnhaddon/glImprovements
IECoreGL Improvements
2 parents 4ab95d0 + bb94632 commit 9e39ecd

26 files changed

+643
-100
lines changed

include/IECore/RefCounted.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ inline void intrusive_ptr_release( const IECore::RefCounted *r )
169169
r->removeRef();
170170
}
171171

172+
/// Implementation of tbb_hasher to allow intrusive_ptrs to be used
173+
/// with tbb_concurrent_* containers.
174+
template<typename T>
175+
inline size_t tbb_hasher( const boost::intrusive_ptr<T> &ptr )
176+
{
177+
// This is the same as what tbb uses for raw pointers
178+
const size_t h = reinterpret_cast<size_t>( ptr.get() );
179+
return (h >> 3) ^ h;
180+
}
181+
172182
} // namespace IECore
173183

174184

include/IECoreGL/HitRecord.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ class HitRecord
5353
/// for the OpenGL select buffer. Raises an exception if
5454
/// more than one name is specified in the record.
5555
HitRecord( const GLuint *hitRecord );
56-
HitRecord( float dMin, float dMax, const IECore::InternedString &primName );
56+
HitRecord( float dMin, float dMax, GLuint name );
5757

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

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

6966
/// Performs comparison based on the depth.min member.
7067
bool operator < ( const HitRecord &other ) const;

include/IECoreGL/Selector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ class Selector : boost::noncopyable
107107
/// If rendering a Scene, this will be called automatically
108108
/// by the NameStateComponents within the Scene.
109109
void loadName( GLuint name );
110+
/// Generates a new name (by incrementing an internal counter) and
111+
/// loads and returns it. No guarantee is made that generated names
112+
/// will not clash with names loaded explicitly with the method above.
113+
GLuint loadName();
110114

111115
/// A State that should be used as the base state for
112116
/// selection drawing.

include/IECoreGL/State.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ class State : public Bindable
6262
/// new bindings. It is the caller's responsibility to keep both arguments
6363
/// alive until after destruction of the ScopedBinding.
6464
ScopedBinding( const State &s, State &currentState );
65+
/// As above, but does nothing if bind is false.
66+
ScopedBinding( const State &s, State &currentState, bool bind );
6567
/// Reverts the state changes and modifications to currentState
6668
/// made by the constructor.
6769
~ScopedBinding();
6870

6971
private :
7072

73+
void init( const State &s, bool bind = true );
74+
7175
State &m_currentState;
7276
std::vector<StateComponentPtr> m_savedComponents;
7377

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREGL_TOGLSTATECONVERTER_H
36+
#define IECOREGL_TOGLSTATECONVERTER_H
37+
38+
#include "IECoreGL/ToGLConverter.h"
39+
40+
namespace IECore
41+
{
42+
43+
IE_CORE_FORWARDDECLARE( CompoundObject )
44+
IE_CORE_FORWARDDECLARE( Data )
45+
46+
} // namespace IECore
47+
48+
namespace IECoreGL
49+
{
50+
51+
IE_CORE_FORWARDDECLARE( State )
52+
IE_CORE_FORWARDDECLARE( StateComponent )
53+
54+
/// Converts IECore::CompoundObject objects containing shaders and attributes
55+
/// into IECoreGL::State objects.
56+
/// \ingroup conversionGroup
57+
class ToGLStateConverter : public ToGLConverter
58+
{
59+
60+
public :
61+
62+
typedef IECore::CompoundObject InputType;
63+
typedef IECoreGL::State ResultType;
64+
65+
IE_CORE_DECLARERUNTIMETYPEDEXTENSION( IECoreGL::ToGLStateConverter, ToGLStateConverterTypeId, ToGLConverter );
66+
67+
ToGLStateConverter( IECore::ConstCompoundObjectPtr toConvert = NULL );
68+
virtual ~ToGLStateConverter();
69+
70+
protected :
71+
72+
virtual IECore::RunTimeTypedPtr doConversion( IECore::ConstObjectPtr src, IECore::ConstCompoundObjectPtr operands ) const;
73+
74+
private :
75+
76+
static ConverterDescription<ToGLStateConverter> g_description;
77+
78+
};
79+
80+
IE_CORE_DECLAREPTR( ToGLStateConverter );
81+
82+
} // namespace IECoreGL
83+
84+
#endif // IECOREGL_TOGLSTATECONVERTER_H

include/IECoreGL/TypeIds.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ enum TypeId
121121
ToGLBufferConverterTypeId = 105078,
122122
UIntTextureTypeId = 105079,
123123
PrimitiveSelectableTypeId = 105080,
124+
ToGLStateConverterTypeId = 105081,
124125
LastCoreGLTypeId = 105999,
125126
};
126127

include/IECoreGL/TextureUnits.h renamed to include/IECoreGL/bindings/CurvesPrimitiveBinding.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2007, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
@@ -32,23 +32,14 @@
3232
//
3333
//////////////////////////////////////////////////////////////////////////
3434

35-
#ifndef IECOREGL_TEXTUREUNITS_H
36-
#define IECOREGL_TEXTUREUNITS_H
37-
38-
#include "IECoreGL/GL.h"
39-
40-
#include <vector>
35+
#ifndef IECOREGL_CURVESPRIMITIVEBINDING_H
36+
#define IECOREGL_CURVESPRIMITIVEBINDING_H
4137

4238
namespace IECoreGL
4339
{
4440

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

5243
} // namespace IECoreGL
5344

54-
#endif // IECOREGL_TEXTUREUNITS_H
45+
#endif // IECOREGL_CURVESPRIMITIVEBINDING_H
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//////////////////////////////////////////////////////////////////////////
2+
//
3+
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without
6+
// modification, are permitted provided that the following conditions are
7+
// met:
8+
//
9+
// * Redistributions of source code must retain the above copyright
10+
// notice, this list of conditions and the following disclaimer.
11+
//
12+
// * Redistributions in binary form must reproduce the above copyright
13+
// notice, this list of conditions and the following disclaimer in the
14+
// documentation and/or other materials provided with the distribution.
15+
//
16+
// * Neither the name of Image Engine Design nor the names of any
17+
// other contributors to this software may be used to endorse or
18+
// promote products derived from this software without specific prior
19+
// written permission.
20+
//
21+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
//
33+
//////////////////////////////////////////////////////////////////////////
34+
35+
#ifndef IECOREGL_TOGLSTATECONVERTERBINDING_H
36+
#define IECOREGL_TOGLSTATECONVERTERBINDING_H
37+
38+
namespace IECoreGL
39+
{
40+
41+
void bindToGLStateConverter();
42+
43+
} // namespace IECoreGL
44+
45+
#endif // IECOREGL_TOGLSTATECONVERTERBINDING_H

src/IECoreGL/HitRecord.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using namespace IECoreGL;
4646
HitRecord::HitRecord( const GLuint *hitRecord )
4747
: depthMin( (float)hitRecord[1]/(float)Imath::limits<GLuint>::max() ),
4848
depthMax( (float)hitRecord[2]/(float)Imath::limits<GLuint>::max() ),
49-
name( NameStateComponent::nameFromGLName( hitRecord[3] ) )
49+
name( hitRecord[3] )
5050

5151
{
5252
if( hitRecord[0] != 1 )
@@ -55,8 +55,8 @@ HitRecord::HitRecord( const GLuint *hitRecord )
5555
}
5656
}
5757

58-
HitRecord::HitRecord( float dMin, float dMax, const IECore::InternedString &primName )
59-
: depthMin( dMin ), depthMax( dMax ), name( primName )
58+
HitRecord::HitRecord( float dMin, float dMax, GLuint name )
59+
: depthMin( dMin ), depthMax( dMax ), name( name )
6060
{
6161
}
6262

src/IECoreGL/Primitive.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "IECoreGL/TypedStateComponent.h"
4646
#include "IECoreGL/ShaderStateComponent.h"
4747
#include "IECoreGL/Shader.h"
48-
#include "IECoreGL/TextureUnits.h"
4948
#include "IECoreGL/NumericTraits.h"
5049
#include "IECoreGL/UniformFunctions.h"
5150
#include "IECoreGL/CachedConverter.h"

0 commit comments

Comments
 (0)