1 /*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include "SamplerData.h"
18
19 #include "aemu/base/files/StreamSerializing.h"
20 #include "GLcommon/GLEScontext.h"
21
SamplerData(android::base::Stream * stream)22 SamplerData::SamplerData(android::base::Stream* stream)
23 : ObjectData(stream) {
24 if (stream) {
25 android::base::loadCollection(stream, &mParamis,
26 [](android::base::Stream* stream) {
27 GLuint idx = stream->getBe32();
28 GLuint val = stream->getBe32();
29 return std::make_pair(idx, val);
30 });
31 android::base::loadCollection(stream, &mParamfs,
32 [](android::base::Stream* stream) {
33 GLuint idx = stream->getBe32();
34 GLfloat val = stream->getFloat();
35 return std::make_pair(idx, val);
36 });
37 }
38 }
39
onSave(android::base::Stream * stream,unsigned int globalName) const40 void SamplerData::onSave(android::base::Stream* stream, unsigned int globalName) const {
41 ObjectData::onSave(stream, globalName);
42 android::base::saveCollection(stream, mParamis,
43 [](android::base::Stream* stream,
44 const std::pair<const GLenum, GLuint>& item) {
45 stream->putBe32(item.first);
46 stream->putBe32(item.second);
47 });
48 android::base::saveCollection(stream, mParamfs,
49 [](android::base::Stream* stream,
50 const std::pair<const GLenum, GLfloat>& item) {
51 stream->putBe32(item.first);
52 stream->putFloat(item.second);
53 });
54 }
55
restore(ObjectLocalName localName,const getGlobalName_t & getGlobalName)56 void SamplerData::restore(ObjectLocalName localName,
57 const getGlobalName_t& getGlobalName) {
58 ObjectData::restore(localName, getGlobalName);
59 int globalName = getGlobalName(NamedObjectType::SAMPLER,
60 localName);
61 GLDispatch& dispatcher = GLEScontext::dispatcher();
62 for (auto& param : mParamis) {
63 dispatcher.glSamplerParameteri(globalName, param.first, param.second);
64 }
65 for (auto& param : mParamfs) {
66 dispatcher.glSamplerParameterf(globalName, param.first, param.second);
67 }
68 }
69
setParami(GLenum pname,GLint param)70 void SamplerData::setParami(GLenum pname, GLint param) {
71 mParamis[pname] = param;
72 }
73
setParamf(GLenum pname,GLfloat param)74 void SamplerData::setParamf(GLenum pname, GLfloat param) {
75 mParamfs[pname] = param;
76 }
77