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