Initial commit

This commit is contained in:
2026-04-03 00:22:39 -05:00
commit eca1e8c458
945 changed files with 218160 additions and 0 deletions

View File

@@ -0,0 +1,288 @@
/*
ZDataBuffer.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 3/20/2011
Purpose:
Interface for graphics device buffered memory, used for uniform buffers, vertex buffers, and
index buffers.
Note that ZDataBuffer is a ZRendererResource, and should be used as such.
License:
TODO
*/
#pragma once
#ifndef _ZDATABUFFER_HPP
#define _ZDATABUFFER_HPP
#include <ZRenderer/ZRendererResource.hpp>
#include <ZSTL/ZArray.hpp>
//Forward Declarations
class ZDataBuffer;
//The type of data buffer
enum ZDataBufferType
{
ZDBT_VERTEX, //Contains Vertex Data
ZDBT_INDEX, //Contains Index Data
ZDBT_UNIFORM, //Contains Uniform (Constant) Data
ZDBT_SIZE
};
//The usage type of the data buffer
enum ZDataBufferUsage
{
ZDBU_STATIC, //Static Buffer (never or rarely updated)
ZDBU_DYNAMIC, //Dynamic Buffer (updated frequently)
ZDBU_STREAMING, //Streaming Buffer (updated every frame)
ZDBU_SIZE
};
//The data type in a stream
enum ZDataBufferStreamType
{
ZDBST_FLOAT32, //32-bit floating point
ZDBST_FLOAT64, //64-bit floating point
ZDBST_INT8, //8-bit integer, signed
ZDBST_INT16, //16-bit integer, signed
ZDBST_INT32, //32-bit integer, signed
ZDBST_UINT8, //8-bit integer, unsigned
ZDBST_UINT16, //16-bit integer, unsigned
ZDBST_UINT32, //32-bit integer, unsigned
ZDBST_SIZE
};
//The data type in a block
enum ZDataBufferBlockType
{
ZDBBT_UNIFORM, //Uniform Data
ZDBBT_INDEX8, //8-bit index data
ZDBBT_INDEX16, //16-bit index data
ZDBBT_INDEX32, //32-bit index data
ZDBBT_SIZE
};
//Struct for stream definitions
struct ZDataBufferStream
{
ZDataBuffer* Buffer; //Parent buffer that contains this stream
size_t ElementSize; //Size of an element in terms of data type (e.g., 2 for vec2, 3 for vec3, etc.)
size_t Offset; //Offset (in bytes) that this stream starts from beginning of data buffer
size_t Stride; //Distance (in bytes) between elements of this stream
ZDataBufferStreamType Type; //Type of data in each element of this stream (this gives us size of each unit of data)
bool Normalize; //true: fixed point value converted to [0,1] or [-1,1] range; false: typecasted.
};
//Struct for block definitions
struct ZDataBufferBlock
{
ZDataBufferBlockType Type; //Type of data contained by this block
size_t Offset; //Offset (in bytes) into the buffer where this block begins
size_t Size; //Size (in bytes) of the block
ZDataBuffer* Buffer; //Parent buffer that contains this block data
};
//Wrapper class for data buffers
class ZDataBuffer : public ZRendererResource
{
private:
DISABLE_COPY_AND_ASSIGN(ZDataBuffer);
public:
//Default Constructor
ZDataBuffer() : ZRendererResource() { }
//Virtual Destructor
virtual ~ZDataBuffer() { }
/*
virtual public ZDataBuffer::DefineBlock
Defines a block of data present in the buffer. Examples of blocks include
index blocks and uniform buffer storage blocks.
@param _type - the type of block (index or uniform)
@param _size - the size of the block (in bytes)
@return (const ZDataBufferBlock*) - the data buffer block created
@context (all)
*/
virtual const ZDataBufferBlock* DefineBlock(ZDataBufferBlockType _type,
size_t _size
) = 0;
/*
virtual public ZDataBuffer::DefineStream
Defines a stream that is present in this buffer. Examples of streams include
the position stream (vertex coordinates), the color stream, the normal stream,
and uv coordinate streams. Other streams can be defined so as to be usable by
shader programs.
@param _type - The type of stream.
@param _elemCount - The number of elements in the stream, e.g., 3D position has an element
count of 3, 2D position has an element count of 2, etc...
@param _offset - The offset into the buffer (in bytes) where this stream begins
@param _stride - The stride between beginnings of consecutive elements (in bytes), or 0 for packed elements
@param _normalize - If true, fixed point data should be normalized (i.e. changed to [0,1] or [-1,1] if unsigned/signed), otherwise
it is converted similar to a C typecast, i.e. 'float value = (float)fixedValue'
@return (const ZDataBufferStream*) - the data buffer stream created
@context (all)
*/
virtual const ZDataBufferStream* DefineStream(ZDataBufferStreamType _type,
size_t _elemCount,
size_t _offset,
size_t _stride,
bool _normalize
) = 0;
/*
virtual public ZDataBuffer::Fill
Fills the buffer with data, as specified. This is equivalent to calling
'MapBuffer', filling the buffer, and calling 'UnmapBuffer'.
@param _data - the data to fill the buffer with
@param _offset - offset into the buffer to start copying to
@param _byteCount - number of bytes to copy from _data
@return (bool) - true if this update was successful, false if the buffer is 'locked' or 'contended'
@context (all)
*/
virtual bool Fill(const void* _data,
size_t _offset,
size_t _byteCount
) = 0;
/*
virtual public ZDataBuffer::GetBlock
Gets the pointer to a block previously defined using DefineBlock().
@param index - The block's index. The first block created with DefineBlock() is 0, the second is 1, and so on.
@return ( const ZDataBufferBlock*) - block definition
@context (all)
*/
virtual const ZDataBufferBlock* GetBlock(size_t index) = 0;
/*
virtual public ZDataBuffer::GetStream
Gets the pointer to a stream previously defined using DefineStream().
@param index - The stream's index. The first stream created with DefineStream() is 0, the second is 1, and so on.
@return (const ZDataBufferStream*) - stream definition
@context (all)
*/
virtual const ZDataBufferStream* GetStream(size_t index) = 0;
/*
virtual public ZDataBuffer::GetBlockCount
Gets the number of blocks that have been defined so far.
@return (size_t) - The number of blocks defined with DefineBlock()
@context (all)
*/
virtual size_t GetBlockCount() const = 0;
/*
virtual public ZDataBuffer::GetStreamCount
Gets the number of streams that have been defined so far.
@return (size_t) - The number of blocks defined with DefineStream()
@context (all)
*/
virtual size_t GetStreamCount() const = 0;
/*
virtual public ZDataBuffer::GetSize
Gets the size of this data buffer.
@return (size_t) - the size (in bytes) of this buffer
@context (all)
*/
virtual size_t GetSize() = 0;
/*
virtual public ZDataBuffer::GetType
Gets the type of this data buffer.
@return (ZDataBufferType) - the buffer type
@context (all)
*/
virtual ZDataBufferType GetType() = 0;
/*
virtual public ZDataBuffer::GetUsage
Gets the usage of this data buffer.
@return (ZDataBufferUsage) - the usage type
@context (all)
*/
virtual ZDataBufferUsage GetUsage() = 0;
/*
virtual public ZDataBuffer::Map
Maps the data buffer into user memory and marks this resource as locked until 'UnmapBuffer' is called.
If the discard parameter is set to true, this tells the implementation that the data
that is currently present in the buffer is not required, and this may result in a faster
return, especially in the case of static usage buffers. If the current data is needed
(discard is false), static usage buffers must wait for the render thread to get the data
from the graphics memory. Dynamic and streaming usage buffers typically suffer no
performance penalty regardless of the value of the discard parameter, though this may
vary based on implementation.
@param _discard - hint to the implementation that the data in the buffer can be discarded
@return (void*) - pointer to the buffer in mapped memory, NULL if this buffer is 'locked' or 'contended'
@context (all)
*/
virtual void* Map(bool _discard = false) = 0;
/*
virtual public ZDataBuffer::UndefBlocks
Undefines all currently set blocks. This will invalidate existing block
definition structures returned from DefineBlock.
@return (void)
@context (all)
*/
virtual void UndefBlocks() = 0;
/*
virtual public ZDataBuffer::UndefStreams
Undefines all currently set streams. This will invalidate existing stream
definition structures returned from DefineStream.
@return (void)
@context (all)
*/
virtual void UndefStreams() = 0;
/*
virtual public ZDataBuffer::Unmap
Unmaps a previously mapped data buffer and unlocks the data buffer.
@return (void)
@context (all)
*/
virtual void Unmap() = 0;
};
#endif

View File

@@ -0,0 +1,130 @@
/*
ZDataBufferBase.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 3/20/2011
Purpose:
The ZDataBufferBase class is meant to be used by implementations that are
required to handle threading and concurrency problems that are not solved by
the graphics library.
License:
TODO
*/
#pragma once
#ifndef _ZDATABUFFERBASE_HPP
#define _ZDATABUFFERBASE_HPP
#include <ZRenderer/ZDataBuffer.hpp>
/*
Base class implementation for the Data Buffer.
*/
class ZDataBufferBase : public ZDataBuffer
{
protected:
//Default Constructor
ZDataBufferBase(ZDataBufferType _type, ZDataBufferUsage _usage, size_t _size);
//Type of the Data Buffer
ZDataBufferType Type;
//Usage setting for the Data Buffer
ZDataBufferUsage Usage;
//Size (in bytes) of the Data Buffer
size_t Size;
//Array of DataBufferBlocks held by this DataBuffer
ZArray<ZDataBufferBlock*> Blocks;
//Array of DataBufferStreams held by this DataBuffer
ZArray<ZDataBufferStream*> Streams;
//Backing buffer, used to double-buffer the graphics device buffer
void* MemBuffer;
//Flag indicating this buffer was mapped or filled
bool bIsDirty;
//Gets the buffer data from graphics memory
virtual void GetDeviceData(void* _buffer) = 0;
//Gets the next block offset we should use from the subclass
virtual size_t GetNextBlockOffset(size_t _size) = 0;
//Resets the block offset to zero
virtual void ResetBlockOffset() = 0;
public:
//Destructor
virtual ~ZDataBufferBase();
/*
public ZDataBufferBase::GetMemBufferResetDirty
Gets the backing memory buffer for this device. This will return
NULL if the buffer has not been modified since the last call to
this function, and in the case it has been modified, a call to this
resets the 'dirty' flag for the buffer.
@return (void*) - the backing memory buffer, NULL if not modified
@context (renderer)
*/
void* GetMemBufferResetDirty();
//Subclass Implementation
virtual const ZDataBufferBlock* DefineBlock(ZDataBufferBlockType _type,
size_t _size
);
//Subclass Implementation
virtual const ZDataBufferStream* DefineStream(ZDataBufferStreamType _type,
size_t _elemCount,
size_t _offset,
size_t _stride,
bool _normalize
);
//Subclass Implementation
virtual bool Fill(const void* _data, size_t _offset, size_t _byteCount);
//Subclass Implementation
virtual const ZDataBufferBlock* GetBlock(size_t index) { return Blocks[index]; }
//Subclass Implementation
virtual const ZDataBufferStream* GetStream(size_t index) { return Streams[index]; }
//Subclass Implementation
virtual size_t GetBlockCount() const { return Blocks.Size(); }
//Subclass Implementation
virtual size_t GetStreamCount() const { return Streams.Size(); }
//Subclass Implementation
virtual size_t GetSize();
//Subclass Implementation
virtual ZDataBufferType GetType();
//Subclass Implementation
virtual ZDataBufferUsage GetUsage();
//Subclass Implementation
virtual void* Map( bool _discard = false );
//Subclass Implementation
virtual void UndefBlocks();
//Subclass Implementation
virtual void UndefStreams();
//Subclass Implementation
virtual void Unmap();
};
#endif

View File

@@ -0,0 +1,91 @@
/*
ZDimensionTexture.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
'Dimension' (1D, 2D, 3D) Texture Interface.
License:
TODO
*/
#pragma once
#ifndef _ZDIMENSIONTEXTURE_HPP
#define _ZDIMENSIONTEXTURE_HPP
#include <ZUtil/ZBitmap.hpp>
#include <ZRenderer/ZTexture.hpp>
//Two dimensional texture interface class
class ZDimensionTexture : public ZTexture
{
public:
//Virtual Destructor
virtual ~ZDimensionTexture() { }
/*
virtual public ZDimensionTexture::Fill
Fills this texture with the data given in the bitmap data structure.
@param _data - the bitmap data
@return (bool) - true if able to fill the texture, false if unable (contested or locked)
@context (all)
*/
virtual bool Fill(const void* _data) = 0;
/*
virtual public ZDimensionTexture::GetBitmap
Function to get the image metadata for a texture as a ZBitmap. Does not get the
bitmap data field in the ZBitmap instance, which is set to NULL.
@return (const ZBitmapFormat) - bitmap format
@context (all)
*/
virtual const ZBitmapFormat GetBitmapFormat() = 0;
/*
virtual public ZDimensionTexture::Map
Maps this texture into memory and locks this texture until 'UnmapTexture' is called.
The bitmap parameter is a description of how the data is laid out in memory.
If the discard parameter is set to true, this tells the implementation that the data
that is currently present in the texture is not required, and this may result in a faster
return.
@param _discard - hint to the implementation that the data in the texture can be discarded
@return (void*) - pointer to the mapped buffer
@context (all)
*/
virtual void* Map( bool _discard) = 0;
/*
virtual public ZDimensionTexture::Unmap
Unmaps a previously mapped texture and unlocks the texture.
@return (void)
@context (all)
*/
virtual void Unmap() = 0;
//Not Implemented
virtual ZTextureType GetType() = 0;
//Not Implemented
virtual ZTextureUsage GetUsage() = 0;
//Not Implemented
virtual bool IsMipmapped() = 0;
};
#endif

View File

@@ -0,0 +1,110 @@
/*
ZDimensionTextureBase.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
Base implementation of a dimension (1D, 2D, 3D) texture.
License:
TODO
*/
#pragma once
#ifndef _ZDIMENSIONTEXTUREBASE_HPP
#define _ZDIMENSIONTEXTUREBASE_HPP
#include <ZRenderer/ZDimensionTexture.hpp>
class ZDimensionTextureBase : public ZDimensionTexture
{
protected:
//Type of texture
ZTextureType Type;
//Format of texture
ZTextureFormat Format;
//Usage type of texture
ZTextureUsage Usage;
//Bitmap format (including memory buffer, if needed)
ZBitmap Bitmap;
//Flag indicating this is a mipmapped texture
bool bIsMipmapped;
//Flag indicating the texture data has been modified
bool bIsDirty;
//Gets the texture data from graphics memory
virtual void GetDeviceData(void* _buffer) = 0;
/*
Parameterized Constructor.
@param _type - the texture type
@param _format - the texture internal storage format
@param _usage - the texture usage hint
@param _bitmap - the bitmap for this texture (or side of texture, in case of cube map)
@param _generateMipmaps - flag indicating we should generate mipmaps for this texture
*/
ZDimensionTextureBase(ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps);
public:
//Virtual Destructor
virtual ~ZDimensionTextureBase();
/*
public ZDimensionTextureBase::GetBitmapResetDirty
Gets the bitmap data for this dimension texture. This will return
NULL if the texture has not been modified since the last call to
this function, and in the case it has been modified, a call to this
resets the 'dirty' flag for the render target.
@return (ZBitmap*) - bitmap data, NULL if not dirty
@context (all)
*/
ZBitmap* GetBitmapResetDirty();
uint32_t GetWidth() { return Bitmap.GetWidth(); }
uint32_t GetHeight() { return Bitmap.GetHeight(); }
uint32_t GetDepth() { return Bitmap.GetDepth(); }
/*****************************/
/* ZDimensionTexture Methods */
/*****************************/
//Subclass Implementation
virtual bool Fill(const void* _data);
//Subclass Implementation
virtual const ZBitmapFormat GetBitmapFormat();
//Subclass Implementation
virtual void* Map(bool _discard);
//Subclass Implementation
virtual void Unmap();
/********************/
/* ZTexture Methods */
/********************/
//Subclass Implementation
virtual ZTextureType GetType();
//Subclass Implementation
virtual ZTextureUsage GetUsage();
//Subclass Implementation
virtual bool IsMipmapped();
};
#endif

View File

@@ -0,0 +1,62 @@
/*
ZDrawParams.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/17/2012
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZDRAWPARAMS_HPP
#define _ZDRAWPARAMS_HPP
#include <ZRenderer/ZRendererBuild.hpp>
//Draw Parameters Types
enum ZDrawParamsType
{
ZDPT_SHADER, //Shader Parameter Binding Structure
ZDPT_VERTEX, //Vertex Parameter Binding Structure
ZDPT_INDEX, //Index Parameter Binding Structure
ZDPT_SIZE
};
class ZDrawParams
{
public:
//Virtual Destructor
virtual ~ZDrawParams() { }
/*
virtual public ZDrawParams::MarkResourcesContended
Marks all resources bound in this draw parameters structure to be
contended by the renderer.
@return (void)
@context (renderer)
*/
virtual void MarkResourcesContended() = 0;
/*
virtual public ZDrawParams::ReleaseResourceContention
Releases resource contention from the renderer.
@return (void)
@context (renderer)
*/
virtual void ReleaseResourceContention() = 0;
};
#endif

View File

