Пример #1
0
PainterShaderProgramPtr ShaderManager::createItemShader(const std::string& name, const std::string& file)
{
    PainterShaderProgramPtr shader = createFragmentShader(name, file);
    if(shader)
        setupItemShader(shader);
    return shader;
}
Пример #2
0
	resource::Resource *ShaderLoader::getResourceByName(const String &n)
	{
		// Swap out .cso to .glsl, this way we can find the glsl version of the shader
		String name = n.substr(0, n.find(".cso")) + ".glsl";

		file::File file = fileManager->openFile(name);

		if (!file.isValid())
			return NULL;

		GL2Shader *shader = NULL;

		if (name.find("_p.glsl") != String::npos)
			shader = createFragmentShader(file->getRawData(), file->getSize());

		if (name.find("_vv.glsl") != String::npos)
			shader = createVertexShader(file->getRawData(), file->getSize());

		ShaderResource *resource = new ShaderResource();

		resource->setName(name);
		resource->file = file;
		resource->shader = &shader->header;

		LOG_INFO("[ShaderLoader] Shader loaded: " << name);
		return resource;
	}
Пример #3
0
GLuint createAndLoadFragmentShaderAll()
{
	const GLuint shader_handle = createFragmentShader();
	if (shader_handle == 0){ return 0; }
	{
		const char* shader_source_file_path_list[] = {
			SHADER_SOURCE_BASE_PATH "circle.frag"
		};
		const int shader_source_file_num = countof(shader_source_file_path_list);
		const GLchar** shader_source_file_list = loadShaderSource(shader_source_file_num, shader_source_file_path_list);
		if (shader_source_file_list)
		{
			glShaderSource(shader_handle, shader_source_file_num, shader_source_file_list, NULL);
			freeShaderSource(shader_source_file_num, shader_source_file_list);
			shader_source_file_list = NULL;
		}
	}
	{
		glCompileShader(shader_handle);
		{
			const GLint shader_compile_result = getShaderResult(shader_handle, GL_COMPILE_STATUS);
			if (shader_compile_result == GL_FALSE){ return 0; }
		}
	}
	return shader_handle;
}
Пример #4
0
Shader::Shader(const std::string& vertShader, const std::string& fragShader)
{
    auto vertSrc = getShaderSource(vertShader);
    auto fragSrc = getShaderSource(fragShader);

    createVertexShader(vertSrc);
    createFragmentShader(fragSrc);
    createProgram();
    freeResources();
}
Пример #5
0
std::shared_ptr<IProgram> SimpleDriver::createProgram() {
	auto vs = createVertexShader();
	auto fs = createFragmentShader();
	auto program = m_shaderProgramService->create();
	m_shaderProgramService->addShader(*program, vs);
	m_shaderProgramService->addShader(*program, fs);
	m_shaderProgramService->link(*program);
	m_shaderProgramService->setUniformIDs(*program, std::vector<std::string>{"model", "view", "proj"});
	m_shaderProgramService->setAttributeIDs(*program, std::vector<std::string>{"position"});
	return program;
}
Пример #6
0
ShaderMapType::const_iterator
PrivateShaderCache::addShaderData (const GLShaderParameters &params)
{
    GLShaderData shaderData;

    shaderData.name = params.id ();
    shaderData.fragmentShader = createFragmentShader (params);
    shaderData.vertexShader = createVertexShader (params);

    std::pair<ShaderMapType::iterator, bool> ret =
        shaderMap.insert(std::pair<GLShaderParameters, GLShaderData>(params,shaderData));

    return ret.first;
}
Пример #7
0
FragmentShader::FragmentShader(std::string& _filePath)
{
    load(_filePath.c_str());
    createFragmentShader();
}
Пример #8
0
FragmentShader::FragmentShader(const char* _filePath)
{
    load(_filePath);
    createFragmentShader();
}
	RenderingContext::RenderingContext(CML::CMWindow *window)
	{

		PIXELFORMATDESCRIPTOR pfd =
		{
			sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    //Flags
			PFD_TYPE_RGBA,            //The kind of framebuffer. RGBA or palette.
			24,                        //Colordepth of the framebuffer.		
			24,                        //Number of bits for the depthbuffer
			8,                        //Number of bits for the stencilbuffer
			0,                        //Number of Aux buffers in the framebuffer.
			PFD_MAIN_PLANE
		};
		WORD  nSize = sizeof(PIXELFORMATDESCRIPTOR);
		WORD  nVersion  = 1;
		DWORD dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits  = 24;
		pfd.cRedBits  = 0;
		pfd.cRedShift  = 0;
		pfd.cGreenBits  = 0;
		pfd.cGreenShift  = 0;
		pfd.cBlueBits  = 0;
		pfd.cBlueShift  = 0;
		pfd.cAlphaBits  = 0;
		pfd.cAlphaShift  = 0;
		pfd.cAccumBits  = 0;
		pfd.cAccumRedBits  = 0;
		pfd.cAccumGreenBits  = 0;
		pfd.cAccumBlueBits  = 0;
		pfd.cAccumAlphaBits  = 0;
		pfd.cDepthBits  = 24;
		pfd.cStencilBits  = 8;
		pfd.cAuxBuffers  = 0;
		pfd.iLayerType  = 0;
		pfd.bReserved  = 0;
		DWORD dwLayerMask  = NULL;
		DWORD dwVisibleMask  = NULL;
		DWORD dwDamageMask  = NULL;


		_window = window;
		HDC ourWindowHandleToDeviceContext = GetDC(window->CMWindowHandle());// 
		g_HDC = ourWindowHandleToDeviceContext;
		int  letWindowsChooseThisPixelFormat;
		letWindowsChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext, &pfd);
		SetPixelFormat(ourWindowHandleToDeviceContext, letWindowsChooseThisPixelFormat, &pfd);

		renderingContext = wglCreateContext(ourWindowHandleToDeviceContext);
		wglMakeCurrent(ourWindowHandleToDeviceContext, renderingContext);


		glewInit();


		_program = glCreateProgram();

		createVertexShader();
		createFragmentShader();

		
	}