#include #define GL_GLEXT_PROTOTYPES #include #include #include using namespace std; SDL_GLContext glRenderContext; SDL_Window *mainWindow; string glErrorToString(GLenum e) { switch (e) { case GL_NO_ERROR: return "GL_NO_ERROR"; case GL_INVALID_ENUM: return "GL_INVALID_ENUM"; case GL_INVALID_VALUE: return "GL_INVALID_VALUE"; case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION"; case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION"; case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY"; case GL_STACK_UNDERFLOW: return "GL_STACK_UNDERFLOW"; case GL_STACK_OVERFLOW: return "GL_STACK_OVERFLOW"; default: return "unknown error"; } } int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) { cout << "Unable to initialize SDL: " << SDL_GetError() << endl; return -1; } int resolutionX = 512; int resolutionY = 512; mainWindow = SDL_CreateWindow( "An SDL2 window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, resolutionX, resolutionY, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL ); if(mainWindow==NULL){ std::cout << "Could not create window: " << SDL_GetError() << std::endl; return -1; } //mesa/radeonsi only supports GL3.3 in Core SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); glRenderContext = SDL_GL_CreateContext(mainWindow); int x = 512; int y = 512; GLenum internalformat = GL_RGBA8; int samples = 2; GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureId); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, internalformat, x, y, GL_TRUE); GLuint fboId; glGenFramebuffers(1, &fboId); glBindFramebuffer(GL_READ_FRAMEBUFFER, fboId); glFramebufferTexture(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureId, 0); //when trying to blit any kind of multi sample fbo, this will always cause an GL_INVALID_OPERATION //KHR_debug: "GL_INVALID_OPERATION in glBlitFramebufferEXT(bad src/dst multisample pixel formats)" glBlitFramebuffer(0, 0, 512, 512, 0, 0, 512, 512, GL_COLOR_BUFFER_BIT, GL_NEAREST); GLenum e = glGetError(); if (e != GL_NO_ERROR) { cout << "glGetError = " << glErrorToString(e) << endl; } SDL_GL_DeleteContext(glRenderContext); SDL_DestroyWindow(mainWindow); SDL_Quit(); return 0; }