2,新增“Apps”; 3,新增“Common”; 4,新增“FileList”; 5,新增“MediaX”; 6,新增“OpenSource”; 7,新增“Samples”; 8,新增“SoftwareBusinessLines”.
147 lines
3.2 KiB
C++
147 lines
3.2 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <thread>
|
|
#include <chrono>
|
|
|
|
#include <mmstream.h>
|
|
#pragma comment(lib, "WinMM")
|
|
|
|
#include <QWindow>
|
|
#include <QDebug>
|
|
|
|
#include "OpenGLView/OpenGLView.h"
|
|
|
|
#define g_FrameW 800//3840//7680
|
|
#define g_FrameH 600//2160//4320
|
|
|
|
static void error_callback(int error, const char* description)
|
|
{
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget* parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
const int pixel_w = g_FrameW;
|
|
const int pixel_h = g_FrameH;
|
|
|
|
GLFWwindow* window = nullptr;
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
/*
|
|
* 01、初始化
|
|
*/
|
|
if (!glfwInit())
|
|
{
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
/*
|
|
* 02、设置属性(必须在创建窗口前)
|
|
*/
|
|
//限制了OpenGL为3.3版本导致一些新特性无法使用
|
|
//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
|
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); //不可改变大小
|
|
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); //不可改变大小
|
|
//glfwWindowHint(GLFW_DECORATED, GL_FALSE); //没有边框和标题栏
|
|
|
|
/*
|
|
* 创建窗口
|
|
*/
|
|
window = glfwCreateWindow(pixel_w, pixel_h, "OpenGL Player", nullptr, nullptr);
|
|
|
|
if (!window)
|
|
{
|
|
glfwTerminate();
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
/*
|
|
HWND hWnd = glfwGetWin32Window(window);
|
|
//QWindow* pWindow = QWindow::fromWinId((WId)hWnd);
|
|
*/
|
|
|
|
glfwMakeContextCurrent(window);
|
|
glfwSwapInterval(1);
|
|
|
|
uint8_t* pData = new uint8_t[pixel_w * pixel_h * 4 * 2 + 1];
|
|
|
|
for (int i = 0; i < pixel_w * pixel_h * 4 * 2; i++)
|
|
{
|
|
pData[i] = i % 255;
|
|
}
|
|
|
|
//OpenGLRender::Texture varTexture;
|
|
//OpenGLRender::PBOTexture varTexture;
|
|
OpenGLView varOpenGLView;
|
|
varOpenGLView.Init(eGL_ImageFormat_RGBA, pixel_w, pixel_h);
|
|
|
|
uint64_t szCounter[100];
|
|
memset(szCounter, 0, sizeof(szCounter) );
|
|
|
|
int nIndex = 0;
|
|
|
|
int nCounter = 0;
|
|
|
|
::timeBeginPeriod(1);
|
|
|
|
while (!glfwWindowShouldClose(window))
|
|
{
|
|
nIndex += pixel_w * 4;
|
|
|
|
if (nIndex >= pixel_w * pixel_h * 4)
|
|
{
|
|
nIndex = 0;
|
|
}
|
|
|
|
varOpenGLView.DrawImage(eGL_ImageFormat_RGBA, reinterpret_cast<char*>(&pData[nIndex]), pixel_w, pixel_h);
|
|
|
|
// swap front and back buffer
|
|
glfwSwapBuffers(window);
|
|
|
|
// poll for and process events
|
|
glfwPollEvents();
|
|
|
|
memcpy(&szCounter[0], &szCounter[1], 99*sizeof(uint64_t) );
|
|
|
|
szCounter[99] = std::chrono::high_resolution_clock::now().time_since_epoch().count();
|
|
|
|
nCounter++;
|
|
|
|
if(nCounter >= 400)
|
|
{
|
|
nCounter = 0;
|
|
|
|
double dSpan = double(szCounter[99] - szCounter[0]);
|
|
|
|
double dFPS = 100.0 / (dSpan/1000000000.0);
|
|
|
|
qDebug("dSpan : %f, fps: %f", dSpan, dFPS);
|
|
int jj = 0;
|
|
}
|
|
|
|
std::this_thread::sleep_for(std::chrono::microseconds(10) ); // 30FPS
|
|
}
|
|
|
|
::timeEndPeriod(0);
|
|
|
|
delete [] pData;
|
|
pData = nullptr;
|
|
|
|
glfwTerminate();
|
|
//exit(EXIT_SUCCESS);
|
|
|
|
/////////////////////////////////////////////////
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|