Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
OpenGLWindow.hpp
1/*
2Copyright (C) 2017-2022,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_OPENGLWINDOW_HPP
17#define AEONGAMES_OPENGLWINDOW_HPP
18
19#include <cstdint>
20#include <vector>
21#include <mutex>
24#include "aeongames/Frustum.hpp"
25#include "aeongames/Texture.hpp"
26#include "OpenGLFunctions.hpp"
27#include "OpenGLBuffer.hpp"
28#include "OpenGLFrameBuffer.hpp"
29#include "OpenGLMemoryPoolBuffer.hpp"
30
31namespace AeonGames
32{
33 class Buffer;
34 class OpenGLRenderer;
37 {
38 public:
39#if defined(_WIN32)
40 OpenGLWindow ( OpenGLRenderer& aOpenGLRenderer, HWND aWindowId );
41#elif defined(__unix__)
42 OpenGLWindow ( OpenGLRenderer& aOpenGLRenderer, Display* aDisplay, ::Window aWindowId );
43#endif
45 OpenGLWindow ( OpenGLWindow&& aOpenGLWindow );
46 OpenGLWindow ( const OpenGLWindow& aOpenGLWindow ) = delete;
47 OpenGLWindow& operator= ( const OpenGLWindow& aOpenGLWindow ) = delete;
48 OpenGLWindow& operator= ( OpenGLWindow&& aOpenGLWindow ) = delete;
51 void* GetWindowId() const;
53 void BeginRender();
55 void EndRender();
56 void Render ( const Matrix4x4& aModelMatrix,
57 const Mesh& aMesh,
58 const Pipeline& aPipeline,
59 const Material* aMaterial = nullptr,
60 const BufferAccessor* aSkeleton = nullptr,
62 uint32_t aVertexStart = 0,
63 uint32_t aVertexCount = 0xffffffff,
64 uint32_t aInstanceCount = 1,
65 uint32_t aFirstInstance = 0 ) const;
69 void WriteOverlayPixels ( int32_t aXOffset, int32_t aYOffset, uint32_t aWidth, uint32_t aHeight, Texture::Format aFormat, Texture::Type aType, const uint8_t* aPixels );
71 void SetProjectionMatrix ( const Matrix4x4& aMatrix );
73 void SetViewMatrix ( const Matrix4x4& aMatrix );
75 void SetClearColor ( float R, float G, float B, float A );
77 const Matrix4x4 & GetProjectionMatrix() const;
79 const Matrix4x4 & GetViewMatrix() const;
81 const Frustum & GetFrustum() const;
83 void ResizeViewport ( int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight );
84 private:
85 void Initialize();
86 void SwapBuffers();
87 OpenGLRenderer& mOpenGLRenderer;
88#if defined(_WIN32)
89 HWND mWindowId {};
90 HDC mDeviceContext{};
91#elif defined(__unix__)
92 Display* mDisplay {};
93 ::Window mWindowId{None};
94#endif
95 Frustum mFrustum {};
96 Matrix4x4 mProjectionMatrix{};
97 Matrix4x4 mViewMatrix{};
98 //OpenGLTexture mOverlay{Texture::Format::RGBA, Texture::Type::UNSIGNED_INT_8_8_8_8_REV};
99 OpenGLFrameBuffer mFrameBuffer{};
100 OpenGLMemoryPoolBuffer mMemoryPoolBuffer;
101 OpenGLBuffer mMatrices{};
102 };
103}
104#endif
Header for the frustum class.
Header for 4x4 matrix class.
Platform-specific macros, includes, and DLL export/import definitions.
Provides access to a region within a memory pool buffer.
Abstract interface for GPU/memory buffer operations.
Definition Buffer.hpp:24
View frustum defined by six clipping planes, extracted from a projection (or view-projection) matrix.
Definition Frustum.hpp:35
Represents a surface material with uniform properties and texture samplers.
Definition Material.hpp:38
4 by 4 matrix in colum mayor order.
Definition Matrix4x4.hpp:35
Represents a polygon mesh with vertex attributes and index data.
Definition Mesh.hpp:31
OpenGL rendering backend implementing the Renderer interface.
void * GetWindowId() const
Get the native window identifier.
const Matrix4x4 & GetProjectionMatrix() const
Get the current projection matrix.
const Frustum & GetFrustum() const
Get the view frustum derived from the current matrices.
void SetClearColor(float R, float G, float B, float A)
Set the clear color for this window.
void SetProjectionMatrix(const Matrix4x4 &aMatrix)
Set the projection matrix for this window.
OpenGLWindow(OpenGLWindow &&aOpenGLWindow)
Move constructor.
void EndRender()
End the current frame and present.
void BeginRender()
Begin rendering a new frame.
void WriteOverlayPixels(int32_t aXOffset, int32_t aYOffset, uint32_t aWidth, uint32_t aHeight, Texture::Format aFormat, Texture::Type aType, const uint8_t *aPixels)
Write pixel data to the overlay texture.
const Matrix4x4 & GetViewMatrix() const
Get the current view matrix.
void Render(const Matrix4x4 &aModelMatrix, const Mesh &aMesh, const Pipeline &aPipeline, const Material *aMaterial=nullptr, const BufferAccessor *aSkeleton=nullptr, Topology aTopology=Topology::TRIANGLE_LIST, uint32_t aVertexStart=0, uint32_t aVertexCount=0xffffffff, uint32_t aInstanceCount=1, uint32_t aFirstInstance=0) const
BufferAccessor AllocateSingleFrameUniformMemory(size_t aSize)
Allocate transient uniform memory for the current frame.
void SetViewMatrix(const Matrix4x4 &aMatrix)
Set the view matrix for this window.
void ResizeViewport(int32_t aX, int32_t aY, uint32_t aWidth, uint32_t aHeight)
Resize the rendering viewport.
Rendering pipeline resource.
Definition Pipeline.hpp:122
Type
Pixel component data type.
Definition Texture.hpp:51
Format
Pixel channel layout format.
Definition Texture.hpp:40
<- This is here just for the literals
Definition AABB.hpp:31
Topology
Primitive topology types for rendering.
Definition Pipeline.hpp:38
@ TRIANGLE_LIST
Independent triangles.
Definition Pipeline.hpp:45