mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 09:34:19 +00:00
use CLineReader instead of fgets, also delete program at destruct
This commit is contained in:
parent
b6e4b4b4a6
commit
f48e186bfd
|
@ -1,5 +1,5 @@
|
||||||
#include "opengl_sl.h"
|
#include "opengl_sl.h"
|
||||||
#include <base/system.h>
|
#include <engine/shared/linereader.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -7,14 +7,18 @@
|
||||||
bool CGLSL::LoadShader(const char* pFile, int Type) {
|
bool CGLSL::LoadShader(const char* pFile, int Type) {
|
||||||
if (m_IsLoaded) return true;
|
if (m_IsLoaded) return true;
|
||||||
IOHANDLE f;
|
IOHANDLE f;
|
||||||
//support read text in system.h/cpp
|
f = io_open(pFile, IOFLAG_READ);
|
||||||
f = (IOHANDLE)fopen(pFile, "rt");
|
|
||||||
|
|
||||||
std::vector<std::string> Lines;
|
std::vector<std::string> Lines;
|
||||||
char buff[500];
|
char buff[500];
|
||||||
if (f) {
|
if (f) {
|
||||||
//support fgets in system.h/cpp
|
CLineReader LineReader;
|
||||||
while (fgets(buff, 500, (FILE*)f)) Lines.push_back(buff);
|
LineReader.Init(f);
|
||||||
|
char* ReadLine = NULL;
|
||||||
|
while ((ReadLine = LineReader.Get())) {
|
||||||
|
Lines.push_back(ReadLine);
|
||||||
|
Lines.back().append("\r\n");
|
||||||
|
}
|
||||||
io_close(f);
|
io_close(f);
|
||||||
|
|
||||||
const char** ShaderCode = new const char*[Lines.size()];
|
const char** ShaderCode = new const char*[Lines.size()];
|
||||||
|
@ -73,3 +77,7 @@ GLuint CGLSL::GetShaderID() {
|
||||||
CGLSL::CGLSL(){
|
CGLSL::CGLSL(){
|
||||||
m_IsLoaded = false;
|
m_IsLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGLSL::~CGLSL(){
|
||||||
|
DeleteShader();
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ public:
|
||||||
GLuint GetShaderID();
|
GLuint GetShaderID();
|
||||||
|
|
||||||
CGLSL();
|
CGLSL();
|
||||||
|
virtual ~CGLSL();
|
||||||
private:
|
private:
|
||||||
GLuint m_ShaderID;
|
GLuint m_ShaderID;
|
||||||
int m_Type;
|
int m_Type;
|
||||||
|
|
Loading…
Reference in a new issue