Esempio n. 1
0
/*
The shader compilation code was spun off into its own function so that it could be called when I want to compile 
the shaders using a hot key during run-time. This helped in speeding up development time as the entire application
would not need to be closed before hand. It compiles the shaders into 2 shader programmes. The first 'first_program_'
is used to drawn sponza normally and some basic graphics debugging features such as wireframe and point rendering.
The second shader program 'spikey_program_' is used draw a debug version of the line drawing along a vertex positions' 
normal vector. If there is an error when the shaders are compiled, then the error(s) for each shader are output to the
console window and reference a specific line in a specific file.
*/
void MyView::CompileShaders()
{
	CompileShader("sponza_vs.glsl", GL_VERTEX_SHADER, vertex_shader);
	CompileShader("sponza_fs.glsl", GL_FRAGMENT_SHADER, fragment_shader);
	CompileShader("spikeysponza_vs.glsl", GL_VERTEX_SHADER, spikeyvertex_shader);
	CompileShader("sponza_gs.glsl", GL_GEOMETRY_SHADER, geometary_shader);
	CompileShader("spikeysponza_fs.glsl", GL_FRAGMENT_SHADER, spikeyfragment_shader);


	first_program_ = glCreateProgram();
	glAttachShader(first_program_, vertex_shader);
	glBindAttribLocation(first_program_, 0, "vertex_position");
	glBindAttribLocation(first_program_, 1, "vertex_normal");
	glBindAttribLocation(first_program_, 2, "vertex_tangent");
	glBindAttribLocation(first_program_, 3, "vertex_texcoord");
	glDeleteShader(vertex_shader);
	glAttachShader(first_program_, fragment_shader);
	glDeleteShader(fragment_shader);
	glLinkProgram(first_program_);

	spikey_program_ = glCreateProgram();
	glAttachShader(spikey_program_, spikeyvertex_shader);
	glBindAttribLocation(spikey_program_, 0, "vertex_position");
	glBindAttribLocation(spikey_program_, 1, "vertex_normal");
	glDeleteShader(spikeyvertex_shader);
	glAttachShader(spikey_program_, geometary_shader);
	glDeleteShader(geometary_shader);
	glAttachShader(spikey_program_, spikeyfragment_shader);
	glDeleteShader(spikeyfragment_shader);
	glLinkProgram(spikey_program_);
	if(CheckLinkStatus(first_program_) && CheckLinkStatus(spikey_program_))
		std::cout << "Shaders Compiled!" << std::endl;

	Getuniforms();
}
NS_IMETHODIMP
nsNotifyAddrListener::Run()
{
    HANDLE ev = CreateEvent(nsnull, FALSE, FALSE, nsnull);
    NS_ENSURE_TRUE(ev, NS_ERROR_OUT_OF_MEMORY);

    HANDLE handles[2] = { ev, mShutdownEvent };
    OVERLAPPED overlapped = { 0 };
    PRBool shuttingDown = PR_FALSE;

    overlapped.hEvent = ev;
    while (!shuttingDown) {
        HANDLE h;
        DWORD ret = sNotifyAddrChange(&h, &overlapped);

        if (ret == ERROR_IO_PENDING) {
            ret = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
            if (ret == WAIT_OBJECT_0) {
                CheckLinkStatus();
            } else {
                shuttingDown = PR_TRUE;
            }
        } else {
            shuttingDown = PR_TRUE;
        }
    }
    CloseHandle(ev);

    return NS_OK;
}
NS_IMETHODIMP
nsNotifyAddrListener::GetIsLinkUp(bool *aIsUp)
{
    if (!mCheckAttempted && !mStatusKnown) {
        mCheckAttempted = true;
        CheckLinkStatus();
    }

    *aIsUp = mLinkUp;
    return NS_OK;
}