Radeon Pro Solid State Graphics Api User Manual - page 16
Rev. 1.01
16
8 AMD Code Sample for OpenGL
// Create file:
FILE_NAME is the file path.
GLfilehandleAMD hSsgFileFile = glCreateFileAMD(
FILE_NAME,
GL_READ_ONLY);
if (
hSsgFileFile
!=
NULL
)
{
s
td::cout
<<
"Error: Unable to open the file."
<< std::endl;
return
;
}
// Get the file-size information.
GLuint64 fileSize = 0;
glGetFileParameteri64vAMD(hSsgFileFile, GL_FILE_SIZE_AMD, &fileSize);
if (glGetError() != GL_NO_ERROR)
{
s
td::cout
<<
"Error: Unable to retrieve file size."
<< std::endl;
return
;
}
// Get the file-system information.
GLuint64 sectorSize = 0;
glGetFileParameteri64vAMD(hSsgFileFile, GL_FILE_BLOCK_SIZE_AMD, §orSize);
if (sectorSize ==
0
) {
s
td::cout
<<
"Error: Unable to retrieve block size."
<< std::endl;
return
;
}
// Create buffer.
GLuint oglBuffer;
glCreateBuffers(1, &
oglBuffer
);
glNamedBufferStorage(
oglBuffer
, SIZE_TO_READ, nullptr,
GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT);
if (glGetError() != GL_NO_ERROR)
{
s
td::cout
<<
"Error: Failed to allocate openGL buffer."
<< std::endl;
return
;
}
// Read information from the file; BUFF_OFFSET, SIZE_TO_READ and FILE_OFFSET must
// align with the sector size.
glReadFileAMD(oglBuffer, hSsgFileFile, BUFF_OFFSET, FILE_OFFSET, SIZE_TO_READ, nullptr);
if (glGetError() != GL_NO_ERROR)
{
s
td::cout
<<
"Error: Failed to read data from the file."
<< std::endl;
return
;
}
// Release the file when you’re done with it.
glReleaseFileAMD(hSsgFileFile);
if (glGetError() != GL_NO_ERROR) {
s
td::cout
<<
"Warning: Unable to release file."
<< std::endl;
}
// Release the buffer when you’re done with it.
glDeleteBuffers(1, oglBuffer);
if (glGetError() != GL_NO_ERROR) {
s
td::cout
<<
"Warning: Unable to release buffer."
<< std::endl;
}