u32 installtex(const char *texname, bool clamp) { auto s = IMG_Load(texname); if (!s) { con::out("couldn't load texture %s", texname); return 0; } #if !defined(__WEBGL__) else if (s->format->BitsPerPixel!=24) { con::out("texture must be 24bpp: %s (got %i bpp)", texname, s->format->BitsPerPixel); return 0; } #endif // __WEBGL__ loopi(int(TEX_NUM)) bindedtexture[i] = 0; con::out("loading %s (%ix%i)", texname, s->w, s->h); if (s->w>glmaxtexsize || s->h>glmaxtexsize) sys::fatal("texture dimensions are too large"); const auto ispowerof2 = ispoweroftwo(s->w) && ispoweroftwo(s->h); const auto minf = ispowerof2 ? 'M' : 'n'; const auto mm = ispowerof2 ? 'G' : ' '; const auto fmt = s->format->BitsPerPixel == 24 ? '3' : '4'; const auto wrap = clamp ? 'e' : 'r'; auto id = maketex("TB I% D% B2 % Ws% Wt% Ml m%",fmt,fmt,s->pixels,s->w,s->h,mm,wrap,wrap,minf); SDL_FreeSurface(s); return id; }
int FrameBufferObject::CreateImageObject(unsigned int width, unsigned int height, int depthbuffer_enabled, int stencilbuffer_enabled) { //Create the Image object ImageObject new_object; new_object.width = width; new_object.height = height; new_object.texture_type = NULL; new_object.texture_id = NULL; new_object.depth_id = NULL; new_object.stencil_id = NULL; //First determine if the requested dimensions are power of two if (ispoweroftwo(width) && ispoweroftwo(height)) { new_object.texture_type = GL_TEXTURE_2D; //Power of two enum LogSystem()->ReportMessage("Using GL_TEXTURE_2D"); } else { new_object.texture_type = 0x84F5; //Non power of two enum } glGenTextures(1, &new_object.texture_id); new_object.texture_id; glBindTexture(GL_TEXTURE_RECTANGLE_ARB, new_object.texture_id); new_object.texture_type = GL_TEXTURE_RECTANGLE_ARB; glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);//GL_CLAMP glTexParameterf(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);//GL_CLAMP glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //Create the depth RenderBuffer if requested if (depthbuffer_enabled != 0) { glGenRenderbuffersEXT(1, &new_object.depth_id); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, new_object.depth_id); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, new_object.width, new_object.height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, new_object.depth_id); } //glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); //Push this new image object onto the list image_objects.push_back(new_object); //Return the 'index' for the id of this texture return (int)image_objects.size() - 1; }
int FrameBufferObject::CreateImageObject(unsigned int width, unsigned int height, int depthbuffer_enabled, int stencilbuffer_enabled) { //Create the Image object ImageObject new_object; EH_DECLARE; new_object.width = width; new_object.height = height; new_object.texture_type = NULL; new_object.texture_id = NULL; new_object.depth_id = NULL; new_object.stencil_id = NULL; EH_Log("CreateImageObject %d %d\n", width, height); //First determine if the requested dimensions are power of two if (ispoweroftwo(width) && ispoweroftwo(height)) { new_object.texture_type = GL_TEXTURE_2D; //Power of two enum EH_Log("Using GL_TEXTURE_2D"); } else { new_object.texture_type = 0x84F5; //Non power of two enum } //Create texture glGenTextures(1, &new_object.texture_id); glBindTexture(new_object.texture_type, new_object.texture_id); glTexImage2D(new_object.texture_type, 0, GL_RGBA, new_object.width, new_object.height, 0, GL_RGBA, GL_FLOAT, NULL); //GLenum filterMode = (new_object.texture_type == 0x84F5) ? GL_NEAREST : GL_LINEAR; //GLenum filterMode = GL_NEAREST; GLfloat filterMode = GL_LINEAR; glTexParameterf(new_object.texture_type, GL_TEXTURE_MIN_FILTER, filterMode); glTexParameterf(new_object.texture_type, GL_TEXTURE_MAG_FILTER, filterMode); glTexParameterf(new_object.texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);//GL_CLAMP glTexParameterf(new_object.texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);//GL_CLAMP #ifdef OM_MULTISAMPLE if (1) { glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, framebuffer_id); glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 2, GL_RGBA8, new_object.width, new_object.height); CheckFramebufferStatus(); } #endif //Create the depth RenderBuffer if requested if (depthbuffer_enabled != 0) { glGenRenderbuffersEXT(1, &new_object.depth_id); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, new_object.depth_id); #ifdef OM_MULTISAMPLE if (1) { //samples=2, format=GL_DEPTH_COMPONENT24, width=256, height=256 glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 2, GL_DEPTH_COMPONENT16, new_object.width, new_object.height); CheckFramebufferStatus(); } else #endif glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, new_object.width, new_object.height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer_id); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, new_object.depth_id); //CheckFramebufferStatus(); } //Create the stencil RenderBuffer if requested if (stencilbuffer_enabled != 0) { glGenRenderbuffersEXT(1, &new_object.stencil_id); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, new_object.stencil_id); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_STENCIL_INDEX, new_object.width, new_object.height); } //Push this new image object onto the list image_objects.push_back(new_object); //Return the 'index' for the id of this texture return (int)image_objects.size() - 1; }