diff --git a/Salmon Engine/Salmon Engine.vcxproj b/Salmon Engine/Salmon Engine.vcxproj
index d7ea6ed..da451f6 100644
--- a/Salmon Engine/Salmon Engine.vcxproj
+++ b/Salmon Engine/Salmon Engine.vcxproj
@@ -30,7 +30,6 @@
-
@@ -74,7 +73,6 @@
-
diff --git a/include/Render/RenderInterface.h b/include/Render/RenderInterface.h
deleted file mode 100644
index 856a4b1..0000000
--- a/include/Render/RenderInterface.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifndef RENDER_INTERFACE_H_INCLUDED
-#define RENDER_INTERFACE_H_INCLUDED
-
-
-#include "include/Utils/Utils.h"
-#include "include/Render/RenderMisc.h"
-#include "include/Render/RenderParams.h"
-
-namespace SE
-{
-
-class TRendererInterface
-{
-protected:
- int ScreenWidth;
- int ScreenHeight;
-
- float MatrixWidth;
- float MatrixHeight;
-
- mat4 ProjectionModelviewMatrix;
-
- std::stack ProjectionMatrixStack;
- std::stack ModelviewMatrixStack;
-
- virtual void TryEnableVertexAttribArrays();
- virtual void TryDisableVertexAttribArrays();
- virtual void DrawQuad(const T2DQuad& quad) = 0;
-public:
- TRendererInterface();
- virtual ~TRendererInterface() { }
-
- virtual void InitOpenGL(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight) = 0;
-
- virtual int GetScreenWidth();
- virtual int GetScreenHeight();
-
- virtual float GetMatrixWidth();
- virtual float GetMatrixHeight();
-
- virtual void SetMatrixWidth(float matrixWidth);
- virtual void SetMatrixHeight(float matrixHeight);
-
- virtual void SetScreenWidthHeight(int screenWidth, int screenHeight);
-
- virtual void SetUniforms() = 0;
-
- virtual void PushMatrix();
- virtual void LoadIdentity();
- virtual void TranslateMatrix(const vec3& p);
- virtual void ScaleMatrix(float scale);
- virtual void ScaleMatrix(const vec3& scale);
- virtual void RotateMatrix(const vec4& q);
- virtual void PushSpecialMatrix(const mat4& m);
- virtual void PopMatrix();
-
- virtual void SetProjectionMatrix(float width, float height);
- virtual void PushProjectionMatrix(float width, float height);
- virtual void PopProjectionMatrix();
-
- virtual void SetFrameViewport(const std::string& frameName);
- virtual void SetFullScreenViewport();
-
- virtual void PushShader(const std::string& shaderName);
- virtual void PopShader();
-
- virtual void DrawRect(const vec2& p1, const vec2& p2);
- virtual void DrawRect(const vec2& p1, const vec2& p2, const vec2& t1, const vec2& t2);
- virtual void DrawTriangleList(const TTriangleList& triangleList) = 0;
-
- virtual void SwitchToScreen() = 0;
- virtual void SwitchToFrameBuffer(const std::string& frameName) = 0;
-
- void DrawFrameFullScreen(const std::string& frameName);
- void DrawFramePartScreen(const std::string& frameName, vec2 posFrom, vec2 posTo); //To draw water. posFrom and posTo goes from 0 to 1
-
-};
-
-} //namespace SE
-
-#endif
\ No newline at end of file
diff --git a/include/Render/RenderMisc.h b/include/Render/RenderMisc.h
index 31b16d2..4156b87 100644
--- a/include/Render/RenderMisc.h
+++ b/include/Render/RenderMisc.h
@@ -115,29 +115,46 @@ class TTriangleList : public TTriangleListAncestor
#endif
-
-void FillVertexCoordVec(std::vector& coordVec, int pos, vec2 posFrom, vec2 posTo);
-
-void FillTexCoordVec(std::vector& coordVec, int pos, vec2 texCoordFrom = vec2(0,0), vec2 texCoordTo = vec2(1,1));
+
+void FillVertexCoordVec(std::vector& coordVec, int pos, vec2 posFrom, vec2 posTo);
+//Adds rect points (6 vertices) into coordVec
+
+void FillTexCoordVec(std::vector& coordVec, int pos, vec2 texCoordFrom = vec2(0,0), vec2 texCoordTo = vec2(1,1));
+//Adds rect points (6 tex coords) into coordVec
std::vector MakeVertexCoordVec(vec2 posFrom, vec2 posTo);
+//Creates array of rect (6 vertices)
std::vector MakeTexCoordVec(vec2 texCoordFrom = vec2(0,0), vec2 texCoordTo = vec2(1,1));
-
+//Creates array of rect (6 tex coords)
TDataTriangleList MakeDataTriangleList(vec2 posFrom, vec2 posTo, vec2 texCoordFrom = vec2(0,0), vec2 texCoordTo = vec2(1,1));
+//Creates a DataTriangleList just containing rect
+
void MoveDataTriangleList(TDataTriangleList& triangleList, vec3 shift);
+//Translates all points in DataTriangleList with shift vector
+
void RotateDataTriangleList(TDataTriangleList& triangleList, const mat3& m);
+//Rotates all points in triangleList with rotation matrix
+
void ScaleDataTriangleList(TDataTriangleList& triangleList, float scale);
+//Scales all points in triangleList by scale value
+
void ScaleDataTriangleList(TDataTriangleList& triangleList, vec3 scaleVec);
+//Scales all points in triangleList by scaleVec vector
+
TDataTriangleList& ClearDataTriangleList(TDataTriangleList& triangleList);
+//Clears triangle list, returning itself
+
TDataTriangleList& InsertIntoDataTriangleList(TDataTriangleList& triangleList, const std::vector& vertexArr, const std::vector& texCoordArr);
+//Inserts additional points and their tex coords into triangle list
void Replace6PointsInTriangleList(TDataTriangleList& triangleList, int pos, vec2 posFrom, vec2 posTo, vec2 texCoordFrom = vec2(0,0), vec2 texCoordTo = vec2(1,1));
-
+//Replaces one rect in triangleList at position pos by new rect. pos is position in array for first vertex of a rectangle
TTriangleList MakeTriangleList(vec2 posFrom, vec2 posTo, vec2 texCoordFrom = vec2(0,0), vec2 texCoordTo = vec2(1,1));
+//Creates triangle list containing rect
void CheckGlError(const std::string& msg = "");
diff --git a/include/Render/SalmonRender/SalmonRenderInterface.h b/include/Render/SalmonRender/SalmonRenderInterface.h
index 3d0240e..12654ce 100644
--- a/include/Render/SalmonRender/SalmonRenderInterface.h
+++ b/include/Render/SalmonRender/SalmonRenderInterface.h
@@ -9,8 +9,6 @@
#include "include/Render/SalmonRender/BackgroundCubemap.h"
-#include "include/Render/RenderInterface.h"
-
#include "include/Render/SalmonRender/Cameras.h"
namespace SE
@@ -18,9 +16,20 @@ namespace SE
-class TSalmonRendererInterface : public TRendererInterface
+class TSalmonRendererInterface
{
protected:
+
+ int ScreenWidth;
+ int ScreenHeight;
+
+ float MatrixWidth;
+ float MatrixHeight;
+
+ mat4 ProjectionModelviewMatrix;
+
+ std::stack ProjectionMatrixStack;
+ std::stack ModelviewMatrixStack;
mat4 CamModelViewMatrix;
mat4 CamInversedModelViewMatrix;
@@ -29,7 +38,11 @@ protected:
vec3 CamPos; //Do not change - call CalcCamPos instead
+
+ virtual void TryEnableVertexAttribArrays();
+ virtual void TryDisableVertexAttribArrays();
virtual void DrawQuad(const T2DQuad& quad) = 0;
+
public:
TCamera Camera;
@@ -48,6 +61,31 @@ public:
virtual void SetUniforms();
+ virtual int GetScreenWidth();
+ virtual int GetScreenHeight();
+
+ virtual float GetMatrixWidth();
+ virtual float GetMatrixHeight();
+
+ virtual void SetMatrixWidth(float matrixWidth);
+ virtual void SetMatrixHeight(float matrixHeight);
+
+ virtual void PushMatrix();
+ virtual void LoadIdentity();
+ virtual void TranslateMatrix(const vec3& p);
+ virtual void ScaleMatrix(float scale);
+ virtual void ScaleMatrix(const vec3& scale);
+ virtual void RotateMatrix(const vec4& q);
+ virtual void PushSpecialMatrix(const mat4& m);
+ virtual void PopMatrix();
+
+ virtual void SetProjectionMatrix(float width, float height);
+ virtual void PushProjectionMatrix(float width, float height);
+ virtual void PopProjectionMatrix();
+
+ virtual void SetFrameViewport(const std::string& frameName);
+ virtual void SetFullScreenViewport();
+
void SetPerspectiveFullScreenViewport();
void SetOrthoFullScreenViewport();
@@ -76,6 +114,16 @@ public:
void BeginDrawToDepthBufferGlobal(std::string& globalBufferName);
void BeginDrawToDepthBufferLocal(std::string& localBufferName);
void EndDrawToDepthBuffer();
+
+ virtual void PushShader(const std::string& shaderName);
+ virtual void PopShader();
+
+ virtual void DrawRect(const vec2& p1, const vec2& p2);
+ virtual void DrawRect(const vec2& p1, const vec2& p2, const vec2& t1, const vec2& t2);
+ virtual void DrawTriangleList(const TTriangleList& triangleList) = 0;
+
+ void DrawFrameFullScreen(const std::string& frameName);
+ void DrawFramePartScreen(const std::string& frameName, vec2 posFrom, vec2 posTo); //To draw water. posFrom and posTo goes from 0 to 1
};
diff --git a/include/ShaderManager/ShaderManager.h b/include/ShaderManager/ShaderManager.h
index b151d74..e93a5f7 100644
--- a/include/ShaderManager/ShaderManager.h
+++ b/include/ShaderManager/ShaderManager.h
@@ -130,7 +130,7 @@ public:
void Clear();
- friend class TRendererInterface;
+ friend class TSalmonRendererInterface;
};
diff --git a/src/Render/RenderInterface.cpp b/src/Render/RenderInterface.cpp
deleted file mode 100644
index e28fc44..0000000
--- a/src/Render/RenderInterface.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
-#include "include/Render/RenderInterface.h"
-#include "include/Engine.h"
-
-namespace SE
-{
-
-TRendererInterface::TRendererInterface()
- : ScreenWidth(0)
- , ScreenHeight(0)
-{
-}
-
-void TRendererInterface::TryEnableVertexAttribArrays()
-{
- AssertIfInMainThread();
-
- EnableVertexAttribArray(CONST_STRING_POSITION_ATTRIB);
- EnableVertexAttribArray(CONST_STRING_NORMAL_ATTRIB);
- EnableVertexAttribArray(CONST_STRING_TEXCOORD_ATTRIB);
- EnableVertexAttribArray(CONST_STRING_TANGENT_ATTRIB);
- EnableVertexAttribArray(CONST_STRING_BINORMAL_ATTRIB);
-}
-
-void TRendererInterface::TryDisableVertexAttribArrays()
-{
- AssertIfInMainThread();
-
- DisableVertexAttribArray(CONST_STRING_BINORMAL_ATTRIB);
- DisableVertexAttribArray(CONST_STRING_TANGENT_ATTRIB);
- DisableVertexAttribArray(CONST_STRING_TEXCOORD_ATTRIB);
- DisableVertexAttribArray(CONST_STRING_NORMAL_ATTRIB);
- DisableVertexAttribArray(CONST_STRING_POSITION_ATTRIB);
-}
-
-
-int TRendererInterface::GetScreenWidth()
-{
- return ScreenWidth;
-}
-
-int TRendererInterface::GetScreenHeight()
-{
- return ScreenHeight;
-}
-
-float TRendererInterface::GetMatrixWidth()
-{
- return MatrixWidth;
-}
-
-
-float TRendererInterface::GetMatrixHeight()
-{
- return MatrixHeight;
-}
-
-void TRendererInterface::SetMatrixWidth(float matrixWidth)
-{
- MatrixWidth = matrixWidth;
-}
-
-void TRendererInterface::SetMatrixHeight(float matrixHeight)
-{
- MatrixHeight = matrixHeight;
-}
-
-
-
-void TRendererInterface::SetScreenWidthHeight(int screenWidth, int screenHeight)
-{
- ScreenWidth = screenWidth;
- ScreenHeight = screenHeight;
-}
-
-void TRendererInterface::PushMatrix()
-{
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
-
- ModelviewMatrixStack.push(ModelviewMatrixStack.top());
-
- if (ModelviewMatrixStack.size() > 64)
- {
- throw ErrorToLog("Modelview matrix stack overflow!!!!");
- }
-}
-
-void TRendererInterface::LoadIdentity()
-{
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
-
- ModelviewMatrixStack.pop();
- ModelviewMatrixStack.push(IdentityMatrix4);
-
- SetUniforms();
-}
-
-void TRendererInterface::TranslateMatrix(const vec3& p)
-{
- mat4 m = IdentityMatrix4;
- m.m[12] = p.v[0];
- m.m[13] = p.v[1];
- m.m[14] = p.v[2];
- m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
-
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
-
- ModelviewMatrixStack.pop();
- ModelviewMatrixStack.push(m);
-
- SetUniforms();
-}
-
-void TRendererInterface::ScaleMatrix(float scale)
-{
- mat4 m = IdentityMatrix4;
- m.m[0] = scale;
- m.m[5] = scale;
- m.m[10] = scale;
- m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
-
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
-
- ModelviewMatrixStack.pop();
- ModelviewMatrixStack.push(m);
-
- SetUniforms();
-}
-
-void TRendererInterface::ScaleMatrix(const vec3& scale)
-{
- mat4 m = IdentityMatrix4;
- m.m[0] = scale.v[0];
- m.m[5] = scale.v[1];
- m.m[10] = scale.v[2];
- m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
-
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
-
- ModelviewMatrixStack.pop();
- ModelviewMatrixStack.push(m);
-
- SetUniforms();
-}
-
-void TRendererInterface::RotateMatrix(const vec4& q)
-{
- mat3 m3(q);
- mat4 m = IdentityMatrix4;
- m.m[0] = m3.m[0];
- m.m[1] = m3.m[1];
- m.m[2] = m3.m[2];
-
- m.m[4] = m3.m[3];
- m.m[5] = m3.m[4];
- m.m[6] = m3.m[5];
-
- m.m[8] = m3.m[6];
- m.m[9] = m3.m[7];
- m.m[10] = m3.m[8];
-
- m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
-
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
-
- ModelviewMatrixStack.pop();
- ModelviewMatrixStack.push(m);
-
- SetUniforms();
-}
-
-void TRendererInterface::PushSpecialMatrix(const mat4& m)
-{
- if (ModelviewMatrixStack.size() > 64)
- {
- throw ErrorToLog("Modelview matrix stack overflow!!!!");
- }
- ModelviewMatrixStack.push(m);
- SetUniforms();
-}
-
-
-void TRendererInterface::PopMatrix()
-{
- if (ModelviewMatrixStack.size() == 0)
- {
- throw ErrorToLog("Modelview matrix stack underflow!!!!");
- }
- ModelviewMatrixStack.pop();
-
- SetUniforms();
-}
-
-void TRendererInterface::PushProjectionMatrix(float width, float height)
-{
- mat4 m = MakeOrthoMatrix(width, height);
- ProjectionMatrixStack.push(m);
- SetUniforms();
-
- if (ProjectionMatrixStack.size() > 64)
- {
- throw ErrorToLog("Projection matrix stack overflow!!!!");
- }
-}
-
-void TRendererInterface::PopProjectionMatrix()
-{
- if (ProjectionMatrixStack.size() == 0)
- {
- throw ErrorToLog("Projection matrix stack underflow!!!!");
- }
- ProjectionMatrixStack.pop();
- SetUniforms();
-}
-
-void TRendererInterface::SetProjectionMatrix(float width, float height)
-{
- mat4 m = MakeOrthoMatrix(width, height);
- if (ProjectionMatrixStack.size() == 0)
- {
- throw ErrorToLog("Projection matrix stack underflow!!!!");
- }
- ProjectionMatrixStack.pop();
- ProjectionMatrixStack.push(m);
- SetUniforms();
-
-}
-
-void TRendererInterface::SetFrameViewport(const std::string& frameName)
-{
- AssertIfInMainThread();
-
- ivec2 frameWidthHeight = ResourceManager->FrameManager.GetFrameWidthHeight(frameName);
- glViewport(0, 0, frameWidthHeight.v[0], frameWidthHeight.v[1]);
-}
-
-void TRendererInterface::SetFullScreenViewport()
-{
- AssertIfInMainThread();
-
- glViewport(0, 0, ScreenWidth, ScreenHeight);
-}
-
-void TRendererInterface::PushShader(const std::string& shaderName)
-{
-
- ResourceManager->ShaderManager.PushShader(shaderName);
- SetUniforms();
- TryEnableVertexAttribArrays();
-}
-
-void TRendererInterface::PopShader()
-{
-
- ResourceManager->ShaderManager.PopShader();
- SetUniforms();
- TryEnableVertexAttribArrays();
-
-}
-
-
-void TRendererInterface::DrawRect(const vec2& p1, const vec2& p2)
-{
-
- T2DQuad quad;
-
- quad.VertexCoord[0] = vec3(p1.v[0], p1.v[1], 0.0f);
- quad.VertexCoord[1] = vec3(p1.v[0], p2.v[1], 0.0f);
- quad.VertexCoord[2] = vec3(p2.v[0], p1.v[1], 0.0f);
- quad.VertexCoord[3] = vec3(p2.v[0], p2.v[1], 0.0f);
-
- quad.TextureCoord[0] = vec2(0.01f, 0.01f);
- quad.TextureCoord[1] = vec2(0.01f, 0.99f);
- quad.TextureCoord[2] = vec2(0.99f, 0.01f);
- quad.TextureCoord[3] = vec2(0.99f, 0.99f);
-
- DrawQuad(quad);
-}
-
-void TRendererInterface::DrawRect(const vec2& p1, const vec2& p2, const vec2& t1, const vec2& t2)
-{
-
- T2DQuad quad;
-
- quad.VertexCoord[0] = vec3(p1.v[0], p1.v[1], 0.0f);
- quad.VertexCoord[1] = vec3(p1.v[0], p2.v[1], 0.0f);
- quad.VertexCoord[2] = vec3(p2.v[0], p1.v[1], 0.0f);
- quad.VertexCoord[3] = vec3(p2.v[0], p2.v[1], 0.0f);
-
- quad.TextureCoord[0] = vec2(t1.v[0], t1.v[1]);
- quad.TextureCoord[1] = vec2(t1.v[0], t2.v[1]);
- quad.TextureCoord[2] = vec2(t2.v[0], t1.v[1]);
- quad.TextureCoord[3] = vec2(t2.v[0], t2.v[1]);
-
- DrawQuad(quad);
-}
-
-
-void TRendererInterface::DrawFrameFullScreen(const std::string& frameName)
-{
-
- DrawFramePartScreen(frameName, vec2(0, 0), vec2(1, 1));
-}
-
-void TRendererInterface::DrawFramePartScreen(const std::string& frameName, vec2 posFrom, vec2 posTo)
-{
- AssertIfInMainThread();
-
- cardinal texID = ResourceManager->FrameManager.GetFrameTexture(frameName.c_str());
-
- if (texID != 0)
- {
- PushProjectionMatrix(1,1);
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- LoadIdentity();
- glBindTexture(GL_TEXTURE_2D,texID);
-
- DrawRect(posFrom, posTo, posFrom, posTo);
-
- PopProjectionMatrix();
-
- }
-
-}
-
-} //namespace SE
\ No newline at end of file
diff --git a/src/Render/SalmonRender/SalmonRenderInterface.cpp b/src/Render/SalmonRender/SalmonRenderInterface.cpp
index 7bedd75..8af4b8e 100644
--- a/src/Render/SalmonRender/SalmonRenderInterface.cpp
+++ b/src/Render/SalmonRender/SalmonRenderInterface.cpp
@@ -12,6 +12,8 @@ namespace SE
TSalmonRendererInterface::TSalmonRendererInterface()
: GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE)
+ , ScreenWidth(0)
+ , ScreenHeight(0)
{
ProjectionMatrixStack.push(IdentityMatrix4);
@@ -98,6 +100,62 @@ void TSalmonRendererInterface::InitOpenGL(int screenWidth, int screenHeight, flo
}
+
+void TSalmonRendererInterface::TryEnableVertexAttribArrays()
+{
+ AssertIfInMainThread();
+
+ EnableVertexAttribArray(CONST_STRING_POSITION_ATTRIB);
+ EnableVertexAttribArray(CONST_STRING_NORMAL_ATTRIB);
+ EnableVertexAttribArray(CONST_STRING_TEXCOORD_ATTRIB);
+ EnableVertexAttribArray(CONST_STRING_TANGENT_ATTRIB);
+ EnableVertexAttribArray(CONST_STRING_BINORMAL_ATTRIB);
+}
+
+void TSalmonRendererInterface::TryDisableVertexAttribArrays()
+{
+ AssertIfInMainThread();
+
+ DisableVertexAttribArray(CONST_STRING_BINORMAL_ATTRIB);
+ DisableVertexAttribArray(CONST_STRING_TANGENT_ATTRIB);
+ DisableVertexAttribArray(CONST_STRING_TEXCOORD_ATTRIB);
+ DisableVertexAttribArray(CONST_STRING_NORMAL_ATTRIB);
+ DisableVertexAttribArray(CONST_STRING_POSITION_ATTRIB);
+}
+
+
+int TSalmonRendererInterface::GetScreenWidth()
+{
+ return ScreenWidth;
+}
+
+int TSalmonRendererInterface::GetScreenHeight()
+{
+ return ScreenHeight;
+}
+
+float TSalmonRendererInterface::GetMatrixWidth()
+{
+ return MatrixWidth;
+}
+
+
+float TSalmonRendererInterface::GetMatrixHeight()
+{
+ return MatrixHeight;
+}
+
+void TSalmonRendererInterface::SetMatrixWidth(float matrixWidth)
+{
+ MatrixWidth = matrixWidth;
+}
+
+void TSalmonRendererInterface::SetMatrixHeight(float matrixHeight)
+{
+ MatrixHeight = matrixHeight;
+}
+
+
vec3 TSalmonRendererInterface::GetCamShift()
{
return boost::apply_visitor(TGetCamShiftVisitor(), Camera);
@@ -165,6 +223,211 @@ mat4 TSalmonRendererInterface::GetModelviewMatrix()
}
+void TSalmonRendererInterface::PushMatrix()
+{
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+
+ ModelviewMatrixStack.push(ModelviewMatrixStack.top());
+
+ if (ModelviewMatrixStack.size() > 64)
+ {
+ throw ErrorToLog("Modelview matrix stack overflow!!!!");
+ }
+}
+
+void TSalmonRendererInterface::LoadIdentity()
+{
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+
+ ModelviewMatrixStack.pop();
+ ModelviewMatrixStack.push(IdentityMatrix4);
+
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::TranslateMatrix(const vec3& p)
+{
+ mat4 m = IdentityMatrix4;
+ m.m[12] = p.v[0];
+ m.m[13] = p.v[1];
+ m.m[14] = p.v[2];
+ m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
+
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+
+ ModelviewMatrixStack.pop();
+ ModelviewMatrixStack.push(m);
+
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::ScaleMatrix(float scale)
+{
+ mat4 m = IdentityMatrix4;
+ m.m[0] = scale;
+ m.m[5] = scale;
+ m.m[10] = scale;
+ m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
+
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+
+ ModelviewMatrixStack.pop();
+ ModelviewMatrixStack.push(m);
+
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::ScaleMatrix(const vec3& scale)
+{
+ mat4 m = IdentityMatrix4;
+ m.m[0] = scale.v[0];
+ m.m[5] = scale.v[1];
+ m.m[10] = scale.v[2];
+ m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
+
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+
+ ModelviewMatrixStack.pop();
+ ModelviewMatrixStack.push(m);
+
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::RotateMatrix(const vec4& q)
+{
+ mat3 m3(q);
+ mat4 m = IdentityMatrix4;
+ m.m[0] = m3.m[0];
+ m.m[1] = m3.m[1];
+ m.m[2] = m3.m[2];
+
+ m.m[4] = m3.m[3];
+ m.m[5] = m3.m[4];
+ m.m[6] = m3.m[5];
+
+ m.m[8] = m3.m[6];
+ m.m[9] = m3.m[7];
+ m.m[10] = m3.m[8];
+
+ m = MultMatrixMatrix(ModelviewMatrixStack.top(), m);
+
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+
+ ModelviewMatrixStack.pop();
+ ModelviewMatrixStack.push(m);
+
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::PushSpecialMatrix(const mat4& m)
+{
+ if (ModelviewMatrixStack.size() > 64)
+ {
+ throw ErrorToLog("Modelview matrix stack overflow!!!!");
+ }
+ ModelviewMatrixStack.push(m);
+ SetUniforms();
+}
+
+
+void TSalmonRendererInterface::PopMatrix()
+{
+ if (ModelviewMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Modelview matrix stack underflow!!!!");
+ }
+ ModelviewMatrixStack.pop();
+
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::PushProjectionMatrix(float width, float height)
+{
+ mat4 m = MakeOrthoMatrix(width, height);
+ ProjectionMatrixStack.push(m);
+ SetUniforms();
+
+ if (ProjectionMatrixStack.size() > 64)
+ {
+ throw ErrorToLog("Projection matrix stack overflow!!!!");
+ }
+}
+
+void TSalmonRendererInterface::PopProjectionMatrix()
+{
+ if (ProjectionMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Projection matrix stack underflow!!!!");
+ }
+ ProjectionMatrixStack.pop();
+ SetUniforms();
+}
+
+void TSalmonRendererInterface::SetProjectionMatrix(float width, float height)
+{
+ mat4 m = MakeOrthoMatrix(width, height);
+ if (ProjectionMatrixStack.size() == 0)
+ {
+ throw ErrorToLog("Projection matrix stack underflow!!!!");
+ }
+ ProjectionMatrixStack.pop();
+ ProjectionMatrixStack.push(m);
+ SetUniforms();
+
+}
+
+void TSalmonRendererInterface::SetFrameViewport(const std::string& frameName)
+{
+ AssertIfInMainThread();
+
+ ivec2 frameWidthHeight = ResourceManager->FrameManager.GetFrameWidthHeight(frameName);
+ glViewport(0, 0, frameWidthHeight.v[0], frameWidthHeight.v[1]);
+}
+
+void TSalmonRendererInterface::SetFullScreenViewport()
+{
+ AssertIfInMainThread();
+
+ glViewport(0, 0, ScreenWidth, ScreenHeight);
+}
+
+void TSalmonRendererInterface::PushShader(const std::string& shaderName)
+{
+
+ ResourceManager->ShaderManager.PushShader(shaderName);
+ SetUniforms();
+ TryEnableVertexAttribArrays();
+}
+
+void TSalmonRendererInterface::PopShader()
+{
+
+ ResourceManager->ShaderManager.PopShader();
+ SetUniforms();
+ TryEnableVertexAttribArrays();
+
+}
+
+
+
void TSalmonRendererInterface::SetPerspectiveProjectionMatrix(float angle, float aspect, float zNear, float zFar)
{
mat4 m = MakePerspectiveMatrix(angle, aspect, zNear, zFar);
@@ -373,6 +636,72 @@ void TSalmonRendererInterface::EndDrawToDepthBuffer()
SetPerspectiveFullScreenViewport();
}
+void TSalmonRendererInterface::DrawRect(const vec2& p1, const vec2& p2)
+{
+
+ T2DQuad quad;
+
+ quad.VertexCoord[0] = vec3(p1.v[0], p1.v[1], 0.0f);
+ quad.VertexCoord[1] = vec3(p1.v[0], p2.v[1], 0.0f);
+ quad.VertexCoord[2] = vec3(p2.v[0], p1.v[1], 0.0f);
+ quad.VertexCoord[3] = vec3(p2.v[0], p2.v[1], 0.0f);
+
+ quad.TextureCoord[0] = vec2(0.01f, 0.01f);
+ quad.TextureCoord[1] = vec2(0.01f, 0.99f);
+ quad.TextureCoord[2] = vec2(0.99f, 0.01f);
+ quad.TextureCoord[3] = vec2(0.99f, 0.99f);
+
+ DrawQuad(quad);
+}
+
+void TSalmonRendererInterface::DrawRect(const vec2& p1, const vec2& p2, const vec2& t1, const vec2& t2)
+{
+
+ T2DQuad quad;
+
+ quad.VertexCoord[0] = vec3(p1.v[0], p1.v[1], 0.0f);
+ quad.VertexCoord[1] = vec3(p1.v[0], p2.v[1], 0.0f);
+ quad.VertexCoord[2] = vec3(p2.v[0], p1.v[1], 0.0f);
+ quad.VertexCoord[3] = vec3(p2.v[0], p2.v[1], 0.0f);
+
+ quad.TextureCoord[0] = vec2(t1.v[0], t1.v[1]);
+ quad.TextureCoord[1] = vec2(t1.v[0], t2.v[1]);
+ quad.TextureCoord[2] = vec2(t2.v[0], t1.v[1]);
+ quad.TextureCoord[3] = vec2(t2.v[0], t2.v[1]);
+
+ DrawQuad(quad);
+}
+
+
+void TSalmonRendererInterface::DrawFrameFullScreen(const std::string& frameName)
+{
+
+ DrawFramePartScreen(frameName, vec2(0, 0), vec2(1, 1));
+}
+
+void TSalmonRendererInterface::DrawFramePartScreen(const std::string& frameName, vec2 posFrom, vec2 posTo)
+{
+ AssertIfInMainThread();
+
+ cardinal texID = ResourceManager->FrameManager.GetFrameTexture(frameName.c_str());
+
+ if (texID != 0)
+ {
+ PushProjectionMatrix(1,1);
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ LoadIdentity();
+ glBindTexture(GL_TEXTURE_2D,texID);
+
+ DrawRect(posFrom, posTo, posFrom, posTo);
+
+ PopProjectionMatrix();
+
+ }
+
+}
+
+
} //namespace SE