Files
chenzhen 222dda1e43 1,新增“App_ThermalImageSystem”;
2,新增“Apps”;
3,新增“Common”;
4,新增“FileList”;
5,新增“MediaX”;
6,新增“OpenSource”;
7,新增“Samples”;
8,新增“SoftwareBusinessLines”.
2026-02-14 23:03:23 +08:00

156 lines
3.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef OpenGLView_H
#define OpenGLView_H
#ifndef GLFW_EXPOSE_NATIVE_WIN32
#define GLFW_EXPOSE_NATIVE_WIN32
#endif
////
// stl
#include <memory>
#include <thread>
#include <chrono>
////
// opengl & glfw
#include <include/GL/glew.h>
#include <include/glfw3.h>
#include <include/glfw3native.h> // GLFW_EXPOSE_NATIVE_WIN32
#define MAX_TEXTURES 32 // texture个数(图层数)
//#define MAX_PBOS (MAX_TEXTURES*2) // PBO个数
/*
* 使用OpenGL渲染视频主要用到纹理、PBO、窗口及事件管理
*/
/*
* OpenGLRender封装纹理及PBO
*/
enum eGL_ImageFormat
{
eGL_ImageFormat_Grey = 1,
eGL_ImageFormat_RGB = 3,
eGL_ImageFormat_RGBA = 4,
};
class OpenGLRender
{
private:
class Texture
{
public:
Texture();
virtual ~Texture();
void Create(int nCount);
void Destroy();
bool Init(int nIndex, eGL_ImageFormat eImageFmt, int nImageWidth, int nImageHeight);
bool DrawImage(int nIndex, eGL_ImageFormat eImageFmt, char* pImageData, int nImageWidth, int nImageHeight);
int GetCount();
protected:
GLuint m_nTextures[MAX_TEXTURES];
int m_nCount;
int m_nCurrentIndex;
bool m_bCreate;
bool m_bInit;
};
private:
class PBOTexture
{
public:
PBOTexture();
virtual ~PBOTexture();
void Create(int nCount);
void Destroy();
bool Init(int nIndex, eGL_ImageFormat eImageFmt, int nImageWidth, int nImageHeight);
bool DrawImage(int nIndex, eGL_ImageFormat eImageFmt, char* pImageData, int nImageWidth, int nImageHeight);
int GetCount();
protected:
GLuint m_nTextures[MAX_TEXTURES];
GLuint m_nPBOs[2];
int m_nCount;
int m_nCurrentIndex;
bool m_bCreate;
bool m_bInit;
uint32_t m_nPBOIndex_Now;
uint32_t m_nPBOIndex_Next;
};
public:
OpenGLRender();
virtual ~OpenGLRender();
bool Init(eGL_ImageFormat eImageFmt, int nImageWidth, int nImageHeight);
void Uninit();
bool DrawImage(char* pImageData, int nImageWidth, int nImageHeight);
protected:
std::shared_ptr<Texture> m_ptrTexture;
std::shared_ptr<PBOTexture> m_ptrPBOTexture;
bool m_bInit;
eGL_ImageFormat m_eImageFmt;
int m_nImageWidth;
int m_nImageHeight;
};
/*
* OpenGLView为完整的对外OpenGL窗口/视图累
* 使用OpenGLRender
* 使用GLFW进行窗口及事件管理
*/
class OpenGLView
{
public:
OpenGLView();
virtual ~OpenGLView();
bool Init(eGL_ImageFormat eImageFmt, int nImageWidth, int nImageHeight);
void Uninit();
bool GetWndHandle(uint32_t& hWnd);
bool DrawImage(char* pImageData, int nImageWidth, int nImageHeight);
bool GlfwShouldClose();
void UpdateGL();
private:
bool InitGLFW(int nWndWidth, int nWndHeight);
void UninitGLFW();
void OnWindowSize(int nWidth, int nHeight);
static void OnErrorCallback(int error, const char* description);
static void OnWindowSizeCallback(GLFWwindow* pWindow, int nWidth, int nHeight);
private:
//
bool m_bInit;
std::shared_ptr<OpenGLRender> m_ptrOpenGLRender;
//
bool m_bInitGLFW;
GLFWwindow* m_pGLFWWindow;
uint8_t m_nDrawCount;
};
#endif // OpenGLView_H