@@ -0,0 +1,138 @@
/*
ZFramebufferRenderTarget.h
Author: James Russell <jcrussell@762studios.com>
Purpose: Interface which defines a FrameBuffer, which is a render target that contains
a set of Textures or RenderBuffers which can be used for off-screen rendering.
Changelog
2011/04/03 - creation (jcrussell)
*/
#pragma once
#ifndef _ZFRAMEBUFFERRENDERTARGET_HPP
#define _ZFRAMEBUFFERRENDERTARGET_HPP
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZRenderTarget.hpp>
#include <ZRenderer/ZTexture.hpp>
#include <ZRenderer/ZRenderBuffer.hpp>
//The maximum number of color buffers supported on a single frame buffer render target
#ifndef ZFBRT_MAX_COLOR_BUFFERS
#define ZFBRT_MAX_COLOR_BUFFERS (16)
#endif
//Frame Buffer Render Target, used for off-screen rendering
class ZFramebufferRenderTarget : public ZRenderTarget
{
public:
/*
public ZFramebufferRenderTarget::AttachColorBuffer
Attach a texture to this frame buffer render target as a color buffer. All textures
set as color buffers must be of the same dimension, and their dimensions must match
that of GetWidth() and GetHeight().
@param _buffer - the texture to bind to this render target
@param _index - the index to bind this color buffer to
@return (bool) - true if able to attach buffer, false if resource contended
@context (all)
*/
virtual bool AttachColorTexture(ZPtr<ZTexture> _texture, size_t _index) = 0;
/*
virtual public ZFramebufferRenderTarget::AttachDepthTexture
Attaches a texture to this frame buffer render target as a depth buffer. The texture
set as the depth buffer must be of the same dimension as the color buffers, and it's
dimension must match that of GetWidth() and GetHeight().
A frame buffer render target cannot have a texture attached as a depth buffer as well
as a render buffer attached for the same purpose.
@param _texture - the texture to bind
@return (bool) - true if able to attach, false otherwise
@context (all)
*/
virtual bool AttachDepthTexture(ZPtr<ZTexture> _texture) = 0;
/*
virtual public ZFramebufferRenderTarget::AttachRenderBuffer
Attaches a render buffer to this frame buffer render target. The type of attachment
is determined by render buffer type.
A render buffer cannot be attached if another buffer is already attached that would
perform it's function, i.e., it is not possible to attach a depth buffer when a
depth texture is in place, and it is not possible to attach a stencil buffer
when a depth buffer is acting as depth and stencil buffer.
@param _buffer - the render buffer to attach
@return (bool) - true if able to attach buffer, false if resource contended
@context (all)
*/
virtual bool AttachRenderBuffer(ZPtr<ZRenderBuffer> _buffer) = 0;
/*
virtual public ZFramebufferRenderTarget::IsComplete
Checks to see if this FrameBuffer is in a 'complete' status and can be used. A
'complete' frame buffer requires at least one color buffer (bound at index 0) and
one depth buffer, and the buffers should be bound by the graphics library to the
frame buffer object.
@return (bool) - true if complete, false otherwise
@context (all)
*/
virtual bool IsComplete() = 0;
/*
virtual public ZFramebufferRenderTarget::RemoveColorBuffers
Removes the current set of color buffers attached to this frame buffer render target.
@return (bool) - true if able to remove buffers, false if resource contended
@context (all)
*/
virtual bool RemoveColorBuffers() = 0;
/*
virtual public ZFramebufferRenderTarget::RemoveDepthBuffer
Removes the current set depth buffers attached to this frame buffer render target.
@return (bool) - true if able to remove buffer, false if resource contended
@context (all)
*/
virtual bool RemoveDepthBuffer() = 0;
/*
virtual public ZFramebufferRenderTarget::RemoveStencilBuffer
Removes the current set stencil buffer attached to this frame buffer render target.
@return (bool) - true if able to remove buffer, false if resource contended
@context (all)
*/
virtual bool RemoveStencilBuffer() = 0;
//Not Implemented
virtual const ZRenderTargetClearFlags& GetClearFlags() = 0;
//Not Implemented
virtual size_t GetHeight() = 0;
//Not Implemented
virtual ZRenderTargetType GetType() = 0;
//Not Implemented
virtual size_t GetWidth() = 0;
//Not Implemented
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags) = 0;
};
#endif

View File

@@ -0,0 +1,150 @@
/*
ZFramebufferRenderTargetBase.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 08/07/2011
Purpose:
Base class implementation of the ZFramebufferRenderTarget interface.
License:
TODO
*/
#pragma once
#ifndef _ZFRAMEBUFFERRENDERTARGETBASE_HPP
#define _ZFRAMEBUFFERRENDERTARGETBASE_HPP
#include <ZRenderer/ZFramebufferRenderTarget.hpp>
#include <ZRenderer/ZTexture.hpp>
#include <ZRenderer/ZRenderBuffer.hpp>
//Buffer Data Struct, used to indicate buffer state
struct ZFramebufferRenderTargetBufferState
{
//Our set of attached Color Buffers
ZPtr<ZTexture> ColorBuffers[ZFBRT_MAX_COLOR_BUFFERS];
//Our attached depth texture
ZPtr<ZTexture> DepthTexture;
//Our attached depth buffer
ZPtr<ZRenderBuffer> DepthBuffer;
//Our attached stencil buffer
ZPtr<ZRenderBuffer> StencilBuffer;
//Indicates we are in a usable state
bool bIsComplete;
ZFramebufferRenderTargetBufferState()
: bIsComplete(false) { }
};
//Base class implementation of a frame buffer render target
class ZFramebufferRenderTargetBase : public ZFramebufferRenderTarget
{
private:
DISABLE_COPY_AND_ASSIGN(ZFramebufferRenderTargetBase);
protected:
//The 'clear' flags
ZRenderTargetClearFlags Flags;
//Width of the FBRT
size_t Width;
//Height of the FBRT
size_t Height;
//Flag indicating state has changed
bool bIsDirty;
//Buffer State for this frame buffer render target
ZFramebufferRenderTargetBufferState BufferState;
/*
Constructor.
@param _width - the width (in pixels / texels) of the FBRT
@param _height - the height (in pixels / texels) of the FBRT
*/
ZFramebufferRenderTargetBase(size_t _width, size_t _height);
public:
//Virtual Destructor
virtual ~ZFramebufferRenderTargetBase() { }
/*
public ZFramebufferRenderTargetBase::GetBufferState
Gets the buffer state for this frame buffer render target.
@return (ZFramebufferRenderTargetBufferState*) - the buffer state
@context (all)
*/
ZFramebufferRenderTargetBufferState* GetBufferState();
/*
public ZFramebufferRenderTargetBase::GetBufferStateResetDirty
Gets the backing buffer state for this render target. This will return
NULL if the buffer state has not been modified since the last call to
this function, and in the case it has been modified, a call to this
resets the 'dirty' flag for the render target.
@return (ZFramebufferRenderTargetBufferState*) - buffer state, NULL if not modified
@context (all)
*/
ZFramebufferRenderTargetBufferState* GetBufferStateResetDirty();
/*************************/
/* ZRenderTarget Methods */
/*************************/
//Subclass Implementation
virtual const ZRenderTargetClearFlags& GetClearFlags();
//Subclass Implementation
virtual size_t GetHeight();
//Subclass Implementation
virtual ZRenderTargetType GetType();
//Subclass Implementation
virtual size_t GetWidth();
//Subclass Implementation
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags);
/************************************/
/* ZFramebufferRenderTarget Methods */
/************************************/
//Subclass Implementation
virtual bool AttachColorTexture(ZPtr<ZTexture> _texture, size_t _index);
//Subclass Implementation
virtual bool AttachDepthTexture(ZPtr<ZTexture> _texture);
//Subclass Implementation
virtual bool AttachRenderBuffer(ZPtr<ZRenderBuffer> _buffer);
//Subclass Implementation
virtual bool IsComplete();
//Subclass Implementation
virtual bool RemoveColorBuffers();
//Subclass Implementation
virtual bool RemoveDepthBuffer();
//Subclass Implementation
virtual bool RemoveStencilBuffer();
};
#endif

View File

@@ -0,0 +1,163 @@
/*
ZIndexParams.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZINDEXPARAMS_HPP
#define _ZINDEXPARAMS_HPP
#include <ZRenderer/ZDrawParams.hpp>
#include <ZSTL/ZSTL.hpp>
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZDataBuffer.hpp>
typedef enum ZIndexPrimitiveType {
ZIPT_TRIANGLES, //Unrelated triangles, n/3 primitives are drawn
ZIPT_TRISTRIP, //Triangle Strip, n-2 primitives are drawn
ZIPT_LINES, //Unrelated lines, n/2 primitives are drawn
ZIPT_LINESTRIP, //Line Strip, n-1 primitives are drawn
ZIPT_POINTS, //Point list, n primitives are drawn
} ZIndexPrimitiveType;
class ZIndexParams : public ZDrawParams
{
private:
//This is the bound index buffer and block
ZPtr<ZDataBuffer> IndexBuffer;
ZPair<ZDataBuffer*, const ZDataBufferBlock*> Binding;
ZIndexPrimitiveType primType;
size_t nrPrims;
size_t offset;
public:
/*
Default Constructor.
*/
ZIndexParams();
/*
public ZIndexParams::ClearBlock
Clears the current block definition and index buffer.
@return (void)
@context (all)
*/
void ClearIndexBlock();
/*
public ZIndexParams::SetBlock
Sets the index buffer and index block that will be being used.
@param _indexBuffer - data buffer containing index data
@param _block - the index block
@return (void)
@context (all)
*/
void SetIndexBlock(ZPtr<ZDataBuffer> _indexBuffer, const ZDataBufferBlock* _block);
/*
public ZIndexParams::SetPrimitiveDrawCount
Sets the number of primitives that will be drawn. This is not the number
of indices used in total. For example, 300 indices with triangles will draw
100 triangles, so the primitive draw count should be 100.
The special value of '0' is interpreted as "draw as many as possible".
@param count - The number of primitives
@return (void)
@context (all)
*/
void SetPrimitiveDrawCount(size_t _count) { nrPrims = _count; }
/*
public ZIndexParams::GetPrimitiveDrawCount
Gets the number of primitives that will be drawn.
@return (size_t) - The number of primitives
@context (all)
*/
size_t GetPrimitiveDrawCount() const { return nrPrims; }
/*
public ZIndexParams::SetDrawOffset
Sets starting point for drawing, measured in whole indices (not bytes). For example,
if you had a stream that contained { 1, 3, 5, 7 } and you wanted to draw
starting at '3', then you would use an offset of 1 -- regardless of the
type of index (8, 16, 32-bit).
@param _offset - The offset measured in whole indices
@return (void)
@context (all)
*/
void SetDrawOffset(size_t _offset) { offset = _offset; }
/*
public ZIndexParams::GetDrawOffset
Gets starting point for drawing, measured in whole indices (not bytes)
@return (size_t) - The offset
@context (all)
*/
size_t GetDrawOffset() const { return offset; }
/*
public ZIndexParams::SetPrimitiveType
Sets primitive type to draw.
@param _type - The primitive type
@return (void)
@context (all)
*/
void SetPrimitiveType(ZIndexPrimitiveType _type) { primType = _type; }
/*
public ZIndexParams::GetPrimitiveType
Gets the type of primitive being rendered
@return (ZIndexPrimitiveType) - The primitive type
@context (all)
*/
ZIndexPrimitiveType GetPrimitiveType() { return primType; }
/*
The following methods are used by the renderer to get the values needed when
binding shader parameter values to pass to the shader program, to mark
all bound resources as contended, and release contention.
*/
const ZPair<ZDataBuffer*, const ZDataBufferBlock*>* GetIndexBlock();
ZDataBuffer* GetIndexBuffer();
//Subclass Override
virtual void MarkResourcesContended();
//Subclass Override
virtual void ReleaseResourceContention();
};
#endif

View File

@@ -0,0 +1,98 @@
/*
ZOpenGLDataBuffer.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 3/20/2011
Purpose:
OpenGL implementation of the ZDataBuffer interfaces.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLDATABUFFER_HPP
#define _ZOPENGLDATABUFFER_HPP
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZDataBufferBase.hpp>
//Forward Declarations
class ZOpenGLRenderer;
/*
OpenGL Data Buffer.
*/
class ZOpenGLDataBuffer : public ZDataBufferBase
{
protected:
//Renderer associated with this buffer
ZOpenGLRenderer *Renderer;
//The current offset to use
size_t NextOffset;
//Offset Alignment Requirement
static int OffsetAlignment;
//Gets the buffer data from the graphics device as part of a thread request
static void GetDeviceData_( ZThread *_renderThread, void *_dataBuffer );
//Subclass Override
virtual void GetDeviceData(void* _buffer);
//Subclass Override
virtual size_t GetNextBlockOffset(size_t _size);
//Subclass Override
virtual void ResetBlockOffset();
public:
//OpenGL Handle to the Buffer
GLuint GLHandle;
//Gets a GLenum based off of type
GLenum GetGLType()
{
switch (Type)
{
case ZDBT_UNIFORM: return GL_UNIFORM_BUFFER;
case ZDBT_VERTEX: return GL_ARRAY_BUFFER;
case ZDBT_INDEX: return GL_ELEMENT_ARRAY_BUFFER;
default: return GL_INVALID_ENUM;
}
}
//Gets a GLenum based off of usage
GLenum GetGLUsage()
{
switch(Usage)
{
case ZDBU_STATIC: return GL_STATIC_DRAW;
case ZDBU_DYNAMIC: return GL_DYNAMIC_DRAW;
case ZDBU_STREAMING: return GL_STREAM_DRAW;
default: return GL_INVALID_ENUM;
}
}
/*
Constructor.
@param _renderer - the current renderer
@param _type - the type of buffer this is
@param _usage - the usage type of this buffer
@param _size - the size (in bytes) of the data buffer
*/
ZOpenGLDataBuffer(ZOpenGLRenderer *_renderer, ZDataBufferType _type, ZDataBufferUsage _usage, size_t _size);
/*
Destructor.
*/
virtual ~ZOpenGLDataBuffer();
};
#endif

View File

