void egolib_console_handler_t::draw_begin() { auto& renderer = Ego::Renderer::get(); // do not use the ATTRIB_PUSH macro, since the glPopAttrib() is in a different function GL_DEBUG( glPushAttrib )( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT ); // don't worry about hidden surfaces renderer.setDepthTestEnabled(false); // draw draw front and back faces of polygons renderer.setCullingMode(Ego::CullingMode::None); renderer.setBlendingEnabled(true); renderer.setBlendFunction(Ego::BlendFunction::SourceAlpha, Ego::BlendFunction::OneMinusSourceAlpha); renderer.setViewportRectangle(0, 0, sdl_scr.x, sdl_scr.y); // Set up an ortho projection for the gui to use. Controls are free to modify this // later, but most of them will need this, so it's done by default at the beginning // of a frame // store the GL_PROJECTION matrix (this stack has a finite depth, minimum of 32) GL_DEBUG( glMatrixMode )( GL_PROJECTION ); GL_DEBUG( glPushMatrix )(); Matrix4f4f matrix = Ego::Math::Transform::ortho(0, sdl_scr.x, sdl_scr.y, 0, -1, 1); renderer.loadMatrix(matrix); // store the GL_MODELVIEW matrix (this stack has a finite depth, minimum of 32) GL_DEBUG( glMatrixMode )( GL_MODELVIEW ); GL_DEBUG( glPushMatrix )(); renderer.loadMatrix(Matrix4f4f::identity()); }
void pie_RemainingPasses(void) { GL_DEBUG("Remaining passes - shadows"); // Draw shadows if (shadows) { pie_DrawShadows(); } // Draw models // TODO, sort list to reduce state changes GL_DEBUG("Remaining passes - opaque models"); for (SHAPE const &shape : shapes) { pie_SetShaderStretchDepth(shape.stretch); pie_Draw3DShape2(shape.shape, shape.frame, shape.colour, shape.teamcolour, shape.flag, shape.flag_data, shape.matrix); } // Draw translucent models last // TODO, sort list by Z order to do translucency correctly GL_DEBUG("Remaining passes - translucent models"); for (SHAPE const &shape : tshapes) { pie_SetShaderStretchDepth(shape.stretch); pie_Draw3DShape2(shape.shape, shape.frame, shape.colour, shape.teamcolour, shape.flag, shape.flag_data, shape.matrix); } pie_SetShaderStretchDepth(0); pie_DeactivateShader(); tshapes.clear(); shapes.clear(); GL_DEBUG("Remaining passes - done"); }
GLuint TextureMgr::LoadTexture(string file, bool repeats, bool compress) { // extende filename file = FF_TEXTURE_PATH + file; uint32 tFlags = SOIL_FLAG_MIPMAPS; if (repeats) tFlags |= SOIL_FLAG_TEXTURE_REPEATS; if (compress) tFlags |= SOIL_FLAG_COMPRESS_TO_DXT; // create texture using SOIL GLuint handle = SOIL_load_OGL_texture(file.c_str(), 0, 0, tFlags); // set texture parameters (fixed at max quality currently) GL_DEBUG(glBindTexture(GL_TEXTURE_2D, handle)); GL_DEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); GL_DEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)); GL_DEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, afLevel)); g_Log.write(LOG_LOAD, "Texture loaded > [%d] '%s'%s%s", handle, file.c_str(), repeats ? " [wrap] " : "", compress ? " [compress]" : ""); // store handle m_textures.push_back(handle); return handle; }
//-------------------------------------------------------------------------------------------- void gl_grab_logic_op_state( gl_logic_op_t * pl ) { pl->index_enabled = GL_DEBUG( glIsEnabled )( GL_INDEX_LOGIC_OP ); pl->color_enabled = GL_DEBUG( glIsEnabled )( GL_COLOR_LOGIC_OP ); if ( pl->index_enabled || pl->color_enabled ) { GL_DEBUG( glGetIntegerv )( GL_LOGIC_OP_MODE, pl->mode ); switch ( pl->mode[0] ) { case GL_CLEAR: pl->mode_sz = "GL_CLEAR"; break; case GL_AND: pl->mode_sz = "GL_AND"; break; case GL_COPY: pl->mode_sz = "GL_COPY"; break; case GL_OR: pl->mode_sz = "GL_OR"; break; case GL_NOOP: pl->mode_sz = "GL_NOOP"; break; case GL_NAND: pl->mode_sz = "GL_NAND"; break; case GL_SET: pl->mode_sz = "GL_SET"; break; case GL_NOR: pl->mode_sz = "GL_NOR"; break; case GL_COPY_INVERTED: pl->mode_sz = "GL_COPY_INVERTED"; break; case GL_XOR: pl->mode_sz = "GL_XOR"; break; case GL_INVERT: pl->mode_sz = "GL_INVERT"; break; case GL_EQUIV: pl->mode_sz = "GL_EQUIV"; break; case GL_AND_REVERSE: pl->mode_sz = "GL_AND_REVERSE"; break; case GL_AND_INVERTED: pl->mode_sz = "GL_AND_INVERTED"; break; case GL_OR_REVERSE: pl->mode_sz = "GL_OR_REVERSE"; break; case GL_OR_INVERTED: pl->mode_sz = "GL_OR_INVERTED"; break; default: pl->mode_sz = "UNKNOWN"; }; } }
//-------------------------------------------------------------------------------------------- void gl_grab_alpha_state( gl_alpha_t * pa ) { pa->test_enabled = GL_DEBUG( glIsEnabled )( GL_ALPHA_TEST ); if ( GL_TRUE == pa->test_enabled ) { GL_DEBUG( glGetIntegerv )( GL_ALPHA_TEST_FUNC, pa->test_func ); switch ( pa->test_func[0] ) { case GL_NEVER: pa->test_func_sz = "GL_NEVER"; break; case GL_ALWAYS: pa->test_func_sz = "GL_ALWAYS"; break; case GL_LESS: pa->test_func_sz = "GL_LESS"; break; case GL_LEQUAL: pa->test_func_sz = "GL_LEQUAL"; break; case GL_EQUAL: pa->test_func_sz = "GL_EQUAL"; break; case GL_GEQUAL: pa->test_func_sz = "GL_GEQUAL"; break; case GL_GREATER: pa->test_func_sz = "GL_GREATER"; break; case GL_NOTEQUAL: pa->test_func_sz = "GL_NOTEQUAL"; break; default: pa->test_func_sz = "UNKNOWN"; }; GL_DEBUG( glGetIntegerv )( GL_ALPHA_TEST_REF, pa->test_ref ); }; GL_DEBUG( glGetFloatv )( GL_ALPHA_SCALE, pa->scale ); GL_DEBUG( glGetFloatv )( GL_ALPHA_BIAS, pa->bias ); }
//-------------------------------------------------------------------------------------------- void oglx_grab_state( ogl_state_t * ps ) { if ( NULL == ps ) return; memset( ps, 0, sizeof( *ps ) ); gl_grab_texturing_state( &ps->texturing ); gl_grab_clipping_state( &ps->clipping ); gl_grab_render_options_state( &ps->options ); gl_grab_mapping_state( &ps->mapping ); gl_grab_unpacking_state( &ps->unpack ); gl_grab_packing_state( &ps->pack ); gl_grab_matrix_state( &ps->matrix ); gl_grab_attrib_state( &ps->attrib ); gl_grab_logic_op_state( &ps->logic_op ); //---- zoom "; GL_DEBUG( glGetFloatv )( GL_ZOOM_X, ps->zoom_x ); GL_DEBUG( glGetFloatv )( GL_ZOOM_Y, ps->zoom_y ); ps->error_value = GL_DEBUG( glGetError )(); if ( GL_NO_ERROR != ps->error_value ) { ps->error_value_sz = gluErrorString( ps->error_value ); } }
//-------------------------------------------------------------------------------------------- void gl_grab_texture_gen_state( gl_texture_gen_t * pt, GLenum coord ) { GL_DEBUG( glGetTexGenfv )( coord, GL_EYE_PLANE, pt->eye_plane ); GL_DEBUG( glGetTexGenfv )( coord, GL_OBJECT_PLANE, pt->object_plane ); GL_DEBUG( glGetTexGenfv )( coord, GL_OBJECT_PLANE, pt->object_plane ); GL_DEBUG( glGetTexGeniv )( coord, GL_TEXTURE_GEN_MODE, pt->mode ); }
void TextureMgr::SetAnisotropic(GLint level) { afLevel = (level >= 0 && level <= afMax) ? level : afMax; for (auto it = m_textures.begin(); it != m_textures.end(); ++it) { GL_DEBUG(glBindTexture(GL_TEXTURE_2D, *it)); GL_DEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, afLevel)); } }
bool SpriteMgr::Init() { m_shader = g_Shader.CreateProgram("sprite.vert", "sprite.frag", 2, FF_ATTRIBUTE_VERTEX, "in_vertex", FF_ATTRIBUTE_TEXTURE0, "in_texture"); m_locTexture = GL_DEBUG(glGetUniformLocation(m_shader, "textureSampler")); m_locMVP = GL_DEBUG(glGetUniformLocation(m_shader, "mvpMatrix")); m_locOffset = GL_DEBUG(glGetUniformLocation(m_shader, "texOffset")); m_locColor = GL_DEBUG(glGetUniformLocation(m_shader, "spriteColor")); return (m_shader != 0); }
void egolib_console_handler_t::draw_end() { // Restore the GL_PROJECTION matrix GL_DEBUG( glMatrixMode )( GL_PROJECTION ); GL_DEBUG( glPopMatrix )(); // Restore the GL_MODELVIEW matrix GL_DEBUG( glMatrixMode )( GL_MODELVIEW ); GL_DEBUG( glPopMatrix )(); // Re-enable any states disabled by gui_beginFrame // do not use the ATTRIB_POP macro, since the glPushAttrib() is in a different function GL_DEBUG( glPopAttrib )(); }
static void *init(xpl_context_t *self) { glEnable(GL_BLEND); GL_DEBUG(); brick_vbo = xpl_bo_new(GL_ARRAY_BUFFER, GL_STATIC_DRAW); xpl_bo_append(brick_vbo, &brick_vertex_data, sizeof(brick_vertex_data)); xpl_bo_commit(brick_vbo); brick_elements = sizeof(brick_vertex_data) / sizeof(brick_vertex_data[0]); brick_vao = xpl_vao_new(); xpl_vao_define_vertex_attrib(brick_vao, "position", brick_vbo, 3, GL_FLOAT, GL_FALSE, sizeof(brick_vertex_data[0]), offsetof(vertex_normal_t, vertex)); GL_DEBUG(); // Quad for effects quad_vbo = xpl_bo_new(GL_ARRAY_BUFFER, GL_STATIC_DRAW); xpl_bo_append(quad_vbo, &plane_xy_vertex_data[0], sizeof(plane_xy_vertex_data)); xpl_bo_commit(quad_vbo); quad_elements = sizeof(plane_xy_vertex_data) / sizeof(plane_xy_vertex_data[0]); quad_vao = xpl_vao_new(); xpl_vao_define_vertex_attrib(quad_vao, "position", quad_vbo, 3, GL_FLOAT, GL_FALSE, sizeof(plane_xy_vertex_data[0]), offsetof(vertex_normal_t, vertex)); GL_DEBUG(); brick_shader = xpl_shader_get_prepared("LogoBackground", "Logo.Vertex", "Logo.Brick.Fragment"); quad_shader = xpl_shader_get_prepared("LogoForeground", "Overlay.Vertex", "Overlay.Fragment"); glUseProgram(quad_shader->id); glUniform1f(xpl_shader_get_uniform(quad_shader, "scanline_amount"), 0.9f); glUniform1f(xpl_shader_get_uniform(quad_shader, "strength"), 0.f); glUniform4f(xpl_shader_get_uniform(quad_shader, "color"), 0.f, 0.f, 0.f, 1.f); glUseProgram(0); GL_DEBUG(); // for (size_t i = 0; i < 3; ++i) { brick[i].position = xvec3_set(i % 2, 1.8f * i, 0.f); // Dude, use a table. brick[i].color = xvec4_set((i + 1) % 3 ? 0.f : 1.f, (i + 2) % 3 ? 0.f : 1.f, i % 3 ? 0.f : 1.f, 0.5f); } return NULL; }
//-------------------------------------------------------------------------------------------- // Controls ui_buttonValues ui_doButton( ui_id_t id, const char *text, Font * font, float vx, float vy, float vwidth, float vheight ) { ui_buttonValues result; int text_w, text_h; int text_x, text_y; // Do all the logic type work for the button result = ui_buttonBehavior( id, vx, vy, vwidth, vheight ); // Draw the button part of the button ui_drawButton( id, vx, vy, vwidth, vheight, NULL ); // And then draw the text that goes on top of the button if ( NULL == font ) font = ui_getFont(); if ( NULL != font && NULL != text && '\0' != text[0] ) { float x1, x2, y1, y2; // convert the virtual coordinates to screen coordinates ui_virtual_to_screen( vx, vy, &x1, &y1 ); ui_virtual_to_screen( vx + vwidth, vy + vheight, &x2, &y2 ); // find the vwidth & vheight of the text to be drawn, so that it can be centered inside // the button fnt_getTextSize( font, text, &text_w, &text_h ); text_x = (( x2 - x1 ) - text_w ) / 2 + x1; text_y = (( y2 - y1 ) - text_h ) / 2 + y1; GL_DEBUG( glColor3f )( 1, 1, 1 ); fnt_drawText( font, NULL, text_x, text_y, text ); } return result; }
// call after swap buffers void wzPerfFrame() { if (!perfStarted) { return; // not started yet } ASSERT(queryActive == PERF_COUNT, "Missing wfPerfEnd() call"); PERF_STORE store; for (int i = 0; i < PERF_COUNT; i++) { glGetQueryObjectui64v(perfpos[i], GL_QUERY_RESULT, &store.counters[i]); } glErrors(); perfList.append(store); perfStarted = false; // Make a screenshot to document sample content time_t aclock; struct tm *t; time(&aclock); /* Get time in seconds */ t = localtime(&aclock); /* Convert time to struct */ ssprintf(screendump_filename, "screenshots/wz2100-perf-sample-%02d-%04d%02d%02d_%02d%02d%02d-%s.png", perfList.size() - 1, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, getLevelName()); screendump_required = true; GL_DEBUG("Performance sample complete"); }
void pie_DrawSkybox(float scale) { GL_DEBUG("Drawing skybox"); glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_FOG_BIT); // no use in updating the depth buffer glDepthMask(GL_FALSE); // fog should not affect the sky glDisable(GL_FOG); // So we have realistic colors glColor4ub(0xFF,0xFF,0xFF,0xFF); // enable alpha pie_SetRendMode(REND_ALPHA); // for the nice blend of the sky with the fog glDisable(GL_ALPHA_TEST); // Apply scale matrix glScalef(scale, scale/2.0f, scale); skyboxGfx->draw(); glPopAttrib(); }
bool replaceTexture(const QString &oldfile, const QString &newfile) { char tmpname[iV_TEXNAME_MAX]; // Load new one to replace it iV_Image image; if (!iV_loadImage_PNG(QString("texpages/" + newfile).toUtf8().constData(), &image)) { debug(LOG_ERROR, "Failed to load image: %s", newfile.toUtf8().constData()); return false; } sstrcpy(tmpname, oldfile.toUtf8().constData()); pie_MakeTexPageName(tmpname); // Have we already loaded this one? for (int i = 0; i < _TEX_PAGE.size(); i++) { if (strcmp(tmpname, _TEX_PAGE[i].name) == 0) { GL_DEBUG("Replacing texture"); debug(LOG_TEXTURE, "Replacing texture %s with %s from index %d (tex id %u)", _TEX_PAGE[i].name, newfile.toUtf8().constData(), i, _TEX_PAGE[i].id); sstrcpy(tmpname, newfile.toUtf8().constData()); pie_MakeTexPageName(tmpname); pie_AddTexPage(&image, tmpname, true, i); iV_unloadImage(&image); return true; } } iV_unloadImage(&image); debug(LOG_ERROR, "Nothing to replace!"); return false; }
//-------------------------------------------------------------------------------------------- void ui_drawImage( ui_id_t id, oglx_texture_t *img, float vx, float vy, float vwidth, float vheight, GLXvector4f image_tint ) { GLXvector4f tmp_tint = {1, 1, 1, 1}; float vw, vh; float tx, ty; float x1, x2, y1, y2; // handle optional parameters if ( NULL == image_tint ) image_tint = tmp_tint; if ( img ) { if ( 0 == vwidth || 0 == vheight ) { vw = img->imgW; vh = img->imgH; } else { vw = vwidth; vh = vheight; } tx = ( float ) oglx_texture_GetImageWidth( img ) / ( float ) oglx_texture_GetTextureWidth( img ); ty = ( float ) oglx_texture_GetImageHeight( img ) / ( float ) oglx_texture_GetTextureHeight( img ); // convert the virtual coordinates to screen coordinates ui_virtual_to_screen( vx, vy, &x1, &y1 ); ui_virtual_to_screen( vx + vw, vy + vh, &x2, &y2 ); // Draw the image oglx_texture_Bind( img ); GL_DEBUG( glColor4fv )( image_tint ); GL_DEBUG( glBegin )( GL_QUADS ); { GL_DEBUG( glTexCoord2f )( 0, 0 ); GL_DEBUG( glVertex2f )( x1, y1 ); GL_DEBUG( glTexCoord2f )( tx, 0 ); GL_DEBUG( glVertex2f )( x2, y1 ); GL_DEBUG( glTexCoord2f )( tx, ty ); GL_DEBUG( glVertex2f )( x2, y2 ); GL_DEBUG( glTexCoord2f )( 0, ty ); GL_DEBUG( glVertex2f )( x1, y2 ); } GL_DEBUG_END(); } }
static void text_buffer_render_cleanup() { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glBindTexture(GL_TEXTURE_2D, GL_NONE); glUseProgram(GL_NONE); glDepthMask(GL_TRUE); GL_DEBUG(); }
//-------------------------------------------------------------------------------------------- void ui_endFrame() { // Restore the GL_PROJECTION matrix GL_DEBUG( glMatrixMode )( GL_PROJECTION ); GL_DEBUG( glPopMatrix )(); // Restore the GL_MODELVIEW matrix GL_DEBUG( glMatrixMode )( GL_MODELVIEW ); GL_DEBUG( glLoadIdentity )(); // Re-enable any states disabled by gui_beginFrame // do not use the ATTRIB_POP macro, since the glPushAttrib() is in a different function GL_DEBUG( glPopAttrib )(); // Clear input states at the end of the frame ui_context.mousePressed = ui_context.mouseReleased = 0; }
void TextureMgr::DeleteTextures() { if (m_textures.empty()) return; GL_DEBUG(glDeleteTextures(m_textures.size(), &m_textures[0])); m_textures.clear(); }
//-------------------------------------------------------------------------------------------- void gl_grab_depth_state( gl_depth_t * pd ) { pd->test_enabled = GL_DEBUG( glIsEnabled )( GL_DEPTH_TEST ); if ( GL_TRUE == pd->test_enabled ) { GL_DEBUG( glGetIntegerv )( GL_DEPTH_FUNC, pd->test_func ); switch ( pd->test_func[0] ) { case GL_NEVER: pd->test_func_sz = "GL_NEVER"; break; case GL_ALWAYS: pd->test_func_sz = "GL_ALWAYS"; break; case GL_LESS: pd->test_func_sz = "GL_LESS"; break; case GL_LEQUAL: pd->test_func_sz = "GL_LEQUAL"; break; case GL_EQUAL: pd->test_func_sz = "GL_EQUAL"; break; case GL_GEQUAL: pd->test_func_sz = "GL_GEQUAL"; break; case GL_GREATER: pd->test_func_sz = "GL_GREATER"; break; case GL_NOTEQUAL: pd->test_func_sz = "GL_NOTEQUAL"; break; default: pd->test_func_sz = "UNKNOWN"; }; }; GL_DEBUG( glGetBooleanv )( GL_DEPTH_WRITEMASK, pd->writemask_enabled ); GL_DEBUG( glGetFloatv )( GL_DEPTH_CLEAR_VALUE, pd->clear_value ); GL_DEBUG( glGetFloatv )( GL_DEPTH_RANGE, pd->range ); GL_DEBUG( glGetFloatv )( GL_DEPTH_SCALE, pd->scale ); GL_DEBUG( glGetFloatv )( GL_DEPTH_BIAS, pd->bias ); }
void App::Resize(int width, int height) { // set the whole application window to be the OpenGL canvas GL_DEBUG(glViewport(0, 0, width, height)); // use a perspective projection for the viewport proj.PushMatrix(perspective(35.f, (float) width / (float) height, 0.1f, 1000.f)); transform.SetMatrices(mv, proj); }
void Utilities::upload_2d(const PixelFormatDescriptor& pfd, GLsizei w, GLsizei h, const void *data) { GLenum internalFormat_gl, format_gl, type_gl; toOpenGL(pfd, internalFormat_gl, format_gl, type_gl); PushClientAttrib pca(GL_CLIENT_PIXEL_STORE_BIT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, 0, internalFormat_gl, w, h, 0, format_gl, type_gl, data); }
bool App::Load() { GL_DEBUG(glEnable(GL_DEPTH_TEST)); GL_DEBUG(glClearColor(.2f, .2f, .2f, 1)); GL_DEBUG(glCullFace(GL_BACK)); GL_DEBUG(glEnable(GL_CULL_FACE)); GL_DEBUG(glEnable(GL_MULTISAMPLE)); SetSize(512, 512); shaderManager.InitializeStockShaders(); mesh.Begin(GL_TRIANGLES, 24); mesh.CopyVertexData3f(vVerts); mesh.CopyColorData4f(vColor); mesh.End(); return true; }
void wzPerfStart() { if (GLEW_ARB_timer_query) { char text[80]; ssprintf(text, "Starting performance sample %02d", perfList.size()); GL_DEBUG(text); perfStarted = true; } }
static void render(xpl_context_t *self, double time, void *data) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(brick_shader->id); glBlendFunc(GL_ONE, GL_ONE); GL_DEBUG(); for (size_t i = 0; i < 3; ++i) { xmat4 m, mvp; xmat4_identity(&m); xmat4_translate(&m, &brick[i].position, NULL); xmat4_multiply(&lookat_vp, &m, &mvp); glUniform4fv(xpl_shader_get_uniform(brick_shader, "color"), 1, brick[i].color.data); glUniformMatrix4fv(xpl_shader_get_uniform(brick_shader, "mvp"), 1, GL_FALSE, mvp.data); GL_DEBUG(); xpl_vao_program_draw_arrays(brick_vao, brick_shader, GL_TRIANGLES, 0, brick_elements); } glUseProgram(quad_shader->id); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); xpl_vao_program_draw_arrays(quad_vao, quad_shader, GL_TRIANGLES, 0, (GLsizei)quad_elements); glUseProgram(GL_NONE); }
void Utilities::upload_2d_mipmap(const PixelFormatDescriptor& pfd, GLsizei w, GLsizei h, const void *data) { GLenum internalFormat_gl, format_gl, type_gl; toOpenGL(pfd, internalFormat_gl, format_gl, type_gl); PushClientAttrib pca(GL_CLIENT_PIXEL_STORE_BIT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, 0, internalFormat_gl, w, h, 0, format_gl, type_gl, data); if (w == 1 && h == 1) return; uint32_t alphaMask = pfd.getAlphaMask(), redMask = pfd.getRedMask(), greenMask = pfd.getGreenMask(), blueMask = pfd.getBlueMask(); int bpp = pfd.getColourDepth().getDepth(); SDL_Surface *surf = SDL_CreateRGBSurfaceFrom((void *)data, w, h, bpp, w * bpp / 8, redMask, greenMask, blueMask, alphaMask); SDL_assert(surf != nullptr); GLsizei newW = w; GLsizei newH = h; GLint level = 0; do { if (newW > 1) newW /= 2; if (newH > 1) newH /= 2; level++; SDL_Surface *newSurf = SDL_CreateRGBSurface(0, newW, newH, bpp, redMask, greenMask, blueMask, alphaMask); SDL_assert(newSurf != nullptr); /// @todo this is 'low-quality' and not thread-safe SDL_SoftStretch(surf, nullptr, newSurf, nullptr); GL_DEBUG(glTexImage2D)(GL_TEXTURE_2D, level, internalFormat_gl, newW, newH, 0, format_gl, type_gl, newSurf->pixels); SDL_FreeSurface(newSurf); } while (!(newW == 1 && newH == 1)); SDL_FreeSurface(surf); }
void wzPerfBegin(PERF_POINT pp, const char *descr) { GL_DEBUG(descr); if (!perfStarted) { return; } ASSERT(queryActive == PERF_COUNT || pp > queryActive, "Out of order timer query call"); glBeginQuery(GL_TIME_ELAPSED, perfpos[pp]); queryActive = pp; glErrors(); }
//-------------------------------------------------------------------------------------------- void gl_grab_blend_state( gl_blend_t * pb ) { pb->enabled = GL_DEBUG( glIsEnabled )( GL_BLEND ); if ( pb->enabled ) { GL_DEBUG( glGetIntegerv )( GL_BLEND_SRC, pb->src ); switch ( pb->src[0] ) { case GL_ZERO: pb->src_sz = "GL_ZERO"; break; case GL_ONE: pb->src_sz = "GL_ONE"; break; case GL_DST_COLOR: pb->src_sz = "GL_DST_COLOR"; break; case GL_SRC_COLOR: pb->src_sz = "GL_SRC_COLOR"; break; case GL_ONE_MINUS_DST_COLOR: pb->src_sz = "GL_ONE_MINUS_DST_COLOR"; break; case GL_ONE_MINUS_SRC_COLOR: pb->src_sz = "GL_ONE_MINUS_SRC_COLOR"; break; case GL_SRC_ALPHA: pb->src_sz = "GL_SRC_ALPHA"; break; case GL_ONE_MINUS_SRC_ALPHA: pb->src_sz = "GL_ONE_MINUS_SRC_ALPHA"; break; case GL_DST_ALPHA: pb->src_sz = "GL_DST_ALPHA"; break; case GL_ONE_MINUS_DST_ALPHA: pb->src_sz = "GL_ONE_MINUS_DST_ALPHA"; break; case GL_SRC_ALPHA_SATURATE: pb->src_sz = "GL_SRC_ALPHA_SATURATE"; break; default: pb->src_sz = "UNKNOWN"; }; GL_DEBUG( glGetIntegerv )( GL_BLEND_DST, pb->dst ); switch ( pb->dst[0] ) { case GL_ZERO: pb->dst_sz = "GL_ZERO"; break; case GL_ONE: pb->dst_sz = "GL_ONE"; break; case GL_DST_COLOR: pb->dst_sz = "GL_DST_COLOR"; break; case GL_SRC_COLOR: pb->dst_sz = "GL_SRC_COLOR"; break; case GL_ONE_MINUS_DST_COLOR: pb->dst_sz = "GL_ONE_MINUS_DST_COLOR"; break; case GL_ONE_MINUS_SRC_COLOR: pb->dst_sz = "GL_ONE_MINUS_SRC_COLOR"; break; case GL_SRC_ALPHA: pb->dst_sz = "GL_SRC_ALPHA"; break; case GL_ONE_MINUS_SRC_ALPHA: pb->dst_sz = "GL_ONE_MINUS_SRC_ALPHA"; break; case GL_DST_ALPHA: pb->dst_sz = "GL_DST_ALPHA"; break; case GL_ONE_MINUS_DST_ALPHA: pb->dst_sz = "GL_ONE_MINUS_DST_ALPHA"; break; case GL_SRC_ALPHA_SATURATE: pb->dst_sz = "GL_SRC_ALPHA_SATURATE"; break; default: pb->dst_sz = "UNKNOWN"; }; }; }
//-------------------------------------------------------------------------------------------- void gl_grab_clipping_state( gl_clipping_t * ps ) { ps->scissor.test_enabled = GL_DEBUG( glIsEnabled )( GL_SCISSOR_TEST ); if ( ps->scissor.test_enabled ) { GL_DEBUG( glGetIntegerv )( GL_SCISSOR_BOX, ps->scissor.box ); } gl_grab_clip_plane_state( ps->clip_plane + 0, 0 ); gl_grab_clip_plane_state( ps->clip_plane + 1, 1 ); gl_grab_clip_plane_state( ps->clip_plane + 2, 2 ); gl_grab_clip_plane_state( ps->clip_plane + 3, 3 ); gl_grab_clip_plane_state( ps->clip_plane + 4, 4 ); gl_grab_clip_plane_state( ps->clip_plane + 5, 5 ); GL_DEBUG( glGetIntegerv )( GL_VIEWPORT, ps->viewport ); ps->cull_face_enabled = GL_DEBUG( glIsEnabled )( GL_CULL_FACE ); if ( GL_TRUE == ps->cull_face_enabled ) { GL_DEBUG( glGetIntegerv )( GL_CULL_FACE_MODE, ps->cull_face_mode ); switch ( ps->cull_face_mode[0] ) { case GL_FRONT: ps->cull_face_mode_sz = "GL_FRONT"; break; case GL_BACK: ps->cull_face_mode_sz = "GL_BACK"; break; case GL_FRONT_AND_BACK: ps->cull_face_mode_sz = "GL_FRONT_AND_BACK"; break; default: ps->cull_face_mode_sz = "UNKNOWN"; }; GL_DEBUG( glGetIntegerv )( GL_FRONT_FACE, ps->front_face ); ps->front_face_sz = ( GL_CW == ps->front_face[0] ) ? "GL_CW" : "GL_CCW"; } }
void TextureMgr::Init() { GLfloat maxAnisotropy = 0.f; if (glewIsSupported("GL_EXT_texture_filter_anisotropic")) { GL_DEBUG(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy)); g_Log.write(LOG_CONFIG, "TextureMgr > %.0fx Anistropic filtering supported.", maxAnisotropy); } else { g_Log.write(LOG_CONFIG, "TextureMgr > Anistropic filtering NOT supported."); } // use max anisotropic filtering by default afLevel = afMax = (GLint) maxAnisotropy; }