angle::Result PixelTransfer11::buildShaderMap(const gl::Context *context) { d3d11::PixelShader bufferToTextureFloat; d3d11::PixelShader bufferToTextureInt; d3d11::PixelShader bufferToTextureUint; Context11 *context11 = GetImplAs<Context11>(context); ANGLE_TRY(mRenderer->allocateResource(context11, ShaderData(g_PS_BufferToTexture_4F), &bufferToTextureFloat)); ANGLE_TRY(mRenderer->allocateResource(context11, ShaderData(g_PS_BufferToTexture_4I), &bufferToTextureInt)); ANGLE_TRY(mRenderer->allocateResource(context11, ShaderData(g_PS_BufferToTexture_4UI), &bufferToTextureUint)); bufferToTextureFloat.setDebugName("BufferToTexture RGBA ps"); bufferToTextureInt.setDebugName("BufferToTexture RGBA-I ps"); bufferToTextureUint.setDebugName("BufferToTexture RGBA-UI ps"); mBufferToTexturePSMap[GL_FLOAT] = std::move(bufferToTextureFloat); mBufferToTexturePSMap[GL_INT] = std::move(bufferToTextureInt); mBufferToTexturePSMap[GL_UNSIGNED_INT] = std::move(bufferToTextureUint); return angle::Result::Continue(); }
kore::Transform::Transform(void) : _global(glm::mat4(1.0f)), _local(glm::mat4(1.0f)), _normalWS(1.0f), _globalI(1.0f), kore::SceneNodeComponent() { ShaderData input = ShaderData(); input.type = GL_FLOAT_MAT4; input.name = "model Matrix"; input.data = glm::value_ptr(_global); input.component = this; _shaderData.push_back(input); input = ShaderData(); input.type = GL_FLOAT_MAT4; input.name = "inverse model Matrix"; input.data = glm::value_ptr(_globalI); input.component = this; _shaderData.push_back(input); input = ShaderData(); input.type = GL_FLOAT_MAT4; input.name = "object Matrix"; input.data = glm::value_ptr(_local); input.component = this; _shaderData.push_back(input); input = ShaderData(); input.type = GL_FLOAT_MAT3; input.name = "normal Matrix"; input.data = glm::value_ptr(_normalWS); input.component = this; _shaderData.push_back(input); _type = COMPONENT_TRANSFORM; }
RayCastRenderer::RayCastRenderer( const GLEWContext* glewContext, const uint32_t samples, const uint32_t componentCount, const GLenum gpuDataType, const GLint internalFormat ) : Renderer( componentCount, gpuDataType, internalFormat ) , nSamples_( samples ) , transferFunctionTexture_( 0 ) { if( !glewContext ) LBTHROW( std::runtime_error( "No GLEW context given" + where( __FILE__, __LINE__ ))); TransferFunction1D< unsigned char > transferFunction; initTransferFunction( transferFunction ); shadersPtr_.reset( new GLSLShaders ); // TODO: Add the shaders from resource directory const int error = shadersPtr_->loadShaders( ShaderData( vertRayCast_glsl, fragRayCast_glsl )); if( error != GL_NO_ERROR ) LBTHROW( std::runtime_error( "Can't load glsl shaders: " + eq::glError( error ) + where( __FILE__, __LINE__ ))); framebufferTempTexturePtr_.reset( new eq::util::Texture( GL_TEXTURE_RECTANGLE_ARB, glewContext )); }
void PhysicsDebug::drawLine(const btVector3& from,const btVector3& to,const btVector3& color) { D3D11_MAPPED_SUBRESOURCE mapStruct; ZeroMemory(&mapStruct, sizeof(mapStruct)); ColourVertex vertexSet[] = { ColourVertex(D3DXVECTOR3(to.x(), to.y(), to.z()), D3DXVECTOR4(color.x(), color.y(), color.z(), 1.0f)), ColourVertex(D3DXVECTOR3(from.x(), from.y(), from.z()), D3DXVECTOR4(color.x(), color.y(), color.z(), 1.0f)) }; if(mContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapStruct) != S_OK) { std::cerr << "Buffer Mapping Failed!" << std::endl; return; } memcpy(mapStruct.pData, &vertexSet[0], sizeof(ColourVertex) * mTotalIndices); mContext->Unmap(mBuffer, 0); mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); mShader.RenderVertexBuffer(mTotalIndices, mBuffer, mDevice, mContext, &ShaderData(mGameCam)); }
GL2Batch::GL2Batch(VAOContainer&& vC, const UniformHolder& uC) : vaoContainer(vC), uniformContainer(uC) { // Setup vbo data buffers for (VBOContainer& vbc : vaoContainer.vbos) { shaderData.emplace(vbc.ref, ShaderData(&vbc, 32 * vbc.stride)); } includeToMap(shaderData, uniformContainer, 0); renderMode = GL_TRIANGLE_STRIP; }
gl::Error PixelTransfer11::buildShaderMap() { d3d11::PixelShader bufferToTextureFloat; d3d11::PixelShader bufferToTextureInt; d3d11::PixelShader bufferToTextureUint; ANGLE_TRY( mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4F), &bufferToTextureFloat)); ANGLE_TRY( mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4I), &bufferToTextureInt)); ANGLE_TRY( mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4UI), &bufferToTextureUint)); bufferToTextureFloat.setDebugName("BufferToTexture RGBA ps"); bufferToTextureInt.setDebugName("BufferToTexture RGBA-I ps"); bufferToTextureUint.setDebugName("BufferToTexture RGBA-UI ps"); mBufferToTexturePSMap[GL_FLOAT] = std::move(bufferToTextureFloat); mBufferToTexturePSMap[GL_INT] = std::move(bufferToTextureInt); mBufferToTexturePSMap[GL_UNSIGNED_INT] = std::move(bufferToTextureUint); return gl::NoError(); }
Impl( const uint32_t samplesPerRay, const uint32_t samplesPerPixel, const VolumeInformation& volInfo ) : _framebufferTexture( GL_TEXTURE_RECTANGLE_ARB, glewGetContext( )) , _nSamplesPerRay( samplesPerRay ) , _nSamplesPerPixel( samplesPerPixel ) , _computedSamplesPerRay( samplesPerRay ) , _volInfo( volInfo ) , _transferFunctionTexture( 0 ) { TransferFunction1D transferFunction; initTransferFunction( transferFunction ); // TODO: Add the shaders from resource directory const int error = _shaders.loadShaders( ShaderData( vertRayCast_glsl, fragRayCast_glsl )); if( error != GL_NO_ERROR ) LBTHROW( std::runtime_error( "Can't load glsl shaders: " + eq::glError( error ) + where( __FILE__, __LINE__ ))); }
bool CPreProcessor::found_include_directive(ContextT const& ctx, std::string const& filename, bool include_next) { //std::cout << "found_include_directive:" << filename << std::endl; boost::regex systemIncludeRegex("<.*>"); if ( !boost::regex_match(filename, systemIncludeRegex)) { std::string editedFilename = filename; // remove any quotations around the filename boost::algorithm::erase_all(editedFilename, "\""); //std::stringstream msg; //msg << "adding: " << editedFilename << " size: " << shaderData_.size(); //LOG_DEBUG( msg.str() ); shaderData_.push_back(ShaderData(editedFilename)); } // ok to include this file return false; }
bool CShaderManager::addShader(GLint shaderIndex, string vertexFile, string fragmentFile) { GLhandleARB v,f; v = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); f = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); string _v = textFileRead(vertexFile); string _f = textFileRead(fragmentFile); if (_v=="" || _f=="") { lastError = "Shader files missing or invalid!"; return false; } const char * vv = _v.c_str(); const char * ff = _f.c_str(); glShaderSourceARB(v,1,&vv,NULL); glShaderSourceARB(f,1,&ff,NULL); glCompileShaderARB(v); glCompileShaderARB(f); GLhandleARB shaderProgram = glCreateProgramObjectARB(); glAttachObjectARB(shaderProgram,v); glAttachObjectARB(shaderProgram,f); glLinkProgramARB(shaderProgram); shaderPrograms[shaderIndex]=ShaderData(shaderProgram); return printInfoLog(shaderProgram); }
void ShaderInterface::clear() { m_mainShader = m_portsShader = ShaderData(); m_parameters.clear(); }
angle::Result PixelTransfer11::loadResources(const gl::Context *context) { if (mResourcesLoaded) { return angle::Result::Continue(); } D3D11_RASTERIZER_DESC rasterDesc; rasterDesc.FillMode = D3D11_FILL_SOLID; rasterDesc.CullMode = D3D11_CULL_NONE; rasterDesc.FrontCounterClockwise = FALSE; rasterDesc.DepthBias = 0; rasterDesc.SlopeScaledDepthBias = 0.0f; rasterDesc.DepthBiasClamp = 0.0f; rasterDesc.DepthClipEnable = TRUE; rasterDesc.ScissorEnable = FALSE; rasterDesc.MultisampleEnable = FALSE; rasterDesc.AntialiasedLineEnable = FALSE; Context11 *context11 = GetImplAs<Context11>(context); ANGLE_TRY(mRenderer->allocateResource(context11, rasterDesc, &mCopyRasterizerState)); D3D11_DEPTH_STENCIL_DESC depthStencilDesc; depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.StencilEnable = FALSE; depthStencilDesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK; depthStencilDesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK; depthStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS; depthStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; ANGLE_TRY(mRenderer->allocateResource(context11, depthStencilDesc, &mCopyDepthStencilState)); D3D11_BUFFER_DESC constantBufferDesc = { 0 }; constantBufferDesc.ByteWidth = roundUp<UINT>(sizeof(CopyShaderParams), 32u); constantBufferDesc.Usage = D3D11_USAGE_DYNAMIC; constantBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; constantBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; constantBufferDesc.MiscFlags = 0; constantBufferDesc.StructureByteStride = 0; ANGLE_TRY(mRenderer->allocateResource(context11, constantBufferDesc, &mParamsConstantBuffer)); mParamsConstantBuffer.setDebugName("PixelTransfer11 constant buffer"); // init shaders ANGLE_TRY(mRenderer->allocateResource(context11, ShaderData(g_VS_BufferToTexture), &mBufferToTextureVS)); mBufferToTextureVS.setDebugName("BufferToTexture VS"); ANGLE_TRY(mRenderer->allocateResource(context11, ShaderData(g_GS_BufferToTexture), &mBufferToTextureGS)); mBufferToTextureGS.setDebugName("BufferToTexture GS"); ANGLE_TRY(buildShaderMap(context)); StructZero(&mParamsData); mResourcesLoaded = true; return angle::Result::Continue(); }
static void includeToMap(ShaderDataMap& map, const UniformHolder& holder, u32 instance) { for (const UniformContainer& it : holder.containers) { map.emplace(it.ref, ShaderData(&it, it.stride)); } }
kore::Camera::Camera() :_fMovementSpeed(50.0f), _fFovDeg(0.0f), _fFar(0.0f), _fNear(0.0f), _matView(1.0f), _matProjection(1.0f), _matViewInverse(1.0f), _matViewProj(1.0f), _fFocalLength(0.0f), _bIsOrtho(false), _fWidth(1.0f), _fHeight(1.0), _name(""), kore::SceneNodeComponent() { // setup bindings ShaderData tmp; tmp.type = GL_FLOAT_MAT4; tmp.name = "view Matrix"; tmp.data = glm::value_ptr(_matView); _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT_MAT4; tmp.name = "inverse view Matrix"; tmp.data = glm::value_ptr(_matViewInverse); _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT_MAT4; tmp.name = "projection Matrix"; tmp.data = glm::value_ptr(_matProjection); _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT_MAT4; tmp.name = "view projection Matrix"; tmp.data = glm::value_ptr(_matViewProj); _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT; tmp.name = "FOV degree"; tmp.data = &_fFovDeg; _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT; tmp.name = "near Plane"; tmp.data = &_fNear; _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT; tmp.name = "far Plane"; tmp.data = &_fFar; _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT; tmp.name = "focal length"; tmp.data = &_fFocalLength; _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT; tmp.name = "width"; tmp.data = &_fWidth; _shaderData.push_back(tmp); tmp = ShaderData(); tmp.type = GL_FLOAT; tmp.name = "height"; tmp.data = &_fHeight; _shaderData.push_back(tmp); _type = COMPONENT_CAMERA; }
/** * @brief Load shaders. * @param aVertexShaderFilename Name of vertex shader. * @param aFragmentShaderFilename Name of fragment shader. */ void PCShaderSurface::LoadShaders(HashString const &aVertexShaderFilename, HashString const &aFragmentShaderFilename) { mVertexShaderFileName = aVertexShaderFilename; mFragmentShaderFileName = aFragmentShaderFilename; HashString shaderKey = aVertexShaderFilename + aFragmentShaderFilename; if(GetManager()->ShaderDataExists(shaderKey)) { mProgramID = GetManager()->GetShaderData(shaderKey).mProgramID; return; } std::ifstream vertexFile(Common::RelativePath("Shaders", aVertexShaderFilename.ToCharArray()).c_str()); std::ifstream fragmentFile(Common::RelativePath("Shaders", aFragmentShaderFilename.ToCharArray()).c_str()); if(vertexFile.is_open() && fragmentFile.is_open()) { GLenum program = glCreateProgram(); GLenum vertexShader = glCreateShader(GL_VERTEX_SHADER); GLenum fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); GLint didCompile = 0; GLint isLinked = 0; HashString vertexFileContents = std::string((std::istreambuf_iterator<char>(vertexFile)), std::istreambuf_iterator<char>()); const char* vertexContents = vertexFileContents.ToCharArray(); // Compile glShaderSource(vertexShader, 1, &vertexContents, NULL); glCompileShader(vertexShader); glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &didCompile); if(didCompile == GL_FALSE) { DebugLogPrint("VERTEX SHADER %s READ:\n%s\n", aVertexShaderFilename.ToCharArray(), vertexContents); GLint maxLength = 0; glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &maxLength); //The maxLength includes the NULL character std::vector<char> infoLog(maxLength); glGetShaderInfoLog(vertexShader, maxLength, &maxLength, &infoLog[0]); DebugLogPrint("GLERROR %s: %s\n", aVertexShaderFilename.ToCharArray(), &infoLog[0]); //We don't need the shader anymore. glDeleteShader(vertexShader); } HashString fragmentFileContents = std::string((std::istreambuf_iterator<char>(fragmentFile)), std::istreambuf_iterator<char>()); const char* fragmentContents = fragmentFileContents.ToCharArray(); glShaderSource(fragmentShader, 1, &fragmentContents, NULL); glCompileShader(fragmentShader); glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &didCompile); if(didCompile == GL_FALSE) { DebugLogPrint("FRAGMENT SHADER %s READ:\n%s\n", aFragmentShaderFilename.ToCharArray(), fragmentContents); GLint maxLength = 0; glGetShaderiv(fragmentShader, GL_INFO_LOG_LENGTH, &maxLength); //The maxLength includes the NULL character std::vector<char> infoLog(maxLength); glGetShaderInfoLog(fragmentShader, maxLength, &maxLength, &infoLog[0]); DebugLogPrint("GLERROR %s: %s\n", aFragmentShaderFilename.ToCharArray(), &infoLog[0]); //We don't need the shader anymore. glDeleteShader(fragmentShader); } // Linking glAttachShader(program, vertexShader); glAttachShader(program, fragmentShader); glLinkProgram(program); glGetProgramiv(program, GL_LINK_STATUS, &isLinked); if(isLinked == GL_FALSE) { GLint maxLength = 0; glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength); //The maxLength includes the NULL character std::vector<GLchar> infoLog(maxLength); glGetProgramInfoLog(program, maxLength, &maxLength, &infoLog[0]); //We don't need the program anymore. glDeleteProgram(program); //Don't leak shaders either. glDeleteShader(vertexShader); glDeleteShader(fragmentShader); DebugLogPrint("GL LINK ERROR: %s\n", &infoLog[0]); } GetManager()->AddShaderPairing(shaderKey, ShaderData(program, vertexShader, fragmentShader, vertexContents, fragmentContents)); mProgramID = program; } else { DebugLogPrint("No shader with name %s or %s found\n", aVertexShaderFilename.ToCharArray(), aFragmentShaderFilename.ToCharArray()); assert(!"Shader file not found."); } }