#pragma once #include "OpenGlExtensions.h" #include "ZLMath.h" #include #include #include "ShaderManager.h" namespace ZL { constexpr size_t CONST_MATRIX_STACK_SIZE = 64; class VBOHolder { GLuint Buffer; public: VBOHolder(); VBOHolder(const VBOHolder& v) = delete; VBOHolder& operator=(const VBOHolder& v) = delete; ~VBOHolder(); GLuint getBuffer(); }; class VAOHolder { GLuint vao; public: VAOHolder(); VAOHolder(const VAOHolder& v) = delete; VAOHolder& operator=(const VAOHolder& v) = delete; ~VAOHolder(); GLuint getBuffer(); }; struct VertexDataStruct { std::vector PositionData; std::vector TexCoordData; std::vector NormalData; std::vector TangentData; std::vector BinormalData; std::vector ColorData; void RotateByMatrix(Matrix3f m); void Scale(float scale); void Move(Vector3f diff); void SwapZandY(); }; struct VertexRenderStruct { VertexDataStruct data; std::shared_ptr vao; std::shared_ptr positionVBO; std::shared_ptr texCoordVBO; std::shared_ptr normalVBO; std::shared_ptr tangentVBO; std::shared_ptr binormalVBO; std::shared_ptr colorVBO; void RefreshVBO(); void AssignFrom(const VertexDataStruct& v); }; VertexDataStruct CreateRect2D(Vector2f center, Vector2f halfWidthHeight, float zLevel); VertexDataStruct CreateRectHorizontalSections2D(Vector2f center, Vector2f halfWidthHeight, float zLevel, size_t sectionCount); VertexDataStruct CreateCube3D(float scale); VertexDataStruct CreateCubemap(float scale = 1000.f); class Renderer { protected: std::stack ProjectionMatrixStack; std::stack ModelviewMatrixStack; Matrix4f ProjectionModelViewMatrix; public: ShaderManager shaderManager; void InitOpenGL(); void PushProjectionMatrix(float width, float height, float zNear = 0.f, float zFar = 1.f); void PushPerspectiveProjectionMatrix(float fovY, float aspectRatio, float zNear, float zFar); void PopProjectionMatrix(); void PushMatrix(); void LoadIdentity(); void TranslateMatrix(const Vector3f& p); void ScaleMatrix(float scale); void ScaleMatrix(const Vector3f& scale); void RotateMatrix(const Vector4f& q); void RotateMatrix(const Matrix3f& m3); void PushSpecialMatrix(const Matrix4f& m); void PopMatrix(); Matrix4f GetProjectionModelViewMatrix(); void SetMatrix(); void EnableVertexAttribArray(const std::string& attribName); void DisableVertexAttribArray(const std::string& attribName); void RenderUniformMatrix4fv(const std::string& uniformName, bool transpose, const float* value); void RenderUniform1i(const std::string& uniformName, const int value); void RenderUniform3fv(const std::string& uniformName, const float* value); void VertexAttribPointer2fv(const std::string& attribName, int stride, const char* pointer); void VertexAttribPointer3fv(const std::string& attribName, int stride, const char* pointer); void DrawVertexRenderStruct(const VertexRenderStruct& VertexRenderStruct); }; void worldToScreenCoordinates(Vector3f objectPos, Matrix4f projectionModelView, int screenWidth, int screenHeight, int& screenX, int& screenY); };