2 * Copyright (c) 2015 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.
19 #include "sampler-api.h"
22 #include <dali/public-api/object/type-registry.h>
26 #include <rendering/sampler-wrapper.h>
37 * Sampler is a handle to an object that can be used to provide the sampling parameters to sample textures
42 Sampler SamplerApi::GetSampler( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
44 v8::HandleScope handleScope( isolate );
46 v8::Local<v8::Object> object = args.This();
47 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
48 void* ptr = field->Value();
50 SamplerWrapper* wrapper = static_cast< SamplerWrapper *>(ptr);
51 return wrapper->GetSampler();
54 Sampler SamplerApi::GetSamplerFromParams( int paramIndex,
57 const v8::FunctionCallbackInfo< v8::Value >& args )
61 v8::HandleScope handleScope( isolate );
62 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::SAMPLER, isolate, args );
66 SamplerWrapper* wrapper = static_cast< SamplerWrapper *>(wrappedObject);
67 return wrapper->GetSampler();
76 * Create a new sampler object.
81 * @return {Object} Sampler
83 Sampler SamplerApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
85 return Sampler::New();
89 * Set the filter modes for this sampler
90 * @method setFilterMode
92 * @param {integer} minFilter The minification filter that will be used
93 * @param {integer} magFilter The magnification filter that will be used
95 * // filter mode is one of the following
96 * dali.FILTER_MODE_NONE // Use GL system defaults (minification NEAREST_MIPMAP_LINEAR, magnification LINEAR)
97 * dali.FILTER_MODE_DEFAULT // Use dali defaults (minification LINEAR, magnification LINEAR)
98 * dali.FILTER_MODE_NEAREST // Filter nearest
99 * dali.FILTER_MODE_LINEAR // Filter linear
101 * sampler.setFilterMode( dali.FILTER_MODE_DEFAULT, dali.FILTER_MODE_LINEAR );
103 void SamplerApi::SetFilterMode( const v8::FunctionCallbackInfo< v8::Value >& args )
105 v8::Isolate* isolate = args.GetIsolate();
106 v8::HandleScope handleScope( isolate );
108 Sampler sampler = GetSampler( isolate, args );
111 int minFilter = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
114 DALI_SCRIPT_EXCEPTION( isolate, "missing minification filter from param 0" );
119 int magFilter = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0 /* default */);
122 DALI_SCRIPT_EXCEPTION( isolate, "missing magnification filter from param 1" );
126 sampler.SetFilterMode(static_cast<FilterMode::Type>(minFilter), static_cast<FilterMode::Type>(magFilter));
131 * Set the wrap modes for this sampler
132 * @method setWrapMode
134 * @param {integer} uWrap Wrap mode for u coordinates
135 * @param {integer} vWrap Wrap mode for v coordinates
137 * // wrap mode is one of the following
138 * dali.WRAP_MODE_DEFAULT
139 * dali.WRAP_MODE_CLAMP_TO_EDGE
140 * dali.WRAP_MODE_REPEAT
141 * dali.WRAP_MODE_MIRRORED_REPEAT
143 * sampler.setWrapMode( dali.WRAP_MODE_CLAMP_TO_EDGE, dali.WRAP_MODE_REPEAT );
145 void SamplerApi::SetWrapMode( const v8::FunctionCallbackInfo< v8::Value >& args )
147 v8::Isolate* isolate = args.GetIsolate();
148 v8::HandleScope handleScope( isolate );
150 Sampler sampler = GetSampler( isolate, args );
153 int uWrap = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 /* default */);
156 DALI_SCRIPT_EXCEPTION( isolate, "missing wrap mode for u coordinates from param 0" );
161 int vWrap = V8Utils::GetIntegerParameter( PARAMETER_1, found, isolate, args, 0 /* default */);
164 DALI_SCRIPT_EXCEPTION( isolate, "missing wrap mode for v coordinates from param 1" );
168 sampler.SetWrapMode(static_cast<WrapMode::Type>(uWrap), static_cast<WrapMode::Type>(vWrap));
172 } // namespace V8Plugin