Пример #1
0
    boost::shared_ptr< attachment > attachment_manager::get_new(const std::uint32_t handle) {
      boost::shared_ptr< attachment > unit_ptr;

      // Look for a free texture unit.
      attachment_map::iterator unit_it = attachments.begin();
      for (; unit_it != attachments.end(); ++unit_it) {
        if (unit_it->second.expired()) {
          break;
        }
      }

      if (unit_it != attachments.end()) {
        std::uint32_t unit_nb = unit_it->first;

        unit_ptr.reset(new attachment(unit_nb));
        attachments[unit_nb]        = unit_ptr;
        attachment_mappings[handle] = unit_ptr;
      } else {
        __gtulu_error() << "unable to find a free color attachment slot."
                        << "Maybe some attachment pointers are still active, or maybe the " << max_attachment
                        << " color attachment limit has been reached.";
      }

      return unit_ptr;
    }
Пример #2
0
        void dynamic_shader_format::compile() {
          obj::shader_base::compile();

          std::uint32_t length = obj::shader_base::get< fshd::property::gl_info_log_length >();

          has_log_ = length > 1;

          if (length > std::numeric_limits< std::uint32_t >::max()) {
            __gtulu_error() << "Log length too long.";
          } else if (!has_log_) {
            log_ = "";
          } else {
            char* buffer = new char[length];
            buffer[0] = 0;

            fct::get_shader_info_log< >::call(obj::shader_base::handle_,
                                              length,
                                              reinterpret_cast< std::int32_t* >(&length),
                                              buffer);

            log_ = std::string(buffer);

            delete[] buffer;
          }
        }
Пример #3
0
        void dynamic_shader_format::load_shader(boost::filesystem::path const& filename) {
          std::string extension     = filename.extension().string();
          bool        parse_outputs = false;

          if ((extension.compare(".fs") == 0) || (extension.compare(".frag") == 0)) {
            obj::shader_base::create_shader< fshd::type::gl_fragment_shader >();
            parse_outputs = true;
          } else if ((extension.compare(".vs") == 0) || (extension.compare(".vert") == 0)) {
            obj::shader_base::create_shader< fshd::type::gl_vertex_shader >();
          } else if ((extension.compare(".gs") == 0) || (extension.compare(".geom") == 0)) {
            obj::shader_base::create_shader< fshd::type::gl_geometry_shader >();
          } else {
            __gtulu_error() << "Unknown shader extension " << extension
                            << ", please use one of .fs/.frag, .gs/.geom or .vs/.vert.";
          }

          std::string source = gu::file::get_contents(filename);
          obj::shader_base::set_source(source.c_str());

          outputs_.clear();
          if (parse_outputs) {
            boost::regex           expression("out\\s+(\\S+)\\s+(\\S+);");
            boost::regex           array_expression("\\s*(\\S+)\\s*\\[(\\S*)\\]\\s*");
            boost::sregex_iterator it(source.begin(), source.end(), expression);
            boost::sregex_iterator end;

            std::uint32_t id = 0;
            while (it != end) {
              std::string type_name = it->str(1);
              std::string name      = it->str(2);

              std::uint32_t size = 1;

              boost::sregex_iterator name_it(name.begin(), name.end(), array_expression);
              boost::sregex_iterator type_it(type_name.begin(), type_name.end(), array_expression);

              // We've found a static sized output vector, that's really nice...
              if (name_it != end) {
                name = name_it->str(1);
                size = boost::lexical_cast< std::uint32_t >(name_it->str(2));

                // We've just found a dynamic sized output vector, what a wonderful idea...
              } else if (type_it != end) {
                type_name = type_it->str(1);
                size      = -1;
              }

              outputs_.push_back(output_info(id++, name, fout::format::get(type_name), size, -1, -1));
              ++it;
            }
          }
        } // load_shader
Пример #4
0
      void platform_context< toolkit::glx, platform::linux_ >::_create< policy::detached >(int arg_count,
                                                                                           char** arg_values) {
        XSetErrorHandler(_x_error);

        Display* display = NULL;
        display = XOpenDisplay(NULL);
        if (display == NULL) {
          __gtulu_fatal() << "unable to open X display.";

        } else {
          int framebuffer_config_count = 0;
          GLXFBConfig* framebuffer_configs = NULL;
          framebuffer_configs = glXChooseFBConfig(display, DefaultScreen(display), NULL, &framebuffer_config_count);
          if (framebuffer_configs == NULL) {
            __gtulu_fatal() << "unable to retrieve framebuffer configuration.";

          } else {
            int context_attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3,
            // GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | GLX_CONTEXT_DEBUG_BIT_ARB,
                                      GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, None };
            GLXContext context = NULL;
            context = glXCreateContextAttribsARB(display, framebuffer_configs[0], NULL, true, context_attribs);
            XFree(framebuffer_configs);

            if (context == NULL) {
              __gtulu_fatal() << "unable to create OpenGL context.";

            } else {
              XSync(display, false);

              context_info_t context_info(display, context);
              if (!context_info.try_acquire()) {
                __gtulu_error() << "unable to create detached context.";

                context_info.drawable = DefaultRootWindow(display);
                context_info.readable = DefaultRootWindow(display);

                if (!context_info.try_acquire()) {
                  __gtulu_fatal() << "unable to attach context to default drawable.";
                }
              }
            }
          }
        }
      }