MCPcopy Create free account
hub / github.com/crownengine/crown / compile_render_state

Method compile_render_state

src/resource/shader_resource.cpp:2923–2976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2921 }
2922
2923 s32 compile_render_state(RenderState::State &state, const char *render_state, const Vector<DynamicString> &defines)
2924 {
2925 TempAllocator512 taa;
2926 DynamicString key(taa);
2927 key = render_state;
2928 const RenderState rs_default(default_allocator());
2929 const RenderState &rs = hash_map::get(_render_states, key, rs_default);
2930
2931 // Compile inherited state if any.
2932 if (!(rs._inherit == "")) {
2933 RETURN_IF_FALSE(SHADER_RESOURCE, hash_map::has(_render_states, rs._inherit)
2934 , _opts
2935 , "Unknown inherit render state: '%s'"
2936 , rs._inherit.c_str()
2937 );
2938
2939 s32 err = compile_render_state(state, rs._inherit.c_str(), defines);
2940 ENSURE_OR_RETURN(SHADER_RESOURCE, err == 0, _opts);
2941 }
2942
2943 // Evaluate expressions and apply states.
2944 if (vector::size(rs._expressions) > 0) {
2945 // Convert defines to plain array.
2946 u32 num_constants = vector::size(defines);
2947 const char **constants = (const char **)default_allocator().allocate(num_constants * sizeof(char *));
2948 f32 *constant_values = (f32 *)default_allocator().allocate(num_constants * sizeof(f32 *));
2949 for (u32 i = 0; i < num_constants; ++i) {
2950 constants[i] = defines[i].c_str();
2951 constant_values[i] = 1.0f;
2952 }
2953
2954 // Evaluate expressions in the same order they occur
2955 // in the source file.
2956 for (u32 i = 0; i < vector::size(rs._expressions); ++i) {
2957 const u32 state_index = rs._states_indices[i].index;
2958 const char *expr = rs._expressions[state_index].c_str();
2959 const RenderState::State &cond_state = rs._states[state_index];
2960
2961 bool eval_result = eval(expr
2962 , num_constants
2963 , constants
2964 , constant_values
2965 , _opts
2966 );
2967 if (eval_result)
2968 state.overwrite_changed_properties(cond_state);
2969 }
2970
2971 default_allocator().deallocate(constant_values);
2972 default_allocator().deallocate(constants);
2973 }
2974
2975 return 0;
2976 }
2977 };
2978
2979 s32 compile(CompileOptions &opts)

Callers

nothing calls this directly

Calls 7

getFunction · 0.85
hasFunction · 0.50
sizeFunction · 0.50
c_strMethod · 0.45
allocateMethod · 0.45
deallocateMethod · 0.45

Tested by

no test coverage detected