change shaderSercve so it can take both of char* and std::filesystem::path
This commit is contained in:
		@@ -1,12 +1,9 @@
 | 
			
		||||
#include "decoder.h"
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
 | 
			
		||||
void InitDecoder(const char* filepath, DecoderParam& param){
 | 
			
		||||
    if(!std::filesystem::exists(filepath)) return;
 | 
			
		||||
    AVFormatContext* fmtCtx = nullptr;
 | 
			
		||||
    AVCodecContext* codecFmt = nullptr;
 | 
			
		||||
    auto ret = avformat_open_input(&fmtCtx, filepath, NULL, NULL);
 | 
			
		||||
    
 | 
			
		||||
    avformat_find_stream_info(fmtCtx, nullptr);
 | 
			
		||||
 | 
			
		||||
    for(int i=0; i<fmtCtx->nb_streams; i++){
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,30 @@
 | 
			
		||||
#include "shaderService.h"
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
ShaderService::ShaderService(const char* vSource, const char* fSource){
 | 
			
		||||
    InitShader(vSource, fSource);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShaderService::InitShader(const char* vSource, const char* fSource){
 | 
			
		||||
    unsigned int frag, vertex;
 | 
			
		||||
    frag = glCreateShader(GL_FRAGMENT_SHADER);
 | 
			
		||||
    vertex = glCreateShader(GL_VERTEX_SHADER);
 | 
			
		||||
    glShaderSource(vertex, 1, &vSource, nullptr);
 | 
			
		||||
    glShaderSource(frag, 1, &fSource, nullptr);
 | 
			
		||||
    glCompileShader(vertex);
 | 
			
		||||
    glCompileShader(frag);
 | 
			
		||||
    if(const auto res = (CheckShader(vertex) && CheckShader(frag));!res){
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    programId = glCreateProgram();
 | 
			
		||||
    glAttachShader(programId, vertex);
 | 
			
		||||
    glAttachShader(programId, frag);
 | 
			
		||||
    glLinkProgram(programId);
 | 
			
		||||
    CheckShader(programId, true);
 | 
			
		||||
 | 
			
		||||
    glDeleteShader(vertex);
 | 
			
		||||
    glDeleteShader(frag);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ShaderService::ShaderService(const std::filesystem::path &vertexShaderPath,
 | 
			
		||||
                             const std::filesystem::path &fragShaderPath) {
 | 
			
		||||
@@ -27,25 +51,7 @@ ShaderService::ShaderService(const std::filesystem::path &vertexShaderPath,
 | 
			
		||||
 | 
			
		||||
    const char* vSource = vertexSource.c_str();
 | 
			
		||||
    const char* fSource = fragmentSource.c_str();
 | 
			
		||||
 | 
			
		||||
    unsigned int frag, vertex;
 | 
			
		||||
    frag = glCreateShader(GL_FRAGMENT_SHADER);
 | 
			
		||||
    vertex = glCreateShader(GL_VERTEX_SHADER);
 | 
			
		||||
    glShaderSource(vertex, 1, &vSource, nullptr);
 | 
			
		||||
    glShaderSource(frag, 1, &fSource, nullptr);
 | 
			
		||||
    glCompileShader(vertex);
 | 
			
		||||
    glCompileShader(frag);
 | 
			
		||||
    if(const auto res = (CheckShader(vertex) && CheckShader(frag));!res){
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    programId = glCreateProgram();
 | 
			
		||||
    glAttachShader(programId, vertex);
 | 
			
		||||
    glAttachShader(programId, frag);
 | 
			
		||||
    glLinkProgram(programId);
 | 
			
		||||
    CheckShader(programId, true);
 | 
			
		||||
 | 
			
		||||
    glDeleteShader(vertex);
 | 
			
		||||
    glDeleteShader(frag);
 | 
			
		||||
    InitShader(vSource, fSource);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ShaderService::Use() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user