Ult3D
Implementation of "Ultimate 3D Game Engine Design & Architecture" by Allan Sherrod
Loading...
Searching...
No Matches
Ult::OpenGLRenderer Class Reference

#include <OpenGLRenderer.h>

Inheritance diagram for Ult::OpenGLRenderer:
Ult::RenderInterface

Public Member Functions

 OpenGLRenderer ()
 
virtual ~OpenGLRenderer ()
 
virtual bool Initialize (const RenderParams *params)
 
virtual void Shutdown ()
 
virtual void SetViewport (int x, int y, int width, int height)
 
virtual void ResizeWindow (float fov, float nearDist, float farDist, int width, int height)
 
virtual void ResizeWindowOrtho (int left, int right, int bottom, int top, float nearDist, float farDist)
 
virtual void SetClearColor (int r, int g, int b, int a)
 
virtual void StartRendering (bool color, bool depth, bool stencil)
 
virtual void EndRendering ()
 
virtual bool Enable (RenderState state)
 
virtual bool Disable (RenderState state)
 
virtual void SetAlphaFunc (AlphaState state, float val)
 
virtual void SetView (float posX, float posY, float posZ, float lookX, float lookY, float lookZ, float upX, float upY, float upZ)
 
virtual void SetMatrix (const float *matrix)
 
virtual void MultiplyToCurrentMatrix (const float *m)
 
virtual bool SwitchMatrixType (MatrixType type)
 
virtual void GetMatrix (MatrixType type, float *matrix)
 
virtual void RotateMatrix (float angle, float x, float y, float z)
 
virtual void TranslateMatrix (float x, float y, float z)
 
virtual void LoadIdentityMatrix ()
 
virtual void PushMatrix ()
 
virtual void PopMatrix ()
 
virtual void ApplyFilters (Texture &handle, FilterListPtr filters)
 
virtual bool AddEmptyTexture (const char *name, int width, int height, int numComponents, TextureType type, TextureFormat format, Texture *handle)
 
virtual bool LoadTexFromFile (const char *fileName, TextureType type, Texture *handle)
 
virtual bool LoadTexFromMemory (const char *name, char *fileData, int length, TextureType type, Texture *handle)
 
virtual bool ApplyTexture (int texUnit, Texture &handle)
 
virtual void DeleteTexture (Texture &handle)
 
virtual bool CreateShaderFromFile (const char *vs, const char *ps, ShaderHandle *handle)
 
virtual bool CreateShaderFromMemory (const char *vsFile, const char *psFile, ShaderHandle *handle)
 
virtual void ApplyShader (ShaderHandle shader)
 
virtual void SetupShaderParameter (const char *pname, ShaderHandle shader, ParameterHandle *param)
 
virtual void SetShaderParameter1i (ParameterHandle param, float val)
 
virtual void SetShaderParameter1f (ParameterHandle param, float val)
 
virtual void SetShaderParameter2f (ParameterHandle param, float x, float y)
 
virtual void SetShaderParameter3f (ParameterHandle param, float x, float y, float z)
 
virtual void SetShaderParameter4f (ParameterHandle param, float x, float y, float z, float w)
 
virtual void Render (PrimitiveType type, VertexDescriptor *desc, char *vertexData, unsigned int *indices, int totalVertices, int totalIndices, int stride)
 
- Public Member Functions inherited from Ult::RenderInterface
 RenderInterface ()
 
virtual ~RenderInterface ()
 

Protected Member Functions

bool InitializeOS (const RenderParams *params)
 
void ShutdownOS ()
 
void InitializeExtensions ()
 

Protected Attributes

VertexDescriptormCurrentDesc
 
bool mVboSupport
 
bool mFboSupport
 
bool mGlslSupport
 
GLuint mVbo
 
GLuint mIbo
 
ResourceManager< GLTexture, Texture > * mTexManager
 
std::vector< GLSLShadermShaders
 
std::vector< GLSLParametermParameters
 
- Protected Attributes inherited from Ult::RenderInterface
int mRed
 
int mGreen
 
int mBlue
 
int mAlpha
 
bool mMultiTexSupport
 
bool mCubeMapSupport
 
RenderParams mParams
 
CGcontext mCgContext
 
CGprofile mVsProfile
 
CGprofile mPsProfile
 

Detailed Description

OpenGL implementation of the RenderInterface.

Constructor & Destructor Documentation

◆ OpenGLRenderer()

Ult::OpenGLRenderer::OpenGLRenderer ( )

◆ ~OpenGLRenderer()

Ult::OpenGLRenderer::~OpenGLRenderer ( )
virtual

Member Function Documentation

◆ AddEmptyTexture()

bool Ult::OpenGLRenderer::AddEmptyTexture ( const char * name,
int width,
int height,
int numComponents,
TextureType type,
TextureFormat format,
Texture * handle )
virtual

Initialize an empty texture and store a handle to it in 'handle'.

Implements Ult::RenderInterface.

◆ ApplyFilters()

void Ult::OpenGLRenderer::ApplyFilters ( Texture & handle,
FilterListPtr filters )
virtual

Apply the input filters to the input texture.