@@ -0,0 +1,262 @@
/*
ZOpenGLDimensionTexture.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
OpenGL implementation of a 'dimensional' (1D, 2D, 3D) texture.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLDIMENSIONTEXTURE_HPP
#define _ZOPENGLDIMENSIONTEXTURE_HPP
#include <SST/SST_GLAPI.h>
#include <ZRenderer/ZDimensionTextureBase.hpp>
//Forward Declarations
class ZOpenGLRenderer;
//OpenGL implementation of the two dimensional texture interface
class ZOpenGLDimensionTexture : public ZDimensionTextureBase
{
private:
DISABLE_COPY_AND_ASSIGN(ZOpenGLDimensionTexture);
protected:
//Gets the texture data from the graphics device as part of a thread request
static void GetDeviceData_( ZThread *_renderThread, void *_dataBuffer );
//Subclass Implementation
virtual void GetDeviceData(void* _buffer);
public:
//Renderer associated with this texture
ZOpenGLRenderer *Renderer;
//The OpenGL handle to the loaded texture
GLuint GLHandle;
//Gets the OpenGL 'target' parameter for this texture type
GLenum GetGLTarget()
{
switch(Type)
{
case ZTT_TEXTURE1D: return GL_TEXTURE_1D;
case ZTT_TEXTURE2D: return GL_TEXTURE_2D;
case ZTT_TEXTURE3D: return GL_TEXTURE_3D;
case ZTT_TEXTURE_CUBE: /* Invalid Here */
default: return GL_INVALID_ENUM;
}
}
//Gets the OpenGL 'internalFormat' parameter for this texture format (used for glTexImage*D)
GLenum GetGLInternalFormat()
{
switch (Format)
{
case ZTF_R8: return GL_R8;
case ZTF_R8_SNORM: return GL_R8_SNORM;
case ZTF_R8I: return GL_R8I;
case ZTF_R8UI: return GL_R8UI;
case ZTF_R16: return GL_R16;
case ZTF_R16_SNORM: return GL_R16_SNORM;
case ZTF_R16I: return GL_R16I;
case ZTF_R16UI: return GL_R16UI;
case ZTF_R16F: return GL_R16F;
case ZTF_R32I: return GL_R32I;
case ZTF_R32UI: return GL_R32UI;
case ZTF_R32F: return GL_R32F;
case ZTF_RG8: return GL_RG8;
case ZTF_RG8_SNORM: return GL_RG8_SNORM;
case ZTF_RG8I: return GL_RG8I;
case ZTF_RG8UI: return GL_RG8UI;
case ZTF_RG16: return GL_RG16;
case ZTF_RG16_SNORM: return GL_RG16_SNORM;
case ZTF_RG16I: return GL_RG16I;
case ZTF_RG16UI: return GL_RG16UI;
case ZTF_RG16F: return GL_RG16F;
case ZTF_RG32I: return GL_RG32I;
case ZTF_RG32UI: return GL_RG32UI;
case ZTF_RG32F: return GL_RG32F;
case ZTF_RGB8: return GL_RGB8;
case ZTF_RGB8_SNORM: return GL_RGB8_SNORM;
case ZTF_RGB8I: return GL_RGB8I;
case ZTF_RGB8UI: return GL_RGB8UI;
case ZTF_RGB16: return GL_RGB16;
case ZTF_RGB16_SNORM: return GL_RGB16_SNORM;
case ZTF_RGB16I: return GL_RGB16I;
case ZTF_RGB16UI: return GL_RGB16UI;
case ZTF_RGB16F: return GL_RGB16F;
case ZTF_RGB32I: return GL_RGB32I;
case ZTF_RGB32UI: return GL_RGB32UI;
case ZTF_RGB32F: return GL_RGB32F;
case ZTF_RGBA8: return GL_RGBA8;
case ZTF_RGBA8_SNORM: return GL_RGBA8_SNORM;
case ZTF_RGBA8I: return GL_RGBA8I;
case ZTF_RGBA8UI: return GL_RGBA8UI;
case ZTF_RGBA16: return GL_RGBA16;
case ZTF_RGBA16_SNORM: return GL_RGBA16_SNORM;
case ZTF_RGBA16I: return GL_RGBA16I;
case ZTF_RGBA16UI: return GL_RGBA16UI;
case ZTF_RGBA16F: return GL_RGBA16F;
case ZTF_RGBA32I: return GL_RGBA32I;
case ZTF_RGBA32UI: return GL_RGBA32UI;
case ZTF_RGBA32F: return GL_RGBA32F;
case ZTF_DEPTH16: return GL_DEPTH_COMPONENT16;
case ZTF_DEPTH24: return GL_DEPTH_COMPONENT24;
case ZTF_DEPTH32: return GL_DEPTH_COMPONENT32;
case ZTF_DEPTH24_STENCIL8: return GL_DEPTH24_STENCIL8;
default: return GL_INVALID_ENUM;
}
}
//Gets the OpenGL 'format' parameter for this texture's bitmap format (used for glTexImage*D)
GLenum GetGLFormat()
{
switch (Bitmap.GetFormat())
{
case ZBF_R8:
case ZBF_R8I:
case ZBF_R16:
case ZBF_R16I:
case ZBF_R32:
case ZBF_R32I:
case ZBF_R32F: return GL_RED;
case ZBF_RG8:
case ZBF_RG8I:
case ZBF_RG16:
case ZBF_RG16I:
case ZBF_RG32:
case ZBF_RG32I:
case ZBF_RG32F: return GL_RG;
case ZBF_RGB8:
case ZBF_RGB8I:
case ZBF_RGB16:
case ZBF_RGB16I:
case ZBF_RGB32:
case ZBF_RGB32I:
case ZBF_RGB32F: return GL_RGB;
case ZBF_RGBA8:
case ZBF_RGBA8I:
case ZBF_RGBA16:
case ZBF_RGBA16I:
case ZBF_RGBA32:
case ZBF_RGBA32I:
case ZBF_RGBA32F: return GL_RGBA;
case ZBF_BGR8:
case ZBF_BGR8I:
case ZBF_BGR16:
case ZBF_BGR16I:
case ZBF_BGR32:
case ZBF_BGR32I:
case ZBF_BGR32F: return GL_BGR;
case ZBF_BGRA8:
case ZBF_BGRA8I:
case ZBF_BGRA16:
case ZBF_BGRA16I:
case ZBF_BGRA32:
case ZBF_BGRA32I:
case ZBF_BGRA32F: return GL_BGRA;
case ZBF_DEPTH32: return GL_DEPTH_COMPONENT;
default: return GL_INVALID_ENUM;
}
}
//Gets the OpenGL 'type' parameter for this texture's bitmap format (used for glTexImage*D calls)
GLenum GetGLType()
{
switch (Bitmap.GetFormat())
{
case ZBF_R8:
case ZBF_RG8:
case ZBF_RGB8:
case ZBF_RGBA8:
case ZBF_BGR8:
case ZBF_BGRA8: return GL_UNSIGNED_BYTE;
case ZBF_R8I:
case ZBF_RG8I:
case ZBF_RGB8I:
case ZBF_RGBA8I:
case ZBF_BGR8I:
case ZBF_BGRA8I: return GL_BYTE;
case ZBF_R16:
case ZBF_RG16:
case ZBF_RGB16:
case ZBF_RGBA16:
case ZBF_BGR16:
case ZBF_BGRA16: return GL_UNSIGNED_SHORT;
case ZBF_R16I:
case ZBF_RG16I:
case ZBF_RGB16I:
case ZBF_RGBA16I:
case ZBF_BGR16I:
case ZBF_BGRA16I: return GL_SHORT;
case ZBF_R32:
case ZBF_RG32:
case ZBF_RGB32:
case ZBF_RGBA32:
case ZBF_BGR32:
case ZBF_BGRA32: return GL_UNSIGNED_INT;
case ZBF_R32I:
case ZBF_RG32I:
case ZBF_RGB32I:
case ZBF_RGBA32I:
case ZBF_BGR32I:
case ZBF_BGRA32I: return GL_INT;
case ZBF_R32F:
case ZBF_RG32F:
case ZBF_RGB32F:
case ZBF_RGBA32F:
case ZBF_BGR32F:
case ZBF_BGRA32F: return GL_FLOAT;
case ZBF_DEPTH32: return GL_UNSIGNED_INT;
default: return GL_INVALID_ENUM;
}
}
/*
Constructor.
@param _renderer - the current renderer instance
@param _type - the type of texture
@param _format - the format of the texture
@param _usage - the usage type of texture
@param _bitmap - the bitmap for this texture (or side, in case of cube map)
@param _generateMipmaps - flag indicating we should generate mipmaps
*/
ZOpenGLDimensionTexture(ZOpenGLRenderer* _renderer, ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps);
//Virtual destructor
virtual ~ZOpenGLDimensionTexture();
};
#endif

View File

@@ -0,0 +1,53 @@
/*
ZOpenGLFrameBufferRenderTarget.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 07/24/2011
Purpose:
OpenGL implementation of the ZFramebufferRenderTargetBase class.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLFRAMEBUFFERRENDERTARGET_HPP
#define _ZOPENGLFRAMEBUFFERRENDERTARGET_HPP
//Forward Declarations
class ZOpenGLRenderer;
#include <ZRenderer/ZFramebufferRenderTargetBase.hpp>
#include <SST/SST_GLAPI.h>
class ZOpenGLFramebufferRenderTarget : public ZFramebufferRenderTargetBase
{
protected:
//Renderer Instance
ZOpenGLRenderer* Renderer;
public:
//The OpenGL handle to the FBO
GLuint GLHandle;
/*
Constructor.
@param _renderer - the current renderer
@param _width - the width this frame buffer render target be be
@param _height - the height this frame buffer render target will be
*/
ZOpenGLFramebufferRenderTarget(ZOpenGLRenderer *_renderer, size_t _width, size_t _height);
/*
Destructor.
*/
~ZOpenGLFramebufferRenderTarget();
};
#endif

View File

@@ -0,0 +1,84 @@
/*
ZOpenGLRenderBuffer.hpp
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Purpose:
Implementation of the render buffer interface for OpenGL renderers.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLRENDERBUFFER_HPP
#define _ZOPENGLRENDERBUFFER_HPP
//Forward Declaration
class ZOpenGLRenderer;
#include <SST/SST_GLAPI.h>
#include <ZRenderer/ZRenderBuffer.hpp>
class ZOpenGLRenderBuffer : public ZRenderBuffer
{
protected:
//Renderer Instance
ZOpenGLRenderer* Renderer;
//The type of render buffer
ZRenderBufferType Type;
//Width of the render buffer
size_t Width;
//Height of the render buffer
size_t Height;
public:
//Gets the GL storage type
inline GLenum GetGLType()
{
switch(Type)
{
case ZRBT_DEPTH16: return GL_DEPTH_COMPONENT16;
case ZRBT_DEPTH24: return GL_DEPTH_COMPONENT24;
case ZRBT_DEPTH32: return GL_DEPTH_COMPONENT32;
case ZRBT_STENCIL8: return GL_STENCIL_INDEX8;
case ZRBT_DEPTH24_STENCIL8: return GL_DEPTH24_STENCIL8;
default: return GL_INVALID_ENUM;
}
}
//The OpenGL handle to the render buffer
GLuint GLHandle;
/*
Constructor.
@param _renderer - the current renderer instance
@param _type - the type of render buffer this will be
@param _width - with of the render buffer
@param _height - height of the render buffer
*/
ZOpenGLRenderBuffer( ZOpenGLRenderer *_renderer, ZRenderBufferType _type, size_t _width, size_t _height);
//Destructor
virtual ~ZOpenGLRenderBuffer();
//Subclass Implementation
virtual size_t GetHeight();
//Subclass Implementation
virtual ZRenderBufferType GetType();
//Subclass Implementation
virtual size_t GetWidth();
};
#endif

View File

@@ -0,0 +1,197 @@
/*
ZOpenGLRenderer.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 3/27/2011
Purpose:
OpenGL implementation of the Renderer. Currently requires OpenGL 3.3.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLRENDERER_HPP
#define _ZOPENGLRENDERER_HPP
#include <SST/SST_GLAPI.h>
#include <SST/SST_WMOpenGL.h>
#include <ZRenderer/ZRendererBase.hpp>
#include <ZRenderer/ZOpenGLDataBuffer.hpp>
#include <ZRenderer/ZOpenGLShader.hpp>
#include <ZRenderer/ZOpenGLShaderProgram.hpp>
#include <ZRenderer/ZOpenGLDimensionTexture.hpp>
#include <ZRenderer/ZOpenGLSampler.hpp>
#include <ZRenderer/ZOpenGLFrameBufferRenderTarget.hpp>
#include <ZRenderer/ZOpenGLRenderBuffer.hpp>
#include <ZRenderer/ZOpenGLWindowRenderTarget.hpp>
#include <ZRenderer/ZOpenGLVertexParams.hpp>
//CHECKGL function, which checks for OpenGL Error conditions and asserts when they are found
void CheckGL();
//CHECKGL macro for debug mode
#if ZRENDERER_CHECKGL
#define CHECKGL() (CheckGL())
#else
#define CHECKGL()
#endif
//Enumeration for various OpenGL resource types
enum ZOpenGLResourceType
{
ZOGLRT_BUFFER, //OpenGL Buffer Object
ZOGLRT_SHADER, //OpenGL Shader Object
ZOGLRT_SHADER_PROGRAM, //OpenGL Shader Program Object
ZOGLRT_TEXTURE, //OpenGL Texture Object
ZOGLRT_SAMPLER, //OpenGL Sampler Object
ZOGLRT_FRAME_BUFFER, //OpenGL Frame Buffer Object
ZOGLRT_RENDER_BUFFER, //OpenGL Render Buffer Object
ZOGLRT_VERTEX_ARRAY, //OpenGL Vertex Array Object
ZOGLRT_SIZE
};
/*
OpenGL Renderer implementation class.
*/
class ZOpenGLRenderer : public ZRendererBase
{
private:
DISABLE_COPY_AND_ASSIGN(ZOpenGLRenderer);
//Resource Generation Thread Request
class ResourceGenerationThreadRequest : public ZThreadRequest
{
public:
//Default Constructor
ResourceGenerationThreadRequest() : ZThreadRequest(true) { }
//Concurrency control lock for resource generation and cleanup
ZMutex ResourceMutex;
//Indicator that we have a pending resource request
bool bPendingResourceRequest;
//Resource Generation Requests
ZArray< ZPtr<ZOpenGLDataBuffer> > DataBufferGenerateRequests;
ZArray< ZPtr<ZOpenGLShader> > ShaderGenerateRequests;
ZArray< ZPtr<ZOpenGLShaderProgram> > ShaderProgramGenerateRequests;
ZArray< ZPtr<ZOpenGLDimensionTexture> > DimensionTextureGenerateRequests;
ZArray<ZPtr<ZOpenGLSampler> > SamplerGenerateRequests;
ZArray< ZPtr<ZOpenGLFramebufferRenderTarget> > FrameBufferGenerateRequests;
ZArray< ZPtr<ZOpenGLRenderBuffer> > RenderBufferGenerateRequests;
ZArray< ZPtr<ZOpenGLVertexParams> > VertexParamsGenerateRequests;
//Resource Delete Requests
ZArray< ZPair<ZOpenGLResourceType, GLuint> > ResourceDeleteRequests;
//Subclass Implementation
virtual void Execute( ZThread *_threadObj );
};
protected:
//The initialization window
SST_Window InitializationWindow;
//The OpenGL Context for this renderer
SST_OpenGLContext GLContext;
//Indicates we own the GLContext
bool bOwnsContext;
//The Current Render State
ZRenderState *CurrentRenderState;
//Resource Request Object
ZPtr<ResourceGenerationThreadRequest> ResourceThreadRequest;
//Subclass Override
virtual bool init();
//Subclass Override
virtual void initThread();
//Subclass Override
virtual void shutdown();
//Subclass Override
virtual void shutdownThread();
//Subclass Override
virtual void Draw(ZArray<ZDrawData*,
ZArrayAllocator< ZDrawData*, ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE> >& _renderList,
ZRenderTarget* _renderTarget);
public:
/*
Constructor.
Initializes this renderer with the given OpenGL context.
The provided window handle is only used for binding to a window so that OpenGL values can be obtained. In order
to render to the provided window, a ZWindowRenderTarget will need to be created using that window handle after
the renderer has finished initializing.
@param _glContext - the OpenGL context to initialize this renderer with
@param _window - window to initialize this renderer with
@param _ownContext - indicates whether this renderer 'owns' the context and should clean up when destructed
*/
ZOpenGLRenderer(SST_OpenGLContext _glContext, SST_Window _window, bool _ownContext);
/*
Destructor.
*/
~ZOpenGLRenderer();
/*
public ZOpenGLRenderer::DeleteResource
This will ask the renderer thread to clean up a previously generated OpenGL resource.
@param _type - the type of resource
@param _handle - the handle to the resource
@return (void)
@context (all)
*/
void DeleteResource(ZOpenGLResourceType _type, GLuint _handle);
//////////////////////////
/* Logistics Operations */
//////////////////////////
//Subclass Override
virtual ZPtr<ZDataBuffer> CreateDataBuffer(ZDataBufferType _type,
ZDataBufferUsage _usage,
size_t _size);
//Subclass Override
virtual ZPtr<ZDrawParams> CreateDrawParams(ZDrawParamsType _type);
//Subclass Override
virtual ZPtr<ZFramebufferRenderTarget> CreateFrameBufferRenderTarget(size_t _width, size_t _height);
//Subclass Override
virtual ZPtr<ZRenderBuffer> CreateRenderBuffer(ZRenderBufferType _type, size_t _width, size_t _height);
//Subclass Override
virtual ZPtr<ZSampler> CreateSampler();
//Subclass Override
virtual ZPtr<ZShader> CreateShader(ZShaderType _type);
//Subclass Override
virtual ZPtr<ZShaderProgram> CreateShaderProgram();
//Subclass Override
virtual ZPtr<ZTexture> CreateTexture(ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps);
//Subclass Override
virtual ZPtr<ZRenderTarget> CreateWindowRenderTarget(SST_Window _window,
size_t _screenIndex);
};
#endif

View File

