Align OpenGL textured integration baselines
This commit is contained in:
@@ -51,7 +51,7 @@ public:
|
|||||||
bool Initialize(OpenGLTextureType type, int width, int height, int depth, int mipLevels, OpenGLFormat format, const void* data = nullptr);
|
bool Initialize(OpenGLTextureType type, int width, int height, int depth, int mipLevels, OpenGLFormat format, const void* data = nullptr);
|
||||||
bool Initialize2D(int width, int height, int channels, const void* data, bool generateMipmap = true);
|
bool Initialize2D(int width, int height, int channels, const void* data, bool generateMipmap = true);
|
||||||
bool InitializeCubeMap(int size, int mipLevels, OpenGLFormat format, const void* data = nullptr);
|
bool InitializeCubeMap(int size, int mipLevels, OpenGLFormat format, const void* data = nullptr);
|
||||||
bool LoadFromFile(const char* path, bool flipVertical = true);
|
bool LoadFromFile(const char* path, bool flipVertical = false);
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
|
|
||||||
void Bind(int slot = 0) const;
|
void Bind(int slot = 0) const;
|
||||||
|
|||||||
@@ -121,13 +121,14 @@ bool OpenGLTexture::InitializeCubeMap(int size, int mipLevels, OpenGLFormat form
|
|||||||
bool OpenGLTexture::LoadFromFile(const char* path, bool flipVertical) {
|
bool OpenGLTexture::LoadFromFile(const char* path, bool flipVertical) {
|
||||||
stbi_set_flip_vertically_on_load(flipVertical ? 1 : 0);
|
stbi_set_flip_vertically_on_load(flipVertical ? 1 : 0);
|
||||||
|
|
||||||
unsigned char* data = stbi_load(path, &m_width, &m_height, &m_channels, 0);
|
unsigned char* data = stbi_load(path, &m_width, &m_height, &m_channels, STBI_rgb_alpha);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
std::cout << "Failed to load texture: " << path << std::endl;
|
std::cout << "Failed to load texture: " << path << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = Initialize2D(m_width, m_height, m_channels, data, true);
|
m_channels = 4;
|
||||||
|
bool result = Initialize2D(m_width, m_height, m_channels, data, false);
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -175,7 +175,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
pipelineState.Apply();
|
pipelineState.Apply();
|
||||||
|
|
||||||
OpenGLTexture texture;
|
OpenGLTexture texture;
|
||||||
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
if (!texture.LoadFromFile("Res/Image/earth.png")) {
|
||||||
Log("[ERROR] Failed to load texture");
|
Log("[ERROR] Failed to load texture");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -215,15 +215,17 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
|
|
||||||
commandList.Draw(PrimitiveType::TriangleStrip, 4, 0);
|
commandList.Draw(PrimitiveType::TriangleStrip, 4, 0);
|
||||||
|
|
||||||
swapChain.Present(0, 0);
|
|
||||||
frameCount++;
|
frameCount++;
|
||||||
|
|
||||||
if (frameCount >= captureEndFrame) {
|
if (frameCount >= captureEndFrame) {
|
||||||
RenderDocCapture::Get().EndCapture();
|
RenderDocCapture::Get().EndCapture();
|
||||||
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
||||||
|
Log("[INFO] Capture complete - taking screenshot!");
|
||||||
|
OpenGLScreenshot::Capture(device, swapChain, "quad.ppm");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swapChain.Present(0, 0);
|
||||||
|
|
||||||
if (frameCount == captureStartFrame) {
|
if (frameCount == captureStartFrame) {
|
||||||
RenderDocCapture::Get().BeginCapture("OpenGL_Quad_Test");
|
RenderDocCapture::Get().BeginCapture("OpenGL_Quad_Test");
|
||||||
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
||||||
@@ -231,9 +233,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log("[INFO] Capture complete - taking screenshot!");
|
|
||||||
OpenGLScreenshot::Capture(device, swapChain, "quad.ppm");
|
|
||||||
|
|
||||||
sampler.Shutdown();
|
sampler.Shutdown();
|
||||||
texture.Shutdown();
|
texture.Shutdown();
|
||||||
vertexArray.Shutdown();
|
vertexArray.Shutdown();
|
||||||
|
|||||||
Binary file not shown.
@@ -11,8 +11,7 @@ uniform mat4 gProjectionMatrix;
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 positionWS = gModelMatrix * aPosition;
|
vec4 positionWS = gModelMatrix * aPosition;
|
||||||
positionWS.x = -positionWS.x;
|
|
||||||
vec4 positionVS = gViewMatrix * positionWS;
|
vec4 positionVS = gViewMatrix * positionWS;
|
||||||
gl_Position = gProjectionMatrix * positionVS;
|
gl_Position = gProjectionMatrix * positionVS;
|
||||||
vTexcoord = vec2(aTexcoord.x, 1.0 - aTexcoord.y);
|
vTexcoord = aTexcoord;
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,8 @@
|
|||||||
#include "XCEngine/Debug/ConsoleLogSink.h"
|
#include "XCEngine/Debug/ConsoleLogSink.h"
|
||||||
#include "XCEngine/Debug/RenderDocCapture.h"
|
#include "XCEngine/Debug/RenderDocCapture.h"
|
||||||
#include "XCEngine/Core/Containers/String.h"
|
#include "XCEngine/Core/Containers/String.h"
|
||||||
|
#include "XCEngine/Core/Math/Matrix4.h"
|
||||||
|
#include "XCEngine/Core/Math/Vector3.h"
|
||||||
|
|
||||||
#pragma comment(lib, "opengl32.lib")
|
#pragma comment(lib, "opengl32.lib")
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@
|
|||||||
using namespace XCEngine::RHI;
|
using namespace XCEngine::RHI;
|
||||||
using namespace XCEngine::Debug;
|
using namespace XCEngine::Debug;
|
||||||
using namespace XCEngine::Containers;
|
using namespace XCEngine::Containers;
|
||||||
|
using namespace XCEngine::Math;
|
||||||
|
|
||||||
static const int gWidth = 1280;
|
static const int gWidth = 1280;
|
||||||
static const int gHeight = 720;
|
static const int gHeight = 720;
|
||||||
@@ -52,30 +55,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||||||
return DefWindowProc(hwnd, msg, wParam, lParam);
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IdentityMatrix(float* m) {
|
|
||||||
memset(m, 0, 16 * sizeof(float));
|
|
||||||
m[0] = m[5] = m[10] = m[15] = 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TranslationMatrix(float* m, float x, float y, float z) {
|
|
||||||
memset(m, 0, 16 * sizeof(float));
|
|
||||||
m[0] = 1.0f; m[12] = x;
|
|
||||||
m[5] = 1.0f; m[13] = y;
|
|
||||||
m[10] = 1.0f; m[14] = z;
|
|
||||||
m[15] = 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void PerspectiveMatrix(float* m, float fov, float aspect, float nearZ, float farZ) {
|
|
||||||
memset(m, 0, 16 * sizeof(float));
|
|
||||||
float tanHalfFov = tanf(fov / 2.0f);
|
|
||||||
m[0] = 1.0f / (aspect * tanHalfFov); // m[0][0]
|
|
||||||
m[5] = 1.0f / tanHalfFov; // m[1][1]
|
|
||||||
m[10] = -(farZ + nearZ) / (farZ - nearZ); // m[2][2]
|
|
||||||
m[14] = -(2.0f * farZ * nearZ) / (farZ - nearZ); // m[2][3]
|
|
||||||
m[15] = 0.0f;
|
|
||||||
m[11] = -1.0f; // m[3][2] = -1 for OpenGL clip space
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
float pos[4];
|
float pos[4];
|
||||||
float texcoord[2];
|
float texcoord[2];
|
||||||
@@ -235,24 +214,23 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
}
|
}
|
||||||
Log("[INFO] Shaders compiled successfully");
|
Log("[INFO] Shaders compiled successfully");
|
||||||
|
|
||||||
float modelMatrix[16];
|
const float aspect = 1280.0f / 720.0f;
|
||||||
float viewMatrix[16];
|
const Matrix4x4 projectionMatrix = Matrix4x4::Perspective(45.0f * 3.141592f / 180.0f, aspect, 0.1f, 1000.0f);
|
||||||
float projectionMatrix[16];
|
const Matrix4x4 viewMatrix = Matrix4x4::Identity();
|
||||||
|
const Matrix4x4 modelMatrix = Matrix4x4::Translation(Vector3(0.0f, 0.0f, 5.0f));
|
||||||
IdentityMatrix(viewMatrix);
|
const Matrix4x4 projectionMatrixT = projectionMatrix.Transpose();
|
||||||
TranslationMatrix(modelMatrix, 0.0f, 0.0f, -5.0f);
|
const Matrix4x4 viewMatrixT = viewMatrix.Transpose();
|
||||||
float aspect = 1280.0f / 720.0f;
|
const Matrix4x4 modelMatrixT = modelMatrix.Transpose();
|
||||||
PerspectiveMatrix(projectionMatrix, 45.0f * 3.14159265f / 180.0f, aspect, 0.1f, 1000.0f);
|
|
||||||
|
|
||||||
Log("[DEBUG] ProjectionMatrix:");
|
Log("[DEBUG] ProjectionMatrix:");
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
||||||
projectionMatrix[i*4], projectionMatrix[i*4+1], projectionMatrix[i*4+2], projectionMatrix[i*4+3]);
|
projectionMatrixT.m[i][0], projectionMatrixT.m[i][1], projectionMatrixT.m[i][2], projectionMatrixT.m[i][3]);
|
||||||
}
|
}
|
||||||
Log("[DEBUG] ModelMatrix:");
|
Log("[DEBUG] ModelMatrix:");
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
||||||
modelMatrix[i*4], modelMatrix[i*4+1], modelMatrix[i*4+2], modelMatrix[i*4+3]);
|
modelMatrixT.m[i][0], modelMatrixT.m[i][1], modelMatrixT.m[i][2], modelMatrixT.m[i][3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGLPipelineState pipelineState;
|
OpenGLPipelineState pipelineState;
|
||||||
@@ -278,12 +256,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
int projLoc = shader.GetUniformLocation("gProjectionMatrix");
|
int projLoc = shader.GetUniformLocation("gProjectionMatrix");
|
||||||
Log("[DEBUG] Uniform locations - gModelMatrix: %d, gViewMatrix: %d, gProjectionMatrix: %d", modelLoc, viewLoc, projLoc);
|
Log("[DEBUG] Uniform locations - gModelMatrix: %d, gViewMatrix: %d, gProjectionMatrix: %d", modelLoc, viewLoc, projLoc);
|
||||||
commandList.SetShader(&shader);
|
commandList.SetShader(&shader);
|
||||||
commandList.SetUniformMat4("gModelMatrix", modelMatrix);
|
commandList.SetUniformMat4("gModelMatrix", &modelMatrixT.m[0][0]);
|
||||||
commandList.SetUniformMat4("gViewMatrix", viewMatrix);
|
commandList.SetUniformMat4("gViewMatrix", &viewMatrixT.m[0][0]);
|
||||||
commandList.SetUniformMat4("gProjectionMatrix", projectionMatrix);
|
commandList.SetUniformMat4("gProjectionMatrix", &projectionMatrixT.m[0][0]);
|
||||||
|
|
||||||
OpenGLTexture texture;
|
OpenGLTexture texture;
|
||||||
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
if (!texture.LoadFromFile("Res/Image/earth.png")) {
|
||||||
Log("[ERROR] Failed to load texture");
|
Log("[ERROR] Failed to load texture");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -340,15 +318,24 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
|
|
||||||
commandList.DrawIndexed(PrimitiveType::Triangles, (uint32_t)indices.size(), 0, 0);
|
commandList.DrawIndexed(PrimitiveType::Triangles, (uint32_t)indices.size(), 0, 0);
|
||||||
|
|
||||||
swapChain.Present(0, 0);
|
|
||||||
frameCount++;
|
frameCount++;
|
||||||
|
|
||||||
if (frameCount >= captureEndFrame) {
|
if (frameCount >= captureEndFrame) {
|
||||||
RenderDocCapture::Get().EndCapture();
|
RenderDocCapture::Get().EndCapture();
|
||||||
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
||||||
|
Log("[INFO] Rendered %d frames (capture was %d-%d)", renderCount, captureStartFrame, captureEndFrame);
|
||||||
|
Log("[INFO] Capture complete - taking screenshot!");
|
||||||
|
|
||||||
|
char exePath[MAX_PATH];
|
||||||
|
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
||||||
|
char* lastSlash = strrchr(exePath, '\\');
|
||||||
|
if (lastSlash) *lastSlash = '\0';
|
||||||
|
strcat_s(exePath, "\\sphere.ppm");
|
||||||
|
OpenGLScreenshot::Capture(device, swapChain, exePath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swapChain.Present(0, 0);
|
||||||
|
|
||||||
if (frameCount == captureStartFrame) {
|
if (frameCount == captureStartFrame) {
|
||||||
RenderDocCapture::Get().BeginCapture("OpenGL_Sphere_Test");
|
RenderDocCapture::Get().BeginCapture("OpenGL_Sphere_Test");
|
||||||
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
||||||
@@ -356,16 +343,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log("[INFO] Rendered %d frames (capture was %d-%d)", renderCount, captureStartFrame, captureEndFrame);
|
|
||||||
Log("[INFO] Capture complete - taking screenshot!");
|
|
||||||
|
|
||||||
char exePath[MAX_PATH];
|
|
||||||
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
|
||||||
char* lastSlash = strrchr(exePath, '\\');
|
|
||||||
if (lastSlash) *lastSlash = '\0';
|
|
||||||
strcat_s(exePath, "\\sphere.ppm");
|
|
||||||
OpenGLScreenshot::Capture(device, swapChain, exePath);
|
|
||||||
|
|
||||||
sampler.Shutdown();
|
sampler.Shutdown();
|
||||||
texture.Shutdown();
|
texture.Shutdown();
|
||||||
indexBuffer.Shutdown();
|
indexBuffer.Shutdown();
|
||||||
|
|||||||
Reference in New Issue
Block a user