xref: /aosp_15_r20/external/deqp/framework/opengl/simplereference/sglrContext.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Simplified GLES reference context.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "sglrContext.hpp"
25 #include "sglrGLContext.hpp"
26 #include "gluTextureUtil.hpp"
27 
28 #include "glwEnums.hpp"
29 
30 namespace sglr
31 {
32 
33 using std::vector;
34 
texImage2D(uint32_t target,int level,uint32_t internalFormat,const tcu::Surface & src)35 void Context::texImage2D(uint32_t target, int level, uint32_t internalFormat, const tcu::Surface &src)
36 {
37     int width  = src.getWidth();
38     int height = src.getHeight();
39     texImage2D(target, level, internalFormat, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
40                src.getAccess().getDataPtr());
41 }
42 
texImage2D(uint32_t target,int level,uint32_t internalFormat,int width,int height)43 void Context::texImage2D(uint32_t target, int level, uint32_t internalFormat, int width, int height)
44 {
45     uint32_t format   = GL_NONE;
46     uint32_t dataType = GL_NONE;
47 
48     switch (internalFormat)
49     {
50     case GL_ALPHA:
51     case GL_LUMINANCE:
52     case GL_LUMINANCE_ALPHA:
53     case GL_RGB:
54     case GL_RGBA:
55         format   = internalFormat;
56         dataType = GL_UNSIGNED_BYTE;
57         break;
58 
59     default:
60     {
61         glu::TransferFormat transferFmt = glu::getTransferFormat(glu::mapGLInternalFormat(internalFormat));
62         format                          = transferFmt.format;
63         dataType                        = transferFmt.dataType;
64         break;
65     }
66     }
67 
68     texImage2D(target, level, internalFormat, width, height, 0, format, dataType, DE_NULL);
69 }
70 
texSubImage2D(uint32_t target,int level,int xoffset,int yoffset,const tcu::Surface & src)71 void Context::texSubImage2D(uint32_t target, int level, int xoffset, int yoffset, const tcu::Surface &src)
72 {
73     int width  = src.getWidth();
74     int height = src.getHeight();
75     texSubImage2D(target, level, xoffset, yoffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE,
76                   src.getAccess().getDataPtr());
77 }
78 
readPixels(tcu::Surface & dst,int x,int y,int width,int height)79 void Context::readPixels(tcu::Surface &dst, int x, int y, int width, int height)
80 {
81     dst.setSize(width, height);
82     readPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, dst.getAccess().getDataPtr());
83 }
84 
85 } // namespace sglr
86