Refactored many functions out of KREngine.mm into KRCamera.cpp in preparation for alpha transparent polygon sorting structures which will be owned by KRCamera

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4065
This commit is contained in:
kearwood
2012-08-15 21:26:06 +00:00
parent e8ad725d45
commit 29e2181c7e
16 changed files with 997 additions and 1024 deletions

View File

@@ -37,11 +37,32 @@
#import "KRMat4.h"
#import "KRVector2.h"
#define KRENGINE_MAX_SHADOW_BUFFERS 3
#define KRENGINE_SHADOW_MAP_WIDTH 2048
#define KRENGINE_SHADOW_MAP_HEIGHT 2048
class KRInstance;
class KRScene;
class KRContext;
class KRCamera {
public:
KRCamera();
~KRCamera();
GLint backingWidth, backingHeight;
void renderFrame(KRContext &context, KRScene &scene, KRMat4 &viewMatrix);
void renderFrame(KRContext &context, KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRVector3 &cameraPosition);
void renderShadowBuffer(KRContext &context, KRScene &scene, int iShadow);
void invalidatePostShader();
void invalidateShadowBuffers();
void allocateShadowBuffers();
void createBuffers();
void loadShaders(KRContext &context);
KRVector3 getPosition() const;
void setPosition(const KRVector3 &position);
@@ -85,9 +106,69 @@ public:
double vignette_falloff;
KRVector2 m_viewportSize;
std::vector<KRInstance *> m_transparentInstances;
int m_cShadowBuffers;
std::string m_debug_text;
private:
KRVector3 m_position;
int m_iFrame;
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
GLuint lightAccumulationBuffer, lightAccumulationTexture;
GLuint shadowFramebuffer[KRENGINE_MAX_SHADOW_BUFFERS], shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];
bool shadowValid[KRENGINE_MAX_SHADOW_BUFFERS];
KRMat4 shadowmvpmatrix[KRENGINE_MAX_SHADOW_BUFFERS]; /* MVP Matrix for view from light source */
// uniform index
enum {
KRENGINE_UNIFORM_MATERIAL_AMBIENT,
KRENGINE_UNIFORM_MATERIAL_DIFFUSE,
KRENGINE_UNIFORM_MATERIAL_SPECULAR,
KRENGINE_UNIFORM_LIGHT_POSITION,
KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE,
KRENGINE_UNIFORM_LIGHT_DIRECTION,
KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE,
KRENGINE_UNIFORM_LIGHT_COLOR,
KRENGINE_UNIFORM_LIGHT_DECAY_START,
KRENGINE_UNIFORM_LIGHT_CUTOFF,
KRENGINE_UNIFORM_LIGHT_INTENSITY,
KRENGINE_UNIFORM_FLARE_SIZE,
KRENGINE_UNIFORM_MVP,
KRENGINE_UNIFORM_INVP,
KRENGINE_UNIFORM_MN2V,
KRENGINE_UNIFORM_M2V,
KRENGINE_UNIFORM_V2M,
KRENGINE_UNIFORM_SHADOWMVP1,
KRENGINE_UNIFORM_SHADOWMVP2,
KRENGINE_UNIFORM_SHADOWMVP3,
KRENGINE_UNIFORM_CAMERAPOS,
KRENGINE_UNIFORM_VIEWPORT,
KRENGINE_NUM_UNIFORMS
};
GLint m_shadowUniforms[KRENGINE_NUM_UNIFORMS];
GLuint m_postShaderProgram;
GLuint m_shadowShaderProgram;
void renderPost(KRContext &context);
void bindPostShader(KRContext &context);
void destroyBuffers();
// Code using these shader functions will later be refactored to integrate with KRShaderManager
static bool ValidateProgram(GLuint prog);
static bool LoadShader(KRContext &context, const std::string &name, GLuint *programPointer, const std::string &options);
static bool CompileShader(GLuint *shader, GLenum type, const std::string &shader_source, const std::string &options);
static bool LinkProgram(GLuint prog);
};
#endif