init
This commit is contained in:
		
							
								
								
									
										25
									
								
								include/decoder.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								include/decoder.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
#ifndef DECODER_H
 | 
			
		||||
#define DECODER_H
 | 
			
		||||
extern "C"{
 | 
			
		||||
    #include "libavcodec/avcodec.h"
 | 
			
		||||
    #include "libavformat/avformat.h"
 | 
			
		||||
    #include "libavutil/imgutils.h"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct DecoderParam{
 | 
			
		||||
    AVFormatContext* fmtCtx;
 | 
			
		||||
    AVCodecContext* codecCtx;
 | 
			
		||||
    int width;
 | 
			
		||||
    int height;
 | 
			
		||||
    int videoStreamIndex;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern "C"{
 | 
			
		||||
    #include "libavcodec/avcodec.h"
 | 
			
		||||
    #include "libavformat/avformat.h"
 | 
			
		||||
    #include "libavutil/imgutils.h"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void InitDecoder(const char* filepath, DecoderParam& param);
 | 
			
		||||
AVFrame* RequestFrame(DecoderParam& param);
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										56
									
								
								include/shaderService.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								include/shaderService.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by jie on 2023/10/11.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#ifndef LEARNOPENGL_SHADERHELPER_H
 | 
			
		||||
#define LEARNOPENGL_SHADERHELPER_H
 | 
			
		||||
 | 
			
		||||
#include "glad/glad.h"
 | 
			
		||||
#include <filesystem>
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
#include <glm/glm.hpp>
 | 
			
		||||
 | 
			
		||||
class ShaderService
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    unsigned int programId;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    ShaderService(const std::filesystem::path &vertexShaderPath, const std::filesystem::path &fragShaderPath);
 | 
			
		||||
    bool CheckShader(unsigned int shaderIndex, bool isProgram = false);
 | 
			
		||||
    void Use();
 | 
			
		||||
    inline unsigned int GetId() { return this->programId; }
 | 
			
		||||
    template <typename T>
 | 
			
		||||
        requires std::is_same_v<T, bool> || std::is_same_v<T, int> || std::is_same_v<T, float> ||
 | 
			
		||||
                 std::is_same_v<T, glm::mat4> || std::is_same_v<T, glm::vec3>
 | 
			
		||||
    void SetUniform(std::string_view name, T value);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
    requires std::is_same_v<T, bool> || std::is_same_v<T, int> || std::is_same_v<T, float> ||
 | 
			
		||||
             std::is_same_v<T, glm::mat4> || std::is_same_v<T, glm::vec3>
 | 
			
		||||
void ShaderService::SetUniform(std::string_view name, T value)
 | 
			
		||||
{
 | 
			
		||||
    if constexpr (std::is_same_v<T, bool>)
 | 
			
		||||
    {
 | 
			
		||||
        glUniform1i(glGetUniformLocation(programId, name.data()), (int)value);
 | 
			
		||||
    }
 | 
			
		||||
    else if constexpr (std::is_same_v<T, int>)
 | 
			
		||||
    {
 | 
			
		||||
        glUniform1i(glGetUniformLocation(programId, name.data()), value);
 | 
			
		||||
    }
 | 
			
		||||
    else if constexpr (std::is_same_v<T, float>)
 | 
			
		||||
    {
 | 
			
		||||
        glUniform1f(glGetUniformLocation(programId, name.data()), value);
 | 
			
		||||
    }
 | 
			
		||||
    else if constexpr (std::is_same_v<T, glm::mat4>)
 | 
			
		||||
    {
 | 
			
		||||
        const auto index = glGetUniformLocation(this->programId, name.data());
 | 
			
		||||
        glUniformMatrix4fv(index, 1, GL_FALSE, &value[0][0]);
 | 
			
		||||
    }
 | 
			
		||||
    else if constexpr (std::is_same_v<T, glm::vec3>){
 | 
			
		||||
        glUniform3fv(glGetUniformLocation(programId, name.data()), 1, &value[0]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // LEARNOPENGL_SHADERHELPER_H
 | 
			
		||||
		Reference in New Issue
	
	Block a user