2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "texture-set-api.h"
23 #include <dali/public-api/object/type-registry.h>
27 #include <rendering/texture-set-wrapper.h>
28 #include <rendering/shader-wrapper.h>
29 #include <rendering/shader-api.h>
30 #include <rendering/sampler-wrapper.h>
31 #include <rendering/sampler-api.h>
32 #include <image/image-wrapper.h>
43 * TextureSet is a handle to an object that contains the textures used by a renderer
49 TextureSet TextureSetApi::GetTextureSet( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
51 v8::HandleScope handleScope( isolate );
53 v8::Local<v8::Object> object = args.This();
54 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
55 void* ptr = field->Value();
57 TextureSetWrapper* wrapper = static_cast< TextureSetWrapper *>(ptr);
58 return wrapper->GetTextureSet();
61 TextureSet TextureSetApi::GetTextureSetFromParams( int paramIndex,
64 const v8::FunctionCallbackInfo< v8::Value >& args )
68 v8::HandleScope handleScope( isolate );
69 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::TEXTURE_SET, isolate, args );
73 TextureSetWrapper* wrapper = static_cast< TextureSetWrapper *>(wrappedObject);
74 return wrapper->GetTextureSet();
83 * Create a new texture set object.
88 * @return {Object} TextureSet
90 TextureSet TextureSetApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
92 return TextureSet::New();
96 * Set the sampler used by a given texture
99 * @param {integer} index The index of the texture in the array of textures
100 * @param {Object} sampler The new sampler
102 void TextureSetApi::SetSampler( const v8::FunctionCallbackInfo< v8::Value >& args )
104 v8::Isolate* isolate = args.GetIsolate();
105 v8::HandleScope handleScope( isolate );
107 TextureSet textureSet = GetTextureSet( isolate, args );
110 int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
113 DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
118 Sampler sampler = SamplerApi::GetSamplerFromParams( PARAMETER_1, found, isolate, args );
121 DALI_SCRIPT_EXCEPTION( isolate, "missing sampler from param 1" );
125 textureSet.SetSampler(index, sampler);
129 } // namespace V8Plugin