create seperate shader

This commit is contained in:
Jonas_sorgenfrei@yahoo.de
2022-04-04 14:34:41 +02:00
parent 8fe4397758
commit 36e0cc9ec3
4 changed files with 154 additions and 55 deletions

View File

@@ -1,49 +0,0 @@
#include <learnopengl/shader_m.h>
class ComputeShader : public Shader
{
public:
ComputeShader(const char* computePath)
{
// 1. retrieve the vertex/fragment source code from filePath
std::string computeCode;
std::ifstream cShaderFile;
// ensure ifstream objects can throw exceptions:
cShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
// open files
cShaderFile.open(computePath);
std::stringstream cShaderStream;
// read file's buffer contents into streams
cShaderStream << cShaderFile.rdbuf();
// close file handlers
cShaderFile.close();
// convert stream into string
computeCode = cShaderStream.str();
}
catch (std::ifstream::failure& e)
{
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ: " << e.what() << std::endl;
}
const char* cShaderCode = computeCode.c_str();
// 2. compile shaders
unsigned int compute;
// compute shader
compute = glCreateShader(GL_COMPUTE_SHADER);
glShaderSource(compute, 1, &cShaderCode, NULL);
glCompileShader(compute);
checkCompileErrors(compute, "COMPUTE");
// shader Program
ID = glCreateProgram();
glAttachShader(ID, compute);
glLinkProgram(ID);
checkCompileErrors(ID, "PROGRAM");
// delete the shaders as they're linked into our program now and no longer necessery
glDeleteShader(compute);
}
};

View File

@@ -5,13 +5,13 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <learnopengl/shader_m.h>
#include <learnopengl/shader_c.h>
#include <learnopengl/camera.h>
#include <iostream>
#include "computeShader.h"
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void renderQuad();