1 Star 0 Fork 1

波波/Gut

forked from 2144/Gut 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SimpleFrame.h 3.11 KB
一键复制 编辑 原始数据 按行查看 历史
2144 提交于 2023-08-31 15:46 . s
#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();
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bobo110/gut.git
git@gitee.com:bobo110/gut.git
bobo110
gut
Gut
master

搜索帮助