mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-17 15:38:11 +08:00
Fix shader compiler
This commit is contained in:
parent
f0a44afb4a
commit
451d3e0c35
@ -3,5 +3,5 @@ out vec4 FragColor;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||||
}
|
}
|
||||||
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GLM/gtc/type_ptr.hpp>
|
#include <GLM/gtc/type_ptr.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
@ -11,8 +14,21 @@ VertexShader::VertexShader(const std::string& source){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VertexShader::compile(const std::string& source) {
|
void VertexShader::compile(const std::string& source) {
|
||||||
const char* sourcePtr = source.c_str();
|
std::string codeStr;
|
||||||
OPENGL_EXTRA_FUNCTIONS->glShaderSource(_shaderId, 1, &sourcePtr, nullptr);
|
std::ifstream file;
|
||||||
|
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
try {
|
||||||
|
file.open(source);
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << file.rdbuf();
|
||||||
|
file.close();
|
||||||
|
codeStr = stream.str();
|
||||||
|
}
|
||||||
|
catch (std::ifstream::failure e) {
|
||||||
|
Logger::error("Failed to read vertex shader file");
|
||||||
|
}
|
||||||
|
const char* code = codeStr.c_str();
|
||||||
|
OPENGL_EXTRA_FUNCTIONS->glShaderSource(_shaderId, 1, &code, nullptr);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glCompileShader(_shaderId);
|
OPENGL_EXTRA_FUNCTIONS->glCompileShader(_shaderId);
|
||||||
int success;
|
int success;
|
||||||
char infoLog[512];
|
char infoLog[512];
|
||||||
@ -29,8 +45,21 @@ FragmentShader::FragmentShader(const std::string& source){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FragmentShader::compile(const std::string& source) {
|
void FragmentShader::compile(const std::string& source) {
|
||||||
const char* sourcePtr = source.c_str();
|
std::string codeStr;
|
||||||
OPENGL_EXTRA_FUNCTIONS->glShaderSource(_shaderId, 1, &sourcePtr, nullptr);
|
std::ifstream file;
|
||||||
|
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
try {
|
||||||
|
file.open(source);
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << file.rdbuf();
|
||||||
|
file.close();
|
||||||
|
codeStr = stream.str();
|
||||||
|
}
|
||||||
|
catch (std::ifstream::failure e) {
|
||||||
|
Logger::error("Failed to read vertex shader file");
|
||||||
|
}
|
||||||
|
const char* code = codeStr.c_str();
|
||||||
|
OPENGL_EXTRA_FUNCTIONS->glShaderSource(_shaderId, 1, &code, nullptr);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glCompileShader(_shaderId);
|
OPENGL_EXTRA_FUNCTIONS->glCompileShader(_shaderId);
|
||||||
int success;
|
int success;
|
||||||
char infoLog[512];
|
char infoLog[512];
|
||||||
@ -47,8 +76,21 @@ GeometryShader::GeometryShader(const std::string& source) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GeometryShader::compile(const std::string& source) {
|
void GeometryShader::compile(const std::string& source) {
|
||||||
const char* sourcePtr = source.c_str();
|
std::string codeStr;
|
||||||
OPENGL_EXTRA_FUNCTIONS->glShaderSource(_shaderId, 1, &sourcePtr, nullptr);
|
std::ifstream file;
|
||||||
|
file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
try {
|
||||||
|
file.open(source);
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << file.rdbuf();
|
||||||
|
file.close();
|
||||||
|
codeStr = stream.str();
|
||||||
|
}
|
||||||
|
catch (std::ifstream::failure e) {
|
||||||
|
Logger::error("Failed to read vertex shader file");
|
||||||
|
}
|
||||||
|
const char* code = codeStr.c_str();
|
||||||
|
OPENGL_EXTRA_FUNCTIONS->glShaderSource(_shaderId, 1, &code, nullptr);
|
||||||
OPENGL_EXTRA_FUNCTIONS->glCompileShader(_shaderId);
|
OPENGL_EXTRA_FUNCTIONS->glCompileShader(_shaderId);
|
||||||
int success;
|
int success;
|
||||||
char infoLog[512];
|
char infoLog[512];
|
||||||
|
|||||||
@ -1 +1,7 @@
|
|||||||
#pragma once
|
#version 330 core
|
||||||
|
layout (location = 0) in vec3 aPos;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user