Пример #1
0
//------------------------------------------------------------------------------
//## UniformBuffer
TEST_F(Test_Shader_Shader, UniformBuffer)
{
    auto shader1 = Shader::create(LN_ASSETFILE("Shader/UniformBufferTest-1.fx"));

    auto vertexDecl1 = newObject<VertexLayout>();
    vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);

    Vector3 v[] = {
        { 0, 0.5, 0 },
        { 0.5, -0.25, 0 },
        { -0.5, -0.25, 0 },
    };
    auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

    // VertexShader からのみ参照されるパラメータ
    shader1->findParameter("_Color1")->setVector(Vector4(1, 0, 0, 1));

    // PixelShader からのみ参照されるパラメータ
    shader1->findParameter("_Color2")->setVector(Vector4(0, 0, 1, 1));

    auto ctx = Engine::graphicsContext();
    TestEnv::resetGraphicsContext(ctx);
    ctx->setVertexLayout(vertexDecl1);
    ctx->setVertexBuffer(0, vb1);
    ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
    ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
    ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);
    ctx->drawPrimitive(0, 1);

    ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-UniformBuffer-1.png"));
}
Пример #2
0
/* 'checkParameters' checks whether all required parameters have been set. */
bool checkParameters(const std::vector<Parameter *>& parameters)
{
    if (userSettings->showHelp) {
        printHelp( parameters );
        return false;
    }

    for (unsigned int parameterIndex = 0; parameterIndex < parameters.size(); parameterIndex++) {
        if (parameters[parameterIndex]->isRequired()
                && !parameters[parameterIndex]->isSet()) {
            LOG_ERROR(*logStream << "Required parameter "
                      << parameters[parameterIndex]-> getShortName() << "/"
                      << parameters[parameterIndex]-> getLongName() << " "
                      << parameters[parameterIndex]-> getDescription()
                      << " needs to be set." << std::endl);
            return false;
        } //if
    }
    // here handle the tricky fact that at least one of -i or -p needs be set; both are not required.
	bool hasBam = parameters[findParameter("-i",parameters)]->isSet();
	bool hasPin = parameters[findParameter("-p",parameters)]->isSet();
	bool hasPinConfig = parameters[findParameter("-P",parameters)]->isSet();
    if (!hasBam && !hasPin && !hasPinConfig) {
        LOG_ERROR(*logStream
                  << "Bam and/or pindel input file required, use -p, -P and/or -i to designate input file(s)."
                  << std::endl);
        return false;
    }
    return true;
}
Пример #3
0
void SmilText::process()
{
    SmilMedia::process();
    SmilMediaParam *p = findParameter("foregroundColor");
    if (!p)
        p = findParameter("foreground-color");
    if (p)
        textColor = parseColor(p->value);
    if (!source.isEmpty() && !waiting) {
        waiting = true;
        sys->transferServer()->requestData(this, source);
    }
}
QVariant ConfigMap::getValue(const std::string& name, const std::vector<quint16>& array) const
{
    ParameterMap::const_iterator f = findParameter(name);
    if (f == m_map.end())
        return QVariant(QString(QObject::tr("undefined")));

    Parameter p = f->second;
    int index = -1;
    for (auto interval : m_registersIntervals)
        if (interval.in(p.m_registerNumber))
        {
            index = p.m_registerNumber - interval.first;
            break;
        }

    assert(index != -1);
  
    int ret = array[index];

    QString errorDescription;
    if (!f->second.m_errorDetector.isValid(ret,errorDescription))
    {
        return QVariant(errorDescription);
    }

    if (p.m_isBool)
    {
        ret =  (ret & (1 << p.m_bitNumber)) ? 1 : 0;
    }

    if (!p.m_decodeMethod.empty())
        ret = decodeWithMethod(ret, p.m_decodeMethod);

    return QVariant(ret);
}
Пример #5
0
bool DrawRule::isJSFunction(StyleParamKey _key) const {
    auto& param = findParameter(_key);
    if (!param) {
        return false;
    }
    return param.function >= 0;
}
Пример #6
0
 virtual void bindStringParam(const char *name, size32_t len, const char *val)
 {
     size32_t utf8chars;
     char *utf8;
     rtlStrToUtf8X(utf8chars, utf8, len, val);
     checkSqliteError(sqlite3_bind_text(stmt, findParameter(name), utf8, rtlUtf8Size(len, utf8), rtlFree));
 }