@@ -0,0 +1,162 @@
/*
ZOpenGLSampler.hpp
Author: James Russell <jcrussell@762studios.com>,
Chris Ertel <crertel@762studios.com>
Created: 7/1/2012
Purpose:
OpenGL implementation of the ZSampler interface class.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLSAMPLER_HPP
#define _ZOPENGLSAMPLER_HPP
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZSamplerBase.hpp>
#include <SST/SST_GLAPI.h>
//Forward Declarations
class ZOpenGLRenderer;
struct ZOpenGLSamplerState
{
GLenum SWrapMode; //Wrapping mode for S
GLenum TWrapMode; //Wrapping mode for T (unused for 1D)
GLenum RWrapMode; //Wrapping mode for R (unused for 1D, 2D)
GLenum MinFilter; //Minification Filter (including mip filter)
GLenum MagFilter; //Magnification Filter
float MaxAnisotropy; //Maximum Anisotropy (< 2.0 has no effect)
float MinLOD; //Minimum LOD
float MaxLOD; //Maximum LOD
float LODBias; //LOD Bias
float BorderColor[4]; //RGBA Border Color
GLenum CompareMode; //Sampler Comparison Mode
GLenum CompareFunc; //Sampler Comparison Function
};
//OpenGL implementation of the ZSampler interface class
class ZOpenGLSampler : public ZSamplerBase
{
private:
DISABLE_COPY_AND_ASSIGN(ZOpenGLSampler);
protected:
//The current renderer
ZOpenGLRenderer* Renderer;
//Sampler State
ZOpenGLSamplerState OpenGLSamplerState;
public:
//OpenGL Handle for the Sampler object
GLuint GLHandle;
//Gets the OpenGL Sampler State
const ZOpenGLSamplerState& GetGLSamplerState()
{
switch (State.SWrapMode)
{
case ZSWM_CLAMP_EDGE: OpenGLSamplerState.SWrapMode = GL_CLAMP_TO_EDGE; break;
case ZSWM_CLAMP_BORDER: OpenGLSamplerState.SWrapMode = GL_CLAMP_TO_BORDER; break;
case ZSWM_MIRROR_REPEAT: OpenGLSamplerState.SWrapMode = GL_MIRRORED_REPEAT; break;
case ZSWM_REPEAT: OpenGLSamplerState.SWrapMode = GL_REPEAT; break;
default: OpenGLSamplerState.SWrapMode = GL_INVALID_ENUM; break;
}
switch (State.TWrapMode)
{
case ZSWM_CLAMP_EDGE: OpenGLSamplerState.TWrapMode = GL_CLAMP_TO_EDGE; break;
case ZSWM_CLAMP_BORDER: OpenGLSamplerState.TWrapMode = GL_CLAMP_TO_BORDER; break;
case ZSWM_MIRROR_REPEAT: OpenGLSamplerState.TWrapMode = GL_MIRRORED_REPEAT; break;
case ZSWM_REPEAT: OpenGLSamplerState.TWrapMode = GL_REPEAT; break;
default: OpenGLSamplerState.TWrapMode = GL_INVALID_ENUM; break;
}
switch (State.RWrapMode)
{
case ZSWM_CLAMP_EDGE: OpenGLSamplerState.RWrapMode = GL_CLAMP_TO_EDGE; break;
case ZSWM_CLAMP_BORDER: OpenGLSamplerState.RWrapMode = GL_CLAMP_TO_BORDER; break;
case ZSWM_MIRROR_REPEAT: OpenGLSamplerState.RWrapMode = GL_MIRRORED_REPEAT; break;
case ZSWM_REPEAT: OpenGLSamplerState.RWrapMode = GL_REPEAT; break;
default: OpenGLSamplerState.RWrapMode = GL_INVALID_ENUM; break;
}
switch(State.MagFilter)
{
case ZSMAGF_NEAREST: OpenGLSamplerState.MagFilter = GL_NEAREST; break;
case ZSMAGF_LINEAR: OpenGLSamplerState.MagFilter = GL_LINEAR; break;
default: OpenGLSamplerState.MagFilter = GL_INVALID_ENUM; break;
}
switch(State.MinFilter)
{
case ZSMINF_NEAREST: OpenGLSamplerState.MinFilter = GL_NEAREST; break;
case ZSMINF_NEAREST_MIP_NEAREST: OpenGLSamplerState.MinFilter = GL_NEAREST_MIPMAP_NEAREST; break;
case ZSMINF_NEAREST_MIP_LINEAR: OpenGLSamplerState.MinFilter = GL_NEAREST_MIPMAP_LINEAR; break;
case ZSMINF_LINEAR: OpenGLSamplerState.MinFilter = GL_LINEAR; break;
case ZSMINF_LINEAR_MIP_NEAREST: OpenGLSamplerState.MinFilter = GL_LINEAR_MIPMAP_NEAREST; break;
case ZSMINF_LINEAR_MIP_LINEAR: OpenGLSamplerState.MinFilter = GL_LINEAR_MIPMAP_LINEAR; break;
default: OpenGLSamplerState.MinFilter = GL_INVALID_ENUM; break;
}
OpenGLSamplerState.MaxAnisotropy = State.MaxAnisotropy;
OpenGLSamplerState.MinLOD = State.MinLOD;
OpenGLSamplerState.MaxLOD = State.MaxLOD;
OpenGLSamplerState.LODBias = State.LODBias;
OpenGLSamplerState.BorderColor[0] = State.BorderColor[0];
OpenGLSamplerState.BorderColor[1] = State.BorderColor[1];
OpenGLSamplerState.BorderColor[2] = State.BorderColor[2];
OpenGLSamplerState.BorderColor[3] = State.BorderColor[3];
switch(State.CompareMode)
{
case ZSCM_NONE: OpenGLSamplerState.CompareMode = GL_NONE; break;
case ZSCM_COMPARE_REF_TO_TEXTURE: OpenGLSamplerState.CompareMode = GL_COMPARE_REF_TO_TEXTURE; break;
default: OpenGLSamplerState.CompareMode = GL_INVALID_ENUM; break;
}
switch(State.CompareFunc)
{
case ZSCF_NEVER: OpenGLSamplerState.CompareFunc = GL_NEVER; break;
case ZSCF_ALWAYS: OpenGLSamplerState.CompareFunc = GL_ALWAYS; break;
case ZSCF_EQUAL: OpenGLSamplerState.CompareFunc = GL_EQUAL; break;
case ZSCF_NOT_EQUAL: OpenGLSamplerState.CompareFunc = GL_NOTEQUAL; break;
case ZSCF_LESS: OpenGLSamplerState.CompareFunc = GL_LESS; break;
case ZSCF_LESS_EQUAL: OpenGLSamplerState.CompareFunc = GL_LEQUAL; break;
case ZSCF_GREATER: OpenGLSamplerState.CompareFunc = GL_GREATER; break;
case ZSCF_GREATER_EQUAL: OpenGLSamplerState.CompareFunc = GL_GEQUAL; break;
default: OpenGLSamplerState.CompareFunc = GL_INVALID_ENUM; break;
}
return OpenGLSamplerState;
}
/*
Default Constructor.
*/
ZOpenGLSampler(ZOpenGLRenderer* _renderer);
/*
Destructor.
*/
~ZOpenGLSampler();
};
#endif

View File

@@ -0,0 +1,66 @@
/*
ZOpenGLShader.hpp
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 04/20/2011
Purpose:
OpenGL implementation of the shader interface.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLSHADER_HPP
#define _ZOPENGLSHADER_HPP
#include <ZRenderer/ZShaderBase.hpp>
#include <ZUtil/ZUtil.hpp>
#include <SST/SST_GLAPI.h>
//Forward Declarations
class ZOpenGLRenderer;
/*
OpenGL Shader Implementation.
*/
class ZOpenGLShader : public ZShaderBase
{
private:
DISABLE_COPY_AND_ASSIGN(ZOpenGLShader);
protected:
//The renderer that created us
ZOpenGLRenderer* Renderer;
//Method used to compile the shader
static void Compile_(ZThread* _thread, void* _shader);
public:
//OpenGL Shader Handle
GLuint GLHandle;
/*
Constructor.
@param _renderer - the current renderer instance
@param _type - the type of shader
*/
ZOpenGLShader(ZOpenGLRenderer* _renderer, ZShaderType _type);
/*
Destructor.
*/
virtual ~ZOpenGLShader();
//Subclass Override
virtual bool Compile();
};
#endif

View File

@@ -0,0 +1,69 @@
/*
ZOpenGLShaderProgram.h
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 04/03/2011
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLSHADERPROGRAM_HPP
#define _ZOPENGLSHADERPROGRAM_HPP
#include <ZRenderer/ZShaderProgramBase.hpp>
#include <ZRenderer/ZOpenGLShader.hpp>
#include <SST/SST_GLAPI.h>
//Forward Declarations
class ZOpenGLRenderer;
//Struct we use to track opengl handles for uniform blocks and block members
struct ZOpenGLUniformBlockData
{
GLuint BlockIndex; //OpenGL Index for UniformBlocks[i]
ZArray<GLuint> MemberIndices; //OpenGL Index for UniformBlocks[i].Members[i]
};
//OpenGL Implementation of ZShaderProgram
class ZOpenGLShaderProgram : public ZShaderProgramBase
{
protected:
//Parent renderer
ZOpenGLRenderer* Renderer;
//Static method used to link a shader program
static void Link_(ZThread* _thread, void* _shaderProgram);
public:
//Handle to the program in OpenGL
GLuint GLHandle;
//Our set of uniform indices, sampler indices, and stream indices
ZArray<ZOpenGLUniformBlockData> OpenGLUniformBlockData;
ZArray<GLuint> OpenGLSamplerData;
ZArray<GLuint> OpenGLStreamData;
/*
Constructor.
@param _renderer - the current renderer
*/
ZOpenGLShaderProgram(ZOpenGLRenderer* _renderer);
//Virtual destructor
virtual ~ZOpenGLShaderProgram();
//Subclass Implementation
virtual bool Link();
};
#endif

View File

@@ -0,0 +1,92 @@
/*
ZOpenGLTextureRenderTarget.h
Author: Chris Ertel (cre1)
Purpose: TODO
Changelog
2011/05/22 - creation (cre1)
*/
#pragma once
#ifndef _ZOPENGLTEXTURERENDERTARGET_H
#define _ZOPENGLTEXTURERENDERTARGET_H
#include <ZRendering/ZTextureRenderTarget.h>
#include <ZRendering/ZOpenGLRenderer.h>
#include <GLee/GLee.h>
class ZOpenGLTexture;
class ZOpenGLTextureRenderTarget;
class ZOpenGLTextureRenderTargetLoadRequest : public ZThreadRequest
{
private:
ZOpenGLTextureRenderTarget *Target;
public:
ZOpenGLTextureRenderTargetLoadRequest(ZOpenGLTextureRenderTarget *_target);
void Execute(ZThread *_renderer);
};
class ZOpenGLTextureRenderTarget : public ZTextureRenderTarget
{
friend class ZOpenGLTextureRenderTargetLoadRequest;
protected:
//The OpenGL Texture
// ZOpenGLTexture Tex;
//The glhandle to the FrameBuffer
GLuint FrameBufferHandle;
//The glhandle to the RenderBuffer
GLuint RenderBufferHandle;
float ClearColor[4];
int Width;
int Height;
int BPP;
public:
//Default Constructor
ZOpenGLTextureRenderTarget(ZOpenGLRenderer *_renderer, int _width, int _height, int _bpp, int _rgbaSize, float *_clearColor = NULL);
//Subclass Implementation
bool Activate();
//Subclass Implementation
void Deactivate();
void SetClearColor(float r, float g, float b, float a);
void SetClearColor(float* _in);
//Subclass Implementation (Currently Non-Functional)
void SetDimensions(int _width, int _height)
{
URFP(_width);
URFP(_height);
}
//Subclass Implementation (Currently Non-Functional)
void SetBitsPerPixel(int _bbp)
{
URFP(_bbp);
}
//Subclass Implementation (Currently Non-Functional)
void SetRGBASize(int _rgbaSize)
{
URFP(_rgbaSize);
}
//Gets the render target as a texture
ZTexture* GetTexture();
//Gets the texture as a render target
ZRenderTarget* GetRenderTarget();
};
#endif

View File

@@ -0,0 +1,46 @@
/*
ZOpenGLVertexParams.hpp
Author: Patrick Baggett <ptbaggett@762studios.com>
Created: 12/13/2012
Purpose:
OpenGL specific version of ZVertexParams that implements VAOs.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLVERTEXPARAMS_HPP
#define _ZOPENGLVERTEXPARAMS_HPP
#include <ZRenderer/ZVertexParams.hpp>
#include <ZRenderer/ZOpenGLShaderProgram.hpp>
#include <SST/SST_GLAPI.h>
class ZOpenGLRenderer;
class ZOpenGLVertexParams : public ZVertexParams
{
public:
ZOpenGLVertexParams(ZOpenGLRenderer* renderer) :
Renderer(renderer), vaoHandle(0), arrayBufferBound(0), elementBufferBound(0)
{
}
~ZOpenGLVertexParams();
void UpdateDirty(ZOpenGLShaderProgram* prgm);
ZOpenGLRenderer* Renderer;
GLuint vaoHandle; //Vertex Array Object (VAO) handle
GLuint arrayBufferBound; //VBO (GL_ARRAY_BUFFER) that was bound
GLuint elementBufferBound; //VBO (GL_ELEMENT_BUFFER) that was bound
};
#endif

View File

@@ -0,0 +1,60 @@
/*
ZOpenGLWindowRenderTarget.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 04/01/2011
Purpose:
Initializes and manages an OpenGL window.
License:
TODO
*/
#pragma once
#ifndef _ZOPENGLWINDOWRENDERTARGET_HPP
#define _ZOPENGLWINDOWRENDERTARGET_HPP
#include <ZRenderer/ZWindowRenderTargetBase.hpp>
//Forward Declarations
class ZOpenGLRenderer;
/*
Screen Render Target for the OpenGL library.
*/
class ZOpenGLWindowRenderTarget : public ZWindowRenderTargetBase
{
private:
DISABLE_COPY_AND_ASSIGN(ZOpenGLWindowRenderTarget);
protected:
//Renderer Instance
ZOpenGLRenderer *Renderer;
public:
//OpenGL Context
SST_OpenGLContext GLContext;
/*
Parameterized Constructor.
@param _renderer - the renderer instance
@param _glContext - the OpenGL context to bind to this window
@param _window - the window instance (created with libsst-wm)
@param _screen - the screen index chosen
*/
ZOpenGLWindowRenderTarget(ZOpenGLRenderer* _renderer, SST_OpenGLContext _glContext, SST_Window _window, size_t _screenIndex);
/*
Destructor.
*/
~ZOpenGLWindowRenderTarget();
//Subclass Override
virtual bool SwapBuffers();
};
#endif

View File

@@ -0,0 +1,71 @@
/*
ZRenderBuffer.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 04/03/2011
Purpose:
Buffer that can be used for depth and stencil buffers in frame buffer render targets
for off-screen rendering.
License:
TODO
*/
#pragma once
#ifndef _ZRENDERBUFFER_HPP
#define _ZRENDERBUFFER_HPP
#include <ZRenderer/ZRendererBuild.hpp>
//Enumeration of render buffer type
enum ZRenderBufferType
{
ZRBT_DEPTH16, //16-bit Depth Storage
ZRBT_DEPTH24, //24-bit Depth Storage
ZRBT_DEPTH32, //32-bit Depth Storage
ZRBT_STENCIL8, //8-bit Stencil Storage
ZRBT_DEPTH24_STENCIL8, //24-bit Depth and 8-bit Stencil
ZRBT_SIZE
};
class ZRenderBuffer
{
public:
//Virtual Destructor
virtual ~ZRenderBuffer() { }
/*
public ZRenderBuffer::GetHeight
Gets the height value for the render buffer (in pixels).
@return (size_t) - height value
@context (all)
*/
virtual size_t GetHeight() = 0;
/*
virtual public ZRenderBuffer::GetType
Gets the type of render buffer this is set up to be (depth or stencil).
@return (ZRenderBufferType) - the type of render buffer
@context (all)
*/
virtual ZRenderBufferType GetType() = 0;
/*
public ZRenderBuffer::GetWidth
Gets the width value for the render buffer (in pixels).
@return (size_t) - width value
@context (all)
*/
virtual size_t GetWidth() = 0;
};
#endif

View File

@@ -0,0 +1,114 @@
/*
ZRenderTarget.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 03/20/2011
Purpose:
Defines an interface for a rendering surface.
License:
TODO
*/
#pragma once
#ifndef _ZRENDERTARGET_HPP
#define _ZRENDERTARGET_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <ZRenderer/ZRendererResource.hpp>
//Enumeration of possible render target types
enum ZRenderTargetType
{
ZRTT_WINDOW, //Used for window render targets
ZRTT_FRAMEBUFFER, //Used for frame buffer render targets
ZRTT_SIZE
};
//Used to flag which buffers should be cleared, and to what value
struct ZRenderTargetClearFlags
{
bool AutoClear; //Indicates that the renderer should 'clear' the toggled buffers before rendering to this target
bool ClearColorBuffer; //Indicates we should clear the color buffer
bool ClearDepthBuffer; //Indicates we should clear the depth buffer
bool ClearStencilBuffer; //Indicates we should clear the stencil buffer
float ClearColor[4]; //RGBA clear color to use
//Default Constructor
ZRenderTargetClearFlags()
: AutoClear(true), ClearColorBuffer(true), ClearDepthBuffer(true), ClearStencilBuffer(false)
{
ClearColor[0] = 0.0f;
ClearColor[1] = 0.0f;
ClearColor[2] = 0.0f;
ClearColor[3] = 1.0f;
}
};
/*
RenderTarget Interface.
*/
class ZRenderTarget : public ZRendererResource
{
public:
//Virtual Destructor
virtual ~ZRenderTarget() { }
/*
public ZRenderTarget::GetClearFlags
Gets the current set of clear flags for this render target.
@return (const ZRenderTargetClearFlags&) - clearing flags for this render target
@context (all)
*/
virtual const ZRenderTargetClearFlags& GetClearFlags() = 0;
/*
public ZRenderTarget::GetHeight
Gets the height value for the render target (in pixels).
@return (size_t)
@context (all)
*/
virtual size_t GetHeight() = 0;
/*
public ZRenderTarget::GetType
Gets the type of render target.
@return (ZRenderTargetType) - the type of render target
@context (all)
*/
virtual ZRenderTargetType GetType() = 0;
/*
public ZRenderTarget::GetWidth
Gets the width value for the render target (in pixels).
@return (size_t)
@context (all)
*/
virtual size_t GetWidth() = 0;
/*
public ZRenderTarget::SetClearFlags
Sets the clear flags for this render target.
@param _flags - flags structure which has our clear settings
@return (bool) - true if able to set flags, false if resource contended
@context (all)
*/
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags) = 0;
};
#endif

View File

