ported the University CGI demo from WINDOWS + GLUT + GLEW + GLU + OpenGL 4 to LINUX WAYLAND + EGL + GLES 2 with minimal cuts

This commit is contained in:
beno
2025-07-03 01:26:25 +02:00
commit 6c125fb35e
85 changed files with 91688 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
#pragma once
#include <glm/gtc/matrix_transform.hpp>
/*
ON MOBILE, GLES 3.1 WOULD BE REQUIRED (compute shader support)
*/
#include <GL/glew.h>
#include <string>
#include <iostream>
using namespace std;
using namespace glm;
enum SIM_PRECISION {
FINE,
REGULAR,
ROUGH
};
class CRT_Shader {
private:
static bool CRT_FLIP_Y;
string resourceRoot = "C:\\Users\\BoBoBoat\\Desktop\\SCUOLA\\CGI\\GL_STUFF\\GL_STUFF\\SOURCES\\EFFECTS\\CRT_SHADER\\";
const float CRT_PIXEL_LENGTH = 2e-3; //value of 1 gets only red (bad bug)
static const int CRT_PIXEL_SCALE = 1; //they work together
const float CRT_DEPTH = 1e0;
static int CRT_HORIZONTAL_PIXELS;
static int CRT_VERTICAL_PIXELS;
static int CRT_WIDTH;
static int CRT_HEIGHT;
static int PARTICLE_COUNT;
static const int GROUP_COUNT = 1024;
static int PARTICLE_GROUP_COUNT;
static const unsigned int COLOR_CHANNELS = 4;
static SIM_PRECISION resolution;
mat4 orthoMat;
vec3 CS_LTN, CS_RBN, CS_LTF, CS_RBF;
GLuint dt_location;
GLuint compute_prog;
GLuint render_prog;
GLuint render_vao;
GLuint end_position_buffer, start_position_buffer, velocity_buffer, color_buffer, magnets_buffer;
float magx;
float magy;
vec4 attractors[8];
GLuint velocity_tbo, start_position_tbo, end_position_tbo, color_tbo;
CRT_Shader();
vec3 scaleToZOne(vec3 vector);
vec3 crt_emission_angle(int index);
void createRenderShader();
void createComputeShader();
void buffersSetup();
void VAOsSetup();
public:
static void setup(int w, int h, bool flipY, SIM_PRECISION precision) {
CRT_FLIP_Y = flipY;
resolution = precision;
CRT_WIDTH = w;
CRT_HEIGHT = h;
CRT_HORIZONTAL_PIXELS = w / CRT_PIXEL_SCALE;
CRT_VERTICAL_PIXELS = h / CRT_PIXEL_SCALE;
PARTICLE_COUNT = CRT_HORIZONTAL_PIXELS * CRT_VERTICAL_PIXELS;
PARTICLE_GROUP_COUNT = (PARTICLE_COUNT / GROUP_COUNT) + ((PARTICLE_COUNT % GROUP_COUNT) ? 1 : 0);
cout << "HPIX " << CRT_HORIZONTAL_PIXELS << "\n";
cout << "VPIX " << CRT_VERTICAL_PIXELS << "\n";
}
static CRT_Shader& get() {
static CRT_Shader instance;
return instance;
}
void draw(unsigned int ONE_TICK_MS, unsigned int timePassed);
void setMagnet(int index, vec4 positionAndMass);
float getLeftBound();
float getRightBound();
float getBottomBound();
float getTopBound();
/*Copies H_PIXELS * V_PIXELS from FrameBuffer to internal VAO */
void loadColorFromFramebuffer(GLuint FBO);
};

View File

@@ -0,0 +1,18 @@
#ifndef PSEUDOCONTEXT
#define PSEUDOCONTEXT
#include <vector>
class PseudoContext {
protected:
//viewport
int width, height;
int top, left;
public:
PseudoContext(int left, int top, int width, int height);
virtual void draw() = 0;
std::vector<int> getBounds();
};
#endif

View File

@@ -0,0 +1,22 @@
#ifndef REELMANAGER_H
#define REELMANAGER_H
/*
#include <GL/glew.h>
*/
#include <GLES2/gl2.h>
#include <vector>
class ReelManager {
private:
unsigned int TEXTURE_NUM;
unsigned int currentIndex = 0;
GLuint* textures;
GLuint FBO;
public:
ReelManager(unsigned int textureNumber, unsigned int width, unsigned int height);
GLuint getFBO();
void clearTexture();
void nextTexture();
std::vector<GLuint> getTextures();
};
#endif

View File

@@ -0,0 +1,26 @@
#ifndef SCENE_H
#define SCENE_H
/*
#include <GL/glew.h>
*/
#include <GLES2/gl2.h>
#include "PseudoContext.h"
class Scene : public PseudoContext{
private:
//aux
GLuint FBO;
GLuint depthRBO;
GLuint outputTexture; /*FBO for communications with other bois*/
public:
Scene(int left, int top, int width, int height);
void setOutTexture(GLuint outTexture);
void draw();
void keyPress(unsigned char key, int x, int y);
GLuint getFrameBuffer();
};
#endif

View File

@@ -0,0 +1,31 @@
#ifndef SCREEN_H
#define SCREEN_H
#include "../SCENE/Model3D.hpp"
#include "PseudoContext.h"
class Screen: public PseudoContext {
private:
//aux
GLuint inputTexture = 0;
GLuint quadVAO, vertVBO;
GLuint program2;
GLuint shaderTexId;
GLfloat quadVerts[18] = {
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f
};
public:
Screen(int left, int top, int width, int height);
void setInputTexture(GLuint inputTexture);
void draw();
};
#endif

View File

@@ -0,0 +1,38 @@
#ifndef TEXMERGER_H
#define TEXMERGER_H
/*
#include <GL/glew.h>
*/
#include <GLES2/gl2.h>
#include <vector>
class TexMerger {
private:
GLuint program;
GLuint* mergeBuffers;
std::vector<bool> usageMap;
GLuint FBO;
GLuint quadVAO, vertVBO;
GLuint shaderTex1Id, shaderTex2Id;
int bufCount;
GLuint reserveBuffer();
bool isBuffer(GLuint number);
void freeBuffer(GLuint number);
GLfloat quadVerts[18] = {
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f
};
public:
TexMerger(GLuint texCount, unsigned int texWidth, unsigned int texHeight);
GLuint merge(std::vector<GLuint> inTextures, int startIndex, int endIndex);
};
#endif // !TEXMERGER_H