void blit_texture(const texture& tex, int x, int y, int w, int h, GLfloat rotate, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) { if(!tex.valid()) { return; } const int w_odd = w % 2; const int h_odd = h % 2; w /= 2; h /= 2; glPushMatrix(); tex.set_as_current_texture(); glTranslatef(x+abs(w),y+abs(h),0.0); glRotatef(rotate,0.0,0.0,1.0); glBegin(GL_QUADS); graphics::texture::set_coord(x1,y1); glVertex3i(-w,-h,0); graphics::texture::set_coord(x1,y2); glVertex3i(-w,h+h_odd,0); graphics::texture::set_coord(x2,y2); glVertex3i(w+w_odd,h+h_odd,0); graphics::texture::set_coord(x2,y1); glVertex3i(w+w_odd,-h,0); glEnd(); glPopMatrix(); }
void blit_texture(const texture& tex, int x, int y, GLfloat rotate) { if(!tex.valid()) { return; } int h = tex.height(); int w = tex.width(); const int w_odd = w % 2; const int h_odd = h % 2; h /= 2; w /= 2; glPushMatrix(); glTranslatef(x+w,y+h,0.0); glRotatef(rotate,0.0,0.0,1.0); tex.set_as_current_texture(); glBegin(GL_QUADS); graphics::texture::set_coord(0.0,0.0); glVertex3i(-w,-h,0); graphics::texture::set_coord(0.0,1.0); glVertex3i(-w,h+h_odd,0); graphics::texture::set_coord(1.0,1.0); glVertex3i(w+w_odd,h+h_odd,0); graphics::texture::set_coord(1.0,0.0); glVertex3i(w+w_odd,-h,0); glEnd(); glPopMatrix(); }
template<> void uniform<texture>::assign(const texture &value) { if (value.bindless()) { glUniformHandleui64ARB(id, value.handle()); } else { glUniform1i(id, value.tmu()); } }
void queue_blit_texture(const texture& tex, int x, int y, int w, int h, int rotate, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) { x &= preferences::xypos_draw_mask; y &= preferences::xypos_draw_mask; if(&tex != blit_current_texture) { flush_blit_texture(); blit_current_texture = &tex; } x1 = tex.translate_coord_x(x1); y1 = tex.translate_coord_y(y1); x2 = tex.translate_coord_x(x2); y2 = tex.translate_coord_y(y2); if(w < 0) { std::swap(x1, x2); w *= -1; } if(h < 0) { std::swap(y1, y2); h *= -1; } blit_tcqueue.push_back(x1); blit_tcqueue.push_back(y1); blit_tcqueue.push_back(x2); blit_tcqueue.push_back(y1); blit_tcqueue.push_back(x1); blit_tcqueue.push_back(y2); blit_tcqueue.push_back(x2); blit_tcqueue.push_back(y2); blit_vqueue.push_back(x); blit_vqueue.push_back(y); blit_vqueue.push_back(x + w); blit_vqueue.push_back(y); blit_vqueue.push_back(x); blit_vqueue.push_back(y + h); blit_vqueue.push_back(x + w); blit_vqueue.push_back(y + h); rect r(x,y,w,h); GLshort* varray = &blit_vqueue[blit_vqueue.size()-8]; rotate_rect(x+(w/2), y+(h/2), rotate, varray); }
void shader::set_texture(const std::string &name, const texture &set_texture) { const auto it = std::find_if(std::begin(m_samplers), std::end(m_samplers), [name](const sampler &samp){ return samp.name == name; }); if(it != m_samplers.end()) { const GLenum target = set_texture.get_gl_dimention(); m_pending_texture_data.emplace_back(pending_texture{set_texture.get_gl_id(), target, it->index}); } else { log_error(GL_NO_ERROR, "shader::set_texture - couldn't find sampler '" + name + "' for texture."); } }
void gen_miplevel(texture &tex, texture &gen) ///call from main mem_alloc func? { int size=tex.get_largest_dimension(); int newsize=size >> 1; gen.c_image.create(newsize, newsize); for(int i=0; i<newsize; i++) { for(int j=0; j<newsize; j++) { sf::Color p4[4]; p4[0]=tex.c_image.getPixel(i*2, j*2); p4[1]=tex.c_image.getPixel(i*2+1, j*2); p4[2]=tex.c_image.getPixel(i*2, j*2+1); p4[3]=tex.c_image.getPixel(i*2+1, j*2+1); sf::Color m=pixel4(p4[0], p4[1], p4[2], p4[3]); gen.c_image.setPixel(i, j, m); } } }
void blit_texture(const texture& tex, int x, int y, GLfloat rotate) { if(!tex.valid()) { return; } x &= preferences::xypos_draw_mask; y &= preferences::xypos_draw_mask; int h = tex.height(); int w = tex.width(); const int w_odd = w % 2; const int h_odd = h % 2; h /= 2; w /= 2; glPushMatrix(); glTranslatef(x+w,y+h,0.0); glRotatef(rotate,0.0,0.0,1.0); tex.set_as_current_texture(); GLfloat varray[] = { (GLfloat)-w, (GLfloat)-h, (GLfloat)-w, (GLfloat)h+h_odd, (GLfloat)w+w_odd, (GLfloat)-h, (GLfloat)w+w_odd, (GLfloat)h+h_odd }; GLfloat tcarray[] = { texture::get_coord_x(0.0), texture::get_coord_y(0.0), texture::get_coord_x(0.0), texture::get_coord_y(1.0), texture::get_coord_x(1.0), texture::get_coord_y(0.0), texture::get_coord_x(1.0), texture::get_coord_y(1.0) }; #if defined(USE_SHADERS) gles2::active_shader()->prepare_draw(); gles2::active_shader()->shader()->vertex_array(2, GL_FLOAT, 0, 0, varray); gles2::active_shader()->shader()->texture_array(2, GL_FLOAT, 0, 0, tcarray); #else glVertexPointer(2, GL_FLOAT, 0, varray); glTexCoordPointer(2, GL_FLOAT, 0, tcarray); #endif glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glPopMatrix(); }
void glsl_program::set_gl_texture(unsigned loc, const texture& tex, unsigned texunit) const { if (used_program != this) throw runtime_error("glsl_program::set_gl_texture, program not bound!"); glActiveTexture(GL_TEXTURE0 + texunit); tex.set_gl_texture(); glUniform1i(loc, texunit); }
void blit_texture(const texture& tex, int x, int y, GLfloat rotate) { if(!tex.valid()) { return; } glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); x &= preferences::xypos_draw_mask; y &= preferences::xypos_draw_mask; int h = tex.height(); int w = tex.width(); const int w_odd = w % 2; const int h_odd = h % 2; h /= 2; w /= 2; glPushMatrix(); glTranslatef(x+w,y+h,0.0); glRotatef(rotate,0.0,0.0,1.0); tex.set_as_current_texture(); GLfloat varray[] = { -w, -h, -w, h+h_odd, w+w_odd, -h, w+w_odd, h+h_odd }; GLfloat tcarray[] = { texture::get_coord_x(0.0), texture::get_coord_y(0.0), texture::get_coord_x(0.0), texture::get_coord_y(1.0), texture::get_coord_x(1.0), texture::get_coord_y(0.0), texture::get_coord_x(1.0), texture::get_coord_y(1.0) }; glVertexPointer(2, GL_FLOAT, 0, varray); glTexCoordPointer(2, GL_FLOAT, 0, tcarray); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glPopMatrix(); }
void queue_blit_texture(const texture& tex, int x, int y, int w, int h, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) { x &= preferences::xypos_draw_mask; y &= preferences::xypos_draw_mask; if(&tex != blit_current_texture) { flush_blit_texture(); blit_current_texture = &tex; } x1 = tex.translate_coord_x(x1); y1 = tex.translate_coord_y(y1); x2 = tex.translate_coord_x(x2); y2 = tex.translate_coord_y(y2); if(w < 0) { std::swap(x1, x2); w *= -1; } if(h < 0) { std::swap(y1, y2); h *= -1; } blit_tcqueue.push_back(x1); blit_tcqueue.push_back(y1); blit_tcqueue.push_back(x2); blit_tcqueue.push_back(y1); blit_tcqueue.push_back(x1); blit_tcqueue.push_back(y2); blit_tcqueue.push_back(x2); blit_tcqueue.push_back(y2); blit_vqueue.push_back(x); blit_vqueue.push_back(y); blit_vqueue.push_back(x + w); blit_vqueue.push_back(y); blit_vqueue.push_back(x); blit_vqueue.push_back(y + h); blit_vqueue.push_back(x + w); blit_vqueue.push_back(y + h); }
void add_texture(texture &tex, int &newid) { int size=tex.get_largest_dimension(); int num=0; cl_uchar4 *firstfree=return_first_free(size, num); sf::Image *T=&tex.c_image; texture_array_descriptor *Td=&obj_mem_manager::tdescrip; int which = Td->texture_nums[num]; int blockalongy = which / (max_tex_size/size); int blockalongx = which % (max_tex_size/size); int ti=0, tj=0; for(int i=blockalongx*size; i<(blockalongx+1)*size; i++) { for(int j=blockalongy*size; j<(blockalongy+1)*size; j++) { sf::Color c=T->getPixel(ti, tj); setpixel(firstfree, c, i, j, max_tex_size, max_tex_size); tj++; } ti++; tj=0; } ///so, num represents which slice its in ///Td->texture_nums[i] represents which position it is in within the slice; int mod=(num << 16) | Td->texture_nums[num]; newid=mod; ///so, now the upper half represents which slice its in, and the lower half, the number within the slice obj_mem_manager::tdescrip.texture_nums[num]++; }
image_handle(const texture<target>& texture, GLint level, bool layered, GLint layer, GLenum format) : id_(glGetImageHandleARB(texture.id(), level, layered, layer, format)) { }
void init() { memset(lastfilename,0,256); memset(musfilename,0,40); initGUI(); sprintf(scenelist->name,"Default"); memset(tooltip,0,256); memset(defaulttooltip,0,256); sprintf(defaulttooltip,"a.D.D.i.c.t. (c) BoyC 2002"); actualtexture=texturelist; lasttexture=texturelist; memset(texturelist,0,sizeof(tTexture)); texturelist->next=NULL; sprintf(texturelist->name,"Default"); memset(cursorstring,0,256); for (x=0;x<=7;x++) modellsubmenu[x]=0; init3dengine(); InitModellerGUI(); BuildFont(); BuildFont2(); BuildFontSmall(); inittextureengine(); generatedtexture.init(); buffertexture.init(); memset(pretextures,0,sizeof(pretextures)); memset(texdata,0,sizeof(texdata)); memset(texsubmenu,0,sizeof(texsubmenu)); texdata[0][3].command[3]=4; texdata[0][5].command[3]=14; texdata[0][5].command[4]=100; texdata[0][6].command[3]=30; texdata[1][1].command[2]=128; texdata[2][4].command[3]=128; texdata[3][2].command[2]=128; texdata[3][4].command[4]=255; texdata[3][6].c.param1=255; texdata[3][6].c.param3=255; texdata[3][6].c.param5=255; glGenTextures(1,&mattexture); glBindTexture(GL_TEXTURE_2D,mattexture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,4,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,generatedtexture.layers[0]); for (x=0;x<4;x++) { glGenTextures(1,&(prelayers[x])); glBindTexture(GL_TEXTURE_2D,prelayers[x]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,4,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,generatedtexture.layers[x]); } for (x=0;x<4;x++) { glGenTextures(1,&(texlayers[x])); glBindTexture(GL_TEXTURE_2D,texlayers[x]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,4,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,generatedtexture.layers[x]); } for (x=0;x<4;x++) { glGenTextures(1,&alayers[x]); glBindTexture(GL_TEXTURE_2D,alayers[x]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,4,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,generatedtexture.layers[x]); } glGenTextures(1,&background); glBindTexture(GL_TEXTURE_2D, background); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); commandnames[DD_fractal] ="Fractal "; commandnames[DD_plasma] ="Plasma "; commandnames[DD_cells] ="Cells "; commandnames[DD_envmap] ="Envmap "; commandnames[DD_subplasm] ="Subplasma "; commandnames[DD_clear] ="Clear "; commandnames[DD_text] ="Text "; commandnames[DD_sindist] ="SinDist "; commandnames[DD_offset] ="Offset "; commandnames[DD_twirl] ="Twirl "; commandnames[DD_blur] ="Blur "; commandnames[DD_map] ="MapDist "; commandnames[DD_dirblur] ="DirBlur "; commandnames[DD_xchng] ="Xchange "; commandnames[DD_copy] ="Copy "; commandnames[DD_mix] ="Mix "; commandnames[DD_mul] ="Mul "; commandnames[DD_add] ="Add "; commandnames[DD_max] ="Max "; commandnames[DD_contrast] ="Contrast "; commandnames[DD_invert] ="Invert "; commandnames[DD_shade] ="Shade "; commandnames[DD_bright] ="Brighten "; commandnames[DD_sincol] ="Color Sine "; commandnames[DD_scale] ="Scale "; commandnames[DD_hsv] ="HSV "; commandnames[DD_colorize] ="Colorize "; commandnames[DD_mixmap] ="MixMap "; commandnames[DD_emboss] ="Emboss "; commandnames[DD_stored] ="Stored "; initkeyframergui(); FSOUND_File_SetCallbacks(memopen, memclose, memread, memseek, memtell); FSOUND_Init(44100,32); }
void main (int argc,char **argv) { setlocale(LC_CTYPE, ""); //making autoconverting for non cp866 symbols // инициализация библиотеки GLUT glutInit(&argc,argv); // инициализация дисплея (формат вывода) glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); // создание окна: // 1. устанавливаем верхний левый угол окна glutInitWindowPosition(200,200); // 2. устанавливаем размер окна glutInitWindowSize(600,600); // 3. создаем окно glutCreateWindow("Anytime, anywhere…"); // устанавливаем обработчик выхода (для освобождения выделенной памяти) atexit(onExit); // переходим в полноэкранный режим //glutFullScreen(); cfg=new Config(); try { cfg->readFile(cfgPath.c_str()); } catch (...) { printf("Config doesn't parsed\n"); } // очистка объектов objects.clear(); cam=new camera(); // загрузка камеры cam->loadCamera(cfg); hasVBO=glutExtensionSupported("GL_ARB_vertex_buffer_object")!=0; // check if VBO supported hasFragmentShader=glutExtensionSupported("GL_ARB_fragment_shader")!=0; // check if fragment shader is supported hasVertexShader=glutExtensionSupported("GL_ARB_vertex_shader")!=0; // check if fragment shader is supported newOGL=atof((const char *)glGetString(GL_VERSION))>=1.5f; // check OGL version // проверяем наличие необходимых расширений object3DS::checkExtensions(); shader::checkExtensions(); if (!hasVBO) { printf("VBO does not supported\n"); } // no VBO if (!hasFragmentShader) { printf("Fragment shaders not supported\n"); } // no fragment shader if (!hasVertexShader) { printf("Vertex shaders not supported\n"); } // no vertex shader if (!newOGL) { printf("OLG 2.0 functions not supported\n"); } // old OGL ilInit(); devilError = ilGetError(); if (devilError != IL_NO_ERROR) { wprintf(L"Devil Error (ilInit): %s\n", iluErrorString(devilError)); exit(2); } iluInit(); ilutInit(); ilutRenderer(ILUT_OPENGL); // загрузка объектов по файлу конфигурации loadObjects(objects); for (unsigned int i=0; i<objects.size(); i++) { objects[i]->buffer(); // buffer objects to VBO } modelShader.loadVertexShader("Phong.vsh"); modelShader.loadFragmentShader("Phong.fsh"); modelShader.createProgram(); planeShader.loadVertexShader("Phong.vsh"); planeShader.loadFragmentShader("Phong.l3.fsh"); planeShader.createProgram(); // 4. устанавливаем функцию, которая будет вызываться для перерисовки окна glutDisplayFunc(display); // 5. устанавливаем функцию, которая будет вызываться при изменении размеров окна glutReshapeFunc(reshape); // 6. устанавливаем таймер для перерисовки окна по времени glutTimerFunc(delayPerFrames,simulation,0); // 7. устанавливаем обработчик обычных клавиш glutKeyboardFunc(processNormalKeys); // 8. устанавливаем обработчик функциональных клавиш glutSpecialFunc(processSpecialKeys); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); surfaceTex.load(L"textures\\ceram.jpg"); // вывод строк описывающих OpenGL // вывод производителя printf("%s\n",glGetString(GL_VENDOR)); printf("%s\n",glGetString(GL_RENDERER)); printf("%s\n",glGetString(GL_VERSION)); // вывод версии шейдерного языка printf("%s\n",glGetString(GL_SHADING_LANGUAGE_VERSION)); // вывод всех доступных расширений char *ext=(char*)glGetString(GL_EXTENSIONS); int i=0; while (ext[i]!=0) printf("%c",ext[i++]==' '?'\n':ext[i-1]); // основной цикл обработки сообщений ОС glutMainLoop(); return; };
// функция вызывается при перерисовке окна // в том числе и принудительно, по командам glutPostRedisplay void display (void) { // отчищаем буфер цвета и буфер глубины int rst=glGetError(); glClearColor(0.78125,0.78125,0.76171875,1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); // отрисовка осей // задание толщины линии glLineWidth(0.5); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(3,GL_FLOAT,sizeof(vertex),&axes[0].color); glVertexPointer(3,GL_FLOAT,sizeof(vertex),&axes[0].coordinate); glDrawArrays(GL_LINES,0,3*2); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glEnable(GL_LIGHTING); // режим вывода полигонов (выводим в виде линии) glPolygonMode(GL_FRONT_AND_BACK,/*GL_LINE*/GL_FILL); // устанавливаем камеру glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //gluLookAt(0,30,20,0,0,0,0,1,0); glMultMatrixd(cam->getOrientation()); // позиция камеры glMultMatrixd(cam->getPosition()); firstLight.use(); secondLight.use(GL_LIGHT1); planeMaterial.use(); planeShader.activate(); glEnable(GL_TEXTURE_2D); glClientActiveTexture(GL_TEXTURE0); GLint texLoc = glGetUniformLocation(planeShader.getProgramId(), "MyTex"); glUniform1i(texLoc,0); glTexEnvi ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); glColor3f(0.4f,0.8f,0.4f); glNormal3f(0.0,1.0,0.0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); surfaceTex.bind(); glTexCoordPointer(2,GL_FLOAT,0,surfaceTexCoord); glVertexPointer(3,GL_FLOAT,sizeof(vertex),&surface[0].coordinate); glDrawElements(GL_TRIANGLES,18*3,GL_UNSIGNED_INT,surfaceIndex); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); glDisable(GL_TEXTURE_2D); modelShader.activate(); for(unsigned int i=0; i<objects.size(); i++) { objects[i]->render(filterMode); // call to object3ds method for rendering } shader::disactivate(); glCullFace(GL_BACK); glColor3f(0.2f,0.2f,0.2f); glutWireSphere(0.07, 16, 16); if (isDrawingFps) { drawFps(); } // смена переднего и заднего буферов glutSwapBuffers(); };
void stb_to_texture(ID3D11Device* device, LPCSTR filename, texture& t) { bool is_hdr = std::string(filename).find(".hdr") != std::string::npos; bool is_jpg = std::string(filename).find(".jpg") != std::string::npos; D3D11_TEXTURE2D_DESC tex_desc; ZeroMemory(&tex_desc, sizeof(tex_desc)); D3D11_SUBRESOURCE_DATA subdata; ZeroMemory(&subdata, sizeof(subdata)); int width, height, nc; unsigned char* ldr_data = nullptr; float* hdr_data = nullptr; if (!is_hdr) { ldr_data = stbi_load(filename, &width, &height, &nc, 4); subdata.SysMemPitch = width * 4; subdata.pSysMem = ldr_data; if (is_jpg) tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; else // TODO: Remap to SRGB later when throwing out D3DX tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // TODO: Need to create mipmaps } else { hdr_data = stbi_loadf(filename, &width, &height, &nc, 4); subdata.SysMemPitch = width * 4 * 4; subdata.pSysMem = hdr_data; tex_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; } if (!ldr_data && !hdr_data) { tstring error = L"can't load"; if (stbi_failure_reason()) error = to_tstring(std::string(stbi_failure_reason())); throw exception(tstring(L"stbi: ") + error); } tex_desc.Width = width; tex_desc.Height = height; tex_desc.MipLevels = 1; tex_desc.ArraySize = 1; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Usage = D3D11_USAGE_DEFAULT; tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; tex_desc.CPUAccessFlags = 0; tex_desc.MiscFlags = 0; t.create(device, tex_desc, &subdata); if (is_hdr) stbi_image_free(hdr_data); else stbi_image_free(ldr_data); }
void texture::settings::apply(const texture &texture) const { save_binding_state save(texture); texture.pixel_unpack_settings().apply(); if (compressed_format(m_internal_format)) { int compressed_image_size = m_compressed_image_size; if (!compressed_image_size) { switch (m_internal_format) { case texture::internal_format::compressed_rgb_s3tc_dxt1: compressed_image_size = ((m_width + 2) / 3) * ((m_height + 2) / 3) * 6; break; case texture::internal_format::compressed_rgba_s3tc_dxt1: compressed_image_size = ((m_width + 3) / 4) * ((m_height + 3) / 4) * 8; break; case texture::internal_format::compressed_rgba_s3tc_dxt3: case texture::internal_format::compressed_rgba_s3tc_dxt5: compressed_image_size = ((m_width + 3) / 4) * ((m_height + 3) / 4) * 16; break; } } __glcheck glCompressedTexImage2D((GLenum)m_parent->get_target(), m_level, (GLint)m_internal_format, m_width, m_height, 0, compressed_image_size, m_pixels); } else { __glcheck glTexImage2D((GLenum)m_parent->get_target(), m_level, (GLint)m_internal_format, m_width, m_height, 0, (GLint)m_format, (GLint)m_type, m_pixels); } __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_MAX_LEVEL, m_max_level); if (m_pixels) { __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_GENERATE_MIPMAP, m_generate_mipmap ? GL_TRUE : GL_FALSE); } __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_WRAP_S, (GLint)m_wrap_s); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_WRAP_T, (GLint)m_wrap_t); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_WRAP_R, (GLint)m_wrap_r); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_COMPARE_MODE, (GLint)m_compare_mode); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_COMPARE_FUNC, (GLint)m_compare_func); __glcheck glTexParameterf((GLenum)m_parent->get_target(), GL_TEXTURE_MIN_LOD, m_max_lod); __glcheck glTexParameterf((GLenum)m_parent->get_target(), GL_TEXTURE_MAX_LOD, m_min_lod); __glcheck glTexParameterf((GLenum)m_parent->get_target(), GL_TEXTURE_LOD_BIAS, m_lod); __glcheck glTexParameterfv((GLenum)m_parent->get_target(), GL_TEXTURE_BORDER_COLOR, m_border_color.rgba); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_MIN_FILTER, (GLint)m_min_filter); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_MAG_FILTER, (GLint)m_mag_filter); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_SWIZZLE_R, (GLint)m_swizzle_r); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_SWIZZLE_G, (GLint)m_swizzle_g); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_SWIZZLE_B, (GLint)m_swizzle_b); __glcheck glTexParameteri((GLenum)m_parent->get_target(), GL_TEXTURE_SWIZZLE_A, (GLint)m_swizzle_a); __glcheck glTexParameterf((GLenum)m_parent->get_target(), GL_TEXTURE_MAX_ANISOTROPY_EXT, m_aniso); }