@@ -0,0 +1,559 @@
/*
ZRenderer.hpp
Authors: Patrick Baggett <ptbaggett@762studios.com>,
Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 3/20/2011
Purpose:
Defines an interface for rendering to screen in graphics-library agnostic fashion.
License:
TODO
*/
#pragma once
#ifndef _ZRENDERER_HPP
#define _ZRENDERER_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <SST/SST_WM.h>
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZDataBuffer.hpp>
#include <ZRenderer/ZRenderTarget.hpp>
#include <ZRenderer/ZFramebufferRenderTarget.hpp>
#include <ZRenderer/ZWindowRenderTarget.hpp>
#include <ZRenderer/ZTexture.hpp>
#include <ZRenderer/ZSampler.hpp>
#include <ZRenderer/ZShader.hpp>
#include <ZRenderer/ZShaderProgram.hpp>
#include <ZRenderer/ZShaderParams.hpp>
#include <ZRenderer/ZVertexParams.hpp>
#include <ZRenderer/ZIndexParams.hpp>
//Forward Declarations
class ZRenderer;
//Typedef for a frame context (opaque handle)
typedef void* ZFrameContext;
//Rendering phases the ZRenderer can exist in
enum ZRenderPhase
{
ZRP_UNINITIALIZED, //Renderer has yet to be initialized
ZRP_IDLE, //Renderer is idle (no frame contexts currently created)
ZRP_FRAME_ACCEPTING, //Renderer is accepting SubmitDrawData calls (frame contexts have been created)
ZRP_FRAME_RENDERING, //Renderer is rendering Geometry (a frame context is rendering)
ZRP_SIZE
};
//Render State Structure, used to set up a render state for SubmitDrawData calls
struct ZRenderState
{
public:
//The default constructor for render state initializes to a sane configuration
ZRenderState()
: EnableStencilTest(false),
EnableBlend(true),
SourceBlendFunc(SBFV_SRC_ALPHA),
DestBlendFunc(DBFV_ONE_MINUS_SRC_ALPHA),
blendR(0), blendG(0), blendB(0), blendA(0),
EnableCullTest(false),
EnableDepthTest(true),
DepthFunc(DFV_LESS_THAN),
EnableDepthWrite(true) { }
/////////////////////////////////
/* Draw Sort Relevant Settings */
/////////////////////////////////
// BLENDING
uint32_t EnableBlend:1; //Enables Blending
uint32_t SourceBlendFunc:4; //Specifies Source Blending Function
uint32_t DestBlendFunc:3; //Specifies Destination Blending Function
enum SourceBlendFuncValue //Values for the Source Blend Function
{
SBFV_ZERO,
SBFV_ONE,
SBFV_SRC_COLOR,
SBFV_ONE_MINUS_SRC_COLOR,
SBFV_DST_COLOR,
SBFV_ONE_MINUS_DST_COLOR,
SBFV_SRC_ALPHA,
SBFV_ONE_MINUS_SRC_ALPHA,
SBFV_DST_ALPHA,
SBFV_ONE_MINUS_DST_ALPHA,
SBFV_CONSTANT_COLOR,
SBFV_ONE_MINUS_CONSTANT_COLOR,
SBFV_CONSTANT_ALPHA,
SBFV_ONE_MINUS_CONSTANT_ALPHA,
SBFV_SRC_ALPHA_SATURATE,
SBFV_SIZE
};
enum DestBlendFuncValue //Values for the Destination Blend Function
{
DBFV_ZERO,
DBFV_ONE,
DBFV_SRC_COLOR,
DBFV_ONE_MINUS_SRC_COLOR,
DBFV_DST_COLOR,
DBFV_ONE_MINUS_DST_COLOR,
DBFV_SRC_ALPHA,
DBFV_ONE_MINUS_SRC_ALPHA,
DBFV_DST_ALPHA,
DBFV_ONE_MINUS_DST_ALPHA,
DBFV_CONSTANT_COLOR,
DBFV_ONE_MINUS_CONSTANT_COLOR,
DBFV_CONSTANT_ALPHA,
DBFV_ONE_MINUS_CONSTANT_ALPHA,
DBFV_SIZE
};
float blendR; //Red value used when blending needs a constant color
float blendG; //Green value used when blending needs a constant color
float blendB; //Blue value used when blending needs a constant color
float blendA; //Alpha value used when blending needs a constant color
// DEPTH
uint32_t EnableDepthTest:1; //Bit Enables Depth Testing
uint32_t EnableDepthWrite:1; //Sets Depth Buffer to Read Only (Depth Values are not written)
uint32_t DepthFunc:3; //Specifies Depth Function
enum DepthFuncValue //Values for the Depth Function
{
DFV_NEVER,
DFV_LESS_THAN,
DFV_EQUAL,
DFV_LESS_THAN_EQUAL,
DFV_GREATER_THAN,
DFV_NOT_EQUAL,
DFV_GREATER_THAN_EQUAL,
DFV_ALWAYS,
DFV_SIZE
};
// CULLING
uint32_t EnableCullTest:1; //Enable or disable face culling.
uint32_t CullMode:2; //Sets up front/back/both culling
enum CullModeValue
{
CMV_FRONT,
CMV_BACK,
CMV_FRONT_AND_BACK,
CMV_SIZE
};
uint32_t CullWinding:1; //Sets winding for culling
enum CullWindingValue
{
CWV_CW,
CWV_CCW,
CWV_SIZE
};
// STENCIL
uint32_t EnableStencilTest:1; //Bit Enables Stencil Testing
uint32_t StencilTestFuncFront:4; //Specifies the stencil comparisons
uint32_t StencilTestMaskFront:8; //Mask for front facing stencil post-op
uint32_t StencilTestReferenceFront:8; //Reference value for front facing stencil post-op
uint32_t StencilTestFuncBack:4; //Specifies the stencil comparisons
uint32_t StencilTestMaskBack:8; //Mask for back facing stencil post-op
uint32_t StencilTestReferenceBack:8; //Reference value for back facing stencil post-op
enum StencilComparisonsValue //Values for the stencil comparisons
{
SCV_NEVER,
SCV_ALWAYS,
SCV_LESS,
SCV_LEQUAL,
SCV_EQUAL,
SCV_GEQUAL,
SCV_GREATER,
SCV_NOTEQUAL,
SCV_SIZE
};
uint32_t StencilOpStencilFailFront:3; //Specifies the stencil operation when stencil test fails for front-facing polys
uint32_t StencilOpStencilPassDepthFailFront:3; //Specifies the stencil operation when stencil test succeeds and depth test fails fails for front-facing polys
uint32_t StencilOpStencilPassDepthPassFront:3; //Specifies the stencil operation when stencil and depth tests pass fails for front-facing polys
uint32_t StencilOpStencilFailBack:3; //Specifies the stencil operation when stencil test fails for back-facing polys
uint32_t StencilOpStencilPassDepthFailBack:3; //Specifies the stencil operation when stencil test succeeds and depth test fails for back-facing polys
uint32_t StencilOpStencilPassDepthPassBack:3; //Specifies the stencil operation when stencil and depth tests pass for back-facing polys
enum StencilOperationValue //Values for the stencil operations
{
SOV_KEEP,
SOV_ZERO,
SOV_REPLACE,
SOV_INCR,
SOV_INCR_WRAP,
SOV_DECR,
SOV_DECR_WRAP,
SOV_INVERT,
SOV_SIZE
};
};
class ZRenderer : public ZThread
{
protected:
//Default Constructor
ZRenderer() : ZThread("ZRenderer Thread") { }
public:
//Virtual Destructor
virtual ~ZRenderer() { }
//////////////////////////
/* Lifecycle Operations */
//////////////////////////
/*
virtual public ZRenderer::Init
Initializes the Renderer for use as a long running subsystem. After this call, the
render thread will be running.
@return (bool)
@context (all)
*/
virtual bool Init() = 0;
/*
virtual public ZRenderer::Shutdown
Shuts down the system and stops the render thread.
@return (void)
@context (all)
*/
virtual void Shutdown() = 0;
///////////////////////////
/* Renderer Data Getters */
///////////////////////////
/*
virtual public ZRenderer::GetCapabilities
Returns a map describing the capabilities and configuration of this renderer. All
renderer implementations must map the following keys:
gl { directx, opengl }
gl.version { 9.0c, 10.0, 10.1, 11.0, 11.1, 2.1, 3.1, 3.2, 3.3 ... }
: version number should always have major.minor format and should be the highest version required
gl.shaderlang { hlsl_40, hlsl_30, hlsl, glsl_14, glsl_13, glsl_12, glsl_11, glsl, ... }
: shading languages accepted should be listed in a comma separated list in order of preference
data_buffer.block_alignment { integer }
: alignment requirement for buffer blocks
frame_buffer_render_target.max_color_attachments { integer }
: maximum number of color buffer attachments
Other keys may be supported depending upon the implementation.
@return (const ZHashMap<ZString, ZString>&) - map of capabilities
@context (all)
*/
virtual const ZHashMap<ZString, ZString>& GetCapabilities() = 0;
/*
virtual public ZRenderer::GetRenderPhase
Gets the current rendering phase.
@return (ZRenderPhase) - current rendering phase
@context (all)
*/
virtual ZRenderPhase GetRenderPhase() = 0;
//////////////////////////
/* Logistics Operations */
//////////////////////////
/*
virtual public ZRenderer::CreateDataBuffer
Creates a data buffer which contains data stored in graphics memory. The data
buffer is created but not initialized with values (use FillBuffer or MapBuffer).
Keep in mind when allocating a buffer that defines block data that determining the
required size to fit all blocks includes taking into account alignment requirements.
The alignment requirement for block data for this renderer can be determined through
the capabilities map with key 'buffer.block_alignment'.
@param _type - the type of buffer to allocate
@param _usage - the usage pattern the buffer will follow
@param _size - the size (in bytes) to allocate
@return (ZDataBuffer) - new data buffer object, NULL if not successful
@context (all)
*/
virtual ZPtr<ZDataBuffer> CreateDataBuffer(ZDataBufferType _type,
ZDataBufferUsage _usage,
size_t _size
) = 0;
/*
virtual public ZRenderer::CreateDrawParams
Creates a draw parameters binding class, which is provided to the draw calls and
is used to bind data to shader variables.
@param _type - the type of draw parameters binding
@return (ZPtr<ZDrawParams>) - new draw parameters object, NULL if not successful
@context (all)
*/
virtual ZPtr<ZDrawParams> CreateDrawParams(ZDrawParamsType _type) = 0;
/*
virtual public ZRenderer::CreateFrameBufferRenderTarget
Function to create a framebuffer-backed render target.
@param _width - number of pixels wide to make the frame buffer
@param _height - number of pixels tall to make the frame buffer
@return (ZPtr<ZFramebufferRenderTarget>) - new frame buffer render target, NULL if not successful
@context (all)
*/
virtual ZPtr<ZFramebufferRenderTarget> CreateFrameBufferRenderTarget(size_t _width, size_t _height) = 0;
/*
virtual public ZRenderer::CreateRenderBuffer
Function to create a render buffer for use in a frame buffer render target.
@param _type - the type of render buffer this will be
@param _width - number of pixels wide to make the render buffer
@param _height - number of pixels tall to make the render buffer
@return (ZPtr<ZRenderBuffer>) - new render buffer, NULL if not successful
@context (all)
*/
virtual ZPtr<ZRenderBuffer> CreateRenderBuffer(ZRenderBufferType _type, size_t _width, size_t _height) = 0;
/*
virtual public ZRenderer::CreateSampler
Creates a sampler object to use as a view onto a texture.
@return (ZPtr<ZSampler>) - new sampler object, NULL if unsuccessful
@context (all)
*/
virtual ZPtr<ZSampler> CreateSampler() = 0;
/*
virtual public ZRenderer::CreateShader
Function to create a shader object for the renderer.
@param _type - type of shader to create:
ZST_SOFT : Soft shaders
ZST_VERTEX : Vertex shaders
ZST_HULL : Hull shaders
ZST_DOMAIN : Domain shaders
ZST_GEOMETRY: Geometry shaders
ZST_FRAGMENT: Fragment (pixel) shaders
@return (ZPtr<ZShader>) - the created shader, NULL if not successful
@context (all)
*/
virtual ZPtr<ZShader> CreateShader(ZShaderType _type) = 0;
/*
virtual public ZRenderer::CreateShaderProgram
Function to create a shader program.
@return (ZPtr<ZShaderProgram>) - new shader program, NULL if not successful
@context (all)
*/
virtual ZPtr<ZShaderProgram> CreateShaderProgram() = 0;
/*
virtual public ZRenderer::CreateTexture
Creates a texture object.
In the case of cube map textures, the bitmap format describes a single 'side'
of the cube map texture.
If the bitmap provided has NULL for data, then the texture storage is initialized
but no data is copied.
@param _type - the type of texture
@param _format - the texture internal storage format
@param _usage - the usage type of the texture
@param _bitmap - bitmap structure containing image format and size, as well as data (can be NULL)
@param _generateMipmaps - indicating whether or not we should generate mipmaps
@return (ZPtr<ZTexture>) - new texture object, NULL if not successful
@context (all)
*/
virtual ZPtr<ZTexture> CreateTexture(ZTextureType _type,
ZTextureFormat _format,
ZTextureUsage _usage,
const ZBitmap& _bitmap,
bool _generateMipmaps) = 0;
/*
virtual public ZRenderer::CreateWindowRenderTarget
Creates a window render target.
@param _window - the window handle (created using libsst-wm)
@param _screenIndex - the screen index bound to the window
@return (ZPtr<ZRenderTarget>) - new window render target, NULL if not successful
@context (all)
*/
virtual ZPtr<ZRenderTarget> CreateWindowRenderTarget(SST_Window _window,
size_t _screenIndex
) = 0;
////////////////////////
/* Frame Data Getters */
////////////////////////
/*
virtual public ZRenderer::GetFrameRenderTarget
Gets the render target set for the given frame context.
@param _frameContext - frame context
@return (ZRenderTarget*) - the render target for the given context
@context (all)
*/
virtual ZRenderTarget* GetFrameRenderTarget(ZFrameContext _frameContext) = 0;
//////////////////////////
/* Rendering Operations */
//////////////////////////
/*
The renderer can maintain a few different states, each of which is described by an enumeration. The various
rendering operations affect this state, and thread synchronization calls such as WaitFrameStart and WaitFrameEnd
will wait until events are triggered after state changes, as follows.
BeginFrame()
| SubmitDrawData()
| | RenderFrame()
| +-------+-------+ |
| | | | |
---------------+---+-------+-------+---+-----------------------+---------------
===============|///////////////////////|///////////////////////|===============
ZRP_IDLE ... =|/ ZRP_FRAME_ACCEPTING /|/ ZRP_FRAME_RENDERING /|= ZRP_IDLE ...
===============|///////////////////////|///////////////////////|===============
| |
+-> WaitFrameStart() +-> WaitFrameEnd()
^ |
| Frame to Render? |
+<----------------------+
Because of the multi threaded nature of ZRenderer, multiple threads can call SubmitDrawData to populate
the render lists full of buffered data to draw. A single call should be placed to BeginFrame for each
frame context that is desired, and a single call to RenderFrame should occur for each frame context that has
been created.
It is guaranteed that order will be maintained between calls to RenderFrame, meaning if RenderFrame is called
for frame context 0, and then afterwards RenderFrame is called for frame context 1, frame context 0 is guaranteed
to render in its entirety before frame context 0 is rendered.
*/
/*
virtual public ZRenderer::BeginFrame
Tells the renderer that threads will begin providing draw data for a frame of rendering. The value returned
is later used as a frame context for render calls.
BeginFrame can be called multiple times, each time returning a new frame context that can be provided
for draw calls.
BeginFrame should be called once for as many frame contexts there will be before beginning render calls
for any of them. Calling BeginFrame after other frames have begun rendering results in undefined
behavior. Frame contexts should never be re-used across multiple render cycles - always ask for a new one.
@param _canvas - the canvas to render to
@return (ZFrameContext) - the frame context that has been created
@context (all)
*/
virtual ZFrameContext BeginFrame(ZPtr<ZRenderTarget> _canvas) = 0;
/*
virtual public ZRenderer::EndFrame
TODO
@param _frameContext - the frame context we are done submitting draw data to
@return (void)
@context (all)
*/
virtual void EndFrame(ZFrameContext _frameContext) = 0;
/*
virtual public ZRenderer::SubmitDrawData
Draws geometry defined in a DataBuffer (Queues them up for rendering).
@param _frameContext - the frame context to provide data for
@param _shaderProgram - the shader program to draw with
@param _shaderParams - the shader parameters binding
@param _vertexParams - the vertex parameters binding
@param _indexParams - the index parameters binding
@param _renderState - the render state to render the geometry with
@param _drawGroup - the draw group to render this call with; objects with lower draw group
are rendered before objects with higher draw group
@return (void)
@context (all)
*/
virtual void SubmitDrawData(ZFrameContext _frameContext,
ZPtr<ZShaderProgram> _shaderProgram,
ZPtr<ZShaderParams> _shaderParams,
ZPtr<ZVertexParams> _vertexParams,
ZPtr<ZIndexParams> _indexParams,
const ZRenderState& _renderState,
int _drawGroup = 0
) = 0;
/*
virtual public ZRenderer::RenderFrame
Renders the frame context.
@param _frameContext - the frame context to render
@return (void)
@context (all)
*/
virtual void RenderFrame(ZFrameContext _frameContext) = 0;
/*
virtual public ZRenderer::WaitFrameStart
Calling thread waits until RenderFrame is called for the given frame context.
@param _frameContext - the frame context to wait for
@return (void)
@context (all)
*/
virtual void WaitFrameStart(ZFrameContext _frameContext) = 0;
/*
virtual public ZRenderer::WaitFrameEnd
Calling thread waits until after the render thread has finished rendering a frame.
@param _frameContext - the frame context to wait for
@return (void)
@context (all)
*/
virtual void WaitFrameEnd(ZFrameContext _frameContext) = 0;
};
#endif

View File