std::string ConfigMap::getParameterDescription(const std::string& name) const
{
    std::string rc;
    ParameterMap::const_iterator f = findParameter(name);
    if (f != m_map.end())
        rc = f->second.m_description;
    return rc;
}
int  ConfigMap::getRegisterNumber(const std::string& name) const
{
    if (!haveVariableWithName(name))
        return -1;

    Parameter p = findParameter(name)->second;
    return p.m_registerNumber;
}
Пример #9
0
void ParameterManager::setParameterFilters(const std::string &name, const std::string &filters)
{
   auto p = findParameter(name);
   auto sp = dynamic_cast<StringParameter *>(p.get());
   assert(sp);
   if (sp)
       setParameterFilters(sp, filters);
}
Пример #10
0
	bool insertParameter(char** str, const vx::sorted_vector<vx::StringID, vx::gl::ShaderParameter> &params, vx::StackAllocator* scratchAllocator)
	{
		auto paramBegin = findParameter(*str);
		auto sizeToParam = paramBegin - *str;
		if (paramBegin[0] == '\0')
			return false;

		++paramBegin;

		auto paramEnd = findParameter(paramBegin);
		if (paramEnd[0] == '\0')
			return false;

		auto paramNameSize = paramEnd - paramBegin;
		char paramName[64] = {};
		strncpy(paramName, paramBegin, paramNameSize);

		auto it = params.find(vx::make_sid(paramName));
		if (it == params.end())
		{
			printf("could not find value for parameter '%s'\n", paramName);
			return false;
		}

		++paramEnd;

		auto sizeToEnd = strlen(paramEnd);

		char paramBuffer[64] = {};

		auto valueSize = (*it)(paramBuffer);

		auto bufferSize = sizeToParam + valueSize + sizeToEnd;

		auto newText = (char*)scratchAllocator->allocate(bufferSize + 1);
		memset(newText, 0, bufferSize + 1);

		strncpy(newText, *str, sizeToParam);
		strncpy(newText + sizeToParam, paramBuffer, valueSize);
		strncpy(newText + sizeToParam + valueSize, paramEnd, sizeToEnd);

		*str = newText;

		return true;
	}
