示例#1
0
    void WindowImpl::handleSurfaceCreation()
    {
        const EGLint surfaceAttribs[] =
        {
            JOP_CHECK_EGL_EXTENSION(EGL_KHR_gl_colorspace) ? EGL_VG_COLORSPACE : EGL_NONE, EGL_VG_COLORSPACE_sRGB,
            EGL_NONE
        };

        auto state = detail::ActivityState::get();
        auto win = state->window;

        if (win && win->m_surface == EGL_NO_SURFACE)
        {
            win->m_surface = eglCheck(eglCreateWindowSurface(getDisplay(), win->m_config, state->nativeWindow, surfaceAttribs));
            JOP_ASSERT(win->m_surface != EGL_NO_SURFACE, "Failed to create window surface!");

            if (win->m_context != EGL_NO_CONTEXT)
            {
                EGLBoolean success = eglCheck(eglMakeCurrent(getDisplay(), win->m_surface, win->m_surface, win->m_context));
                JOP_ASSERT(success == EGL_TRUE, "Failed to make context current!");
            }

            if (win->m_fullScreen)
                goFullscreen();

            updateSize(win->m_size, win->m_surface);
        }
    }
    //TODO make template
    jop::WeakReference<jop::Object>& UI::createScreen(const std::string& root, const std::vector<glm::vec3>& positions, const std::vector<std::string>& names,
        const unsigned int mask = 0u,
        const std::vector<int>& values = std::vector<int>(),
        const std::vector<jop::Color>& colors = std::vector<jop::Color>())
    {
        JOP_ASSERT(names.size() > 1u, "Too small element");

        bool useValues(!values.empty());
        if (useValues)
            JOP_ASSERT(names.size() == values.size() && names.size() == positions.size(), "createScreen sizes don't match");

        Screen newScreen;

        //Root
        newScreen.obj = m_scene.createChild(root);
        newScreen.obj->setScale(0.02f);
        newScreen.mask = mask;

        //Names
        newScreen.names = names;

        //Children
        for (unsigned int i = 0u; i < names.size(); ++i)
        {
            newScreen.obj->createChild(names[i].c_str());

            auto& o = newScreen.obj->findChild(names[i].c_str());

            o->setPosition(positions[i]);
            o->createComponent<jop::Text>(m_scene.getRenderer()).setRenderGroup(mask);

            auto* t = o->getComponent<jop::Text>();

            if (useValues)
                t->setString(names[i] + std::to_string(values[i]));
            else
                t->setString(names[i]);

            if (i >= colors.size())
                t->setColor(jop::Color::Green);
            else
                t->setColor(colors[i]);
        }

        m_screens.push_back(newScreen);
        return newScreen.obj;
    }
示例#3
0
    ActivityState* ActivityState::create(ANativeActivity* activity)
    {
        JOP_ASSERT(ns_instance == nullptr, "There must only be one ActivityState!");

        ns_instance.reset(new ActivityState);
        ns_instance->nativeActivity = activity;

        ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON, AWINDOW_FLAG_KEEP_SCREEN_ON);

        Thread::attachJavaThread(activity->vm, activity->env);

        // Get the screen size
        {
            auto env = Thread::getCurrentJavaEnv();

            if (!env)
            {
                JOP_DEBUG_ERROR("No current java environment, function \"" << __func__ << "\"");
                return get();
            }

            jclass activityClass = env->GetObjectClass(activity->clazz);

            jclass displayMetricsClass = env->FindClass("android/util/DisplayMetrics");
            jmethodID displayMetricsInit = env->GetMethodID(displayMetricsClass, "<init>", "()V");
            jobject displayMetricsObject = env->NewObject(displayMetricsClass, displayMetricsInit);

            jmethodID getWindowManagerMethod = env->GetMethodID(activityClass, "getWindowManager", "()Landroid/view/WindowManager;");
            jobject windowManagerObject = env->CallObjectMethod(activity->clazz, getWindowManagerMethod);

            jclass windowManagerClass = env->FindClass("android/view/WindowManager");
            jmethodID getDefaultDisplayMethod = env->GetMethodID(windowManagerClass, "getDefaultDisplay", "()Landroid/view/Display;");
            jobject displayObject = env->CallObjectMethod(windowManagerObject, getDefaultDisplayMethod);

            jclass displayClass = env->FindClass("android/view/Display");
            jmethodID getMetricsMethod = env->GetMethodID(displayClass, "getMetrics", "(Landroid/util/DisplayMetrics;)V");
            env->CallVoidMethod(displayObject, getMetricsMethod, displayMetricsObject);

            jfieldID pixelsWidth = env->GetFieldID(displayMetricsClass, "widthPixels", "I");
            jfieldID pixelsHeight = env->GetFieldID(displayMetricsClass, "heightPixels", "I");

            ns_instance->screenSize.x = env->GetIntField(displayMetricsObject, pixelsWidth);
            ns_instance->screenSize.y = env->GetIntField(displayMetricsObject, pixelsHeight);

            //jmethodID getRefreshRateMethod = env->GetMethodID(displayClass, "getRefreshRate", "(Landroid/view/Display;)F");
            ns_instance->screenRefreshRate = 60;//env->CallFloatMethod(displayObject, getRefreshRateMethod);

            env->DeleteLocalRef(activityClass);
            env->DeleteLocalRef(displayMetricsObject);
            env->DeleteLocalRef(windowManagerObject);
            env->DeleteLocalRef(windowManagerClass);
            env->DeleteLocalRef(displayObject);
            env->DeleteLocalRef(displayClass);
        }

        return get();
    }