@@ -0,0 +1,259 @@
/*
ZRendererBase.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 3/23/2011
Purpose:
Base implementation of the ZRenderer class, which handles many of the details that
are common to multi threaded renderers.
License:
TODO
*/
#pragma once
#ifndef _ZRENDERERBASE_HPP
#define _ZRENDERERBASE_HPP
#include <ZRenderer/ZRenderer.hpp>
#include <ZRenderer/ZDataBufferBase.hpp>
//Forward Declarations
struct ZFrameData;
//Maximum number of concurrent frame contexts
#ifndef ZRB_MAX_FRAME_CONTEXT_COUNT
#define ZRB_MAX_FRAME_CONTEXT_COUNT (4)
#endif
//Default slab allocation of Draw Objects, will auto correct at runtime if exceeded
#ifndef ZRB_DEFAULT_DRAWDATA_COUNT
#define ZRB_DEFAULT_DRAWDATA_COUNT (128)
#endif
//Default buffer size for a draw list
#ifndef ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE
#define ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE (128)
#endif
/*
Used to contain only the minimum data necessary to draw geometry
and hold no ownership (in smart pointer terms) over the parameters.
*/
struct ZDrawData
{
ZShaderProgram* ShaderProgram; //The shader program we will be drawing with
ZShaderParams* ShaderParams; //The shader parameters we will be using
ZVertexParams* VertexParams; //The vertex parameters we will be using
ZIndexParams* IndexParams; //The index parameters we will be using
ZRenderState RenderState; //The renderer state we will be using
int DrawGroup; //The draw group for drawing data
ZFrameData* Parent; //The parent ZFrameData struct that holds ownership
//Default Constructor
ZDrawData()
: ShaderProgram(NULL),
ShaderParams(NULL), VertexParams(NULL), IndexParams(NULL),
RenderState(), DrawGroup(-1),
Parent(NULL)
{ }
};
/*
Used to contain references to the data necessary to draw geometry per frame. Holds
strong references long enough to ensure parameters do not get deleted.
*/
struct ZFrameData
{
ZArray< ZPtr<ZShaderProgram> > ShaderPrograms; //The shader programs we will be using
ZArray< ZPtr<ZShaderParams> > ShaderParams; //The shader parameters we will be using
ZArray< ZPtr<ZVertexParams> > VertexParams; //The vertex parameters we will be using
ZArray< ZPtr<ZIndexParams> > IndexParams; //The index parameters we will be using
ZPtr<ZRenderTarget> RenderTarget; //The render target for this frame
ZArray<ZDrawData*,
ZArrayAllocator<ZDrawData*, ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE> > DrawData; //Our set of draw data
//Concurrency Control Variables
ZMutex FrameLock;
ZEvent FrameEndSignal;
ZEvent FrameStartSignal;
};
/*
ZRendererBase class, which can be extended by GL-specific renderers.
*/
class ZRendererBase : public ZRenderer
{
private:
//The renderer lock
ZMutex RendererLock;
//Current Render Phase
volatile ZRenderPhase Phase;
//Slab allocator for ZFrameData
ZSlabAllocator<ZDrawData, ZRB_DEFAULT_DRAWDATA_COUNT> DrawDataAllocator;
//Slab allocator for ZFrameData
ZSlabAllocator<ZFrameData, ZRB_MAX_FRAME_CONTEXT_COUNT> FrameDataAllocator;
//The frame data available queue (available for use)
ZRingBuffer<ZFrameData*,
ZRingBuffer_OverflowUnsafe,
ZArrayAllocator<ZFrameData*, ZRB_MAX_FRAME_CONTEXT_COUNT> > FrameAvailableQueue;
//The frame data render queue (pending renders)
ZRingBuffer<ZFrameData*,
ZRingBuffer_OverflowUnsafe,
ZArrayAllocator<ZFrameData*, ZRB_MAX_FRAME_CONTEXT_COUNT> > FrameRenderQueue;
//The frame data we are rendering
ZFrameData* CurrentFrame;
protected:
//Capabilities mapping
ZHashMap<ZString, ZString> Capabilities;
//Protected Constructor
ZRendererBase();
/*
virtual protected ZRendererBase::init
This will be called by ZRendererBase::Init and should handle subclass
initialization.
@return (bool) - true if successful, false otherwise
*/
virtual bool init() = 0;
/*
virtual protected ZRendererBase::shutdown
This will be called by ZRendererBase::Shutdown and should handle subclass
shutdown.
@return (void)
*/
virtual void shutdown() = 0;
/*
virtual protected ZRendererBase::Draw
Method which should, given a list of render data, draw it to the provided render target.
@param _renderList - the sorted list of draw data objects to draw
@param _renderTarget - the render target to draw to
@return (void)
*/
virtual void Draw(ZArray<ZDrawData*,
ZArrayAllocator<ZDrawData*, ZRB_DEFAULT_DRAWDATA_BUFFER_SIZE> >& _renderList,
ZRenderTarget* _renderTarget) = 0;
public:
/*
Destructor.
*/
virtual ~ZRendererBase();
//////////////////////////
/* Lifecycle Operations */
//////////////////////////
//Subclass Implementation
virtual bool Init();
//Subclass Implementation
virtual void Shutdown();
///////////////////////////
/* Renderer Data Getters */
///////////////////////////
//Subclass Override
virtual const ZHashMap<ZString, ZString>& GetCapabilities();
//Subclass Override
virtual ZRenderPhase GetRenderPhase();
//////////////////////////
/* Logistics Operations */
//////////////////////////
//Subclass Implementation
virtual ZPtr<ZDrawParams> CreateDrawParams(ZDrawParamsType _type);
//Not Implemented
virtual ZPtr<ZDataBuffer> CreateDataBuffer(ZDataBufferType _type,
ZDataBufferUsage _usage,
size_t _size
) = 0;
//Not Implemented
virtual ZPtr<ZFramebufferRenderTarget> CreateFrameBufferRenderTarget(size_t _width, size_t _height) = 0;
//Not Implemented
virtual ZPtr<ZRenderBuffer> CreateRenderBuffer(ZRenderBufferType _type, size_t _width, size_t _height) = 0;
//Not Implemented
virtual ZPtr<ZSampler> CreateSampler() = 0;
//Not Implemented
virtual ZPtr<ZShader> CreateShader(ZShaderType _type) = 0;
//Not Implemented
virtual ZPtr<ZShaderProgram> CreateShaderProgram() = 0;
//Not Implemented
virtual ZPtr<ZTexture> CreateTexture(ZTextureType _type, ZTextureFormat _format, ZTextureUsage _usage, const ZBitmap& _bitmap, bool _generateMipmaps) = 0;
//Not Implemented
virtual ZPtr<ZRenderTarget> CreateWindowRenderTarget(SST_Window _window, size_t _screenIndex) = 0;
////////////////////////
/* Frame Data Getters */
////////////////////////
//Subclass Implementation
virtual ZRenderTarget* GetFrameRenderTarget(ZFrameContext _frameContext);
//////////////////////////
/* Rendering Operations */
//////////////////////////
//Subclass Implementation
virtual ZFrameContext BeginFrame(ZPtr<ZRenderTarget> _canvas);
virtual void EndFrame(ZFrameContext _frameContext);
//Subclass Implementation
virtual void SubmitDrawData(ZFrameContext _frameContext,
ZPtr<ZShaderProgram> _shaderProgram,
ZPtr<ZShaderParams> _shaderParams,
ZPtr<ZVertexParams> _vertexParams,
ZPtr<ZIndexParams> _indexParams,
const ZRenderState& _renderState,
int _drawGroup = 0
);
//Subclass Implementation
virtual void RenderFrame(ZFrameContext _frameContext);
//Subclass Implementation
virtual void WaitFrameStart(ZFrameContext _frameContext);
//Subclass Implementation
virtual void WaitFrameEnd(ZFrameContext _frameContext);
//Implementation of the render thread
virtual ZThreadReturn run(uint64_t _dt);
};
#endif

View File

@@ -0,0 +1,49 @@
/*
ZRendererBuild.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 5/21/2012
Purpose:
Used to generate definitions for the preprocessor using only compiler-set variables
and include headers necessary to ensure previous project build files are included
in the correct order.
License:
TODO
*/
#pragma once
#ifndef _ZRENDERERBUILD_HPP
#define _ZRENDERERBUILD_HPP
#include "ZBuild.hpp"
#include <ZUtil/ZUtilBuild.hpp>
//Version number constants for ZRenderer
#define ZRENDERER_VERSION_MAJOR 0x01
#define ZRENDERER_VERSION_MINOR 0x00
#define ZRENDERER_VERSION_PATCH 0x0000
#define ZRENDERER_VERSION (ZRENDERER_VERSION_MAJOR << 24) | (ZRENDERER_VERSION_MINOR << 16) | (ZRENDERER_VERSION_PATCH)
#define ZRENDERER_VERSION_STRING "1.0.0"
#if ZASSERT_RENDERER_ENABLE
//ZASSERT_RENDERER macro, which will trigger a breakpoint if the condition is not met
//ZASSERT_RENDERER is meant to be used within the ZRenderer project for internal assertion debugging
//ZASSERT should be used when the error condition can be caused by user actions
#define ZASSERT_RENDERER(_condition, _message) SST_OS_DebugAssert(_condition, _message)
#else
//ZASSERT_RENDERER is disabled
#define ZASSERT_RENDERER(_condition, _message) ((void)sizeof(_condition), sizeof(_message))
#endif //ZASSERT_RENDERER_ENABLE
#endif

View File

@@ -0,0 +1,153 @@
/*
ZRendererResource.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/8/2012
Purpose:
A renderer resource is anything that is created by the renderer and is used as part of
the rendering process. Generally, renderer resources are objects that act as an interface
to graphics device state, such as buffers, textures, etc.
It should be noted that resources are not safe to be used across multiple threads, even though
the renderer is multi thread capable. A resource should only be used within the context of a
single thread, and draw calls using that resource should also remain within the same thread
(this is done to avoid costly concurrent operations).
Different resources are free to be used across different threads.
Usage:
A renderer resource can be 'available', 'locked', or 'contended'. When a resource is available,
all calls to methods that modify the underlying data (or make the underlying data available for
modification) succeed and this will be indicated by the return value. If the resource is locked
or contended, the return value of the method will indicate failure to modify the resource.
If a resource is 'locked', then the resource is currently in the midst of modification. This
means that some modification methods will be unavailable. As an example, 'MapBuffer' cannot
be called while the buffer is already mapped, and 'FillBuffer' will fail if a buffer has
been mapped. A locked resource can be unlocked and returned to 'available' state before
rendering.
If a resource is contended, this means that the renderer is relying on the data that is currently
present in graphics memory, as a draw call has been placed using the data at the time of contention.
This means that any calls that would allow the user to modify the underlying data will fail. A
contended buffer becomes available when the renderer has finished reading the data needed from
the resource, which will occur at frame end.
Note that this means that the following set of actions (using an example of ZDataBuffer):
buffer = dataBuffer->MapBuffer(true);
... //Update Buffer
dataBuffer->UnmapBuffer();
renderer->SubmitDrawData(...); //Draw using this buffer
buffer = dataBuffer->MapBuffer(true);
... //Update Buffer
dataBuffer->UnmapBuffer();
renderer->SubmitDrawData(...); //Draw using the updated buffer
renderer->RenderFrame(...); //Render this frame
Will not work. The second call to 'MapBuffer' will fail because the buffer became contended
as soon as the buffer was used as an argument to 'SubmitDrawData'. The renderer's 'WaitFameEnd'
method will enable you to wait until the resource is no longer contended.
License:
TODO
*/
#pragma once
#ifndef _ZRENDERERRESOURCE_HPP
#define _ZRENDERERRESOURCE_HPP
#include <ZRenderer/ZRendererBuild.hpp>
class ZRendererResource
{
private:
DISABLE_COPY_AND_ASSIGN(ZRendererResource);
protected:
//Counter of 'owners' claiming contention
int ContentionCount;
//Flag indicating that this resource has been 'locked'
bool bIsLocked;
public:
//Default Constructor
ZRendererResource();
//Virtual Destructor
virtual ~ZRendererResource() { }
/*
public ZRendererResource::Available
Returns whether or not this resource is currently available (able to be modified).
If a resource is locked or contended, then it is not available for modification.
@return (bool) - true if available, false otherwise
@context (all)
*/
bool IsAvailable();
/*
public ZRendererResource::Lock
Locks this resource, making it unavailable for modification.
@return (void)
@context (all)
*/
void Lock();
/*
public ZRendererResource::MarkContended
Marks this resource as contended. Resources should, from this point out,
understand that modification of the underlying resource should not happen
until after the frame is drawn that would release this resource from
contention. From this point out, the caller 'owns' the resource.
Resources can be marked as contended by multiple sources, and the resource
will not be available until all owners who have marked contended have
released their claim.
Generally, this should only be called by the renderer.
@return (void)
@context (renderer)
*/
void MarkContended();
/*
public ZRendererResource::ReleaseContended
Removes a previous claim of contention. If all previous owners have
released their contention, then the resource is available.
@return (void)
@context (all)
*/
void ReleaseContention();
/*
public ZRendererResource::Unlock
Unlocks a resource, making it available for modification.
@return (void)
@context (all)
*/
void Unlock();
};
#endif

View File

@@ -0,0 +1,192 @@
/*
ZSampler.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
Samplers act as a view onto a texture object, encapsulating all the filtering, mipmapping,
and addressing settings for shaders to access a texture.
TODO - A writeup here on the various settings and how they interact, or at least a link to
some place that does
License:
TODO
*/
#pragma once
#ifndef _ZSAMPLER_HPP
#define _ZSAMPLER_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <ZRenderer/ZRendererResource.hpp>
//This should be ~log2 of ZT_MAX_TEXTURE_DIMENSION
#ifndef ZS_DEFAULT_MAX_LOD
#define ZS_DEFAULT_MAX_LOD (13.0f)
#endif
//Enumeration of sampler wrapping modes
enum ZSamplerWrapMode
{
ZSWM_CLAMP_EDGE, //Sampling beyond the edge results in the last pixel value
ZSWM_CLAMP_BORDER, //Sampling beyond the edge results in the specified border value
ZSWM_MIRROR_REPEAT, //Sampling beyond the edge wraps back in on itself
ZSWM_REPEAT, //Sampling beyond the edge wraps around to the other side
ZSWM_SIZE
};
//Enumeration of magnification sampler filtering modes
enum ZSamplerMagFilter
{
ZSMAGF_NEAREST, //Nearest mode filter
ZSMAGF_LINEAR, //Linear mode filter
ZSMAGF_SIZE
};
//Enumeration of minification sampler filtering modes
enum ZSamplerMinFilter
{
ZSMINF_NEAREST, //Nearest-neighbor pixel, no mip levels
ZSMINF_NEAREST_MIP_NEAREST, //Nearest-neighbor sampling on nearest mip level
ZSMINF_NEAREST_MIP_LINEAR, //Nearest-neighbor sampling on lerped mip level
ZSMINF_LINEAR, //Linear interpolation, no mip levels
ZSMINF_LINEAR_MIP_NEAREST, //Lerped sampling on nearest mip level
ZSMINF_LINEAR_MIP_LINEAR, //Lerped sampling on lerped mip level
ZSMINF_SIZE
};
//Enumeration of sampler comparison modes
enum ZSamplerCompareMode
{
ZSCM_COMPARE_REF_TO_TEXTURE, //Compares reference to texture
ZSCM_NONE, //No comparison
ZSCM_SIZE
};
//Enumeration of sampler comparison functions
enum ZSamplerCompareFunc
{
ZSCF_LESS_EQUAL, //Less than or equal
ZSCF_GREATER_EQUAL, //Greater than or equal
ZSCF_LESS, //Less than
ZSCF_GREATER, //Greater than
ZSCF_EQUAL, //Equal
ZSCF_NOT_EQUAL, //Not Equal
ZSCF_ALWAYS, //Always
ZSCF_NEVER, //Never
ZSCF_SIZE
};
//Struct that encapsulates the sampler state
struct ZSamplerState
{
ZSamplerWrapMode SWrapMode; //Wrapping mode for S
ZSamplerWrapMode TWrapMode; //Wrapping mode for T (unused for 1D)
ZSamplerWrapMode RWrapMode; //Wrapping mode for R (unused for 1D, 2D)
ZSamplerMinFilter MinFilter; //Minification Filter
ZSamplerMagFilter MagFilter; //Magnification Filter
float MaxAnisotropy; //Maximum Anisotropy (< 2.0 has no effect)
float MinLOD; //Minimum LOD
float MaxLOD; //Maximum LOD
float LODBias; //LOD Bias
float BorderColor[4]; //RGBA Border Color
ZSamplerCompareMode CompareMode; //Sampler Comparison Mode
ZSamplerCompareFunc CompareFunc; //Sampler Comparison Function
//Default Configuration
ZSamplerState()
: SWrapMode(ZSWM_REPEAT), TWrapMode(ZSWM_REPEAT), RWrapMode(ZSWM_REPEAT),
MinFilter(ZSMINF_LINEAR), MagFilter(ZSMAGF_LINEAR),
MaxAnisotropy(1.0), MinLOD(0), MaxLOD(ZS_DEFAULT_MAX_LOD), LODBias(0),
CompareMode(ZSCM_NONE), CompareFunc(ZSCF_ALWAYS)
{ }
};
/*
Sampler interface class.
*/
class ZSampler : public ZRendererResource
{
public:
//Virtual Destructor
virtual ~ZSampler() { }
/*
ZSampler::Get*
The following methods are getters for the various ZSampler settings
that can be set on a given sampler. For a greater explanation of each
setting and what it does, see above.
*/
//Getters for the S, T, and R Wrap Mode set on this sampler
virtual ZSamplerWrapMode GetSWrapMode() = 0;
virtual ZSamplerWrapMode GetTWrapMode() = 0;
virtual ZSamplerWrapMode GetRWrapMode() = 0;
//Getters for the minification filter and magnification filter
virtual ZSamplerMagFilter GetMagFilter() = 0;
virtual ZSamplerMinFilter GetMinFilter() = 0;
//Getters for the maximum anisotropy, minimum LOD, maximum LOD, and LOD bias
virtual float GetMaxAnisotropy() = 0;
virtual float GetMinLOD() = 0;
virtual float GetMaxLOD() = 0;
virtual float GetLODBias() = 0;
//Getter for the border color setting (four-element array, RGBA)
virtual const float* GetBorderColor() = 0;
//Getter for the comparison mode and comparison function
virtual ZSamplerCompareMode GetCompareMode() = 0;
virtual ZSamplerCompareFunc GetCompareFunc() = 0;
//Getter for the entire sampler state
virtual const ZSamplerState& GetSamplerState() = 0;
/*
ZSampler::Set*
The following methods are setters for the various ZSampler settings than
can be set on a given sampler. For a greater explanation of each setting and what it
does, see above.
If any of the setters returns false, it is because the resource is contended.
*/
//Setters for the S, T, and R wrapping modes
virtual bool SetSWrapMode(ZSamplerWrapMode _mode) = 0;
virtual bool SetTWrapMode(ZSamplerWrapMode _mode) = 0;
virtual bool SetRWrapMode(ZSamplerWrapMode _mode) = 0;
//Setters for the minification and magnification filter
virtual bool SetMagFilter(ZSamplerMagFilter _filter) = 0;
virtual bool SetMinFilter(ZSamplerMinFilter _filter) = 0;
//Setters for maximum anisotropy, minimum LOD, maximum LOD, and LOD bias
virtual bool SetMaxAnisotropy(float _max) = 0;
virtual bool SetMinLOD(float _min) = 0;
virtual bool SetMaxLOD(float _max) = 0;
virtual bool SetLODBias(float _bias) = 0;
//Setter for border color
virtual bool SetBorderColor(float _r, float _g, float _b, float _a) = 0;
//Setter for comparison mode and comparison function
virtual bool SetCompareMode(ZSamplerCompareMode _mode) = 0;
virtual bool SetCompareFunc(ZSamplerCompareFunc _func) = 0;
//Setter for entire sampler state
virtual bool SetSamplerState(const ZSamplerState& _state) = 0;
};
#endif

