use CLineReader instead of fgets, also delete program at destruct

This commit is contained in:
Jupeyy 2017-09-14 19:35:31 +02:00
parent b6e4b4b4a6
commit f48e186bfd
2 changed files with 14 additions and 5 deletions

View file

@ -1,5 +1,5 @@
#include "opengl_sl.h"
#include <base/system.h>
#include <engine/shared/linereader.h>
#include <vector>
#include <stdio.h>
#include <string>
@ -7,14 +7,18 @@
bool CGLSL::LoadShader(const char* pFile, int Type) {
if (m_IsLoaded) return true;
IOHANDLE f;
//support read text in system.h/cpp
f = (IOHANDLE)fopen(pFile, "rt");
f = io_open(pFile, IOFLAG_READ);
std::vector<std::string> Lines;
char buff[500];
if (f) {
//support fgets in system.h/cpp
while (fgets(buff, 500, (FILE*)f)) Lines.push_back(buff);
CLineReader LineReader;
LineReader.Init(f);
char* ReadLine = NULL;
while ((ReadLine = LineReader.Get())) {
Lines.push_back(ReadLine);
Lines.back().append("\r\n");
}
io_close(f);
const char** ShaderCode = new const char*[Lines.size()];
@ -73,3 +77,7 @@ GLuint CGLSL::GetShaderID() {
CGLSL::CGLSL(){
m_IsLoaded = false;
}
CGLSL::~CGLSL(){
DeleteShader();
}

View file

@ -11,6 +11,7 @@ public:
GLuint GetShaderID();
CGLSL();
virtual ~CGLSL();
private:
GLuint m_ShaderID;
int m_Type;