1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
#include <iostream>
#include <SFML/Graphics.hpp>
#include <GL/glext.h>
#include <windows.h>
#define glCreateShader(arg1) (* glCreateShaderProc)(arg1)
#define glShaderSource(arg1, arg2, arg3, arg4) (* glCreateSourceProc)(arg1, arg2, arg3, arg4)
#define glCompileShader(arg1) (* glCompileShaderProc)(arg1)
#define glGetShaderiv(arg1, arg2, arg3) (* glGetShaderivProc)(arg1, arg2, arg3)
#define glDeleteShader(arg1) (* glDeleteShaderProc)(arg1)
#define glCreateProgram() (* glCreateProgramProc)()
#define glDeleteProgram(arg1) (* glDeleteProgramProc)(arg1)
#define glAttachShader(arg1, arg2) (* glAttachShaderProc)(arg1, arg2)
#define glLinkProgram(arg1) (* glLinkProgramProc)(arg1)
#define glGetProgramiv(arg1, arg2, arg3) (* glGetProgramivProc)(arg1, arg2, arg3)
#define glGetActiveUniformBlockiv(arg1, arg2, arg3, arg4) (* glGetActiveUniformBlockivProc)(arg1, arg2, arg3, arg4)
#define glGetActiveUniformBlockName(arg1, arg2, arg3, arg4, arg5) (* glGetActiveUniformBlockNameProc)(arg1, arg2, arg3, arg4, arg5)
#define glGetActiveUniform(arg1, arg2, arg3, arg4, arg5, arg6, arg7) (* glGetActiveUniformProc)(arg1, arg2, arg3, arg4, arg5, arg6, arg7)
int main(void)
{
{
// creation du context opengl
sf::RenderWindow app;
app.Create(sf::VideoMode(800, 600, 32), "SFML window");
// recuperation des procedures opengl
PFNGLCREATESHADERPROC glCreateShaderProc = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader");
if (glCreateShaderProc == NULL) {std::cout << "La procedure opengl glCreateShader n'existe pas.\n"; return -1;}
PFNGLSHADERSOURCEPROC glCreateSourceProc = (PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource");
if (glCreateSourceProc == NULL){std::cout << "La procedure opengl glShaderSource n'existe pas.\n"; return -1;}
PFNGLCOMPILESHADERPROC glCompileShaderProc = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader");
if (glCompileShaderProc == NULL){std::cout << "La procedure opengl glCompileShader n'existe pas.\n"; return -1;}
PFNGLGETSHADERIVPROC glGetShaderivProc = (PFNGLGETSHADERIVPROC)wglGetProcAddress("glGetShaderiv");
if (glGetShaderivProc == NULL){std::cout << "La procedure opengl glGetShaderiv n'existe pas.\n"; return -1;}
PFNGLDELETESHADERPROC glDeleteShaderProc = (PFNGLDELETESHADERPROC)wglGetProcAddress("glDeleteShader");
if (glDeleteShaderProc == NULL){std::cout << "La procedure opengl glDeleteShader n'existe pas.\n"; return -1;}
PFNGLCREATEPROGRAMPROC glCreateProgramProc = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");
if (glCreateProgramProc == NULL){std::cout << "La procedure opengl glCreateProgram n'existe pas.\n"; return -1;}
PFNGLDELETEPROGRAMPROC glDeleteProgramProc = (PFNGLDELETEPROGRAMPROC)wglGetProcAddress("glDeleteProgram");
if (glDeleteProgramProc == NULL){std::cout << "La procedure opengl glDeleteProgram n'existe pas.\n"; return -1;}
PFNGLATTACHSHADERPROC glAttachShaderProc = (PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader");
if (glAttachShaderProc == NULL){std::cout << "La procedure opengl glAttachShader n'existe pas.\n"; return -1;}
PFNGLLINKPROGRAMPROC glLinkProgramProc = (PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram");
if (glLinkProgramProc == NULL){std::cout << "La procedure opengl glLinkProgram n'existe pas.\n"; return -1;}
PFNGLGETPROGRAMIVPROC glGetProgramivProc = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv");
if (glGetProgramivProc == NULL){std::cout << "La procedure opengl glGetProgramiv n'existe pas.\n"; return -1;}
PFNGLGETACTIVEUNIFORMBLOCKIVPROC glGetActiveUniformBlockivProc = (PFNGLGETACTIVEUNIFORMBLOCKIVPROC)wglGetProcAddress("glGetActiveUniformBlockiv");
if (glGetActiveUniformBlockivProc == NULL){std::cout << "La procedure opengl glGetActiveUniformBlockiv n'existe pas.\n"; return -1;}
PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC glGetActiveUniformBlockNameProc = (PFNGLGETACTIVEUNIFORMBLOCKNAMEPROC)wglGetProcAddress("glGetActiveUniformBlockName");
if (glGetActiveUniformBlockNameProc == NULL){std::cout << "La procedure opengl glGetActiveUniformBlockName n'existe pas.\n"; return -1;}
PFNGLGETACTIVEUNIFORMPROC glGetActiveUniformProc = (PFNGLGETACTIVEUNIFORMPROC)wglGetProcAddress("glGetActiveUniform");
if (glGetActiveUniformProc == NULL){std::cout << "La procedure opengl glGetActiveUniform n'existe pas.\n"; return -1;}
// affichage de la configuration
std::cout << "VERSION : " << glGetString(GL_VERSION) << "\n";
std::cout << "SHADER VERSION : " << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
std::cout << "VENDOR : " << glGetString(GL_VENDOR) << "\n";
std::cout << "RENDERER : " << glGetString(GL_RENDERER) << "\n";
// creation du vertex shader
const char * vsSource =
"#version 150 \n"
"layout(shared) uniform MyBlock \n"
"{ \n"
" vec4 v1; \n"
" vec4 v2; \n"
"}; \n"
"in vec4 position; \n"
"void main() \n"
"{ \n"
" gl_Position = position; \n"
"} \n";
GLuint vShad = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vShad, 1, & vsSource, NULL);
glCompileShader(vShad);
GLint vsCompStat;
glGetShaderiv(vShad, GL_COMPILE_STATUS, & vsCompStat);
if (vsCompStat == GL_FALSE){std::cout << "Erreur de compilation dans le vertex shader\n"; return -1;}
// creation du fragment shader
const char * fsSource =
"#version 150 \n"
"out vec4 output; \n"
"void main() \n"
"{ \n"
" output = vec4(1.0, 1.0, 1.0, 1.0); \n"
"} \n";
GLuint fShad = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fShad, 1, & fsSource, NULL);
glCompileShader(fShad);
GLint fsCompStat;
glGetShaderiv(fShad, GL_COMPILE_STATUS, & fsCompStat);
if (fsCompStat == GL_FALSE){std::cout << "Erreur de compilation dans le fragment shader\n"; return -1;}
// creation du program
GLuint myProgram = glCreateProgram();
glAttachShader(myProgram, vShad);
glAttachShader(myProgram, fShad);
glLinkProgram(myProgram);
GLint linkStat;
glGetProgramiv(myProgram, GL_LINK_STATUS, & linkStat);
if (linkStat == GL_FALSE){std::cout << "Erreur de link dans myProgram\n"; return -1;}
// VOICI LE CODE INTERRESSANT
// recherche des uniform blocks actifs
GLint nbBlocks;
glGetProgramiv(myProgram, GL_ACTIVE_UNIFORM_BLOCKS, & nbBlocks);
std::cout << nbBlocks << " uniform block(s) :\n";
for (GLint i = 0 ; i < nbBlocks ; ++i)
{
GLint lengthName;
glGetActiveUniformBlockiv(myProgram, i, GL_UNIFORM_BLOCK_NAME_LENGTH, & lengthName);
GLchar * name = new GLchar[lengthName];
glGetActiveUniformBlockName(myProgram, i, lengthName, NULL, name);
std::cout << "\t" << name << "\n";
delete[] name;
}
// recherche des uniforms actifs
GLint nbUniforms;
glGetProgramiv(myProgram, GL_ACTIVE_UNIFORMS, & nbUniforms);
std::cout << nbUniforms << " uniform(s) :\n";
GLint sizeUniformName;
glGetProgramiv(myProgram, GL_ACTIVE_UNIFORM_MAX_LENGTH, & sizeUniformName);
GLchar * name = new GLchar[sizeUniformName];
for (GLint i = 0 ; i < nbUniforms ; ++i)
{
GLint size;
GLenum type;
glGetActiveUniform(myProgram, i, sizeUniformName, NULL, & size, & type, name);
std::cout << "\t" << name << "\n";
}
delete[] name;
// destruction des donnees opengl
glDeleteShader(vShad);
glDeleteShader(fShad);
glDeleteProgram(myProgram);
// destruction du context opengl
app.Close();
}
return 0;
} |
Partager