IGraphicsDataToken and IGraphicsCommandQueue::stopRenderer()

This commit is contained in:
Jack Andersen
2015-12-04 14:41:30 -10:00
parent 32d4797ac6
commit d145e15ecb
9 changed files with 81 additions and 28 deletions

View File

@@ -58,7 +58,6 @@ public:
/* Creates a new context on current thread!! Call from client loading thread */
virtual IGraphicsDataFactory* getLoadContextDataFactory()=0;
};
}

View File

@@ -18,25 +18,31 @@ enum class EMouseButton
Aux2 = 5
};
struct SWindowCoord
{
int pixel[2];
int virtualPixel[2];
float norm[2];
};
struct SWindowRect
{
int location[2];
int size[2];
bool operator !=(const SWindowRect& other) const
bool operator!=(const SWindowRect& other) const
{
return location[0] != other.location[0] ||
location[1] != other.location[1] ||
size[0] != other.size[0] ||
size[1] != other.size[1];
}
bool operator ==(const SWindowRect& other) const {return !(*this != other);}
};
bool operator==(const SWindowRect& other) const {return !(*this != other);}
struct SWindowCoord
{
int pixel[2];
int virtualPixel[2];
float norm[2];
bool coordInRect(const SWindowCoord& coord) const
{
return coord.pixel[0] >= location[0] && coord.pixel[0] < location[0] + size[0] &&
coord.pixel[1] >= location[1] && coord.pixel[1] < location[1] + size[1];
}
};
struct STouchCoord
@@ -246,7 +252,6 @@ public:
/* Creates a new context on current thread!! Call from client loading thread */
virtual IGraphicsDataFactory* getLoadContextDataFactory()=0;
};
}

View File

@@ -17,9 +17,11 @@ class GLDataFactory : public IGraphicsDataFactory
struct GLData* m_deferredData = nullptr;
std::unordered_set<struct GLData*> m_committedData;
std::vector<int> m_texUnis;
void destroyData(IGraphicsData*);
void destroyAllData();
public:
GLDataFactory(IGraphicsContext* parent);
~GLDataFactory() {}
~GLDataFactory() {destroyAllData();}
Platform platform() const {return Platform::OGL;}
const SystemChar* platformName() const {return _S("OGL");}
@@ -54,9 +56,7 @@ public:
size_t texCount, ITexture** texs);
void reset();
IGraphicsData* commit();
void destroyData(IGraphicsData*);
void destroyAllData();
IGraphicsDataToken commit();
};
}

View File

@@ -38,6 +38,8 @@ struct IGraphicsCommandQueue
virtual void resolveDisplay(ITextureR* source)=0;
virtual void execute()=0;
virtual void stopRenderer()=0;
};
}

View File

@@ -7,6 +7,7 @@
namespace boo
{
struct IGraphicsCommandQueue;
struct IGraphicsBuffer
{
@@ -145,12 +146,9 @@ struct IShaderPipeline {};
* as a reference */
struct IShaderDataBinding {};
/** Opaque token for maintaining ownership of factory-created resources
* deletion of this token triggers mass-deallocation of the factory's
* resource batch. */
struct IGraphicsData
{
};
/** Opaque object for maintaining ownership of factory-created resources */
struct IGraphicsData {};
class IGraphicsDataToken;
/** Used by platform shader pipeline constructors */
enum class BlendFactor
@@ -220,11 +218,55 @@ struct IGraphicsDataFactory
size_t texCount, ITexture** texs)=0;
virtual void reset()=0;
virtual IGraphicsData* commit()=0;
virtual IGraphicsDataToken commit()=0;
private:
friend class IGraphicsDataToken;
virtual void destroyData(IGraphicsData*)=0;
virtual void destroyAllData()=0;
};
/** Opaque token for maintaining ownership of factory-created resources
* deletion of this token triggers mass-deallocation of the factory's
* IGraphicsData. */
class IGraphicsDataToken
{
friend class GLDataFactory;
friend class D3D12DataFactory;
friend class D3D11DataFactory;
friend class MetalDataFactory;
IGraphicsDataFactory* m_factory = nullptr;
IGraphicsData* m_data = nullptr;
IGraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data)
: m_factory(factory), m_data(data) {}
void doDestroy()
{
if (m_factory && m_data)
m_factory->destroyData(m_data);
}
public:
IGraphicsDataToken() = default;
IGraphicsDataToken(const IGraphicsDataToken& other) = delete;
IGraphicsDataToken(IGraphicsDataToken&& other)
{
m_factory = other.m_factory;
other.m_factory = nullptr;
m_data = other.m_data;
other.m_data = nullptr;
}
IGraphicsDataToken& operator=(const IGraphicsDataToken& other) = delete;
IGraphicsDataToken& operator=(IGraphicsDataToken&& other)
{
doDestroy();
m_factory = other.m_factory;
other.m_factory = nullptr;
m_data = other.m_data;
other.m_data = nullptr;
return *this;
}
~IGraphicsDataToken() {doDestroy();}
};
}
#endif // IGFXDATAFACTORY_HPP