Implements Ult::RenderInterface.

◆ ApplyShader()

void Ult::OpenGLRenderer::ApplyShader ( ShaderHandle shader)
virtual

Use the given input shader for rendering.

Implements Ult::RenderInterface.

◆ ApplyTexture()

bool Ult::OpenGLRenderer::ApplyTexture ( int texUnit,
Texture & handle )
virtual

Use the given texture for rendering in the given texture unit.

Implements Ult::RenderInterface.

◆ CreateShaderFromFile()

bool Ult::OpenGLRenderer::CreateShaderFromFile ( const char * vs,
const char * ps,
ShaderHandle * handle )
virtual

Load/create a shader from the vertex/pixel files and store the result in handle.

Returns
True on success, false on failure.

Implements Ult::RenderInterface.

◆ CreateShaderFromMemory()

bool Ult::OpenGLRenderer::CreateShaderFromMemory ( const char * vsFile,
const char * psFile,
ShaderHandle * handle )
virtual

Load/create a shader from vertex/pixel shader strings and store the result in handle.

Returns
True on success, false on failure.

Implements Ult::RenderInterface.

◆ DeleteTexture()

void Ult::OpenGLRenderer::DeleteTexture ( Texture & handle)
virtual

Free the texture given by the input handle.

Implements Ult::RenderInterface.

◆ Disable()

bool Ult::OpenGLRenderer::Disable ( RenderState state)
virtual

Disables the input render parameter.

Implements Ult::RenderInterface.

◆ Enable()

bool Ult::OpenGLRenderer::Enable ( RenderState state)
virtual

Enables the input render parameter.

Implements Ult::RenderInterface.

◆ EndRendering()

void Ult::OpenGLRenderer::EndRendering ( )
virtual

Updates the window, swaps front/back render buffers.

Implements Ult::RenderInterface.

◆ GetMatrix()

void Ult::OpenGLRenderer::GetMatrix ( MatrixType type,
float * matrix )
virtual

Copy the matrix of the input type into the input matrix (as 16 floats).

Implements Ult::RenderInterface.

◆ Initialize()

bool Ult::OpenGLRenderer::Initialize ( const RenderParams * params)
virtual

Initialize the render system with the given parameters. Assumes the window handle is already created/set.

Implements Ult::RenderInterface.

◆ InitializeExtensions()

void Ult::OpenGLRenderer::InitializeExtensions ( )
protected

◆ InitializeOS()

bool Ult::OpenGLRenderer::InitializeOS ( const RenderParams * params)
protected

◆ LoadIdentityMatrix()

void Ult::OpenGLRenderer::LoadIdentityMatrix ( )
virtual

Set the current matrix to an identity matrix.

Implements Ult::RenderInterface.

◆ LoadTexFromFile()

bool Ult::OpenGLRenderer::LoadTexFromFile ( const char * fileName,
TextureType type,
Texture * handle )
virtual

Initialize a texture from a file and store a handle to it in 'handle'.

Implements Ult::RenderInterface.

◆ LoadTexFromMemory()

bool Ult::OpenGLRenderer::LoadTexFromMemory ( const char * name,
char * fileData,
int length,
TextureType type,
Texture * handle )
virtual

Initialize a texture from memory and store a handle to it in 'handle'.

Implements Ult::RenderInterface.

◆ MultiplyToCurrentMatrix()

void Ult::OpenGLRenderer::MultiplyToCurrentMatrix ( const float * m)
virtual

Multiplies the input matrix (as 16 floats) with the current matrix type.

Implements Ult::RenderInterface.

◆ PopMatrix()

void Ult::OpenGLRenderer::PopMatrix ( )
virtual

Pop the top of the internal matrix stack to the current matrix.

Implements Ult::RenderInterface.

◆ PushMatrix()

void Ult::OpenGLRenderer::PushMatrix ( )
virtual

Push the current matrix to the internal matrix stack.

Implements Ult::RenderInterface.

◆ Render()

void Ult::OpenGLRenderer::Render ( PrimitiveType type,
VertexDescriptor * desc,
char * vertexData,
unsigned int * indices,
int totalVertices,
int totalIndices,
int stride )
virtual

Render a buffer of primitives using the current renderer settings.

Parameters
typeThe type of primitives contained in vertexData.
descPointer to a descriptor listing the different elements within a single vertex.
vertexDataByte pointer to the buffer of vertices to render.
indicesOptional pointer to an index buffer to render with.
totalVerticesThe size of vertexData in bytes.
totalIndicesThe count/number of indices contained in the indices pointer.
strideThe size of 1 vertex in bytes.

Implements Ult::RenderInterface.

◆ ResizeWindow()

void Ult::OpenGLRenderer::ResizeWindow ( float fov,
float nearDist,
float farDist,
int width,
int height )
virtual

Update the size of the window. Recalculates the perspective-projection matrix with the given parameters.

Implements Ult::RenderInterface.

◆ ResizeWindowOrtho()

void Ult::OpenGLRenderer::ResizeWindowOrtho ( int left,
int right,
int bottom,
int top,
float nearDist,
float farDist )
virtual