Пример #11
0
const string contentTypeField::getBoundary() const
{
	shared_ptr <parameter> param = findParameter("boundary");

	if (param)
		return param->getValue().getBuffer();
	else
		return "";
}
Пример #12
0
const charset contentTypeField::getCharset() const
{
	shared_ptr <parameter> param = findParameter("charset");

	if (param)
		return param->getValueAs <charset>();
	else
		return charset();
}
Пример #13
0
const string contentTypeField::getReportType() const
{
	shared_ptr <parameter> param = findParameter("report-type");

	if (param)
		return param->getValue().getBuffer();
	else
		return "";
}
Пример #14
0
//------------------------------------------------------------------------------
//## MultiTechMultiTexture
TEST_F(Test_Shader_Shader, MultiTechMultiTexture)
{
    auto shader1 = Shader::create(LN_ASSETFILE("Shader/MultiTechMultiTexture-1.fx"));

    auto vertexDecl1 = newObject<VertexLayout>();
    vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);

    Vector3 v[] = {
        { 0, 0.5, 0 },
        { 0.5, -0.25, 0 },
        { -0.5, -0.25, 0 },
    };
    auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

    auto t1 = Texture2D::create(2, 2, TextureFormat::RGBA8);
    t1->clear(Color::Red);
    shader1->findParameter("_Texture1")->setTexture(t1);

    auto t2 = Texture2D::create(2, 2, TextureFormat::RGBA8);
    t2->clear(Color::Green);
    shader1->findParameter("_Texture2")->setTexture(t2);

    auto ctx = Engine::graphicsContext();
    TestEnv::resetGraphicsContext(ctx);
    ctx->setVertexLayout(vertexDecl1);
    ctx->setVertexBuffer(0, vb1);
    ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
    ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);

	// _Texture1 のみ (赤)
    ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
    ctx->drawPrimitive(0, 1);
    ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-MultiTechMultiTexture-1.png"));

	// _Texture2 のみ (緑)
    ctx->setShaderPass(shader1->techniques()[1]->passes()[0]);
    ctx->drawPrimitive(0, 1);
    ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-MultiTechMultiTexture-2.png"));

	// _Texture1 + _Texture2 (黄)
	ctx->setShaderPass(shader1->techniques()[2]->passes()[0]);
	ctx->drawPrimitive(0, 1);
	ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-MultiTechMultiTexture-3.png"));
}
const TraceEvent::TraceValueUnion& TraceEventDispatcher::TraceEvent::parameter(const char* name, unsigned char expectedType) const
{
    static WebCore::TraceEvent::TraceValueUnion missingValue;
    size_t index = findParameter(name);
    if (index == kNotFound || m_argumentTypes[index] != expectedType) {
        ASSERT_NOT_REACHED();
        return missingValue;
    }
    return *reinterpret_cast<const WebCore::TraceEvent::TraceValueUnion*>(m_argumentValues + index);
}
Пример #16
0
const std::string& DrawRule::getStyleName() const {

    const auto& style = findParameter(StyleParamKey::style);

    if (style) {
        return style.value.get<std::string>();
    } else {
        return *name;
    }
}
Пример #17
0
parameter* command::addParameter(parameter *par)
{
	assert(par);
	parameter *pParam = nullptr;
	if(pParam = findParameter(par->getName())) return pParam;

	pParam = new parameter(par);
	m_vecParameter.push_back(pParam);
	return pParam;
}
Пример #18
0
parameter* command::addParameter(PCWSTR pparamName, double dblValue)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	if(pParam = findParameter(pparamName)) return pParam;

	pParam = new parameter(pparamName, dblValue);
	m_vecParameter.push_back(pParam);

	return pParam;
}
Пример #19
0
parameter* command::addParameter(PCWSTR pparamName, const std::wstring &wsValue)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	if(pParam = findParameter(pparamName)) return pParam;

	pParam = new parameter(pparamName, wsValue);
	m_vecParameter.push_back(pParam);

	return pParam;
}
Пример #20
0
parameter* command::addParameter(PCWSTR pparamName, const gtc::datetime &dtValue)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	if(pParam = findParameter(pparamName)) return pParam;

	pParam = new parameter(pparamName, dtValue);
	m_vecParameter.push_back(pParam);

	return pParam;
}
Пример #21
0
parameter* command::addParameter(PCWSTR pparamName, const SBDataType &sbData)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	if(pParam = findParameter(pparamName)) return pParam;

	pParam = new parameter(pparamName, sbData);
	m_vecParameter.push_back(pParam);

	return pParam;
}
Пример #22
0
const TraceEvent::TraceValueUnion& TraceEventDispatcher::TraceEvent::parameter(const char* name, unsigned char expectedType) const
{
    static blink::TraceEvent::TraceValueUnion missingValue;
    size_t index = findParameter(name);
    ASSERT(isMainThread());
    if (index == kNotFound || m_argumentTypes[index] != expectedType) {
        ASSERT_NOT_REACHED();
        return missingValue;
    }
    return m_argumentValues[index];
}
Пример #23
0
parameter* command::updateParameter(PCWSTR pparamName, const std::wstring &wsValue)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	pParam = findParameter(pparamName);
	assert(pParam);
	if(pParam)
	{
		pParam->setValue(wsValue);
	}
	return pParam;
}
Пример #24
0
parameter* command::updateParameter(PCWSTR pparamName, const gtc::datetime &dtValue)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	pParam = findParameter(pparamName);
	assert(pParam);
	if(pParam)
	{
		pParam->setValue(dtValue);
	}
	return pParam;
}
Пример #25
0
parameter* command::updateParameter(PCWSTR pparamName, const SBDataType &sbData)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	pParam = findParameter(pparamName);
	assert(pParam);
	if(pParam)
	{
		pParam->setValue(sbData);
	}
	return pParam;
}
Пример #26
0
parameter* command::updateParameter(PCWSTR pparamName)
{	//将指定参数值设为null
	assert(pparamName);
	parameter *pParam = nullptr;
	pParam = findParameter(pparamName);
	assert(pParam);
	if(pParam)
	{
		pParam->setValue(gtc::variant::null);
	}
	return pParam;
}	
Пример #27
0
parameter* command::updateParameter(PCWSTR pparamName, double dblValue)
{
	assert(pparamName);
	parameter *pParam = nullptr;
	pParam = findParameter(pparamName);
	assert(pParam);
	if(pParam)
	{
		pParam->setValue(dblValue);
	}
	return pParam;
}
Пример #28
0
//------------------------------------------------------------------------------
//## Basic
TEST_F(Test_Shader_Shader, IndependentSamplerState)
{
    auto shader1 = Shader::create(LN_ASSETFILE("Shader/IndependentSamplerState.fx"));

    auto vertexDecl1 = newObject<VertexLayout>();
    vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
    vertexDecl1->addElement(0, VertexElementType::Float2, VertexElementUsage::TexCoord, 0);

    struct Vertex
    {
        Vector3 pos;
        Vector2 uv;
    };
    Vertex v[] = {
        { { -1, 1, 0 }, { 0, 0 }, },	// 0.5 で中央の face からサンプリングする
        { { 0, 1, 0 }, { 1, 0 }, },
        { { -1, 0, 0 }, { 0, 1 }, },
        { { 0, 0, 0 }, { 1, 1 }, },
    };
    auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

    auto tex1 = newObject<Texture2D>(2, 2, TextureFormat::RGBA8);
    auto bmp1 = tex1->map(MapMode::Write);
    bmp1->setPixel32(0, 0, ColorI(255, 0, 0, 255));
    bmp1->setPixel32(1, 0, ColorI(255, 0, 255, 255));
    bmp1->setPixel32(0, 1, ColorI(0, 255, 0, 255));
    bmp1->setPixel32(1, 1, ColorI(0, 0, 255, 255));

    // TODO: まだ SamplerState 直接指定をサポートしていないので Texture に対してセットする方法でテストケースだけ用意しておく。
    // 後でサポートするとき、shader1->findParameter("mySamplerState")->setSamplerState(samplerState); とかに書き換える。
    auto samplerState = newObject<SamplerState>();
    samplerState->setFilterMode(TextureFilterMode::Linear);
    tex1->setSamplerState(samplerState);

    shader1->findParameter("_Texture")->setTexture(tex1);

    auto ctx = Engine::graphicsContext();
    TestEnv::resetGraphicsContext(ctx);
    ctx->setVertexLayout(vertexDecl1);
    ctx->setVertexBuffer(0, vb1);
    ctx->setIndexBuffer(nullptr);
    ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);

    // * [ ] default
    {
        ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);
		ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
        ctx->drawPrimitive(0, 2);

        ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-IndependentSamplerState-1.png"));
    }
}
bool ConfigMap::isVariableBool(const std::string& name, int& bitNumber)
{
    assert(haveVariableWithName(name));

    Parameter p = findParameter(name)->second;
    if (p.m_isBool)
    {
        bitNumber = p.m_bitNumber;
        return true;
    }
    
    return false;
}
Пример #30
0
/* 'readParameters' reads the parameters as entered in the command line. */
void readParameters(int argc, char *argv[], std::vector<Parameter *>& parameters)
{

    for (int argumentIndex = 1; argumentIndex < argc; argumentIndex++) {
        std::string currentArgument = argv[argumentIndex];

        //find argument in parameterlist
        int parameterIndex = findParameter(currentArgument, parameters);
        if (parameterIndex == -1) {
            LOG_ERROR(*logStream << "unknown argument: " << currentArgument << std::endl);
            return;
        }

        if (parameters[parameterIndex]->isUnary()) {
            parameters[parameterIndex]->setValue(true); // default
            if ((argumentIndex + 1 < argc) && (argv[argumentIndex + 1][0]
                                               != '-')) { // so there are more arguments, and next one isn't regular -x
                if (tolower(argv[argumentIndex + 1][0]) == 'f'
                        || (argv[argumentIndex + 1][0] == '0')) {
                    parameters[parameterIndex]->setValue(false);
                }
                argumentIndex++; // in any case increase the argument index
            }
        }
        else {   // argument needs a parameter
            argumentIndex++; // move on to next argument in the list
            if (argumentIndex >= argc) {
                LOG_ERROR(*logStream << "argument of " << currentArgument << " lacking.\n");
                return;
            }
            if (argv[argumentIndex][0] == '-') {
                LOG_ERROR(*logStream << "argument of " << currentArgument
                          << " seems erroneous.\n");
                return;
            }
            // but if everything is allright,
            LOG_DEBUG(*logStream << "Giving " << currentArgument << " the value " << argv[ argumentIndex ] << std::endl);
            parameters[parameterIndex]->setValue(
                std::string(argv[argumentIndex]));
        }
    }
}