View File

@@ -0,0 +1,98 @@
/*
ZSamplerBase.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZSAMPLERBASE_HPP
#define _ZSAMPLERBASE_HPP
#include <ZRenderer/ZSampler.hpp>
//Base implementation of ZSampler Interface
class ZSamplerBase : public ZSampler
{
private:
DISABLE_COPY_AND_ASSIGN(ZSamplerBase);
protected:
//Current sampler state
ZSamplerState State;
//Flag indicating values have changed
bool bIsDirty;
//Default Constructor, which initializes with some sane default settings
ZSamplerBase();
public:
//Virtual Destructor
virtual ~ZSamplerBase() { }
/*
public ZSamplerBase::GetSamplerStateResetDirty
Gets the sampler state for this device. This will return
NULL if the sampler has not been modified since the last call to
this function, and in the case it has been modified, a call to this
resets the 'dirty' flag for the buffer.
@return (ZSamplerState*)
@context (all)
*/
ZSamplerState* GetSamplerStateResetDirty();
//Subclass Getter Implementations
virtual ZSamplerWrapMode GetSWrapMode();
virtual ZSamplerWrapMode GetTWrapMode();
virtual ZSamplerWrapMode GetRWrapMode();
virtual ZSamplerMinFilter GetMinFilter();
virtual ZSamplerMagFilter GetMagFilter();
virtual float GetMaxAnisotropy();
virtual float GetMinLOD();
virtual float GetMaxLOD();
virtual float GetLODBias();
virtual const float* GetBorderColor();
virtual ZSamplerCompareMode GetCompareMode();
virtual ZSamplerCompareFunc GetCompareFunc();
virtual const ZSamplerState& GetSamplerState();
//Subclass Setter Implementations
virtual bool SetSWrapMode( ZSamplerWrapMode _mode );
virtual bool SetTWrapMode( ZSamplerWrapMode _mode );
virtual bool SetRWrapMode( ZSamplerWrapMode _mode );
virtual bool SetMinFilter( ZSamplerMinFilter _filter );
virtual bool SetMagFilter( ZSamplerMagFilter _filter );
virtual bool SetMaxAnisotropy( float _max );
virtual bool SetMinLOD( float _min );
virtual bool SetMaxLOD( float _max );
virtual bool SetLODBias( float _bias );
virtual bool SetBorderColor( float _r, float _g, float _b, float _a );
virtual bool SetCompareMode(ZSamplerCompareMode _mode);
virtual bool SetCompareFunc(ZSamplerCompareFunc _func);
virtual bool SetSamplerState(const ZSamplerState& _state);
};
#endif

View File

@@ -0,0 +1,122 @@
/*
ZShader.hpp
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 4/20/2011
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZSHADER_HPP
#define _ZSHADER_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <ZRenderer/ZRendererResource.hpp>
#include <ZSTL/ZString.hpp>
//Shader Type
enum ZShaderType
{
ZST_SOFT, //Software Shader (unsupported)
ZST_VERTEX, //Vertex Shader
ZST_FRAGMENT, //Fragment/Pixel Shader
ZST_GEOMETRY, //Geometry Shader (unsupported)
ZST_HULL, //Hull Shader (unsupported)
ZST_DOMAIN, //Domain Shader (unsupported)
ZST_SIZE
};
//For you non OpenGL types
#define ZST_PIXEL (ZST_FRAGMENT)
class ZShader : public ZRendererResource
{
public:
/*
virtual public ZShader::ClearLog
Function to clear the log of a shader.
@return (void)
@context (all)
*/
virtual void ClearCompileLog() = 0;
/*
virtual public ZShdaer::Compile
Function to compile a shader.
@return (bool) - true if successfully compiled, false otherwise.
@context (all)
*/
virtual bool Compile() = 0;
/*
virtual public ZShdaer::IsUsable
Function to compile a shader.
@return (bool) - true if successfully compiled, false otherwise.
@context (all)
*/
virtual bool IsUsable() = 0;
/*
virtual public ZShader::GetLog
Function to get the log of a shader.
@return (ZString) - the log of the shader.
@context (all)
*/
virtual const ZString& GetCompileLog() = 0;
/*
virtual public ZShader::GetSource
Function to get the source of a shader.
@return (ZString) - the source of the shader.
@context (all)
*/
virtual const ZString& GetSource() = 0;
/*
virtual public ZShader::GetType
Function to get the type of a shader.
ZST_SOFT : Soft shaders
ZST_VERTEX : Vertex shaders
ZST_HULL : Hull shaders
ZST_DOMAIN : Domain shaders
ZST_GEOMETRY: Geometry shaders
ZST_FRAGMENT: Fragment (pixel) shaders
@return (ZShaderType) - type of shader.
@context (all)
*/
virtual ZShaderType GetType() = 0;
/*
virtual public ZShader::SetSource
Function to set the source of a shader.
@param _source - shader source, as a string
@return (void)
@context (all)
*/
virtual void SetSource(const ZString& _source) = 0;
};
#endif

View File

@@ -0,0 +1,74 @@
/*
ZShaderBase.hpp
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 4/20/2011
Purpose:
Base implementation of the ZShader interface.
License:
TODO
*/
#pragma once
#ifndef _ZSHADERBASE_HPP
#define _ZSHADERBASE_HPP
#include <ZRenderer/ZShader.hpp>
/*
Shader base class implementation.
*/
class ZShaderBase : public ZShader
{
protected:
//The type of shader
ZShaderType Type;
//The shader source
ZString Source;
//The shader compilation log
ZString Log;
//Boolean set to true indicates this is a usable shader
bool bIsUsable;
public:
/*
Constructor.
@param _type - the type of shader this is
*/
ZShaderBase(ZShaderType _type);
//Virtual Destructor
virtual ~ZShaderBase();
//Subclass Implementation
virtual void ClearCompileLog();
//Subclass Implementation
virtual const ZString& GetCompileLog();
//Subclass Implementation
virtual const ZString& GetSource();
//Subclass Implementation
virtual ZShaderType GetType();
//Subclass Implementation
virtual bool IsUsable();
//Subclass Implementation
virtual void SetSource( const ZString& _source );
//Not Implemented
virtual bool Compile() = 0;
};
#endif

View File

@@ -0,0 +1,147 @@
/*
ZShaderParams.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
Shader parameters class, to which uniform buffers and samplers are bound
and passed to draw calls. The attached buffers and samplers will be used
to provide data to the shader.
License:
TODO
*/
#pragma once
#ifndef _ZSHADERPARAMS_HPP
#define _ZSHADERPARAMS_HPP
#include <ZRenderer/ZDrawParams.hpp>
#include <ZSTL/ZSTL.hpp>
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZDataBuffer.hpp>
#include <ZRenderer/ZTexture.hpp>
#include <ZRenderer/ZSampler.hpp>
#ifndef ZSP_MAX_UNIFORM_BLOCKS
#define ZSP_MAX_UNIFORM_BLOCKS (128)
#endif
#ifndef ZSP_MAX_SAMPLERS
#define ZSP_MAX_SAMPLERS (32)
#endif
//Shader Parameters Structure, used to hold shader parameters
class ZShaderParams : public ZDrawParams
{
private:
DISABLE_COPY_AND_ASSIGN(ZShaderParams);
protected:
//A uniform block binding
struct UniformBlockBinding
{
ZName Name; //Name of the uniform block binding
ZPtr<ZDataBuffer> Buffer; //Parent buffer
ZPair<ZDataBuffer*, const ZDataBufferBlock*> Binding; //Pair Binding
};
//A sampler binding
struct SamplerBinding
{
ZName Name; //Name of the sampler binding
ZPtr<ZSampler> Sampler; //Sampler
ZPtr<ZTexture> Texture; //Texture
ZPair<ZSampler*, ZTexture*> Binding; //Pair binding
};
//These are the buffer bindings and samplers that are provided to the shader program
UniformBlockBinding UniformBlockBindings[ZSP_MAX_UNIFORM_BLOCKS];
SamplerBinding SamplerBindings[ZSP_MAX_SAMPLERS];
//Our current uniform block count and sampler count
size_t UniformBlockBindingCount;
size_t SamplerBindingCount;
public:
/*
Default Constructor.
*/
ZShaderParams();
virtual ~ZShaderParams() { }
/*
public ZShaderParams::ClearUniformBufferBlocks
Clears the current set of uniform buffer blocks.
@return (void)
@context (all)
*/
void ClearUniformBufferBlocks();
/*
public ZShaderParams::ClearSamplers
Clears the current set of sampler bindings.
@return (void)
@context (all)
*/
void ClearSamplers();
/*
public ZShaderParams::SetUniformBufferBlock
Sets the value of a uniform buffer block for a shader. Set to NULL using overload
to remove binding.
@param _name - the name of the uniform block in the shader
@param _buffer - the buffer containing the values
@param _block - the block definition for the buffer block
@return (void)
@context (all)
*/
void SetUniformBufferBlock(const ZName& _name, ZPtr<ZDataBuffer> _buffer, const ZDataBufferBlock* _block);
/*
public ZShaderParams::SetSampler
Sets the value of a sampler for a shader.
@param _name - the name of the sampler in the shader
@param _sampler - the sampler object to use
@param _texture - the texture the sampler object is a view onto
@return (void)
@context (all)
*/
void SetSampler(const ZName& _name, ZPtr<ZSampler> _sampler, ZPtr<ZTexture> _texture);
/*
The following methods are used by the renderer to get the values needed when
binding shader parameter values to pass to the shader program, to mark
all bound resources as contended, and release contention.
*/
const ZPair<ZDataBuffer*, const ZDataBufferBlock*>* GetUniformBlockByName(const ZName& _name);
const ZPair<ZSampler*, ZTexture*>* GetSamplerByName(const ZName& _name);
//Subclass Override
virtual void MarkResourcesContended();
//Subclass Override
virtual void ReleaseResourceContention();
};
#endif

View File

@@ -0,0 +1,315 @@
/*
ZShaderProgram.hpp
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 04/03/2011
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZSHADERPROGRAM_HPP
#define _ZSHADERPROGRAM_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <ZRenderer/ZRendererResource.hpp>
#include <ZRenderer/ZShader.hpp>
#include <ZRenderer/ZSampler.hpp>
#include <ZSTL/ZString.hpp>
#include <ZUtil/ZUtil.hpp>
//Enumeration for shader stream attribute types
enum ZShaderStreamAttributeType
{
// VECTOR TYPE
ZSSAT_VECTOR_MIN,
// Single-precision float
ZSSAT_FLOAT,
ZSSAT_FLOAT_VEC2,
ZSSAT_FLOAT_VEC3,
ZSSAT_FLOAT_VEC4,
ZSSAT_VECTOR_MAX,
// MATRIX TYPE
ZSSAT_MATRIX_MIN,
// Single-precision float matrix
ZSSAT_MAT_22,
ZSSAT_MAT_23,
ZSSAT_MAT_24,
ZSSAT_MAT_32,
ZSSAT_MAT_33,
ZSSAT_MAT_34,
ZSSAT_MAT_42,
ZSSAT_MAT_43,
ZSSAT_MAT_44,
ZSSAT_MATRIX_MAX,
ZSSAT_SIZE,
ZSSAT_UNKNOWN
};
//Enumeration for types of shader uniform block member types
enum ZShaderUniformBlockMemberType
{
//VECTOR TYPE
ZSUBMT_VECTOR_MIN,
//Signed integer
ZSUBMT_INT,
ZSUBMT_INT_VEC2,
ZSUBMT_INT_VEC3,
ZSUBMT_INT_VEC4,
//Unsigned integer
ZSUBMT_UINT,
ZSUBMT_UINT_VEC2,
ZSUBMT_UINT_VEC3,
ZSUBMT_UINT_VEC4,
//Single-precision float
ZSUBMT_FLOAT,
ZSUBMT_FLOAT_VEC2,
ZSUBMT_FLOAT_VEC3,
ZSUBMT_FLOAT_VEC4,
//Half-precision float
ZSUBMT_HALF,
ZSUBMT_HALF_VEC2,
ZSUBMT_HALF_VEC3,
ZSUBMT_HALF_VEC4,
//Boolean
ZSUBMT_BOOL,
ZSUBMT_BOOL_VEC2,
ZSUBMT_BOOL_VEC3,
ZSUBMT_BOOL_VEC4,
ZSUBMT_VECTOR_MAX,
//MATRIX
ZSUBMT_MATRIX_MIN,
//Single-precision float matrix
ZSUBMT_MAT_22,
ZSUBMT_MAT_23,
ZSUBMT_MAT_24,
ZSUBMT_MAT_32,
ZSUBMT_MAT_33,
ZSUBMT_MAT_34,
ZSUBMT_MAT_42,
ZSUBMT_MAT_43,
ZSUBMT_MAT_44,
ZSUBMT_MATRIX_MAX,
ZSUBMT_SIZE
};
//Enumeration of sampler types
enum ZShaderSamplerType
{
ZSST_SAMPLER_1D, //1D texture map
ZSST_SAMPLER_2D, //2D texture map
ZSST_SAMPLER_3D, //3D texture map
ZSST_SAMPLER_CUBE, //Cubic texture map (unsupported)
ZSST_SAMPLER_1D_SHADOW, //1D shadow map (unsupported)
ZSST_SAMPLER_2D_SHADOW, //2D shadow map (unsupported)
ZSST_SIZE
};
//Struct defining a shader stream attribute
struct ZShaderStreamAttribute
{
ZName Name; //The name of the attribute
size_t Size; //The size of the attribute in terms of elements (arrays have Size > 1)
size_t Index; //Index of this attribute in the attributes array
ZShaderStreamAttributeType Type; //The type of the attribute
};
//Struct defining a uniform block member
struct ZShaderUniformBlockMember
{
ZName Name; //Name of the member
size_t Offset; //Offset (within the block) to the member
size_t Size; //Size of the member in terms of elements (arrays have Size > 1)
size_t Index; //Index of this member in the member array
size_t ArrayStride; //Stride between elements in an array (0 if not array)
size_t MatrixStride; //Stride between columns (or rows) of a matrix type (0 if not matrix type)
enum { ROW_MAJOR, COLUMN_MAJOR } MatrixOrder; //Order of a matrix type (row or column)
ZShaderUniformBlockMemberType Type; //Type of the member
};
//Struct defining a uniform block layout
struct ZShaderUniformBlock
{
ZName Name; //Name of the block
size_t Size; //Size of the block (in bytes)
size_t Index; //Index of this block in the blocks array
ZArray<ZShaderUniformBlockMember> Members; //Members contained in the block
/*
public ZShaderUniformBlock::GetMemberByName
This lookup method is used to get a pointer to a member by name, or NULL if not found.
Bear in mind that the name is qualified by the block name.
@param _name - the qualified name of the parameter
@return (const ZShaderUniformBlockMember*) - pointer to member if found, NULL if not found
*/
inline const ZShaderUniformBlockMember* GetMemberByName(const ZName& _name) const
{
for (size_t i = 0; i < Members.Size(); i++) {
if (Members.Data()[i].Name == _name) {
return &Members.Data()[i];
}
}
return NULL;
}
};
//Struct defining a shader sampler
struct ZShaderSampler
{
ZName Name; //Name of the sampler
size_t Index; //Index of this sampler in the samplers array
ZShaderSamplerType Type; //Type of the sampler
};
/*
Interface for a shader program.
*/
class ZShaderProgram : public ZRendererResource
{
public:
//Virtual Destructor
virtual ~ZShaderProgram() { }
/*
virtual public ZShaderProgram::AttachShader
Function to attach a shader. This will compile the shader.
@param _shader - The shader to attach to this shader program.
@return (bool) - true if able to compile and attach the shader
@context (all)
*/
virtual bool AttachShader(ZPtr<ZShader> _shader) = 0;
/*
virtual public ZShaderProgram::ClearLog
Function to clear the log of a shader program.
@return (void)
@context (all)
*/
virtual void ClearLog() = 0;
/*
virtual public ZShaderProgram::DetachShaders
Function to get the remove all attached shaders.
@return (void)
@context (all)
*/
virtual void DetachShaders() = 0;
/*
virtual public ZShaderProgram::GetLinkLog
Function to get the link log of a shader program.
@return (ZString) The log of the shader.
@context (all)
*/
virtual const ZString& GetLinkLog() = 0;
/*
virtual public ZShaderProgram::GetShaders
Function to get the an array of the currently attached shaders.
@return (ZArray< ZPtr<ZShader> >)
@context (all)
*/
virtual const ZArray< ZPtr<ZShader> >& GetShaders() = 0;
/*
virtual public ZShaderProgram::GetStreamAttributes
Function to get the stream shader attributes declarations for a linked shader program.
This returns an empty array until after linking.
@return (const ZArray<ZShaderStreamAttribute>&) List of shader attributes.
@context (all)
*/
virtual const ZArray<ZShaderStreamAttribute>& GetStreamDeclarations() = 0;
/*
virtual public ZShaderProgram::GetUniformBlockDeclarations
Function to get the shader uniform block declarations for a linked shader program.
This returns an empty array until after linking.
@return (const ZArray<ZShaderUniformBlock>&)
@context (all)
*/
virtual const ZArray<ZShaderUniformBlock>& GetUniformBlockDeclarations() = 0;
/*
virtual public ZShaderProgram::GetShaderSamplerDeclarations
Function to get teh shader sampler declarations for a linked shader program.
This returns an empty array until after linking.
@return (const ZArray<ZShaderSampler>&)
@context (all)
*/
virtual const ZArray<ZShaderSampler>& GetShaderSamplerDeclarations() = 0;
/*
virtual public ZShaderProgram::Link
Function to link the attached shaders into a usable shader program object.
@return (bool) True if successfully linked, false otherwise.
@context (all)
*/
virtual bool Link() = 0;
/*
virtual public ZShaderProgram::IsUsable
Function to see if shader program is usable.
@return (bool) True if shader program is usable, false otherwise.
@context (all)
*/
virtual bool IsUsable() = 0;
};
#endif