示例#4
0
 ResourceManager::ResourceManager()
     : Subsystem             (0),
       m_resources           (),
       m_loadPhaseResources  (),
       m_loadPhase           (false),
       m_mutex               ()
 {
     JOP_ASSERT(m_instance == nullptr, "Only one jop::ResourceManager object must exist at a time!");
 
     m_instance = this;
 }
示例#5
0
ShaderProgram& ShaderAssembler::getShader(const uint64 materialAttribs, const uint64 drawableAttribs)
{
    JOP_ASSERT(m_instance != nullptr, "Couldn't load shader, no ShaderAssembler instance!");

    auto& cont = m_instance->m_shaders;

    const std::size_t combinedAttribs = combinedHash(materialAttribs, drawableAttribs);

    {
        std::unique_lock<std::recursive_mutex> lock(m_instance->m_mutex);

        auto itr = cont.find(combinedAttribs);
        if (itr != cont.end() && !itr->second.expired())
            return *itr->second;
    }

    const auto& uber = m_instance->m_uber;
    const std::string shaderName = "jop_shader_" + std::to_string(combinedAttribs);

    std::string pp = Material::getShaderPreprocessorDef(materialAttribs) +
                     Drawable::getShaderPreprocessorDef(drawableAttribs);

    ShaderProgram* s = &ResourceManager::getNamed<ShaderProgram>(shaderName, pp, Shader::Type::Vertex, uber[0], Shader::Type::Geometry, uber[1], Shader::Type::Fragment, uber[2]);

    if (!ResourceManager::isError(*s))
    {
        s->setShouldSerialize(false);
        s->setPersistence(5);

        {
            std::unique_lock<std::recursive_mutex> lock(m_instance->m_mutex);

            cont[combinedAttribs] = static_ref_cast<ShaderProgram>(s->getReference());
        }

        // Needed so that different samplers don't all point to zero
        if ((materialAttribs & Material::FragLightingAttribs) != 0)
        {
            static const int maxUnits = Texture::getMaxTextureUnits();

            for (std::size_t i = 0; i < LightSource::getMaximumLights(LightSource::Type::Point); ++i)
                s->setUniform("u_PointLightShadowMaps[" + std::to_string(i) + "]", maxUnits - 1);
        }
    }

    return *s;
}
示例#6
0
ShaderAssembler::ShaderAssembler()
    : Subsystem (0),
      m_plugins (),
      m_shaders (),
      m_uber    (),
      m_mutex   ()
{
    JOP_ASSERT(m_instance == nullptr, "There must only be one ShaderAssembler instance!");
    m_instance = this;

    m_uber[0].assign(reinterpret_cast<const char*>(jopr::defaultUberShaderVert), sizeof(jopr::defaultUberShaderVert));
    m_uber[2].assign(reinterpret_cast<const char*>(jopr::defaultUberShaderFrag), sizeof(jopr::defaultUberShaderFrag));

    // Load plugins
    addPlugins(std::string(reinterpret_cast<const char*>(jopr::compatibilityPlugins), sizeof(jopr::compatibilityPlugins)));
    addPlugins(std::string(reinterpret_cast<const char*>(jopr::lightingPlugins), sizeof(jopr::lightingPlugins)));
    addPlugins(std::string(reinterpret_cast<const char*>(jopr::structurePlugins), sizeof(jopr::structurePlugins)));
    addPlugins(std::string(reinterpret_cast<const char*>(jopr::shadowPlugins), sizeof(jopr::shadowPlugins)));
}
    void updateScreenValues(const std::string& root, const std::vector<int>& newValues)
    {
        int index = findScreen(root);

        if (index == -1)
        {
            JOP_DEBUG_INFO("updateScreen not found: " << root);
            return;
        }

        auto& s = m_screens[index];

        JOP_ASSERT(s.names.size() == newValues.size(), "updateScreen newValues size not matching with old.");

        for (unsigned int i = 0u; i < s.obj->getChildren().size() - 1u; ++i)
        {
            s.obj->findChild(s.names[i])->getComponent<jop::Text>()->setString(std::to_string(newValues[i]));
        }

    }
示例#8
0
    GearJoint2D::GearJoint2D(World2D& worldRef, RigidBody2D& bodyA, RigidBody2D& bodyB, const bool collide, const float ratio, const Joint2D& joint1, const Joint2D& joint2) :
        Joint2D(worldRef, bodyA, bodyB, collide),
        m_jointL(nullptr)
    {
        b2GearJointDef jointDef;
        jointDef.bodyA = getBody(bodyA);
        jointDef.bodyB = getBody(bodyB);
        jointDef.collideConnected = collide;
        jointDef.ratio = ratio;

        if ((joint1.m_joint->GetType() == b2JointType::e_prismaticJoint || joint1.m_joint->GetType() == b2JointType::e_revoluteJoint) &&
            (joint2.m_joint->GetType() == b2JointType::e_prismaticJoint || joint2.m_joint->GetType() == b2JointType::e_revoluteJoint))
        {
            jointDef.joint1 = static_cast<b2Joint*>(joint1.m_joint);
            jointDef.joint2 = static_cast<b2Joint*>(joint2.m_joint);
        }
        else
            JOP_ASSERT(false, "GearJoint2D can only be constructed with any combination of PistonJoint2Ds and RotationJoint2Ds.");

        m_joint = static_cast<b2GearJoint*>(getBody(bodyA)->GetWorld()->CreateJoint(&jointDef));
        m_jointL = static_cast<b2GearJoint*>(m_joint);
    }
示例#9
0
文件: World2D.cpp 项目: Jopnal/Jopnal
 World2D* World2D::clone(Object&) const
 {
     JOP_ASSERT(false, "Copying jop::World2D is forbidden!");
     return nullptr;
 }