Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 831 vs 832 for /trunk/Source Code/Platform/Video/OpenGL/Shaders/glShaderProgram.cpp

Diff revisions: vs.
  @@ -120,7 +120,7 @@
120 120 GLint binaryLength = 0;
121 121 glGetProgramiv(_shaderProgramID, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
122 122 // allocate a big enough buffer to hold it
123 - void* binary = (void*)malloc(binaryLength);
123 + char* binary = MemoryManager_NEW char[binaryLength];
124 124 DIVIDE_ASSERT(binary != NULL,
125 125 "glShaderProgram error: could not allocate memory "
126 126 "for the program binary!");
  @@ -129,21 +129,13 @@
129 129 if (_binaryFormat != GL_NONE) {
130 130 // dump the buffer to file
131 131 stringImpl outFileName(Paths::Shaders::g_CacheLocationBin + getName() + ".bin");
132 - FILE* outFile = fopen(outFileName.c_str(), "wb");
133 - if (outFile != NULL) {
134 - fwrite(binary, binaryLength, 1, outFile);
135 - fclose(outFile);
136 - }
132 + writeFile(outFileName, binary, (size_t)binaryLength, FileType::BINARY);
137 133 // dump the format to a separate file (highly non-optimised. Should dump formats to a database instead)
138 134 outFileName += ".fmt";
139 - outFile = fopen(outFileName.c_str(), "wb");
140 - if (outFile != NULL) {
141 - fwrite((void*)&_binaryFormat, sizeof(GLenum), 1, outFile);
142 - fclose(outFile);
143 - }
144 - }
135 + writeFile(outFileName, to_stringImpl(to_uint(_binaryFormat)).c_str(), FileType::BINARY);
136 + }
145 137 // delete our local code buffer
146 - free(binary);
138 + MemoryManager::DELETE(binary);
147 139 }
148 140 // clear validation queue flag
149 141 _validationQueued = false;
  @@ -324,36 +316,20 @@
324 316 assert(_shaderProgramIDTemp == 0);
325 317 stringImpl fileName(Paths::Shaders::g_CacheLocationBin + _resourceName + ".bin");
326 318 // Load the program's binary format from file
327 - FILE* inFile = fopen((fileName + ".fmt").c_str(), "wb");
328 - if (inFile) {
329 - fread(&_binaryFormat, sizeof(GLenum), 1, inFile);
330 - fclose(inFile);
331 - // If we loaded the binary format successfully, load the binary
332 - inFile = fopen(fileName.c_str(), "rb");
319 + vectorImpl<Byte> data;
320 + bool fmtExists = readFile(fileName + ".fmt", data, FileType::BINARY);
321 + if (fmtExists) {
322 + _binaryFormat = *((GLenum const *)&data[0]);
333 323 }
334 - else {
335 - // If the binary format load failed, we don't need to load the
336 - // binary code as it's useless without a proper format
337 - inFile = nullptr;
338 - }
339 - if (inFile && _binaryFormat != GL_ZERO/* && _binaryFormat != GL_NONE*/) {
340 - // Jump to the end of the file
341 - fseek(inFile, 0, SEEK_END);
342 - // And get the file's content size
343 - GLint binaryLength = (GLint)ftell(inFile);
344 - // Allocate a sufficiently large local buffer to hold the contents
345 - void* binary = (void*)malloc(binaryLength);
346 - // Jump back to the start of the file
347 - fseek(inFile, 0, SEEK_SET);
348 - // Read the contents from the file and save them locally
349 - fread(binary, binaryLength, 1, inFile);
350 - // Allocate a new handle
324 +
325 + if (fmtExists && _binaryFormat != GL_ZERO/* && _binaryFormat != GL_NONE*/) {
326 + data.clear();
327 + readFile(fileName, data, FileType::BINARY);
328 + // Allocate a new handle
351 329 _shaderProgramIDTemp = glCreateProgram();
352 330 // glCreateProgramPipelines(1, &_shaderProgramIDTemp);
353 331 // Load binary code on the GPU
354 - glProgramBinary(_shaderProgramIDTemp, _binaryFormat, binary, binaryLength);
355 - // Delete the local binary code buffer
356 - free(binary);
332 + glProgramBinary(_shaderProgramIDTemp, _binaryFormat, data.data(), (GLint)data.size());
357 333 // Check if the program linked successfully on load
358 334 GLint success = 0;
359 335 glGetProgramiv(_shaderProgramIDTemp, GL_LINK_STATUS, &success);
  @@ -363,8 +339,6 @@
363 339 _loadedFromBinary = _linked = true;
364 340 }
365 341 }
366 - // Close the file
367 - fclose(inFile);
368 342 }
369 343 }
370 344