View File

@@ -0,0 +1,85 @@
/*
ZShaderProgramBase.hpp
Author: Chris Ertel <crertel@762studios.com>,
James Russell <jcrussell@762studios.com>
Created: 04/03/2011
Purpose:
ZShaderProgramBase handles the simple logistics for shader programs (e.g., log access, check usability). It
is intended to be extended by subclasses to handle implementation-specific issues.
License:
TODO
*/
#pragma once
#ifndef _ZSHADERPROGRAMBASE_HPP
#define _ZSHADERPROGRAMBASE_HPP
#include <ZRenderer/ZShaderProgram.hpp>
#include <ZUtil/ZUtil.hpp>
class ZShaderProgramBase : public ZShaderProgram
{
protected:
//Default Constructor
ZShaderProgramBase();
//Our attached shaders (currently only support vertex and fragment)
ZPtr<ZShader> VertexShader;
ZPtr<ZShader> FragmentShader;
ZArray< ZPtr<ZShader> > Shaders;
//Our cached set of uniform blocks, samplers, and vertex streams
ZArray<ZShaderUniformBlock> UniformBlocks;
ZArray<ZShaderSampler> Samplers;
ZArray<ZShaderStreamAttribute> Streams;
//Link log for shader program
ZString Log;
//Flag for shader in usable state
bool bIsUsable;
public:
//Virtual destructor
virtual ~ZShaderProgramBase();
//Subclass Implementation
virtual bool AttachShader(ZPtr<ZShader> _shader);
//Subclass Implementation
virtual void ClearLog();
//Subclass Implementation
virtual void DetachShaders();
//Subclass Implementation
virtual const ZString& GetLinkLog();
//Subclass Implementation
virtual const ZArray<ZShaderStreamAttribute>& GetStreamDeclarations();
//Subclass Implementation
virtual const ZArray<ZShaderUniformBlock>& GetUniformBlockDeclarations();
//Subclass Implementation
virtual const ZArray<ZShaderSampler>& GetShaderSamplerDeclarations();
//Subclass Implementation
virtual const ZArray< ZPtr<ZShader> >& GetShaders();
//Subclass Implementation
virtual bool IsUsable();
//Not Implemented
virtual bool Link() = 0;
};
#endif

View File

@@ -0,0 +1,162 @@
/*
ZTexture.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 04/06/2011
Purpose:
Texture interface for the ZEngine. Texture instances are loaded and created by the
renderer, which acts as a factory for the correct type of texture.
License:
TODO
*/
#pragma once
#ifndef _ZTEXTURE_HPP
#define _ZTEXTURE_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <ZRenderer/ZRendererResource.hpp>
#include <ZUtil/ZUtil.hpp>
#include <ZUtil/ZBitmap.hpp>
//Our maximum size for a texture
#ifndef ZT_MAX_TEXTURE_DIMENSION
#define ZT_MAX_TEXTURE_DIMENSION (8096)
#endif
/*
Enumeration of texture types. Not all are currently supported.
*/
enum ZTextureType
{
ZTT_TEXTURE1D, //1D texture map
ZTT_TEXTURE2D, //2D texture map
ZTT_TEXTURE3D, //3D texture map (unsupported)
ZTT_TEXTURE_CUBE, //Cubic texture map (unsupported)
ZTT_SIZE
};
/*
Enumeration of internal storage format for texture types.
*/
enum ZTextureFormat
{
ZTF_R8, //8-bit Unsigned Red (Normalized)
ZTF_R8_SNORM, //8-bit Signed Red (Normalized)
ZTF_R8I, //8-bit Signed Red
ZTF_R8UI, //8-bit Unsigned Red
ZTF_R16, //16-bit Unsigned Red (Normalized)
ZTF_R16_SNORM, //16-bit Signed Red (Normalized)
ZTF_R16I, //16-bit Signed Red
ZTF_R16UI, //16-bit Unsigned Red
ZTF_R16F, //16-bit Floating Point Red
ZTF_R32I, //32-bit Signed Red
ZTF_R32UI, //32-bit Unsigned Red
ZTF_R32F, //32-bit Floating Point Red
ZTF_RG8, //8-bit Unsigned Red, Green (Normalized)
ZTF_RG8_SNORM, //8-bit Signed Red, Green (Normalized)
ZTF_RG8I, //8-bit Signed Red, Green
ZTF_RG8UI, //8-bit Unsigned Red, Green
ZTF_RG16, //16-bit Unsigned Red, Green (Normalized)
ZTF_RG16_SNORM, //16-bit Signed Red, Green (Normalized)
ZTF_RG16I, //16-bit Signed Red, Green
ZTF_RG16UI, //16-bit Unsigned Red, Green
ZTF_RG16F, //16-bit Floating Point Red, Green
ZTF_RG32, //32-bit Unsigned Red, Green (Normalized)
ZTF_RG32_SNORM, //32-bit Signed Red, Green (Normalized)
ZTF_RG32I, //32-bit Signed Red, Green
ZTF_RG32UI, //32-bit Unsigned Red, Green
ZTF_RG32F, //32-bit Floating Point Red, Green
ZTF_RGB8, //8-bit Unsigned Red, Green, Blue (Normalized)
ZTF_RGB8_SNORM, //8-bit Signed Red, Green, Blue (Normalized)
ZTF_RGB8I, //8-bit Signed Red, Green, Blue
ZTF_RGB8UI, //8-bit Unsigned Red, Green, Blue
ZTF_RGB16, //16-bit Unsigned Red, Green, Blue (Normalized)
ZTF_RGB16_SNORM, //16-bit Signed Red, Green, Blue (Normalized)
ZTF_RGB16I, //16-bit Signed Red, Green, Blue
ZTF_RGB16UI, //16-bit Unsigned Red, Green, Blue
ZTF_RGB16F, //16-bit Floating Point Red, Green, Blue
ZTF_RGB32, //32-bit Unsigned Red, Green, Blue (Normalized)
ZTF_RGB32_SNORM, //32-bit Signed Red, Green, Blue (Normalized)
ZTF_RGB32I, //32-bit Signed Red, Green, Blue
ZTF_RGB32UI, //32-bit Unsigned Red, Green, Blue
ZTF_RGB32F, //32-bit Floating Point Red, Green, Blue
ZTF_RGBA8, //8-bit Unsigned Red, Green, Blue, Alpha (Normalized)
ZTF_RGBA8_SNORM, //8-bit Signed Red, Green, Blue, Alpha (Normalized)
ZTF_RGBA8I, //8-bit Signed Red, Green, Blue, Alpha
ZTF_RGBA8UI, //8-bit Unsigned Red, Green, Blue, Alpha
ZTF_RGBA16, //16-bit Unsigned Red, Green, Blue, Alpha (Normalized)
ZTF_RGBA16_SNORM, //16-bit Signed Red, Green, Blue, Alpha (Normalized)
ZTF_RGBA16I, //16-bit Signed Red, Green, Blue, Alpha
ZTF_RGBA16UI, //16-bit Unsigned Red, Green, Blue, Alpha
ZTF_RGBA16F, //16-bit Floating Point Red, Green, Blue, Alpha
ZTF_RGBA32, //32-bit Unsigned Red, Green, Blue, Alpha (Normalized)
ZTF_RGBA32_SNORM, //32-bit Signed Red, Green, Blue, Alpha (Normalized)
ZTF_RGBA32I, //32-bit Signed Red, Green, Blue, Alpha
ZTF_RGBA32UI, //32-bit Unsigned Red, Green, Blue, Alpha
ZTF_RGBA32F, //32-bit Floating Point Red, Green, Blue, Alpha
ZTF_DEPTH16, //16-bit Depth Texture
ZTF_DEPTH24, //24-bit Depth Texture
ZTF_DEPTH32, //32-bit Depth Texture
ZTF_DEPTH24_STENCIL8, //32-bit Depth, 8-bit Stencil
ZTF_SIZE
};
/*
Enumeration of texture usage types.
*/
enum ZTextureUsage
{
ZTU_STATIC, //Static Texture (never or rarely updated)
ZTU_DYNAMIC, //Dynamic Texture (updated frequently)
ZTU_STREAMING, //Streaming Texture (updated every frame)
ZTU_SIZE
};
class ZTexture : public ZRendererResource
{
public:
//Virtual Destructor
virtual ~ZTexture() { }
/*
virtual public ZTexture::GetType
Gets the type of this texture.
@return (ZTextureType) - the type of texture
*/
virtual ZTextureType GetType() = 0;
/*
virtual public ZTexture::GetUsage
Gets the usage type of this texture.
@return (ZTextureUsage)
@context (all)
*/
virtual ZTextureUsage GetUsage() = 0;
/*
public ZTexture::IsMipmapped
Tells you whether or not this texture has been mipmapped.
@return (bool) - true if mipmapped, false otherwise
@context (all)
*/
virtual bool IsMipmapped() = 0;
};
#endif

View File

@@ -0,0 +1,106 @@
/*
ZVertexParams.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 7/1/2012
Purpose:
TODO
License:
TODO
*/
#pragma once
#ifndef _ZVERTEXPARAMS_HPP
#define _ZVERTEXPARAMS_HPP
#include <ZRenderer/ZDrawParams.hpp>
#include <ZSTL/ZSTL.hpp>
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZDataBuffer.hpp>
#ifndef ZVP_MAX_STREAMS
#define ZVP_MAX_STREAMS (128)
#endif
class ZVertexParams : public ZDrawParams
{
private:
//A binding for a vertex stream
struct VertexStreamBinding
{
ZName Name; //Name of the stream attribute
ZPair<ZDataBuffer*, const ZDataBufferStream*> Binding; //Pair Binding
};
//This is the bound vertex buffer and streams
ZPtr<ZDataBuffer> VertexBuffer;
VertexStreamBinding VertexStreams[ZVP_MAX_STREAMS];
//Our current set number of streams
size_t CurrentStreamCount;
protected:
//Does this vertex parameter object need to be updated before rendered with?
bool Dirty;
public:
/*
Default Constructor.
*/
ZVertexParams();
/*
public ZVertexParams::ClearStreams
Clears the list of currently set streams.
@return (void)
@context (all)
*/
void ClearVertexStreams();
/*
public ZVertexParams::SetStream
Sets a vertex buffer stream. The vertex buffer provided to each call
of 'SetVertexStream' must be the same.
@param _name - the name of the stream binding
@param _vertexBuffer - the vertex buffer to bind streams from
@param _stream - the stream definition
@return (void)
@context (all)
*/
void SetVertexStream(const ZName& _name, ZPtr<ZDataBuffer> _vertexBuffer, const ZDataBufferStream* _stream);
/*
The following methods are used by the renderer to get the values needed when
binding shader parameter values to pass to the shader program, to mark
all bound resources as contended, and release contention.
*/
const ZPair<ZDataBuffer*, const ZDataBufferStream*>* GetStreamByName(const ZName& _name);
ZDataBuffer* GetVertexBuffer();
bool IsDirty() const { return Dirty; }
size_t GetStreamCount() const { return CurrentStreamCount; }
//Subclass Override
virtual void MarkResourcesContended();
//Subclass Override
virtual void ReleaseResourceContention();
};
#endif

View File

@@ -0,0 +1,106 @@
/*
ZWindowRenderTarget.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 04/01/2011
Purpose:
Interface class for a window render target. This interface requires that windows
be created and manipulated using libsst-wm.
License:
TODO
*/
#pragma once
#ifndef _ZWINDOWRENDERTARGET_HPP
#define _ZWINDOWRENDERTARGET_HPP
#include <ZRenderer/ZRendererBuild.hpp>
#include <SST/SST_WM.h>
#include <ZUtil/ZUtil.hpp>
#include <ZRenderer/ZRenderTarget.hpp>
class ZWindowRenderTarget : public ZRenderTarget
{
public:
//Virtual destructor
virtual ~ZWindowRenderTarget() { }
/*
virtual public ZWindowRenderTarget::GetAutoSwapBuffers
Gets the flag indicating whether or not this target will auto-swap buffers by the
renderer when used as a render target.
@return (bool)
@context (all)
*/
virtual bool GetAutoSwapBuffers() = 0;
/*
virtual public ZWindowRenderTarget::GetScreenIndex
Gets the screen index held by this window render target. Used to interface with libsst-wm
functionality.
@return (size_t) - the screen index
@context (all)
*/
virtual size_t GetScreenIndex() = 0;
/*
virtual public ZWindowRenderTarget::GetWindowHandle
Gets the window handle held by this window render target. Used to interface with
libsst-wm functionality.
@return (SST_Window) - the window handle
*/
virtual SST_Window GetWindowHandle() = 0;
/*
virtual public ZWindowRenderTarget::SetAutoSwapBuffers
Indicates that the renderer should automatically swap buffers after a render is
complete with this render target.
@param _value - true if we can, false if not
@return (bool) - true if able to set flag, false if resource contended
@context (all)
*/
virtual bool SetAutoSwapBuffers(bool _value) = 0;
/*
virtual public ZWindowRenderTarget::SwapBuffers
Swaps the buffers on the screen, bringing the back buffer to the front buffer. This should be called
every frame, and signals the end of the frame. This is only safe to call from within the render thread.
@return (bool) - true if able to swapbuffers, false if resource contended
@context (renderer)
*/
virtual bool SwapBuffers() = 0;
//Not Implemented
virtual const ZRenderTargetClearFlags& GetClearFlags() = 0;
//Not Implemented
virtual size_t GetHeight() = 0;
//Not Implemented
virtual ZRenderTargetType GetType() = 0;
//Not Implemented
virtual size_t GetWidth() = 0;
//Not Implemented
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags) = 0;
};
#endif

View File

@@ -0,0 +1,88 @@
/*
ZWindowRenderTargetBase.hpp
Author: James Russell <jcrussell@762studios.com>
Created: 04/03/2011
Purpose:
Base class for a window render target.
License:
TODO
*/
#pragma once
#ifndef _ZWINDOWRENDERTARGETBASE_HPP
#define _ZWINDOWRENDERTARGETBASE_HPP
#include <ZRenderer/ZWindowRenderTarget.hpp>
class ZWindowRenderTargetBase : public ZWindowRenderTarget
{
protected:
//The Window Handle
SST_Window WindowHandle;
//The Screen Index
size_t ScreenIndex;
//Our current clear flags
ZRenderTargetClearFlags ClearFlags;
//Whether or not we should auto-swap buffers
bool bAutoSwapBuffers;
/*
Parameterized Constructor.
@param _window - the libsst-wm window handle to this render target
@param _screenIndex - the libsst-wm index of this screen
*/
ZWindowRenderTargetBase(SST_Window _window, size_t _screenIndex);
public:
//Virtual Destructor
virtual ~ZWindowRenderTargetBase() { }
/*************************/
/* ZRenderTarget Methods */
/*************************/
//Subclass Implementation
virtual const ZRenderTargetClearFlags& GetClearFlags();
//Subclass Implementation
virtual size_t GetHeight();
//Subclass Implementation
virtual ZRenderTargetType GetType();
//Subclass Implementation
virtual size_t GetWidth();
//Subclass Implementation
virtual bool SetClearFlags(const ZRenderTargetClearFlags& _flags);
/***********************************/
/* ZWindowRenderTargetBase Methods */
/***********************************/
//Subclass Implementation
virtual bool GetAutoSwapBuffers();
//Subclass Implementation
virtual size_t GetScreenIndex();
//Subclass Implementation
virtual SST_Window GetWindowHandle();
//Subclass Implementation
virtual bool SetAutoSwapBuffers(bool _value);
//Not Implemented
virtual bool SwapBuffers() = 0;
};
#endif