代码拉取完成,页面将自动刷新
同步操作将从 2144/Gut 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#pragma once
#include "Framebuffer.h"
#include "Texture.h"
struct SimpleFrame
{
FrameBuffer frameBuffer;
std::vector<Texture2D> outColors;
Texture2DDesc texDesc;
Texture2D depthMap;
Texture2DDesc depthDesc;
RenderBuffer rBuffer;
int mWidth, mHeight;
struct Desc
{
int width, height;
int numTexture;
int format = GL_RGBA;
int internalFormat = GL_RGBA;
int dataType = GL_FLOAT;
int target = GL_TEXTURE_2D;
};
void Create(const Desc& desc)
{
mWidth = desc.width;
mHeight = desc.height;
frameBuffer.Create();
texDesc.target = desc.target;
texDesc.width = desc.width;
texDesc.height = desc.height;
texDesc.internalformat = desc.internalFormat;
texDesc.format = desc.format;
texDesc.data = 0;
texDesc.dataType = desc.dataType;
std::vector<unsigned int> attachments;
for (int i = 0; i < desc.numTexture; i++)
{
Texture2D outColor;
outColor.Create();
outColor.TexImage2D(texDesc);
outColor.Bind();
SamplerDesc samDesc;
samDesc.minFilter = GL_LINEAR;
samDesc.magFilter = GL_LINEAR;
outColor.SetSampler(samDesc);
outColor.Mipmap();
frameBuffer.BufferTexture2D(GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, outColor.ID);
attachments.emplace_back(GL_COLOR_ATTACHMENT0 + i);
outColors.emplace_back(outColor);
}
depthDesc.target = desc.target;
depthDesc.width = desc.width;
depthDesc.height = desc.height;
depthDesc.internalformat = GL_DEPTH_COMPONENT;
depthDesc.format = GL_DEPTH_COMPONENT;
depthDesc.dataType = desc.dataType;
depthDesc.data = 0;
depthMap.Create();
depthMap.TexImage2D(depthDesc);
SamplerDesc samDesc;
samDesc.minFilter = GL_NEAREST;
samDesc.magFilter = GL_NEAREST;
samDesc.wrapS = GL_CLAMP_TO_EDGE;
samDesc.wrapT = GL_CLAMP_TO_EDGE;
samDesc.useBorderColor = true;
samDesc.borderColor[0] = 1.0f;
samDesc.borderColor[1] = 1.0f;
samDesc.borderColor[2] = 1.0f;
samDesc.borderColor[3] = 1.0f;
depthMap.SetSampler(samDesc);
attachments.emplace_back(GL_DEPTH_ATTACHMENT);
frameBuffer.DrawBuffers(&attachments[0], attachments.size());
rBuffer.Create();
rBuffer.Storage(GL_DEPTH24_STENCIL8, desc.width, desc.height);
frameBuffer.RenderBuffer(GL_DEPTH_STENCIL_ATTACHMENT, rBuffer.ID);
frameBuffer.CheckError();
}
void Resize(int width, int height)
{
texDesc.width = width;
texDesc.height = height;
for (auto& outColor : outColors)
{
outColor.TexImage2D(texDesc);
}
depthDesc.width = width;
depthDesc.height = height;
depthMap.TexImage2D(depthDesc);
rBuffer.Storage(GL_DEPTH24_STENCIL8, width, height);
mWidth = width;
mHeight = height;
}
void Begin()
{
frameBuffer.Bind();
glViewport(0, 0, mWidth, mHeight);
}
void End()
{
frameBuffer.UnBind();
}
struct ScreenShotDesc
{
int attachment = GL_COLOR_ATTACHMENT0;
int x = 0;
int y = 0;
int width = 1;
int height = 1;
int format = GL_FLOAT;
int type = GL_RGBA;
void* out = 0;
};
void SceenShot(const ScreenShotDesc& desc)
{
frameBuffer.Bind();
glReadBuffer(desc.attachment);
glReadPixels(desc.x, desc.y, desc.width, desc.height, desc.format, desc.type, desc.out);
frameBuffer.UnBind();
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。