Example #1
0
GLuint GLContext::Program::createGLShader(GLenum type, const String& typeStr, const String& source)
{
    GLuint shader = glCreateShader(type);
    const char* sourcePtr = source.getPtr();
    int sourceLen = source.getLength();
    glShaderSource(shader, 1, &sourcePtr, &sourceLen);
    glCompileShader(shader);

    GLint status = 0;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (!status)
    {
        GLint infoLen = 0;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
        if (!infoLen)
            fail("glCompileShader(%s) failed!", typeStr.getPtr());

        Array<char> info(NULL, infoLen);
        info[0] = '\0';
        glGetShaderInfoLog(shader, infoLen, &infoLen, info.getPtr());
        fail("glCompileShader(%s) failed!\n\n%s", typeStr.getPtr(), info.getPtr());
    }

    GLContext::checkErrors();
    return shader;
}
Example #2
0
CudaKernel CudaModule::getKernel(const String& name)
{
    CUfunction kernel = findKernel(name);
    if (!kernel)
        fail("CudaModule: Kernel not found '%s'!", name.getPtr());
    return CudaKernel(this, kernel);
}
Example #3
0
CUsurfref CudaModule::getSurfRef(const String& name)
{
#if (CUDA_VERSION >= 3010)
    CUsurfref surfRef;
    checkError("cuModuleGetSurfRef", cuModuleGetSurfRef(&surfRef, m_module, name.getPtr()));
    return surfRef;
#else
    FW_UNREF(name);
    fail("CudaModule: getSurfRef() requires CUDA 3.1 or later!");
    return NULL;
#endif
}
Example #4
0
CUtexref CudaModule::getTexRef(const String& name)
{
    S32* found = m_texRefHash.search(name);
    if (found)
        return m_texRefs[*found];

    CUtexref texRef;
    checkError("cuModuleGetTexRef", cuModuleGetTexRef(&texRef, m_module, name.getPtr()));

    m_texRefHash.add(name, m_texRefs.getSize());
    m_texRefs.add(texRef);
    return texRef;
}
void FW::fail(const char* fmt, ...)
{
    // Fail only once.

    s_lock.enter();
    bool alreadyFailed = s_hasFailed;
    s_hasFailed = true;
    s_lock.leave();
    if (alreadyFailed)
        return;

    // Print message.

    String tmp;
    va_list args;
    va_start(args, fmt);
    tmp.setfv(fmt, args);
    va_end(args);
    printf("\n%s\n", tmp.getPtr());

    // Try to prevent any user code from being executed.

    Thread::suspendAll();
    setDiscardEvents(true);

    // Display modal dialog.

    MessageBox(NULL, tmp.getPtr(), "Fatal error", MB_OK);

    // Running under a debugger => break here.

    if (IsDebuggerPresent())
        __debugbreak();

    // Kill the app.

    FatalExit(1);
}
Example #6
0
// Load in objects from standard input into the global variables: 
// gCtrlPoints, gCurves, gCurveNames, gSurfaces, gSurfaceNames.  If
// loading fails, this will exit the program.
void App::loadModel(const String& fileName)
{
    int end = fileName.lastIndexOf('.');
    String prefix = (end > 0) ? fileName.substring(0, end) : fileName;
    String skeletonFile = prefix + ".skel";
    String meshFile = prefix + ".obj";
    String attachmentsFile = prefix + ".attach";

    cout << "skeleton:   " << skeletonFile.getPtr() << endl;
    cout << "mesh:       " << meshFile.getPtr() << endl;
    cout << "attachment: " << attachmentsFile.getPtr() << endl;

    m_model.load(skeletonFile.getPtr(), meshFile.getPtr(), attachmentsFile.getPtr());
}
Example #7
0
void App::screenshot (const String& name) {
    // Capture image.
    const Vec2i& size = window_.getGL()->getViewSize();
    Image image(size, ImageFormat::R8_G8_B8_A8);
    glUseProgram(0);
    glWindowPos2i(0, 0);
    glReadPixels(0, 0, size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getMutablePtr());

    // Display the captured image immediately.
    for (int i = 0; i < 3; ++i) {
        glDrawPixels(size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPtr());
        window_.getGL()->swapBuffers();
    }
    glDrawPixels(size.x, size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.getPtr());

    // Export.
    image.flipY();
    exportImage(name, &image);
    printf("Saved screenshot to '%s'", name.getPtr());
}
Example #8
0
CUfunction CudaModule::findKernel(const String& name)
{
    // Search from hash.

    CUfunction* found = m_kernels.search(name);
    if (found)
        return *found;

    // Search from module.

    CUfunction kernel = NULL;
    cuModuleGetFunction(&kernel, m_module, name.getPtr());
    if (!kernel)
        cuModuleGetFunction(&kernel, m_module, (String("__globfunc_") + name).getPtr());
    if (!kernel)
        return NULL;

    // Add to hash.

    m_kernels.add(name, kernel);
    return kernel;
}
Example #9
0
 bool            operator!=  (const String& other) const     { return (strcmp(getPtr(), other.getPtr()) != 0); }
Example #10
0
void App::loadOBJ(string filename) {
    window_.showModalMessage(sprintf("Loading mesh from '%s'...", filename.c_str()));

    String oldError = clearError();
	MeshBase* mesh = importMesh((FW::String)filename.c_str());
    String newError = getError();

    if (restoreError(oldError)) {
        delete mesh;
        common_ctrl_.message(sprintf("Error while loading '%s': %s", filename.c_str(), newError.getPtr()));
        return;
    }

	// get rid of the old meshes if necessary
	subdivided_meshes_.clear();

	// first, weld vertices
	Mesh<VertexP> meshP(*mesh);
	meshP.collapseVertices();

	// center mesh to origin and normalize scale
	Vec3f bbmin, bbmax;
	meshP.getBBox(bbmin, bbmax);
	float scale = 10.0f / (bbmax-bbmin).length();
	Vec3f ctr = 0.5f*(bbmin+bbmax);
	Mat4f T = Mat4f::translate( -ctr );
	Mat4f S = Mat4f::scale(Vec3f(scale, scale, scale));
	meshP.xformPositions(S*T);

	// then, recompute normals to make them smooth
	Mesh<VertexPNC>* meshPNC = new Mesh<VertexPNC>(meshP);
	meshPNC->recomputeNormals();
	for (int i = 0; i < meshPNC->numVertices(); ++i)
		meshPNC->mutableVertex(i).c = Vec4f(1.0f, 1.0f, 1.0f, 1.0f);
	delete mesh;

	subdivided_meshes_.push_back(std::unique_ptr<MeshBase>(meshPNC));

	common_ctrl_.message(sprintf("Loaded mesh from '%s'", filename.c_str()));
}
Example #11
0
CudaModule::CudaModule(const String& cubinFile)
{
    staticInit();
    checkError("cuModuleLoad", cuModuleLoad(&m_module, cubinFile.getPtr()));
}
Example #12
0
GLint GLContext::Program::getUniformLoc(const String& name) const
{
    return glGetUniformLocation(m_glProgram, name.getPtr());
}