Skip to content

Commit

Permalink
Merging glNext
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfb committed Apr 25, 2015
2 parents 4dca1c3 + 75bc9de commit f952900
Show file tree
Hide file tree
Showing 59 changed files with 1,551 additions and 1,788 deletions.
24 changes: 4 additions & 20 deletions include/cinder/Capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class Capture {
//! Creates a new Capture requesting (but not promising) a resolution of \a width x \a height pixels.
static CaptureRef create( int32_t width, int32_t height, const DeviceRef device = DeviceRef() ) { return CaptureRef( new Capture( width, height, device ) ); }

Capture() {}
~Capture() {}
~Capture();

//! Begin capturing video
void start();
Expand Down Expand Up @@ -127,29 +126,14 @@ class Capture {

protected:
Capture( int32_t width, int32_t height, const DeviceRef device );

struct Obj {
Obj( int32_t width, int32_t height, const Capture::DeviceRef device );
virtual ~Obj();

#if defined( CINDER_MAC ) || defined( CINDER_COCOA_TOUCH_DEVICE )
CaptureImplAvFoundation *mImpl;
CaptureImplAvFoundation *mImpl;
#elif defined( CINDER_COCOA_TOUCH_SIMULATOR )
CaptureImplCocoaDummy *mImpl;
CaptureImplCocoaDummy *mImpl;
#elif defined( CINDER_MSW )
CaptureImplDirectShow *mImpl;
CaptureImplDirectShow *mImpl;
#endif
};

std::shared_ptr<Obj> mObj;

public:
//@{
//! Emulates shared_ptr-like behavior
typedef std::shared_ptr<Obj> Capture::*unspecified_bool_type;
operator unspecified_bool_type() const { return ( mObj.get() == 0 ) ? 0 : &Capture::mObj; }
void reset() { mObj.reset(); }
//@}
};

class CaptureExc : public Exception {
Expand Down
8 changes: 5 additions & 3 deletions include/cinder/Perlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ class Perlin
/// Class Perlin look: fractal Brownian motion by summing 'mOctaves' worth of noise
float fBm( float v ) const;
float fBm( const vec2 &v ) const;
float fBm( float x, float y ) const { return fBm( vec2( x, y ) ); }
float fBm( float x, float y ) const { return fBm( vec2( x, y ) ); }
float fBm( const vec3 &v ) const;
float fBm( float x, float y, float z ) const { return fBm( vec3( x, y, z ) ); }
float fBm( float x, float y, float z ) const { return fBm( vec3( x, y, z ) ); }

/// Derivative of fractal Brownian motion, corresponding with the values returned by fBm()
// float dfBm( float v ) const;
vec2 dfBm( const vec2 &v ) const;
vec2 dfBm( float x, float y ) const { return dfBm( vec2( x, y ) ); }
vec2 dfBm( float x, float y ) const { return dfBm( vec2( x, y ) ); }
vec3 dfBm( const vec3 &v ) const;
vec3 dfBm( float x, float y, float z ) const { return dfBm( vec3( x, y, z ) ); }

/// Calculates a single octave of noise
float noise( float x ) const;
float noise( float x, float y ) const;
float noise( const vec2 &v ) const { return noise( v.x, v.y ); }
float noise( float x, float y, float z ) const;
float noise( const vec3 &v ) const { return noise( v.x, v.y, v.z ); }

/// Calculates the derivative of a single octave of noise
// float dnoise( float x ) const;
Expand Down
71 changes: 39 additions & 32 deletions include/cinder/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,16 @@

#include "cinder/Cinder.h"
#include "cinder/Exception.h"
#include "cinder/Noncopyable.h"

#include <string>
#include <vector>

#if defined( CINDER_MAC )
#include <termios.h>
#elif defined( CINDER_MSW )
#include <windows.h>
#undef min
#undef max
#endif

namespace cinder {

class Serial {
typedef std::shared_ptr<class Serial> SerialRef;

class Serial : private Noncopyable {
public:
class Device {
public:
Expand All @@ -60,10 +55,10 @@ class Serial {
static Serial::Device findDeviceByName( const std::string &name, bool forceRefresh = false );
//! Returns the first Serial::Device whose name contains the string \a searchString. Returns a null Serial::Device if none are found. Uses a cached list of the serial devices unless \a forceRefresh.
static Serial::Device findDeviceByNameContains( const std::string &searchString, bool forceRefresh = false );

Serial() {}
Serial( const Serial::Device &device, int baudRate );

//! Creates and returns a shared Serial object.
static SerialRef create( const Serial::Device &device, int baudRate ) { return SerialRef( new Serial( device, baudRate ) ); }
~Serial();

//! Returns the Device associated with this Serial port
const Device& getDevice() const;
Expand Down Expand Up @@ -92,46 +87,58 @@ class Serial {
size_t getNumBytesAvailable() const;

protected:
struct Obj {
Obj();
Obj( const Serial::Device &device, int baudRate );
~Obj();

Device mDevice;

#ifdef CINDER_MSW
::HANDLE mDeviceHandle;
::COMMTIMEOUTS mSavedTimeouts;
#else
int mFd;
::termios mSavedOptions;
#endif
};

std::shared_ptr<Obj> mObj;

Serial( const Serial::Device &device, int baudRate );

private:
Device mDevice;

struct Impl;
std::unique_ptr<Impl> mImpl;

static bool sDevicesInited;
static std::vector<Serial::Device> sDevices;
static std::vector<Serial::Device> sDevices;
};

class SerialExc : public Exception {
public:
SerialExc( const std::string &description )
: Exception( description )
{}
};

class SerialExcOpenFailed : public SerialExc {
public:
SerialExcOpenFailed()
: SerialExc( "Serial failed to open." )
{}
};

class SerialExcDeviceEnumerationFailed : public SerialExc {
public:
SerialExcDeviceEnumerationFailed()
: SerialExc( "Serial device enumeration failed." )
{}
};

class SerialExcReadFailure : public SerialExc {
public:
SerialExcReadFailure()
: SerialExc( "Serial failed to read." )
{}
};

class SerialExcWriteFailure : public SerialExc {
public:
SerialExcWriteFailure()
: SerialExc( "Serial failed to write." )
{}
};

class SerialTimeoutExc : public SerialExc {
public:
SerialTimeoutExc()
: SerialExc( "Serial timed out." )
{}
};

} // namespace cinder
4 changes: 4 additions & 0 deletions include/cinder/Sphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#pragma once

#include "cinder/Matrix.h"
#include "cinder/Vector.h"
#include "cinder/Ray.h"

Expand Down Expand Up @@ -51,6 +52,9 @@ class Sphere {
static Sphere calculateBoundingSphere( const std::vector<vec3> &points );
static Sphere calculateBoundingSphere( const vec3 *points, size_t numPoints );

//! Converts sphere to another coordinate system. Note that it will not return correct results if there are non-uniform scaling, shears, or other unusual transforms in \a transform.
Sphere transformed( const mat4 &transform );

//! Calculates the projection of the Sphere (an oriented ellipse) given \a focalLength. Returns \c false if calculation failed, rendering only \a outCenter correct. Algorithm due to Iñigo Quilez.
void calcProjection( float focalLength, vec2 *outCenter, vec2 *outAxisA, vec2 *outAxisB ) const;
//! Calculates the projection of the Sphere (an oriented ellipse) given \a focalLength. Algorithm due to Iñigo Quilez.
Expand Down
28 changes: 22 additions & 6 deletions include/cinder/TriMesh.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2010, The Barbarian Group
Copyright (c) 2015, The Barbarian Group
All rights reserved.
Portions of this code (C) Paul Houx
Expand Down Expand Up @@ -297,10 +297,14 @@ class TriMesh : public geom::Source {
//! Calculates the bounding box of all vertices as transformed by \a transform. Fails if the positions are not 3D.
AxisAlignedBox3f calcBoundingBox( const mat4 &transform ) const;

//! This allows you read a TriMesh in from a data file, for instance an .obj file. At present .obj and .dat files are supported
void read( DataSourceRef in );
//! This allows to you write a mesh out to a data file. At present .obj and .dat files are supported.
void write( DataTargetRef out ) const;
//! Fills this TriMesh with the data from a binary file, which was created with TriMesh::write().
void read( const DataSourceRef &dataSource );
//! Writes this TriMesh out to a binary data file.
void write( const DataTargetRef &dataTarget ) const { write( dataTarget, ~0 ); }
//! Writes this TriMesh out to a binary data file. If \a writeNormals or \a writeTangents is \c true, normals and/or tangents are written to the file.
void write( const DataTargetRef &dataTarget, bool writeNormals, bool writeTangents ) const;
//! Writes this TriMesh out to a binary data file. You can specify which attributes to write by supplying a list of \a attribs.
void write( const DataTargetRef &dataTarget, const std::set<geom::Attrib> &attribs ) const;

/*! Adds or replaces normals by calculating them from the vertices and faces. If \a smooth is TRUE,
similar vertices are grouped together to calculate their average. This will not change the mesh,
Expand All @@ -316,7 +320,6 @@ class TriMesh : public geom::Source {
Optionally, vertices are normalized if \a normalize is TRUE. */
void subdivide( int division = 2, bool normalize = false );


//! Create TriMesh from vectors of vertex data.
/* static TriMesh create( std::vector<uint32_t> &indices, const std::vector<ColorAf> &colors,
const std::vector<vec3> &normals, const std::vector<vec3> &positions,
Expand All @@ -337,6 +340,19 @@ class TriMesh : public geom::Source {
//! Returns whether or not the vertex, color etc. at both indices is the same.
bool verticesEqual( uint32_t indexA, uint32_t indexB ) const;

void readImplV2( const IStreamRef &in );
void readImplV1( const IStreamRef &in );

/*! Writes this TriMesh out to a binary data file. The \a writeMask parameter can be used to specify
* what data should be included (e.g. toMask(POSITION) | toMask(COLOR) )
* or what should be excluded (e.g. ~toMask( NORMAL ) & ~toMask( TEX_COORD_0) ). */
void write( const DataTargetRef &dataTarget, uint32_t writeMask ) const;

//! Converts a geom::Attrib to an attribute bitmask.
static uint32_t toMask( geom::Attrib attrib );
//! Converts an attribute bitmask to a geom::Attrib.
static geom::Attrib fromMask( uint32_t attrib );

uint8_t mPositionsDims, mNormalsDims, mTangentsDims, mBitangentsDims, mColorsDims;
uint8_t mTexCoords0Dims, mTexCoords1Dims, mTexCoords2Dims, mTexCoords3Dims;

Expand Down
2 changes: 0 additions & 2 deletions include/cinder/app/cocoa/AppImplMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
- (void)setFrameRate:(float)frameRate;
- (void)disableFrameRate;
- (bool)isFrameRateEnabled;
- (void)quit;

- (cinder::app::RendererRef)findSharedRenderer:(cinder::app::RendererRef)match;
- (cinder::app::WindowRef)getWindow;
Expand Down Expand Up @@ -105,7 +104,6 @@
- (cinder::ivec2)getPos;
- (float)getContentScale;
- (void)setPos:(cinder::ivec2)pos;
- (float)getContentScale;
- (void)close;
- (NSString *)getTitle;
- (void)setTitle:(NSString *)title;
Expand Down
25 changes: 23 additions & 2 deletions include/cinder/gl/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,28 @@ class Context {
void popLineWidth( bool forceRestore = false );
//! Returns the current line width.
float getLineWidth();

//! Analogous to glDepthMask()
//! Analogous to glDepthMask(). Enables or disables writing into the depth buffer.
void depthMask( GLboolean enable );
//! Push the depth buffer writing flag.
void pushDepthMask( GLboolean enable );
//! Push the depth buffer writing flag.
void pushDepthMask();
//! Pops the depth buffer writing flag. If \a forceRestore then redundancy checks are skipped and the hardware state is always set.
void popDepthMask( bool forceRestore = false );
//! Returns the depth buffer writing flag.
GLboolean getDepthMask();

//! Set the depth buffer comparison function. Analogous to glDepthFunc(). Valid arguments are \c GL_NEVER, \c GL_LESS, \c GL_EQUAL, \c GL_LEQUAL, \c GL_GREATER, \c GL_NOTEQUAL, \c GL_GEQUAL and \c GL_ALWAYS. Default is \c GL_LESS.
void depthFunc( GLenum func );
//! Push the depth buffer comparison function. Valid arguments are \c GL_NEVER, \c GL_LESS, \c GL_EQUAL, \c GL_LEQUAL, \c GL_GREATER, \c GL_NOTEQUAL, \c GL_GEQUAL and \c GL_ALWAYS. Default is \c GL_LESS.
void pushDepthFunc( GLenum func );
//! Push the depth buffer comparison function.
void pushDepthFunc();
//! Pops the depth buffer comparison function. If \a forceRestore then redundancy checks are skipped and the hardware state is always set.
void popDepthFunc( bool forceRestore = false );
//! Returns the depth buffer comparison function, either \c GL_NEVER, \c GL_LESS, \c GL_EQUAL, \c GL_LEQUAL, \c GL_GREATER, \c GL_NOTEQUAL, \c GL_GEQUAL or \c GL_ALWAYS.
GLenum getDepthFunc();

#if ! defined( CINDER_GL_ES )
//! Sets the current polygon rasterization mode. \a face must be \c GL_FRONT_AND_BACK. \c GL_POINT, \c GL_LINE & \c GL_FILL are legal values for \a mode.
Expand Down Expand Up @@ -454,6 +473,8 @@ class Context {
std::vector<GLenum> mCullFaceStack;
std::vector<GLenum> mFrontFaceStack;
std::vector<GLenum> mPolygonModeStack;
std::vector<GLboolean> mDepthMaskStack;
std::vector<GLenum> mDepthFuncStack;

std::map<GLenum,std::vector<GLboolean>> mBoolStateStack;
// map<TextureUnit,map<TextureTarget,vector<Binding ID Stack>>>
Expand Down
2 changes: 2 additions & 0 deletions include/cinder/gl/Fbo.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class Fbo : public std::enable_shared_from_this<Fbo> {
GLint getDepthBufferInternalFormat() const { return mDepthBufferInternalFormat; }
//! Returns the Texture::Format for the default color texture at GL_COLOR_ATTACHMENT0.
const Texture::Format& getColorTextureFormat() const { return mColorTextureFormat; }
//! Returns the Texture::Format for the depth texture.
const Texture::Format& getDepthTextureFormat() const { return mDepthTextureFormat; }
//! Returns the number of samples used in MSAA-style antialiasing. Defaults to none, disabling multisampling.
int getSamples() const { return mSamples; }
//! Returns the number of coverage samples used in CSAA-style antialiasing. Defaults to none. MSW only.
Expand Down
12 changes: 10 additions & 2 deletions include/cinder/gl/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ class TextureBase {
void setBaseMipmapLevel( GLuint level ) { mBaseMipmapLevel = level; }
//! Sets the max mipmap level. Default (expressed as \c -1) is derived from the size of the texture. Ignored on ES 2.
void setMaxMipmapLevel( GLint level ) { mMaxMipmapLevel = level; }
//! Returns the index of the lowest defined mipmap level.
GLuint getBaseMipmapLevel() const { return mBaseMipmapLevel; }
//! Returns the max mipmap level.
GLuint getMaxMipmapLevel() const { return mMaxMipmapLevel; }

//! Sets whether the storage for the cannot be changed in the future (making glTexImage*D() calls illegal). More efficient when possible. Default is \c false.
void setImmutableStorage( bool immutable = true ) { mImmutableStorage = immutable; }
Expand All @@ -179,7 +183,12 @@ class TextureBase {
// Specifies the texture comparison mode for currently bound depth textures.
void setCompareMode( GLenum compareMode ) { mCompareMode = compareMode; }
// Specifies the comparison operator used when \c GL_TEXTURE_COMPARE_MODE is set to \c GL_COMPARE_R_TO_TEXTURE
void setCompareFunc( GLenum compareFunc ) { mCompareFunc = compareFunc; }
void setCompareFunc( GLenum compareFunc ) { mCompareFunc = compareFunc; }
//! Returns the texture comparison mode for currently bound depth texture.
GLenum getCompareMode() const { return mCompareMode; }
//! Returns the comparison operator used when \c GL_TEXTURE_COMPARE_MODE is set to \c GL_COMPARE_R_TO_TEXTURE
GLenum getCompareFunc() const { return mCompareFunc; }

//! Sets the wrapping behavior when a texture coordinate falls outside the range of [0,1]. Possible values are \c GL_REPEAT, \c GL_CLAMP_TO_EDGE, etc. Default is \c GL_CLAMP_TO_EDGE.
void setWrap( GLenum wrapS, GLenum wrapT ) { setWrapS( wrapS ); setWrapT( wrapT ); }
#if ! defined( CINDER_GL_ES )
Expand Down Expand Up @@ -269,7 +278,6 @@ class TextureBase {
bool mImmutableStorage;
GLfloat mMaxAnisotropy;
GLint mInternalFormat, mDataType;
GLint mDataFormat;
bool mSwizzleSpecified;
std::array<GLint,4> mSwizzleMask;
bool mBorderSpecified;
Expand Down
19 changes: 18 additions & 1 deletion include/cinder/gl/scoped.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct ScopedState : private Noncopyable {
struct ScopedColor : private Noncopyable {
ScopedColor();
ScopedColor( const ColorAf &color );
ScopedColor( float red, float green, float blue, float alpha = 1 );
~ScopedColor();

private:
Expand Down Expand Up @@ -190,7 +191,7 @@ struct ScopedProjectionMatrix : private Noncopyable {
~ScopedProjectionMatrix() { gl::popProjectionMatrix(); }
};

//! Preserves all
//! Preserves all matrices
struct ScopedMatrices : private Noncopyable {
ScopedMatrices() { gl::pushMatrices(); }
~ScopedMatrices() { gl::popMatrices(); }
Expand All @@ -209,6 +210,22 @@ struct ScopedFaceCulling : private Noncopyable {
bool mSaveFace;
};

//! Scopes state of depth testing and writing
struct ScopedDepth : private Noncopyable {
//! Enables or disables both depth comparisons and writing to the depth buffer
ScopedDepth( bool enableReadAndWrite );
//! Enables or disables depth comparisons and/or writing to the depth buffer
ScopedDepth( bool enableRead, bool enableWrite );
//! Enables or disables depth comparisons, writing to the depth buffer and specifies a depth comparison function, either \c GL_NEVER, \c GL_LESS, \c GL_EQUAL, \c GL_LEQUAL, \c GL_GREATER, \c GL_NOTEQUAL, \c GL_GEQUAL and \c GL_ALWAYS.
ScopedDepth( bool enableRead, bool enableWrite, GLenum depthFunc );
~ScopedDepth();

private:
Context *mCtx;
bool mSaveMask;
bool mSaveFunc;
};

//! Scopes state of Renderbuffer binding
struct ScopedRenderbuffer : private Noncopyable {
ScopedRenderbuffer( const RenderbufferRef &renderBuffer );
Expand Down
Loading

0 comments on commit f952900

Please sign in to comment.