modify gl check and ipc moudle
This commit is contained in:
parent
0e8879d543
commit
96a324e5b7
@ -16,9 +16,15 @@ void ImageBuffer::Uninitialize() {
|
|||||||
void ImageBuffer::PushImage(ImageBuffer::IBType type, std::vector<unsigned char> data,
|
void ImageBuffer::PushImage(ImageBuffer::IBType type, std::vector<unsigned char> data,
|
||||||
uint32 width, uint32 height, uint32 comp) {
|
uint32 width, uint32 height, uint32 comp) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ImageBuffer::IBType::Background:
|
case ImageBuffer::IBType::Human:
|
||||||
PushBackgroundImage(std::move(data), width, height, comp);
|
PushHumanImage(std::move(data), width, height, comp);
|
||||||
break;
|
break;
|
||||||
|
case ImageBuffer::IBType::Face:
|
||||||
|
PushFaceImage(std::move(data), width, height, comp);
|
||||||
|
break;
|
||||||
|
case ImageBuffer::IBType::FaceMask:
|
||||||
|
PushFaceMaskImage(std::move(data), width, height, comp);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -26,28 +32,71 @@ void ImageBuffer::PushImage(ImageBuffer::IBType type, std::vector<unsigned char>
|
|||||||
|
|
||||||
void ImageBuffer::Update(IBType type, Texture2D* texture) {
|
void ImageBuffer::Update(IBType type, Texture2D* texture) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ImageBuffer::IBType::Background:
|
case ImageBuffer::IBType::Human:
|
||||||
UpdateBackground(texture);
|
UpdateHuman(texture);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case IBType::Face:
|
||||||
|
UpdateFace(texture);
|
||||||
|
|
||||||
|
case IBType::FaceMask:
|
||||||
|
UpdateFaceMask(texture);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageBuffer::PushBackgroundImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp) {
|
void ImageBuffer::PushHumanImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp) {
|
||||||
ScopeLock<CriticalSection> lock(&cs_);
|
ScopeLock<CriticalSection> lock(&human_cs_);
|
||||||
|
|
||||||
background_.data = std::move(data);
|
human_.data = std::move(data);
|
||||||
background_.width = width;
|
human_.width = width;
|
||||||
background_.height = height;
|
human_.height = height;
|
||||||
background_.comp = comp;
|
human_.comp = comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageBuffer::UpdateBackground(Texture2D* texture) {
|
void ImageBuffer::UpdateHuman(Texture2D* texture) {
|
||||||
if (background_.data.empty()) {
|
if (human_.data.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeLock<CriticalSection> lock(&cs_);
|
ScopeLock<CriticalSection> lock(&human_cs_);
|
||||||
texture->Update(background_.width, background_.height, background_.comp, background_.data.data());
|
texture->Update(human_.width, human_.height, human_.comp, human_.data.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageBuffer::PushFaceImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp) {
|
||||||
|
ScopeLock<CriticalSection> lock(&face_cs_);
|
||||||
|
|
||||||
|
face_.data = std::move(data);
|
||||||
|
face_.width = width;
|
||||||
|
face_.height = height;
|
||||||
|
face_.comp = comp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageBuffer::UpdateFace(class Texture2D* texture) {
|
||||||
|
if (face_.data.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopeLock<CriticalSection> lock(&face_cs_);
|
||||||
|
texture->Update(face_.width, face_.height, face_.comp, face_.data.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageBuffer::PushFaceMaskImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp) {
|
||||||
|
ScopeLock<CriticalSection> lock(&face_mask_cs_);
|
||||||
|
|
||||||
|
faceMask_.data = std::move(data);
|
||||||
|
faceMask_.width = width;
|
||||||
|
faceMask_.height = height;
|
||||||
|
faceMask_.comp = comp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageBuffer::UpdateFaceMask(class Texture2D* texture) {
|
||||||
|
if (faceMask_.data.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopeLock<CriticalSection> lock(&face_mask_cs_);
|
||||||
|
texture->Update(faceMask_.width, faceMask_.height, faceMask_.comp, faceMask_.data.data());
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,9 @@
|
|||||||
class ImageBuffer : public Singleton<ImageBuffer> {
|
class ImageBuffer : public Singleton<ImageBuffer> {
|
||||||
public:
|
public:
|
||||||
enum class IBType {
|
enum class IBType {
|
||||||
Background,
|
Human,
|
||||||
|
Face,
|
||||||
|
FaceMask,
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
explicit ImageBuffer() noexcept = default;
|
explicit ImageBuffer() noexcept = default;
|
||||||
@ -26,8 +27,14 @@ public:
|
|||||||
void Update(IBType type, class Texture2D* texture);
|
void Update(IBType type, class Texture2D* texture);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void PushBackgroundImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
|
void PushHumanImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
|
||||||
void UpdateBackground(class Texture2D* texture);
|
void UpdateHuman(class Texture2D* texture);
|
||||||
|
|
||||||
|
void PushFaceImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
|
||||||
|
void UpdateFace(class Texture2D* texture);
|
||||||
|
void PushFaceMaskImage(std::vector<uint8> data, uint32 width, uint32 height, uint32 comp);
|
||||||
|
void UpdateFaceMask(class Texture2D* texture);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Image {
|
struct Image {
|
||||||
std::vector<uint8> data;
|
std::vector<uint8> data;
|
||||||
@ -35,8 +42,14 @@ private:
|
|||||||
uint32 height;
|
uint32 height;
|
||||||
uint32 comp;
|
uint32 comp;
|
||||||
};
|
};
|
||||||
CriticalSection cs_;
|
CriticalSection human_cs_;
|
||||||
Image background_;
|
Image human_;
|
||||||
|
|
||||||
|
CriticalSection face_cs_;
|
||||||
|
Image face_;
|
||||||
|
|
||||||
|
CriticalSection face_mask_cs_;
|
||||||
|
Image faceMask_;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,13 @@ void OnParseImageData(const char* data, size_t size) {
|
|||||||
std::vector<uint8> img_data(img_size);
|
std::vector<uint8> img_data(img_size);
|
||||||
memcpy(img_data.data(), img_bytes, img_size);
|
memcpy(img_data.data(), img_bytes, img_size);
|
||||||
|
|
||||||
ImageBuffer::Get()->PushImage(ImageBuffer::IBType::Background, std::move(img_data), width, height, bit_depth);
|
if (0x01 == identifier) {
|
||||||
|
ImageBuffer::Get()->PushImage(ImageBuffer::IBType::Human, std::move(img_data), width, height, bit_depth);
|
||||||
|
} else if (0x02 == identifier) {
|
||||||
|
ImageBuffer::Get()->PushImage(ImageBuffer::IBType::Face, std::move(img_data), width, height, bit_depth);
|
||||||
|
} else if (0x03 == identifier) {
|
||||||
|
ImageBuffer::Get()->PushImage(ImageBuffer::IBType::FaceMask, std::move(img_data), width, height, bit_depth);
|
||||||
|
}
|
||||||
// Further processing of img_bytes can be done here
|
// Further processing of img_bytes can be done here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
src/Main.cpp
17
src/Main.cpp
@ -128,13 +128,22 @@ static int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevI
|
|||||||
}
|
}
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
|
int32 imageWidth = 1080;
|
||||||
|
int32 imageHeight = 1920;
|
||||||
Texture2D huaman;
|
Texture2D huaman;
|
||||||
huaman.Create(1920, 1080, 4, nullptr);
|
huaman.Create(imageWidth, imageHeight, 4, nullptr);
|
||||||
|
|
||||||
|
Texture2D huamanFace;
|
||||||
|
huamanFace.Create(imageWidth, imageHeight, 3, nullptr);
|
||||||
|
Texture2D huamanFaceMask;
|
||||||
|
huamanFace.Create(imageWidth, imageHeight, 3, nullptr);
|
||||||
|
|
||||||
Shader shader("./data/shader/texture.vs", "./data/shader/texture.fs");
|
Shader shader("./data/shader/texture.vs", "./data/shader/texture.fs");
|
||||||
shader.use();
|
shader.use();
|
||||||
shader.setInt("background", 0);
|
shader.setInt("background", 0);
|
||||||
shader.setInt("human", 1);
|
shader.setInt("human", 1);
|
||||||
|
shader.setInt("face", 2);
|
||||||
|
shader.setInt("face_mask", 3);
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
|
||||||
@ -152,12 +161,16 @@ static int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevI
|
|||||||
view = glm::lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
|
view = glm::lookAt(glm::vec3(0, 0, 10), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
|
||||||
projection = glm::perspective(glm::radians(60.f), ratio, 1.f, 1000.f);
|
projection = glm::perspective(glm::radians(60.f), ratio, 1.f, 1000.f);
|
||||||
|
|
||||||
ImageBuffer::Get()->Update(ImageBuffer::IBType::Background, &huaman);
|
ImageBuffer::Get()->Update(ImageBuffer::IBType::Human, &huaman);
|
||||||
|
ImageBuffer::Get()->Update(ImageBuffer::IBType::Face, &huamanFace);
|
||||||
|
ImageBuffer::Get()->Update(ImageBuffer::IBType::FaceMask, &huamanFaceMask);
|
||||||
|
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
shader.use();
|
shader.use();
|
||||||
background.Active(0);
|
background.Active(0);
|
||||||
huaman.Active(1);
|
huaman.Active(1);
|
||||||
|
huamanFace.Active(2);
|
||||||
|
huamanFaceMask.Active(3);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
//#include <glad/glad.h>
|
|
||||||
#include "Core/Logger.h"
|
#include "Core/Logger.h"
|
||||||
|
|
||||||
#define GLEW_STATIC
|
#define GLEW_STATIC
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <glfw/glfw3.h>
|
#include <glfw/glfw3.h>
|
||||||
|
|
||||||
#define __CHECK_GL_ERROR__ { \
|
inline void CheckGLError(const char* file, int line) {
|
||||||
auto gl_error_code=glGetError();\
|
GLenum err = glGetError();
|
||||||
if(gl_error_code!=GL_NO_ERROR){\
|
if (err != GL_NO_ERROR) {
|
||||||
ERRORLOG("gl_error_code: {}", static_cast<int>(gl_error_code));\
|
ERRORLOG("GL Error: {} - {}:{}", err, file, line);
|
||||||
}\
|
assert(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __CHECK_GL_ERROR__ CheckGLError(__FILE__, __LINE__);
|
||||||
|
@ -31,22 +31,14 @@ bool Texture2D::Create(int32 width, int32 height, int32 nrChannels, uint8* data)
|
|||||||
} else if (nrChannels == 4) {
|
} else if (nrChannels == 4) {
|
||||||
format = GL_RGBA;
|
format = GL_RGBA;
|
||||||
}
|
}
|
||||||
bool alloced = false;
|
|
||||||
if (nullptr == data) {
|
|
||||||
const uint32 size = width * height * nrChannels;
|
|
||||||
data = new uint8[size];
|
|
||||||
memset(data, 0, size);
|
|
||||||
alloced = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_);
|
glBindTexture(GL_TEXTURE_2D, texture_);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
|
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); __CHECK_GL_ERROR__
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); __CHECK_GL_ERROR__
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); __CHECK_GL_ERROR__
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); __CHECK_GL_ERROR__
|
||||||
|
|
||||||
if (alloced) {
|
|
||||||
delete[] data;
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
|
||||||
|
|
||||||
//glGenerateMipmap(GL_TEXTURE_2D);
|
//glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
return true;
|
return true;
|
||||||
@ -56,13 +48,15 @@ void Texture2D::Update(int32 width, int32 height, int32 channels, uint8* data) n
|
|||||||
if (0 == texture_ || nullptr == data) {
|
if (0 == texture_ || nullptr == data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texture_); __CHECK_GL_ERROR__
|
glBindTexture(GL_TEXTURE_2D, texture_); __CHECK_GL_ERROR__
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); __CHECK_GL_ERROR__
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); __CHECK_GL_ERROR__
|
||||||
if (3 == channels){
|
if (3 == channels){
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); __CHECK_GL_ERROR__
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data); __CHECK_GL_ERROR__
|
||||||
} else if (4 == channels) {
|
} else if (4 == channels) {
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); __CHECK_GL_ERROR__
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); __CHECK_GL_ERROR__
|
||||||
}
|
}
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0); __CHECK_GL_ERROR__
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture2D::Active(int32 txture) {
|
void Texture2D::Active(int32 txture) {
|
||||||
|
Loading…
Reference in New Issue
Block a user