Update the size of the window. Recalculates the projection matrix as an orthographic projection using the given parameters.

Implements Ult::RenderInterface.

◆ RotateMatrix()

void Ult::OpenGLRenderer::RotateMatrix ( float angle,
float x,
float y,
float z )
virtual

Applies a rotation about the given axis to the current matrix.

Parameters
angleRotation angle in degrees.
x,y,zAxis of rotation.

Implements Ult::RenderInterface.

◆ SetAlphaFunc()

void Ult::OpenGLRenderer::SetAlphaFunc ( AlphaState state,
float val )
virtual

Sets the type of alpha blending to use during render.

Implements Ult::RenderInterface.

◆ SetClearColor()

void Ult::OpenGLRenderer::SetClearColor ( int r,
int g,
int b,
int a )
virtual

Sets the background color of the window upon StartRendering.

Implements Ult::RenderInterface.

◆ SetMatrix()

void Ult::OpenGLRenderer::SetMatrix ( const float * matrix)
virtual

Copy the input matrix (as 16 floats) to the current matrix type.

Implements Ult::RenderInterface.

◆ SetShaderParameter1f()

void Ult::OpenGLRenderer::SetShaderParameter1f ( ParameterHandle param,
float val )
virtual

Set a shader uniform float to the given value.

Implements Ult::RenderInterface.

◆ SetShaderParameter1i()

void Ult::OpenGLRenderer::SetShaderParameter1i ( ParameterHandle param,
float val )
virtual

Set a shader uniform int to the given value.

Implements Ult::RenderInterface.

◆ SetShaderParameter2f()

void Ult::OpenGLRenderer::SetShaderParameter2f ( ParameterHandle param,
float x,
float y )
virtual

Set a shader uniform vec2 to the given values.

Implements Ult::RenderInterface.

◆ SetShaderParameter3f()

void Ult::OpenGLRenderer::SetShaderParameter3f ( ParameterHandle param,
float x,
float y,
float z )
virtual

Set a shader uniform vec3 to the given values.

Implements Ult::RenderInterface.

◆ SetShaderParameter4f()

void Ult::OpenGLRenderer::SetShaderParameter4f ( ParameterHandle param,
float x,
float y,
float z,
float w )
virtual

Set a shader uniform vec4 to the given values.

Implements Ult::RenderInterface.

◆ SetupShaderParameter()

void Ult::OpenGLRenderer::SetupShaderParameter ( const char * pname,
ShaderHandle shader,
ParameterHandle * param )
virtual

Store a handle to the shader uniform given by pname in the input shader into param. If the uniform isn't found, it prints an error message and does nothing.

Implements Ult::RenderInterface.

◆ SetView()

void Ult::OpenGLRenderer::SetView ( float posX,
float posY,
float posZ,
float lookX,
float lookY,
float lookZ,
float upX,
float upY,
float upZ )
virtual

Sets the camera/view/lookat matrix from the given parameters.

Implements Ult::RenderInterface.

◆ SetViewport()

void Ult::OpenGLRenderer::SetViewport ( int x,
int y,
int width,
int height )
virtual

Sets the window viewport - position and size of the rendering area.

Implements Ult::RenderInterface.

◆ Shutdown()

void Ult::OpenGLRenderer::Shutdown ( )
virtual

Deinits the render system. Does not free the render params window.

Implements Ult::RenderInterface.

◆ ShutdownOS()

void Ult::OpenGLRenderer::ShutdownOS ( )
protected

◆ StartRendering()

void Ult::OpenGLRenderer::StartRendering ( bool color,
bool depth,
bool stencil )
virtual

Clears the corresponding buffers if its boolean is set to true (color buffer, depth buffer, stencil buffer).

Implements Ult::RenderInterface.

◆ SwitchMatrixType()

bool Ult::OpenGLRenderer::SwitchMatrixType ( MatrixType type)
virtual

Change the currently used matrix to the input type.

Implements Ult::RenderInterface.

◆ TranslateMatrix()

void Ult::OpenGLRenderer::TranslateMatrix ( float x,
float y,
float z )
virtual

Applies a translation of x,y,z to the current matrix.

Implements Ult::RenderInterface.

Member Data Documentation

◆ mCurrentDesc

VertexDescriptor* Ult::OpenGLRenderer::mCurrentDesc
protected

◆ mFboSupport

bool Ult::OpenGLRenderer::mFboSupport
protected

◆ mGlslSupport

bool Ult::OpenGLRenderer::mGlslSupport
protected

◆ mIbo

GLuint Ult::OpenGLRenderer::mIbo
protected

◆ mParameters

std::vector<GLSLParameter> Ult::OpenGLRenderer::mParameters
protected

◆ mShaders

std::vector<GLSLShader> Ult::OpenGLRenderer::mShaders
protected

◆ mTexManager

ResourceManager<GLTexture,Texture>* Ult::OpenGLRenderer::mTexManager
protected

◆ mVbo

GLuint Ult::OpenGLRenderer::mVbo
protected

◆ mVboSupport

bool Ult::OpenGLRenderer::mVboSupport
protected

The documentation for this class was generated from the following files: